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
This commit is contained in:
parent
a34fbbadf5
commit
e6a49e03b9
77
ietf/dbtemplate/fixtures/initial_data.xml
Normal file
77
ietf/dbtemplate/fixtures/initial_data.xml
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<django-objects version="1.0">
|
||||
<object pk="1" model="dbtemplate.dbtemplate">
|
||||
<field type="CharField" name="path">/nomcom/defaults/home.rst</field>
|
||||
<field type="CharField" name="title">Home page of group</field>
|
||||
<field type="TextField" name="variables"></field>
|
||||
<field to="name.dbtemplatetypename" name="type" rel="ManyToOneRel">rst</field>
|
||||
<field type="TextField" name="content">Home page
|
||||
=========
|
||||
|
||||
This is the home page of the nomcom group.</field>
|
||||
<field to="group.group" name="group" rel="ManyToOneRel"><None></None></field>
|
||||
</object>
|
||||
<object pk="2" model="dbtemplate.dbtemplate">
|
||||
<field type="CharField" name="path">/nomcom/defaults/email/inexistent_person.txt</field>
|
||||
<field type="CharField" name="title">Email sent to chair of nomcom and secretariat when Email and Person are created if some of them don't exist</field>
|
||||
<field type="TextField" name="variables">$email: Newly created email
|
||||
$fullname: Fullname of the new person
|
||||
$person_id: Id of the new Person object
|
||||
$group: Name of the group</field>
|
||||
<field to="name.dbtemplatetypename" name="type" rel="ManyToOneRel">plain</field>
|
||||
<field type="TextField" name="content">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.</field>
|
||||
<field to="group.group" name="group" rel="ManyToOneRel"><None></None></field>
|
||||
</object>
|
||||
<object pk="3" model="dbtemplate.dbtemplate">
|
||||
<field type="CharField" name="path">/nomcom/defaults/email/new_nominee.txt</field>
|
||||
<field type="CharField" name="title">Email sent to nominees when they are nominated</field>
|
||||
<field type="TextField" name="variables">$nominee: Full name of the nominee
|
||||
$position: Name of the position</field>
|
||||
<field to="name.dbtemplatetypename" name="type" rel="ManyToOneRel">plain</field>
|
||||
<field type="TextField" name="content">Hello $nominee.
|
||||
|
||||
You have been nominated for $position.</field>
|
||||
<field to="group.group" name="group" rel="ManyToOneRel"><None></None></field>
|
||||
</object>
|
||||
<object pk="4" model="dbtemplate.dbtemplate">
|
||||
<field type="CharField" name="path">/nomcom/defaults/email/new_nomination.txt</field>
|
||||
<field type="CharField" name="title">Email sent to nominators and secretariat when the nominators make the nominations</field>
|
||||
<field type="TextField" name="variables">$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</field>
|
||||
<field to="name.dbtemplatetypename" name="type" rel="ManyToOneRel">plain</field>
|
||||
<field type="TextField" name="content">A new nomination have been received.
|
||||
|
||||
Nominator: $nominator <$email>
|
||||
Nominee: $nominee <$email>
|
||||
Position: $position</field>
|
||||
<field to="group.group" name="group" rel="ManyToOneRel"><None></None></field>
|
||||
</object>
|
||||
<object pk="5" model="dbtemplate.dbtemplate">
|
||||
<field type="CharField" name="path">/nomcom/defaults/position/questionnaire.txt</field>
|
||||
<field type="CharField" name="title">Questionnaire sent to the nomine</field>
|
||||
<field type="TextField" name="variables">$nominee: Full name of the nomine
|
||||
$position: Position</field>
|
||||
<field to="name.dbtemplatetypename" name="type" rel="ManyToOneRel">plain</field>
|
||||
<field type="TextField" name="content">Hi $nominee, please fill this questionnaire for the position $position:
|
||||
|
||||
Questionnaire</field>
|
||||
<field to="group.group" name="group" rel="ManyToOneRel"><None></None></field>
|
||||
</object>
|
||||
<object pk="6" model="dbtemplate.dbtemplate">
|
||||
<field type="CharField" name="path">/nomcom/defaults/position/requirements.txt</field>
|
||||
<field type="CharField" name="title">Position requirements</field>
|
||||
<field type="TextField" name="variables">$position: Position</field>
|
||||
<field to="name.dbtemplatetypename" name="type" rel="ManyToOneRel">plain</field>
|
||||
<field type="TextField" name="content">These are the requirements for the position $position:
|
||||
|
||||
Requirements.</field>
|
||||
<field to="group.group" name="group" rel="ManyToOneRel"><None></None></field>
|
||||
</object>
|
||||
</django-objects>
|
|
@ -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'},
|
||||
|
|
|
@ -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')
|
||||
|
|
43
ietf/nomcom/utils.py
Normal file
43
ietf/nomcom/utils.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue