Beispiel #1
0
def staffform(request, staff_id):
    member = get_object_or_404(Staff, pk=staff_id)
    if request.method == 'POST':
        form = StaffForm(request.POST, instance=member)
        if form.is_valid():
            form.save(commit=true)
            return index(request)

    else:
        form = StaffForm(instance=member)
        form.fields['number'].widget.attrs['readonly'] = True
    return render(request, 'staff/staffform.html', {'form': form})
Beispiel #2
0
    def post(self, request, *args, **kwargs):

        try:

            charge = stripe.Charge.create(
                amount=500,
                currency='eur',
                description='Calendarize Shared',
                source=request.POST['stripeToken']
            )

            if(charge.paid == True):
                staff = StaffForm(request.POST)

            if staff.is_valid():
                staff.save()

            message = "success"

        except:

            logger.warning("Failed to process payment")
            message = "failed"

        return HttpResponseRedirect(reverse('payment', kwargs = { 'message': message }))
Beispiel #3
0
    def test_staff_form_valid(self):
        form = StaffForm(data={
            'firstname': 'Jan',
            'secondname': 'pona',
            'academic_rank': 'mgr',
        })

        self.assertTrue(form.is_valid())
Beispiel #4
0
def staff(request):
    if request.method == 'GET':
        context = {'form': StaffForm}
        return render(request, 'staff.html', context)

    else:
        form = StaffForm(request.POST)
        if form.is_valid():
            data = form.save()
            data.save()
            return redirect('staff')

        return render(request, 'staff.html')
Beispiel #5
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['key'] = settings.STRIPE_PUBLISHABLE_KEY
     context['contactForm'] = ContactForm()
     context['staff'] = StaffForm()
     return context
Beispiel #6
0
def staff_registration(request, *args, **kwargs):
    if request.method == "POST":
        form = StaffForm(request.POST or None)
        if form.is_valid():
            details = form.cleaned_data
            new_username = details['username']
            new_fName = details['firstName']
            new_mName = details['middleName']
            new_lName = details['lastName']
            new_passwd = details['passwd']
            new_email = details['email']
            new_dob = details['date']
            new_gender = details['gender']
            new_mobile = details['mobile']
            new_branch = details['branch']
            new_designation = details['designation']
            new_isAdmin = False
            new_isPending = True
            new_account_id = id_generator()

            #sets category of user
            new_category = ''
            if new_designation in ['Professor', 'Assistant Professor']:
                new_category = 'Faculty'
            elif new_designation == 'Head of Department':
                new_category = 'Head of Department'
            elif new_designation in ['Lab Instructor', 'Lab Assistant']:
                new_category = 'Staff'

            # find the number of users in staff
            staff_count = int(Staff.objects.count())

            # if there are no staff members, the first created user will be admin
            if staff_count < 1:
                new_isAdmin = True
                new_category = 'Admin'
                new_isPending = False

            try:
                validate_password(new_passwd, form)
            except ValidationError as e:
                form.add_error('passwd', e)
                return render(request, "common/staffregistration.html",
                              {'form': form})

            # try:
            #     user_credentials = [new_username, new_fName, new_lName, new_mName, new_mobile]
            #     for item in user_credentials:
            #         if item.lower() in new_passwd.lower():
            #             raise ValidationError('Password too similar to credentials.')
            # except ValidationError as e:
            #     form.add_error('passwd', e)
            #     return render(request, "common/staffregistration.html", {'form': form})

            newStaff = Staff(firstName=str(new_fName.capitalize()),
                             middleName=str(new_mName.capitalize()),
                             lastName=str(new_lName.capitalize()),
                             username=str(new_username),
                             passwd=str(new_passwd),
                             account_id=str(new_account_id),
                             date=str(new_dob),
                             mobile=str(new_mobile),
                             branch=str(new_branch),
                             email=str(new_email.lower()),
                             gender=str(new_gender),
                             designation=str(new_designation),
                             isAdmin=new_isAdmin,
                             isPending=new_isPending,
                             category=str(new_category))

            # newUser = AppUser(
            #             firstName=str(new_fName.capitalize()),
            #             lastName=str(new_lName.capitalize()),
            #             username=str(new_username),
            #             passwd=str(new_passwd),
            #             email=str(new_email.lower()),
            #             category=str(new_category),
            #             isAdmin=new_isAdmin,
            #             isPending=new_isPending
            # )

            newUser = User.objects.create_user(
                username=str(new_username),
                password=str(new_passwd),
                first_name=str(new_fName.capitalize()),
                last_name=str(new_lName.capitalize()),
                email=str(new_email.lower()),
            )

            # newDjangoUser.save()
            newStaff.save()
            newUser.save()

            if new_isPending:
                return redirect("../pending-account")
            else:
                return redirect("../account-created")
    else:
        form = StaffForm(request.POST or None)
        for field in form.errors:
            form[field].field.widget.attrs['class'] += 'error'

    return render(request, "common/staffregistration.html", {'form': form})
Beispiel #7
0
    def test_staff_form_is_not_valid(self):
        form = StaffForm(data={})

        self.assertFalse(form.is_valid())
        self.assertEqual(len(form.errors), 3)