def form_valid(self, form): u = self.request.user data = form.cleaned_data form_name = get_user_next_form(u) logger.info("User %s filled %s" % (u, form_name)) Answer.objects.create(user=u, q13e_slug=form_name, data=data) # Save personal information if form_name == FORM_NAMES[0]: dirty = False if not u.first_name: u.first_name = data['hebrew_first_name'] dirty = True if not u.last_name: u.last_name = data['hebrew_last_name'] dirty = True if dirty: u.save() message = "\n".join(u"{label}: {html}".format(**fld) for fld in get_pretty_answer(form, data)['fields']) mail_managers(u"{}: {hebrew_last_name} {hebrew_first_name}".format( _("New User"), **data), message) if get_user_next_form(u) is None: messages.success(self.request, _("Registration completed! Thank you very much!")) mail_managers(_("User registered: %s") % u, ":-)") return redirect('dashboard') messages.success(self.request, _("'%s' was saved.") % form.form_title) return redirect('register')
def get_pretty(self): # TODO: refactor from q13es.forms import get_pretty_answer dct = get_pretty_answer(self.survey.get_form_class(), self.data) dct["answer"] = self return dct
def form_valid(self, form): u = self.request.user data = form.cleaned_data form_name = get_user_next_form(u) logger.info("User %s filled %s" % (u, form_name)) a = Answer.objects.create(user=u, q13e_slug=form_name, data=data) # Save personal information if form_name == FORM_NAMES[0]: if not u.first_name: u.first_name = data['hebrew_first_name'] if not u.last_name: u.last_name = data['hebrew_last_name'] update_personal_details(u, data) u.save() # keep it on the safe side message = "\n".join(u"{label}: {html}".format(**fld) for fld in get_pretty_answer(form, data)['fields']) mail_managers(u"{}: {hebrew_last_name} {hebrew_first_name}".format( _("New User"), **data), message) elif form_name == 'cohort1': COHORTS = ( ('group_monday_morning', 1), ('group_thursday_morning', 2), ('group_evenings', 3), ) cohorts = {x[1]: Cohort.objects.get(ordinal=x[1]) for x in COHORTS} for k, ordinal in COHORTS: v = data[k] == u"כן" UserCohort.objects.create(user=u, cohort=cohorts[ordinal], status=UserCohortStatus.AVAILABLE if v else UserCohortStatus.UNAVAILABLE) # update denormalized index fields u.forms_filled = u.answers.count() u.last_form_filled = a.created_at u.save() if get_user_next_form(u) is None: messages.success(self.request, _("Registration completed! Thank you very much!")) url = self.request.build_absolute_uri(reverse('user_dashboard', args=(u.id,))) mail_managers(_("User registered: %s") % u.email, url) return redirect('dashboard') messages.success(self.request, _("'%s' was saved.") % form.form_title) return redirect('register')
def form_valid(self, form): u = self.request.user data = form.cleaned_data o = self.get_object() o.data = data o.answered_at = timezone.now() o.save() message = "\n\n".join(u"{label}:\n {html}".format(**fld) for fld in get_pretty_answer(form, data)['fields']) url = self.request.build_absolute_uri(o.survey.get_absolute_url()) message += "\n%s" % url mail_managers(u"{}: {}".format(form.form_title, u), message) messages.success(self.request, _("Thank you!")) return redirect('register')
def form_valid(self, form): data = form.cleaned_data o = self.get_object() o.data = data o.answered_at = timezone.now() o.save() user_url = self.request.build_absolute_uri(o.user.get_absolute_url()) message = "{} <{}>\n{}\n\n".format(o.user, o.user.email, user_url) message += "\n\n".join(u"{label}:\n {html}".format(**fld) for fld in get_pretty_answer(form, data)['fields']) url = self.request.build_absolute_uri(o.survey.get_absolute_url()) message += "\n\n%s" % url mail_managers("{}: {}".format(o.survey.email_subject, o.user), message) messages.success(self.request, _("Thank you!")) return redirect('sa:dashboard')
def get_pretty(self): dct = get_pretty_answer(self.survey.get_form_class(), self.data) dct['answer'] = self return dct
def get_pretty(self, form): # TODO: refactor from q13es.forms import get_pretty_answer dct = get_pretty_answer(form, self.data) dct['answer'] = self return dct
def get_pretty(self): form = consts.FORMS[self.q13e_slug] return dict(get_pretty_answer(form, self.data), answer=self)
def get_pretty(self, form): dct = get_pretty_answer(form, self.data) dct['answer'] = self return dct