From: Jan Szejko Date: Tue, 16 Jan 2018 10:12:43 +0000 (+0100) Subject: link field type X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/6b3b8a3c3de4896fc99256fe0768797c9ec956d3?hp=de60a37ddc37314cd50e9b378968e6f9c96db26b link field type --- diff --git a/stage2/forms.py b/stage2/forms.py index b956a23..ee25a03 100644 --- a/stage2/forms.py +++ b/stage2/forms.py @@ -80,8 +80,8 @@ class AssignmentFieldForm(forms.Form): option.save() else: for opt in self.answer.fieldoption_set.all(): - opt.answer = None - opt.save() + opt.answer = None + opt.save() else: self.answer.field_values[self.label] = value self.answer.save() diff --git a/stage2/models.py b/stage2/models.py index fb50152..a5815fd 100644 --- a/stage2/models.py +++ b/stage2/models.py @@ -8,6 +8,7 @@ from django.core.urlresolvers import reverse from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver +from django.utils.html import format_html from django.utils.translation import ugettext_lazy as _ from django.utils import timezone from jsonfield import JSONField @@ -110,11 +111,14 @@ class Answer(models.Model): def fields(self): for field_desc in self.assignment.field_descriptions: field_name, params = field_desc - if params['type'] == 'text': - yield (field_name, self.field_values.get(field_name, '')) - else: # options + if params['type'] == 'options': option = self.fieldoption_set.filter(set__name=params['option_set']) - yield (field_name, option.get().value if option else '--------') + value = option.get().value if option else '--------' + else: # text, link + value = self.field_values.get(field_name, '') + if params['type'] == 'link': + value = format_html(u'{url}', url=value) + yield (field_name, value) def update_complete(self): marks = self.mark_set.all()