def addStaff(request): if request.method == 'POST': form = StaffForm(request.POST, request.FILES) if form.is_valid(): staff = form.save() type_staff = form.cleaned_data['type_staff'] if type_staff == 'employee': messages.add_message(request, messages.SUCCESS, 'Se guardo exitosamente, ahora complete' + ' los datos del personal') return HttpResponseRedirect(staff.get_absolute_url() + '/create_employee/') else: messages.add_message(request, messages.SUCCESS, 'Se guardo exitosamente, ahora complete' + ' los datos del guardia') return HttpResponseRedirect(staff.get_absolute_url() + '/create_guard/') else: messages.add_message(request, messages.ERROR, 'Los datos que ingreso son incorrectos') return render_to_response('create_staff.html', {'form': form}, context_instance=RequestContext(request)) else: form = StaffForm() return render_to_response('create_staff.html', {'form': form}, context_instance=RequestContext(request))
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 }))
def test_staff_form_valid(self): form = StaffForm(data={ 'firstname': 'Jan', 'secondname': 'pona', 'academic_rank': 'mgr', }) self.assertTrue(form.is_valid())
def create_staff(request): if request.method == 'POST': form = StaffForm(request.POST) if form.is_valid(): form.save() #message = "School added" return render(request, 'staff_added.html', {'form': form}) else: form = StaffForm() context_data = {'form': form} return render(request, 'create_staff.html', context_data)
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})
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')
def staff_edit(request, pk): staff = get_object_or_404(Staff, pk=pk) if request.method == 'POST': form = StaffForm(request.POST, instance=staff) if form.is_valid(): form.save() #message = "School added" return render(request, 'staff_added.html', {'form': form}) else: form = StaffForm(instance=staff) context_data = {'form': form} # return HttpResponse('create_school.html', context_data) # return render_to_response('create_school.html', context_data, # context_instance=RequestContext(request)) return render(request, 'create_staff.html', context_data)
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})
def add_staff(request): context_vars = dict() context_vars['header'] = capfirst(_('add new staff')) staff_form = StaffForm() address_form = AddressForm() if request.method == "POST": staff_form = StaffForm(request.POST, request.FILES) address_form = AddressForm(request.POST, request.FILES) try: if staff_form.is_valid() and address_form.is_valid(): staff = staff_form.save() address_form = AddressForm(request.POST, request.FILES, instance=staff.address) if not address_form.is_valid(): raise InvalidForm() address_form.save() if settings.WORKFLOWMAX_APIKEY and settings.WORKFLOWMAX_ACCOUNTKEY: staff.wm_sync() return HttpResponseRedirect(reverse('staff-view', args=[staff.id])) except InvalidForm: pass context_vars['staff_form'] = staff_form context_vars['address_form'] = address_form return direct_to_template(request, template='staff/form.html', extra_context=context_vars)
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
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})
def test_staff_form_is_not_valid(self): form = StaffForm(data={}) self.assertFalse(form.is_valid()) self.assertEqual(len(form.errors), 3)
context_vars['staff_form'] = staff_form context_vars['address_form'] = address_form return direct_to_template(request, template='staff/form.html', extra_context=context_vars) @login_required def edit_staff(request, object_id): context_vars = dict() try: object_id = int(object_id) staff = Staff.objects.get(id=object_id) except ValueError, ObjectDoesNotExist: return HttpResponseRedirect(reverse('staff-list')) context_vars['header'] = capfirst(_('edit staff %s') % staff.username) staff_form = StaffForm(instance=staff) address_form = AddressForm(instance=staff.address) if request.method == "POST": staff_form = StaffForm(request.POST, request.FILES, instance=staff) address_form = AddressForm(request.POST, request.FILES, instance=staff.address) if staff_form.is_valid() and address_form.is_valid(): staff = staff_form.save() address_form.save() if settings.WORKFLOWMAX_APIKEY and settings.WORKFLOWMAX_ACCOUNTKEY: staff.wm_sync() return HttpResponseRedirect(reverse('staff-view', args=[staff.id])) context_vars['staff_form'] = staff_form context_vars['address_form'] = address_form return direct_to_template(request, template='staff/form.html', extra_context=context_vars)