Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add_staff(request):
- form = StaffForm(request.POST or None, request.FILES or None)
- context = {'form': form, 'page_title': 'Add Staff'}
- if request.method == 'POST':
- if form.is_valid():
- first_name = form.cleaned_data.get('first_name')
- last_name = form.cleaned_data.get('last_name')
- email = form.cleaned_data.get('email')
- gender = form.cleaned_data.get('gender')
- password = form.cleaned_data.get('password')
- course = form.cleaned_data.get('course')
- try:
- passport = request.FILES.get('profile_pic')
- fs = FileSystemStorage()
- filename = fs.save(passport.name, passport)
- passport_url = fs.url(filename)
- except:
- passport = None
- passport_url = None
- address = form.cleaned_data.get('address')
- try:
- user = CustomUser.objects.create_user(
- email=email, password=password, user_type=2, first_name=first_name, last_name=last_name, profile_pic=passport_url)
- user.gender = gender
- user.address = address
- user.staff.course = course
- user.save()
- messages.success(request, "Successfully Added")
- return redirect(reverse('add_staff'))
- except Exception as e:
- messages.error(request, "Could Not Add " + str(e))
- else:
- messages.error(request, "Please fulfil all requirements")
- return render(request, 'hod_template/add_staff_template.html', context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement