fix multiple breakage in Thing.__getitem__

2019-08-17
Marnanel Thurman 2019-07-09 10:24:11 +01:00
rodzic 3ab67f5d33
commit 21a872ddf4
2 zmienionych plików z 6 dodań i 7 usunięć

Wyświetl plik

@ -23,8 +23,7 @@ FIELD_CHOICES = [
(FIELD_BCC, 'bcc'), (FIELD_BCC, 'bcc'),
] ]
FIELD_NAMES = dict([(v,f) for (f,v) in FIELD_CHOICES]) AUDIENCE_FIELD_NAMES = dict([(v,f) for (f,v) in FIELD_CHOICES])
AUDIENCE_FIELD_NAMES = FIELD_NAMES.keys()
class Audience(models.Model): class Audience(models.Model):
@ -69,14 +68,14 @@ class Audience(models.Model):
where it's needed. where it's needed.
""" """
if field not in FIELD_NAMES: if field not in AUDIENCE_FIELD_NAMES:
raise ValueError('%s is not an audience field' % ( raise ValueError('%s is not an audience field' % (
field, field,
)) ))
logger.debug('Adding Audiences for %s: %s=%s', logger.debug('Adding Audiences for %s: %s=%s',
thing.number, field, value) thing.number, field, value)
field = FIELD_NAMES[field] field = AUDIENCE_FIELD_NAMES[field]
if value is None: if value is None:
value = [] value = []

Wyświetl plik

@ -211,11 +211,11 @@ class Thing(PolymorphicModel):
elif name in AUDIENCE_FIELD_NAMES: elif name in AUDIENCE_FIELD_NAMES:
try: try:
result = Audience.objects.find( result = Audience.objects.filter(
parent = self, parent = self,
field = name, field = AUDIENCE_FIELD_NAMES[name],
) )
except Audience.ObjectDoesNotExist: except Audience.DoesNotExist:
result = None result = None
else: else:
others = json.loads(self.other_fields) others = json.loads(self.other_fields)