def edit_profile(request): """ Edit the profile fields """ profile = request.user.profile form = forms.ProfileForm(instance=profile) if request.method == 'POST': if settings.SYSTEM_MAINTENANCE_NO_UPLOAD: # Allow submitting the form, but do not allow the photo to # be modified. if 'delete_photo' in request.POST or request.FILES: raise ServiceUnavailable() if 'edit_profile' in request.POST: # Update the profile and return to the same page. Place a message # at the top of the page: 'your profile has been updated' form = forms.ProfileForm(data=request.POST, files=request.FILES, instance=profile) if form.is_valid(): form.save() messages.success(request, 'Your profile has been updated.') elif 'delete_photo' in request.POST: profile.delete_photo() messages.success(request, 'Your profile photo has been deleted.') if not form.errors: form = forms.ProfileForm(instance=profile) return render(request, 'user/edit_profile.html', {'form': form})
def credential_application(request): """ Page to apply for credentially """ user = request.user license = License.objects.get(id='6') if user.is_credentialed or CredentialApplication.objects.filter(user=user, status=0): return redirect('edit_credentialing') if settings.SYSTEM_MAINTENANCE_NO_UPLOAD: raise ServiceUnavailable() if request.method == 'POST': # We use the individual forms to render the errors in the template # if not all valid personal_form = forms.PersonalCAF(user=user, data=request.POST, prefix="application") training_form = forms.TrainingCAF(data=request.POST, files=request.FILES, prefix="application") research_form = forms.ResearchCAF(data=request.POST, prefix="application") reference_form = forms.ReferenceCAF(data=request.POST, prefix="application", user=user) form = forms.CredentialApplicationForm(user=user, data=request.POST, files=request.FILES, prefix="application") if (personal_form.is_valid() and training_form.is_valid() and reference_form.is_valid() and form.is_valid()) and research_form.is_valid(): application = form.save() credential_application_request(request, application) return render(request, 'user/credential_application_complete.html') else: messages.error(request, 'Invalid submission. See errors below.') else: personal_form = forms.PersonalCAF(user=user, prefix="application") training_form = forms.TrainingCAF(prefix="application") reference_form = forms.ReferenceCAF(prefix="application", user=user) research_form = forms.ResearchCAF(prefix="application") form = None return render( request, 'user/credential_application.html', { 'form': form, 'personal_form': personal_form, 'training_form': training_form, 'reference_form': reference_form, 'license': license, 'research_form': research_form })
def credential_application(request): """ Page to apply for credentialing """ user = request.user if user.is_credentialed or CredentialApplication.objects.filter(user=user, status=0): return redirect('edit_credentialing') if settings.SYSTEM_MAINTENANCE_NO_UPLOAD: raise ServiceUnavailable() if request.method == 'POST': # We use the individual forms to render the errors in the template # if not all valid personal_form = forms.PersonalCAF(user=user, data=request.POST, prefix="application") research_form = forms.ResearchCAF(data=request.POST, prefix="application") reference_form = forms.ReferenceCAF(data=request.POST, prefix="application", user=user) form = forms.CredentialApplicationForm(user=user, data=request.POST, files=request.FILES, prefix="application") if (personal_form.is_valid() and reference_form.is_valid() and form.is_valid()) and research_form.is_valid(): application = form.save() credential_application_request(request, application) CodeOfConductSignature.objects.get_or_create( code_of_conduct=CodeOfConduct.objects.filter( is_active=True).first(), user=request.user, ) return render(request, 'user/credential_application_complete.html') else: messages.error(request, 'Invalid submission. See errors below.') else: personal_form = forms.PersonalCAF(user=user, prefix="application") reference_form = forms.ReferenceCAF(prefix="application", user=user) research_form = forms.ResearchCAF(prefix="application") form = None code_of_conduct = CodeOfConduct.objects.filter(is_active=True).first() return render( request, 'user/credential_application.html', { 'form': form, 'personal_form': personal_form, 'reference_form': reference_form, 'research_form': research_form, 'code_of_conduct': code_of_conduct, }, )