Skip to content

Commit

Permalink
When using Firefox 16 some fields from JSON are missing in report mod…
Browse files Browse the repository at this point in the history
…el and `create` fails. See #24

Added check so that only existing fields in the model are passed to
`create` to prevent any future similar errors.
  • Loading branch information
mitar authored and James Socol committed Oct 31, 2012
1 parent 1be6df9 commit 2a29f95
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions csp/models.py
Expand Up @@ -53,6 +53,9 @@ class Report(models.Model):
violated_directive = models.CharField(max_length=1000, null=True, violated_directive = models.CharField(max_length=1000, null=True,
blank=True, db_index=True) blank=True, db_index=True)
original_policy = models.TextField(null=True, blank=True) original_policy = models.TextField(null=True, blank=True)
source_file = models.CharField(max_length=400, null=True, blank=True)
line_number = models.IntegerField(null=True, blank=True)
script_sample = models.TextField(null=True, blank=True)
reported = models.DateTimeField(default=datetime.now, db_index=True) reported = models.DateTimeField(default=datetime.now, db_index=True)


@classmethod @classmethod
Expand All @@ -63,6 +66,11 @@ def create(cls, report):
except ValueError: except ValueError:
raise BadReportError() raise BadReportError()
kw = dict((k.replace('-', '_'), v) for k, v in report.items()) kw = dict((k.replace('-', '_'), v) for k, v in report.items())
fields = cls._meta.get_all_field_names()
for key in kw.keys():
if key not in fields:
del kw[key]
print kw
return cls(**kw) return cls(**kw)


def __unicode__(self): def __unicode__(self):
Expand Down

0 comments on commit 2a29f95

Please sign in to comment.