Add form to change email of nominees.

Refactor merge form to avoid merge old duplicate nominees.
See #1013
 - Legacy-Id: 5747
This commit is contained in:
Emilio Jiménez 2013-05-20 18:17:31 +00:00
parent ee1eec7de8
commit f998e0d29f
5 changed files with 107 additions and 6 deletions

View file

@ -313,7 +313,7 @@ class MergeForm(BaseNomcomForm, forms.Form):
def clean_primary_email(self):
email = self.cleaned_data['primary_email']
nominees = Nominee.objects.get_by_nomcom(self.nomcom).filter(email__address=email)
nominees = Nominee.objects.get_by_nomcom(self.nomcom).not_duplicated().filter(email__address=email)
if not nominees:
msg = "Does not exist a nomiee with this email"
self._errors["primary_email"] = self.error_class([msg])
@ -807,8 +807,7 @@ class MutableFeedbackForm(forms.ModelForm):
nominee=nominee,
comments=feedback,
nominator_email=nominator_email,
user=self.user,
)
user=self.user)
return feedback
else:
feedback.save()
@ -827,3 +826,45 @@ class FullFeedbackFormSet(forms.models.BaseModelFormSet):
form = MutableFeedbackForm
can_order = False
can_delete = False
class EditNomineeForm(forms.ModelForm):
nominee_email = forms.EmailField(label="Nominee email",
widget=forms.TextInput(attrs={'size': '40'}))
def __init__(self, *args, **kwargs):
super(EditNomineeForm, self).__init__(*args, **kwargs)
self.fields['nominee_email'].initial = self.instance.email.address
def save(self, commit=True):
nominee = super(EditNomineeForm, self).save(commit=False)
nominee_email = self.cleaned_data.get("nominee_email")
if nominee_email != nominee.email.address:
# create a new nominee with the new email
new_email, created_email = Email.objects.get_or_create(address=nominee_email)
new_email.person = nominee.email.person
new_email.save()
# Chage emails between nominees
old_email = nominee.email
nominee.email = new_email
nominee.save()
new_nominee = Nominee.objects.create(email=old_email, nomcom=nominee.nomcom)
# new nominees point to old nominee
new_nominee.duplicated = nominee
new_nominee.save()
return nominee
class Meta:
model = Nominee
fields = ('nominee_email',)
def clean_nominee_email(self):
nominee_email = self.cleaned_data['nominee_email']
nominees = Nominee.objects.exclude(email__address=self.instance.email.address).filter(email__address=nominee_email)
if nominees:
raise forms.ValidationError('This emails already does exists in another nominee, please go to merge form')
return nominee_email

View file

@ -13,6 +13,7 @@ urlpatterns = patterns('ietf.nomcom.views',
url(r'^(?P<year>\d{4})/private/view-feedback/unrelated/$', 'view_feedback_unrelated', name='nomcom_view_feedback_unrelated'),
url(r'^(?P<year>\d{4})/private/view-feedback/pending/$', 'view_feedback_pending', name='nomcom_view_feedback_pending'),
url(r'^(?P<year>\d{4})/private/view-feedback/nominee/(?P<nominee_id>\d+)$', 'view_feedback_nominee', name='nomcom_view_feedback_nominee'),
url(r'^(?P<year>\d{4})/private/edit/nominee/(?P<nominee_id>\d+)$', 'edit_nominee', name='nomcom_edit_nominee'),
url(r'^(?P<year>\d{4})/private/merge/$', 'private_merge', name='nomcom_private_merge'),
url(r'^(?P<year>\d{4})/private/send-reminder-mail/$', 'send_reminder_mail', name='nomcom_send_reminder_mail'),
url(r'^(?P<year>\d{4})/private/edit-members/$', EditMembersFormPreview(EditMembersForm), name='nomcom_edit_members'),

View file

@ -23,8 +23,8 @@ from ietf.name.models import NomineePositionState, FeedbackType
from ietf.nomcom.decorators import nomcom_member_required, nomcom_private_key_required
from ietf.nomcom.forms import (NominateForm, FeedbackForm, QuestionnaireForm,
MergeForm, NomComTemplateForm, PositionForm,
PrivateKeyForm, EditNomcomForm, PendingFeedbackForm,
ReminderDatesForm, FullFeedbackFormSet)
PrivateKeyForm, EditNomcomForm, EditNomineeForm,
PendingFeedbackForm, ReminderDatesForm, FullFeedbackFormSet)
from ietf.nomcom.models import Position, NomineePosition, Nominee, Feedback, NomCom, ReminderDates
from ietf.nomcom.utils import (get_nomcom_by_year, store_nomcom_private_key,
get_hash_nominee_position, send_reminder_to_nominees,
@ -512,6 +512,30 @@ def view_feedback_nominee(request, year, nominee_id):
'nomcom': nomcom}, RequestContext(request))
@nomcom_member_required(role='chair')
def edit_nominee(request, year, nominee_id):
nomcom = get_nomcom_by_year(year)
nominee = get_object_or_404(Nominee, id=nominee_id)
message = None
if request.method == 'POST':
form = EditNomineeForm(request.POST,
instance=nominee)
if form.is_valid():
form.save()
message = ('success', 'The nominee has been changed')
else:
form = EditNomineeForm(instance=nominee)
return render_to_response('nomcom/edit_nominee.html',
{'year': year,
'selected': 'index',
'nominee': nominee,
'form': form,
'message': message,
'nomcom': nomcom}, RequestContext(request))
@nomcom_member_required(role='chair')
def edit_nomcom(request, year):
nomcom = get_nomcom_by_year(year)

View file

@ -0,0 +1,35 @@
{% extends "nomcom/nomcom_private_base.html" %}
{% load nomcom_tags %}
{% block pagehead %}
{{ block.super }}
<script type="text/javascript" src="/js/lib/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/js/yui/yui-20100305.js"></script>
<script type="text/javascript" src="/js/base.js"></script>
{% endblock pagehead %}
{% block subtitle %} - Edit nominee {{ nominee }}{% endblock %}
{% block nomcom_content %}
<p>Back to list of <a href="{% url nomcom_private_index year %}">nominees</a></p>
<h2>Edit email of {{ nominee }} </h2>
{% if message %}
<div class="info-message-{{ message.0 }}">{{ message.1 }}</div>
{% endif %}
{% if form.errors %}<div class="info-message-error">Please correct the following errors</div>{% endif %}
<form enctype="multipart/form-data" action="" method="post">{% csrf_token %}
<table>
{{ form }}
</table>
<p><input type="submit" value="Save" /></p>
</form>
{% endblock %}

View file

@ -108,7 +108,7 @@ replied to the nomination notification they have received.){% endif %}</p>
{% if is_chair %}
<td><input class="batch-select" type="checkbox" value="{{ np.id }}" name="selected"/></td>
{% endif %}
<td>{{ np.nominee }}</td>
<td>{{ np.nominee }}{% if is_chair %} <a href="{% url nomcom_edit_nominee year np.nominee.id %}">(edit)</a>{% endif %}</td>
<td>{{ np.position.name }}</td>
<td>{{ np.state }}</td>
<td>{{ np.questionnaires|yesno:"Yes,No,No" }}