Skip to content
Extraits de code Groupes Projets
Valider f4c27a69 rédigé par Arnaud Fabre's avatar Arnaud Fabre
Parcourir les fichiers

adds hashable field to group and constituency, get_or_create for group is case...

adds hashable field to group and constituency, get_or_create for group is case insensitive, with fingerprint it will be bulletproof
parent 0e9c73c6
Branches
Étiquettes
Aucune requête de fusion associée trouvée
......@@ -38,6 +38,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('fingerprint', models.CharField(unique=True, max_length=40)),
('name', models.CharField(max_length=255)),
],
options={
......@@ -63,6 +64,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('fingerprint', models.CharField(unique=True, max_length=40)),
('name', models.CharField(max_length=255)),
('abbreviation', models.CharField(default=b'', max_length=10, blank=True)),
('kind', models.CharField(default=b'', max_length=255, blank=True)),
......
......@@ -168,7 +168,7 @@ class Phone(Contact):
address = models.ForeignKey(Address, null=True, related_name='phones')
class Group(TimeStampedModel):
class Group(HashableModel, TimeStampedModel):
"""
An entity represented by a representative through a mandate
"""
......@@ -176,14 +176,8 @@ class Group(TimeStampedModel):
abbreviation = models.CharField(max_length=10, blank=True, default='')
kind = models.CharField(max_length=255, blank=True, default='')
@cached_property
def fingerprint(self):
fingerprint = hashlib.sha1()
fingerprint.update(smart_str(self.name))
fingerprint.update(smart_str(self.abbreviation))
fingerprint.update(smart_str(self.kind))
return fingerprint.hexdigest()
hashable_fields = ['name', 'abbreviation', 'kind']
@cached_property
def active(self):
return self.mandates.filter(end_date__gte=datetime.now()).exists()
......@@ -192,17 +186,13 @@ class Group(TimeStampedModel):
return unicode(self.name)
class Constituency(TimeStampedModel):
class Constituency(HashableModel, TimeStampedModel):
"""
An authority for which a representative has a mandate
"""
name = models.CharField(max_length=255)
@cached_property
def fingerprint(self):
fingerprint = hashlib.sha1()
fingerprint.update(smart_str(self.name))
return fingerprint.hexdigest()
hashable_fields = ['name']
@cached_property
def active(self):
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter