From e6a49e03b901c522d8e085949465c12f522a479e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20A=2E=20S=C3=A1nchez=20L=C3=B3pez?= Date: Wed, 5 Dec 2012 13:25:02 +0000 Subject: [PATCH] Modified public_key field in the NomCom model to be not required. The chair will set the public_key after the NomCom object creation. Added default templates for nomcom application. Duplicate default templates when creating a new NomCom object or a new Position object. Fixes #906 - Legacy-Id: 5099 --- ietf/dbtemplate/fixtures/initial_data.xml | 77 +++++++++++++++++++++++ ietf/nomcom/migrations/0001_initial.py | 26 +++++--- ietf/nomcom/models.py | 28 ++++++++- ietf/nomcom/utils.py | 43 +++++++++++++ 4 files changed, 162 insertions(+), 12 deletions(-) create mode 100644 ietf/dbtemplate/fixtures/initial_data.xml create mode 100644 ietf/nomcom/utils.py diff --git a/ietf/dbtemplate/fixtures/initial_data.xml b/ietf/dbtemplate/fixtures/initial_data.xml new file mode 100644 index 000000000..83e9ee9a9 --- /dev/null +++ b/ietf/dbtemplate/fixtures/initial_data.xml @@ -0,0 +1,77 @@ + + + + /nomcom/defaults/home.rst + Home page of group + + rst + Home page +========= + +This is the home page of the nomcom group. + + + + /nomcom/defaults/email/inexistent_person.txt + Email sent to chair of nomcom and secretariat when Email and Person are created if some of them don't exist + $email: Newly created email +$fullname: Fullname of the new person +$person_id: Id of the new Person object +$group: Name of the group + plain + Hello, + +A new person with name $fullname and email $email has been created. The new Person object has the following id: '$i'. + +Please, check if there is some more action nedeed. + + + + /nomcom/defaults/email/new_nominee.txt + Email sent to nominees when they are nominated + $nominee: Full name of the nominee +$position: Name of the position + plain + Hello $nominee. + +You have been nominated for $position. + + + + /nomcom/defaults/email/new_nomination.txt + Email sent to nominators and secretariat when the nominators make the nominations + $nominator: Full name of the nominator +$email: Email of the nominator +$nominee: Full name of the nominee +$nominee_email: Email of the nominee +$position: Nomination position + plain + A new nomination have been received. + +Nominator: $nominator <$email> +Nominee: $nominee <$email> +Position: $position + + + + /nomcom/defaults/position/questionnaire.txt + Questionnaire sent to the nomine + $nominee: Full name of the nomine +$position: Position + plain + Hi $nominee, please fill this questionnaire for the position $position: + +Questionnaire + + + + /nomcom/defaults/position/requirements.txt + Position requirements + $position: Position + plain + These are the requirements for the position $position: + +Requirements. + + + \ No newline at end of file diff --git a/ietf/nomcom/migrations/0001_initial.py b/ietf/nomcom/migrations/0001_initial.py index baf2f7895..07308d5d6 100644 --- a/ietf/nomcom/migrations/0001_initial.py +++ b/ietf/nomcom/migrations/0001_initial.py @@ -11,7 +11,7 @@ class Migration(SchemaMigration): # Adding model 'NomCom' db.create_table('nomcom_nomcom', ( ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('public_key', self.gf('django.db.models.fields.files.FileField')(max_length=100)), + ('public_key', self.gf('django.db.models.fields.files.FileField')(max_length=100, null=True, blank=True)), ('group', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['group.Group'])), ('send_questionnaire', self.gf('django.db.models.fields.BooleanField')(default=False)), )) @@ -65,8 +65,8 @@ class Migration(SchemaMigration): ('name', self.gf('django.db.models.fields.CharField')(max_length=255)), ('description', self.gf('django.db.models.fields.TextField')()), ('initial_text', self.gf('django.db.models.fields.TextField')(blank=True)), - ('requirement', self.gf('django.db.models.fields.related.ForeignKey')(related_name='requirement', to=orm['dbtemplate.DBTemplate'])), - ('questionnaire', self.gf('django.db.models.fields.related.ForeignKey')(related_name='questionnaire', to=orm['dbtemplate.DBTemplate'])), + ('requirement', self.gf('django.db.models.fields.related.ForeignKey')(related_name='requirement', null=True, to=orm['dbtemplate.DBTemplate'])), + ('questionnaire', self.gf('django.db.models.fields.related.ForeignKey')(related_name='questionnaire', null=True, to=orm['dbtemplate.DBTemplate'])), ('is_open', self.gf('django.db.models.fields.BooleanField')(default=False)), ('incumbent', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['person.Email'])), )) @@ -151,11 +151,11 @@ class Migration(SchemaMigration): 'Meta': {'object_name': 'DBTemplate'}, 'content': ('django.db.models.fields.TextField', [], {}), 'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['group.Group']", 'null': 'True', 'blank': 'True'}), - 'help_text': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'path': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), - 'template_type': ('django.db.models.fields.CharField', [], {'default': "'rst'", 'max_length': '10'}), - 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) + 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['name.DBTemplateTypeName']"}), + 'variables': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}) }, 'doc.docalias': { 'Meta': {'object_name': 'DocAlias'}, @@ -237,6 +237,14 @@ class Migration(SchemaMigration): 'unused_states': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['doc.State']", 'symmetrical': 'False', 'blank': 'True'}), 'unused_tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['name.DocTagName']", 'symmetrical': 'False', 'blank': 'True'}) }, + 'name.dbtemplatetypename': { + 'Meta': {'ordering': "['order']", 'object_name': 'DBTemplateTypeName'}, + 'desc': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'slug': ('django.db.models.fields.CharField', [], {'max_length': '8', 'primary_key': 'True'}), + 'used': ('django.db.models.fields.BooleanField', [], {'default': 'True'}) + }, 'name.docrelationshipname': { 'Meta': {'ordering': "['order']", 'object_name': 'DocRelationshipName'}, 'desc': ('django.db.models.fields.TextField', [], {'blank': 'True'}), @@ -331,7 +339,7 @@ class Migration(SchemaMigration): 'Meta': {'object_name': 'NomCom'}, 'group': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['group.Group']"}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'public_key': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}), + 'public_key': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), 'send_questionnaire': ('django.db.models.fields.BooleanField', [], {'default': 'False'}) }, 'nomcom.nomination': { @@ -369,8 +377,8 @@ class Migration(SchemaMigration): 'is_open': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), 'nomcom': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['nomcom.NomCom']"}), - 'questionnaire': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'questionnaire'", 'to': "orm['dbtemplate.DBTemplate']"}), - 'requirement': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'requirement'", 'to': "orm['dbtemplate.DBTemplate']"}) + 'questionnaire': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'questionnaire'", 'null': 'True', 'to': "orm['dbtemplate.DBTemplate']"}), + 'requirement': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'requirement'", 'null': 'True', 'to': "orm['dbtemplate.DBTemplate']"}) }, 'person.email': { 'Meta': {'object_name': 'Email'}, diff --git a/ietf/nomcom/models.py b/ietf/nomcom/models.py index 658a41e3a..f34fca12d 100644 --- a/ietf/nomcom/models.py +++ b/ietf/nomcom/models.py @@ -12,6 +12,10 @@ from ietf.group.models import Group from ietf.name.models import NomineePositionState, FeedbackType from ietf.dbtemplate.models import DBTemplate +from ietf.nomcom.utils import (initialize_templates_for_group, + initialize_questionnaire_for_position, + initialize_requirements_for_position) + def upload_path_handler(instance, filename): return os.path.join(instance.group.acronym, filename) @@ -19,7 +23,7 @@ def upload_path_handler(instance, filename): class NomCom(models.Model): public_key = models.FileField(storage=FileSystemStorage(location=settings.PUBLIC_KEYS_URL), - upload_to=upload_path_handler) + upload_to=upload_path_handler, blank=True, null=True) group = models.ForeignKey(Group) send_questionnaire = models.BooleanField(verbose_name='Send automatically questionnaires"', @@ -32,6 +36,11 @@ class NomCom(models.Model): def __unicode__(self): return self.group.acronym + def save(self, *args, **kwargs): + created = not self.id + super(NomCom, self).save(*args, **kwargs) + if created: + initialize_templates_for_group(self) class Nomination(models.Model): position = models.ForeignKey('Position') @@ -86,8 +95,8 @@ class Position(models.Model): description = models.TextField(verbose_name='Despcription') initial_text = models.TextField(verbose_name='Initial text for nominations', blank=True) - requirement = models.ForeignKey(DBTemplate, related_name='requirement') - questionnaire = models.ForeignKey(DBTemplate, related_name='questionnaire') + requirement = models.ForeignKey(DBTemplate, related_name='requirement', null=True) + questionnaire = models.ForeignKey(DBTemplate, related_name='questionnaire', null=True) is_open = models.BooleanField(verbose_name='Is open') incumbent = models.ForeignKey(Email) @@ -97,6 +106,19 @@ class Position(models.Model): def __unicode__(self): return u"%s: %s" % (self.nomcom, self.name) + def save(self, *args, **kwargs): + created = not self.id + super(Position, self).save(*args, **kwargs) + changed = False + if created and self.id and not self.requirement_id: + self.requirement = initialize_requirements_for_position(self) + changed = True + if created and self.id and not self.questionnaire_id: + self.questionnaire = initialize_questionnaire_for_position(self) + changed = True + if changed: + self.save() + class Feedback(models.Model): author = models.EmailField(verbose_name='Author') diff --git a/ietf/nomcom/utils.py b/ietf/nomcom/utils.py new file mode 100644 index 000000000..2e6640923 --- /dev/null +++ b/ietf/nomcom/utils.py @@ -0,0 +1,43 @@ +from ietf.dbtemplate.models import DBTemplate + +MAIN_NOMCOM_TEMPLATE_PATH = '/nomcom/defaults/' +DEFAULT_NOMCOM_TEMPLATES = 'home.rst', 'email/inexistent_person.txt', 'email/new_nomination.txt', 'email/new_nominee.txt' +DEFAULT_QUESTIONNAIRE_TEMPLATE = 'position/questionnaire.txt' +DEFAULT_REQUIREMENTS_TEMPLATE = 'position/requirements.txt' + + +def initialize_templates_for_group(group): + for template_name in DEFAULT_NOMCOM_TEMPLATES: + template_path = MAIN_NOMCOM_TEMPLATE_PATH + template_name + template = DBTemplate.objects.get(path=template_path) + DBTemplate.objects.create( + group=group.group, + title=template.title, + path='/nomcom/' + group.group.acronym + '/' + template_name, + variables=template.variables, + type_id=template.type_id, + content=template.content) + + +def initialize_questionnaire_for_position(position): + questionnaire_path = MAIN_NOMCOM_TEMPLATE_PATH + DEFAULT_QUESTIONNAIRE_TEMPLATE + template = DBTemplate.objects.get(path=questionnaire_path) + return DBTemplate.objects.create( + group=position.nomcom.group, + title=template.title + '[%s]' % position.name, + path='/nomcom/' + position.nomcom.group.acronym + '/' + str(position.id) + '/' + DEFAULT_QUESTIONNAIRE_TEMPLATE, + variables=template.variables, + type_id=template.type_id, + content=template.content) + + +def initialize_requirements_for_position(position): + requirements_path = MAIN_NOMCOM_TEMPLATE_PATH + DEFAULT_REQUIREMENTS_TEMPLATE + template = DBTemplate.objects.get(path=requirements_path) + return DBTemplate.objects.create( + group=position.nomcom.group, + title=template.title + '[%s]' % position.name, + path='/nomcom/' + position.nomcom.group.acronym + '/' + str(position.id) + '/' + DEFAULT_REQUIREMENTS_TEMPLATE, + variables=template.variables, + type_id=template.type_id, + content=template.content)