kopia lustrzana https://gitlab.com/marnanel/chapeau
fix multiple breakage in Thing.__getitem__
rodzic
3ab67f5d33
commit
21a872ddf4
|
@ -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 = []
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Ładowanie…
Reference in New Issue