Esempio n. 1
0
 def test_SpiritualActivitiesSurveyForm_invalid(self):
     data = {
         "date": "2017-01-01",
         "student_id": 1,
         "personal_attend_church": "Y"
     }
     form = SpiritualActivitiesSurveyForm(data)
     self.assertFalse(form.is_valid())
     # frequency_of_attending is required when personal_attend_church = Yes
     self.assertEqual(
         form.errors,
         {'frequency_of_attending': [u'This field is required.']})
Esempio n. 2
0
def spiritualactivities_survey(request, student_id=0):

    if request.method == "POST":
        form = SpiritualActivitiesSurveyForm(request.POST)

        if form.is_valid():
            instance = form.save()
            message = "Performed spiritual activities survey for " + unicode(instance.student_id.name)
            log = NotificationLog(user=request.user, text=message, font_awesome_icon="fa-fire")
            log.save()
            # then return
            return HttpResponseRedirect(reverse("success"))
    else:
        if student_id > 0:
            form = SpiritualActivitiesSurveyForm({"student_id": student_id})
        else:
            form = SpiritualActivitiesSurveyForm()

    context = {"form": form, "student_id": student_id}
    return render(request, "mande/spiritualactivitiessurvey.html", context)
Esempio n. 3
0
def spiritualactivities_survey(request,student_id=0):

    if request.method == 'POST':
        form = SpiritualActivitiesSurveyForm(request.POST)

        if form.is_valid():
            instance = form.save()
            message = ('Performed spiritual activities survey for '+
                        unicode(instance.student_id.name))
            log = NotificationLog(  user=request.user,
                                    text=message,
                                    font_awesome_icon='fa-fire')
            log.save()
            #then return
            return HttpResponseRedirect(reverse('success'))
    else:
        if student_id > 0:
            form = SpiritualActivitiesSurveyForm({'student_id':student_id})
        else:
            form = SpiritualActivitiesSurveyForm()

    context = {'form': form,'student_id':student_id}
    return render(request, 'mande/spiritualactivitiessurvey.html', context)
Esempio n. 4
0
 def test_SpiritualActivitiesSurveyForm_valid(self):
     data = {
         "date": "2017-01-01",
         "student_id": 1,
         "personal_attend_church": "Y",
         "frequency_of_attending": "EVERY_WEEK"
     }
     data2 = {
         "date": "2017-01-01",
         "student_id": 1,
         "personal_attend_church": "N",
     }
     form = SpiritualActivitiesSurveyForm(data)
     form2 = SpiritualActivitiesSurveyForm(data2)
     self.assertTrue(form.is_valid())
     self.assertTrue(form2.is_valid())
Esempio n. 5
0
def spiritualactivities_survey(request, student_id=0):

    if request.method == 'POST':
        form = SpiritualActivitiesSurveyForm(request.POST)

        if form.is_valid():
            instance = form.save()
            message = ('Performed spiritual activities survey for ' +
                       unicode(instance.student_id.name))
            log = NotificationLog(user=request.user,
                                  text=message,
                                  font_awesome_icon='fa-fire')
            log.save()
            #then return
            return HttpResponseRedirect(reverse('success'))
    else:
        if student_id > 0:
            form = SpiritualActivitiesSurveyForm({'student_id': student_id})
        else:
            form = SpiritualActivitiesSurveyForm()

    context = {'form': form, 'student_id': student_id}
    return render(request, 'mande/spiritualactivitiessurvey.html', context)
Esempio n. 6
0
def spiritualactivities_survey(request, student_id=0, survey_id=None):
    #get current method name
    method_name = inspect.currentframe().f_code.co_name
    if user_permissions(method_name, request.user):
        next_url = request.GET.get('next')
        data_church_names = list(
            SpiritualActivitiesSurvey.objects.all().values_list(
                'church_name', flat=True).distinct())
        # sort khmer
        data_church_names = [
            x.encode('utf-8').strip() for x in data_church_names
            if x is not None
        ]
        data_church_names = sorted(set(data_church_names),
                                   key=collator.getSortKey)
        if int(student_id) > 0:
            if survey_id != None:
                try:
                    #editing
                    instance = SpiritualActivitiesSurvey.objects.get(
                        pk=survey_id)
                    form = SpiritualActivitiesSurveyForm(instance=instance)
                    action = "Editing"
                except ObjectDoesNotExist:
                    #adding form
                    instance = None
                    form = SpiritualActivitiesSurveyForm(
                        initial={
                            'student_id': student_id,
                            'date': date.today().isoformat()
                        })
                    action = 'Adding'
            else:
                instance = None
                form = SpiritualActivitiesSurveyForm(
                    initial={
                        'student_id': student_id,
                        'date': date.today().isoformat()
                    })
                action = "Adding"
        else:
            instance = None
            form = SpiritualActivitiesSurveyForm()
            action = "Performing"
        if request.method == 'POST':
            if instance != None:
                form = SpiritualActivitiesSurveyForm(request.POST,
                                                     instance=instance)
            else:
                form = SpiritualActivitiesSurveyForm(request.POST)
            if form.is_valid():
                instance = form.save()
                sms = action.replace('ing', 'ed')
                message = (sms + ' spiritual activities survey for ' +
                           unicode(instance.student_id.name))
                log = NotificationLog(user=request.user,
                                      text=message,
                                      font_awesome_icon='fa-fire')
                log.save()
                #then return
                if (next_url != None) & (next_url != 'None'):
                    return HttpResponseRedirect(next_url +
                                                '#spiritual_activities')
                return HttpResponseRedirect(reverse('success'))

        context = {
            'form': form,
            'student_id': student_id,
            'survey_id': survey_id,
            'next_url': next_url,
            'action': action,
            'data_church_names': json.dumps(data_church_names),
        }
        return render(request, 'mande/spiritualactivitiessurvey.html', context)
    else:
        raise PermissionDenied