views/forms: fix formatting of course name

- try to get the real sponsor from the document
 - group name must be before the sponsor name
 - group name must be formatted as 'Gr' + group number
This commit is contained in:
Benjamin Dauvergne 2013-02-11 11:15:20 +01:00
parent b9767c2e49
commit 5b1a57cdf0
3 changed files with 12 additions and 3 deletions

View File

@ -91,7 +91,7 @@ class CreateCourseForm(forms.Form):
raise forms.ValidationError(u'vous devez sélectionner une UE')
course_id = [ cleaned_data['entity'].code.upper(), settings.POLYNUM_BB_COURSE_YEAR ]
if cleaned_data['td_group']:
course_id.append(cleaned_data['td_group'])
course_id.append('Gr' + cleaned_data['td_group'])
cleaned_data['course_id'] = u'_'.join(course_id)
return cleaned_data

View File

@ -2,6 +2,7 @@
{% load crispy_forms_tags %}
<div id="create-course" class="modal hide fade large">
<form action="{% url 'create_course' %}" method="POST">
<input type="hidden" name="request-id" value="{{ object.id }}"/>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>Création d'un nouveau cours</h3>

View File

@ -28,17 +28,25 @@ def create_course(request):
"success": 0,
"course_year": settings.POLYNUM_BB_COURSE_YEAR
}
try:
document = Request.objects.get(id=request.POST.get('request-id'))
except Request.DoesNotExist:
document = None
if form.is_valid():
conn = django_ws.get_bb_conn()
course_id = form.cleaned_data['course_id']
entity = form.cleaned_data['entity']
diploma = entity.parents().get(
entity_type__name=settings.POLYNUM_BB_DIPLOMA_DESIGNATION)
owner_name = request.user.display_name().title()
if document and '(' in document.sponsor:
owner_name = document.sponsor.split('(')[0]
course_label = diploma.get_name() + '_' + \
settings.POLYNUM_BB_COURSE_YEAR + '_' + \
entity.get_name() + '_' + request.user.display_name().title()
entity.get_name()
if form.cleaned_data.get('td_group'):
course_label += '_' + form.cleaned_data['td_group']
course_label += '_Gr' + form.cleaned_data['td_group']
course_label += '_' + owner_name
ok, result = conn.create_course(course_id,
course_label,
form.cleaned_data['category'],