Skip to content

Commit bd335e3

Browse files
committed
now nominee has a nomcom field, it's necessary to separate nominees for distinct nomcom when two nomcom are active
when a nomcom is deleted, templates and files of nomcom are deleted too change publick key file path in settings See ietf-tools#976 - Legacy-Id: 5580
1 parent 3a03cb0 commit bd335e3

File tree

7 files changed

+33
-6
lines changed

7 files changed

+33
-6
lines changed

ietf/nomcom/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def save(self, commit=True):
345345
email.save()
346346

347347
# Add the nomination for a particular position
348-
nominee, created = Nominee.objects.get_or_create(email=email)
348+
nominee, created = Nominee.objects.get_or_create(email=email, nomcom=self.nomcom)
349349
nominee_position, nominee_position_created = NomineePosition.objects.get_or_create(position=position, nominee=nominee)
350350

351351
# Complete nomination data

ietf/nomcom/managers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_query_set(self):
3838

3939
class NomineeManager(models.Manager):
4040
def get_by_nomcom(self, nomcom):
41-
return self.filter(nominee_position__nomcom=nomcom)
41+
return self.filter(nomcom=nomcom)
4242

4343

4444
class PositionQuerySet(QuerySet):

ietf/nomcom/migrations/0001_initial.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ def forwards(self, orm):
3737
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
3838
('email', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['person.Email'])),
3939
('duplicated', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['nomcom.Nominee'], null=True, blank=True)),
40+
('nomcom', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['nomcom.NomCom'])),
4041
))
4142
db.send_create_signal('nomcom', ['Nominee'])
4243

44+
# Adding unique constraint on 'Nominee', fields ['email', 'nomcom']
45+
db.create_unique('nomcom_nominee', ['email_id', 'nomcom_id'])
46+
4347
# Adding model 'NomineePosition'
4448
db.create_table('nomcom_nomineeposition', (
4549
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
@@ -94,6 +98,9 @@ def backwards(self, orm):
9498
# Removing unique constraint on 'NomineePosition', fields ['position', 'nominee']
9599
db.delete_unique('nomcom_nomineeposition', ['position_id', 'nominee_id'])
96100

101+
# Removing unique constraint on 'Nominee', fields ['email', 'nomcom']
102+
db.delete_unique('nomcom_nominee', ['email_id', 'nomcom_id'])
103+
97104
# Deleting model 'NomCom'
98105
db.delete_table('nomcom_nomcom')
99106

@@ -364,10 +371,11 @@ def backwards(self, orm):
364371
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
365372
},
366373
'nomcom.nominee': {
367-
'Meta': {'object_name': 'Nominee'},
374+
'Meta': {'unique_together': "(('email', 'nomcom'),)", 'object_name': 'Nominee'},
368375
'duplicated': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['nomcom.Nominee']", 'null': 'True', 'blank': 'True'}),
369376
'email': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['person.Email']"}),
370377
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
378+
'nomcom': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['nomcom.NomCom']"}),
371379
'nominee_position': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['nomcom.Position']", 'through': "orm['nomcom.NomineePosition']", 'symmetrical': 'False'})
372380
},
373381
'nomcom.nomineeposition': {

ietf/nomcom/models.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# -*- coding: utf-8 -*-
12
import os
23

34
from django.db import models
5+
from django.db.models.signals import post_delete
46
from django.conf import settings
57
from django.core.files.storage import FileSystemStorage
68
from django.contrib.auth.models import User
@@ -17,7 +19,8 @@
1719
PositionManager, FeedbackManager
1820
from ietf.nomcom.utils import (initialize_templates_for_group,
1921
initialize_questionnaire_for_position,
20-
initialize_requirements_for_position)
22+
initialize_requirements_for_position,
23+
delete_nomcom_templates)
2124

2225

2326
def upload_path_handler(instance, filename):
@@ -46,6 +49,14 @@ def save(self, *args, **kwargs):
4649
initialize_templates_for_group(self)
4750

4851

52+
def delete_nomcom(sender, **kwargs):
53+
nomcom = kwargs.get('instance', None)
54+
delete_nomcom_templates(nomcom)
55+
storage, path = nomcom.public_key.storage, nomcom.public_key.path
56+
storage.delete(path)
57+
post_delete.connect(delete_nomcom, sender=NomCom)
58+
59+
4960
class Nomination(models.Model):
5061
position = models.ForeignKey('Position')
5162
candidate_name = models.CharField(verbose_name='Candidate name', max_length=255)
@@ -69,11 +80,13 @@ class Nominee(models.Model):
6980
email = models.ForeignKey(Email)
7081
nominee_position = models.ManyToManyField('Position', through='NomineePosition')
7182
duplicated = models.ForeignKey('Nominee', blank=True, null=True)
83+
nomcom = models.ForeignKey('NomCom')
7284

7385
objects = NomineeManager()
7486

7587
class Meta:
7688
verbose_name_plural = 'Nominees'
89+
unique_together = ('email', 'nomcom')
7790

7891
def __unicode__(self):
7992
return u'%s' % self.email

ietf/nomcom/test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def nomcom_test_data():
150150
email=email)
151151
# nominee
152152
email = Email.objects.get(person__name=COMMUNITY_USER)
153-
nominee, created = Nominee.objects.get_or_create(email=email)
153+
nominee, created = Nominee.objects.get_or_create(email=email, nomcom=nomcom)
154154

155155
# positions
156156
for name, description in POSITIONS.iteritems():

ietf/nomcom/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ def initialize_requirements_for_position(position):
112112
content=template.content)
113113

114114

115+
def delete_nomcom_templates(nomcom):
116+
nomcom_template_path = '/nomcom/' + nomcom.group.acronym
117+
DBTemplate.objects.filter(path__contains=nomcom_template_path).delete()
118+
119+
115120
def retrieve_nomcom_private_key(request, year):
116121
private_key = request.session.get('NOMCOM_PRIVATE_KEY_%s' % year, None)
117122

ietf/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,11 @@
261261

262262
# NomCom Tool settings
263263
ROLODEX_URL = ""
264-
PUBLIC_KEYS_URL = BASE_DIR + '/public_keys/'
264+
PUBLIC_KEYS_URL = BASE_DIR + '/nomcom/public_keys/'
265265
NOMCOM_FROM_EMAIL = DEFAULT_FROM_EMAIL
266266
NOMCOM_ADMIN_EMAIL = DEFAULT_FROM_EMAIL
267267
OPENSSL_COMMAND = '/usr/bin/openssl'
268+
DAYS_TO_EXPIRE_NOMINATION_LINK = ''
268269

269270
# Days from meeting to cut off dates on submit
270271
FIRST_CUTOFF_DAYS = 19

0 commit comments

Comments
 (0)