def test_should_not_give_error_if_after_deadline_is_not_checked(self): data = { 'should_send_reminders_after_deadline': False, 'number_of_days_after_deadline': '1', 'reminder_text_after_deadline': '1 day left' } form = ReminderForm(data) self.assertTrue(form.is_valid()) cleaned_data_value = { 'deadline_week': u'', 'deadline_type_week': u'', 'deadline_month': u'', 'deadline_type_month': u'', 'deadline_type': u'', 'frequency_period': u'', 'should_send_reminders_before_deadline': False, 'number_of_days_before_deadline': None, 'reminder_text_before_deadline': u'', 'should_send_reminders_on_deadline': False, 'reminder_text_on_deadline': u'', 'should_send_reminders_after_deadline': False, 'number_of_days_after_deadline': Decimal('1'), 'reminder_text_after_deadline': u'1 day left', 'whom_to_send_message': False } self.assertEqual(cleaned_data_value, form.cleaned_data)
def test_should_give_error_if_on_deadline_field_is_blank(self): data = { 'should_send_reminders_on_deadline': True, 'reminder_text_on_deadline': '' } form = ReminderForm(data) self.assertFalse(form.is_valid()) error_message = { 'reminder_text_on_deadline': [u'This field is required'] } self.assertEqual(error_message, form.errors)
def reminder_settings(request, project_id): dbm = get_database_manager(request.user) project = Project.load(dbm.database, project_id) questionnaire = FormModel.get(dbm, project.qid) from datawinners.project.views.views import make_project_links project_links = make_project_links(project, questionnaire.form_code) org_id = (NGOUserProfile.objects.get(user=request.user)).org_id organization = Organization.objects.get(org_id=org_id) html = 'project/reminders_trial.html' if organization.in_trial_mode else 'project/reminder_settings.html' if request.method == 'GET': form = ReminderForm(data=(_reminder_info_about_project(project))) return render_to_response(html, {'project_links': project_links, 'is_quota_reached': is_quota_reached(request, organization=organization), 'project': project, 'form': form}, context_instance=RequestContext(request)) if request.method == 'POST': form = ReminderForm(data=request.POST.copy()) if form.is_valid(): org_id = NGOUserProfile.objects.get(user=request.user).org_id organization = Organization.objects.get(org_id=org_id) reminder_list = Reminder.objects.filter(project_id=project.id) action = _get_activity_log_action(reminder_list, form.cleaned_data) project, set_deadline = _add_reminder_info_to_project(form.cleaned_data, project, organization, reminder_list=reminder_list) project.save(dbm) if action is not None: UserActivityLog().log(request, action=action, project=project.name) if set_deadline: UserActivityLog().log(request, action=SET_DEADLINE, project=project.name) messages.success(request, _("Reminder settings saved successfully.")) return HttpResponseRedirect('') else: return render_to_response(html, {'project_links': project_links, 'is_quota_reached': is_quota_reached(request, organization=organization), 'project': project, 'form': form}, context_instance=RequestContext(request))