diff options
-rw-r--r-- | workshop_app/forms.py | 66 | ||||
-rw-r--r-- | workshop_app/templates/registration/password_change_done.html | 19 | ||||
-rw-r--r-- | workshop_app/templates/registration/password_change_form.html | 62 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/base.html | 3 | ||||
-rw-r--r-- | workshop_app/templates/workshop_app/view_profile.html | 127 | ||||
-rw-r--r-- | workshop_app/urls.py | 1 | ||||
-rw-r--r-- | workshop_app/views.py | 60 |
7 files changed, 240 insertions, 98 deletions
diff --git a/workshop_app/forms.py b/workshop_app/forms.py index 46049f0..2b993fd 100644 --- a/workshop_app/forms.py +++ b/workshop_app/forms.py @@ -125,24 +125,6 @@ class UserLoginForm(forms.Form): return user -class ProfileForm(forms.ModelForm): - """ profile form for coordinator and instructor """ - - class Meta: - model = Profile - fields = ['first_name', 'last_name', 'institute', 'department'] - - first_name = forms.CharField(max_length=32) - last_name = forms.CharField(max_length=32) - - def __init__(self, *args, **kwargs): - if 'user' in kwargs: - user = kwargs.pop('user') - super(ProfileForm, self).__init__(*args, **kwargs) - self.fields['first_name'].initial = user.first_name - self.fields['last_name'].initial = user.last_name - - class WorkshopForm(forms.ModelForm): """ Coordinators will propose a workshop and date @@ -215,3 +197,51 @@ class AttachmentFileForm(forms.ModelForm): class Meta: model = AttachmentFile exclude = ['workshop_type'] + + +class ProfileForm(forms.ModelForm): + """ profile form for coordinators and instructors """ + + class Meta: + model = Profile + exclude = ["user", "is_email_verified", "activation_key", + "key_expiry_time", "how_did_you_hear_about_us"] + + first_name = forms.CharField(max_length=30, widget=forms.TextInput( + {'class': "form-control", 'placeholder': "First Name"})) + last_name = forms.CharField(max_length=30, widget=forms.TextInput( + {'class': "form-control", 'placeholder': "Last Name"})) + + def __init__(self, *args, **kwargs): + if 'user' in kwargs: + user = kwargs.pop('user') + super(ProfileForm, self).__init__(*args, **kwargs) + self.fields['first_name'].initial = user.first_name + self.fields['first_name'].widget.attrs.update( + {'class': "form-control", 'placeholder': 'First Name'} + ) + self.fields['last_name'].initial = user.last_name + self.fields['last_name'].widget.attrs.update( + {'class': "form-control", 'placeholder': 'Last Name'} + ) + self.fields['institute'].widget.attrs.update( + {'class': "form-control", 'placeholder': 'Institute'} + ) + self.fields['department'].widget.attrs.update( + {'class': "custom-select"} + ) + self.fields['title'].widget.attrs.update( + {'class': "custom-select"} + ) + self.fields['state'].widget.attrs.update( + {'class': "custom-select"} + ) + self.fields['phone_number'].widget.attrs.update( + {'class': "form-control", 'placeholder': 'Phone Number'} + ) + self.fields['position'].widget.attrs.update( + {'class': "form-control", 'placeholder': 'Position'} + ) + self.fields['location'].widget.attrs.update( + {'class': "form-control", 'placeholder': 'Location'} + ) diff --git a/workshop_app/templates/registration/password_change_done.html b/workshop_app/templates/registration/password_change_done.html new file mode 100644 index 0000000..321f57f --- /dev/null +++ b/workshop_app/templates/registration/password_change_done.html @@ -0,0 +1,19 @@ +{% extends "workshop_app/base.html" %} + +{% block content %} +<br><br> +<center> + <div class="container row align-items-center"> + <div class="col"> + <h3>Your password has been changed successfully.</h3> + <h4>Redirecting ...</h4> + </div> + </div> +</center> +<script type="text/javascript"> + window.setTimeout(function() + { + location.href="{% url 'workshop_app:index' %}" + }, 2000); +</script> +{% endblock %} diff --git a/workshop_app/templates/registration/password_change_form.html b/workshop_app/templates/registration/password_change_form.html new file mode 100644 index 0000000..99cdbdf --- /dev/null +++ b/workshop_app/templates/registration/password_change_form.html @@ -0,0 +1,62 @@ +{% extends "workshop_app/base.html" %} + +<!DOCTYPE html> +{% block pagetitle %} +Change Password +{% endblock %} +{% block title %} Change Password {% endblock %} + +{% block content %} +<form action="" method="post" > + {% csrf_token %} + <center> + <div class="container col-md-6"> + <table class="table table-responsive-sm"> + {% if form.errors %} + {% for field in form %} + {% for error in field.errors %} + <div class="alert alert-dismissible alert-danger"> + <button type="button" class="close" data-dismiss="alert"> + <i class="fa fa-close"></i> + </button> + <strong>{{ error|escape }}</strong> + </div> + {% endfor %} + {% endfor %} + {% for error in form.non_field_errors %} + <div class="alert alert-dismissible alert-danger"> + <button type="button" class="close" data-dismiss="alert"> + <i class="fa fa-close"></i> + </button> + <strong>{{ error|escape }}</strong> + </div> + {% endfor %} + {% endif %} + {% for field in form %} + <tr> + <td>{{ field.label }}</td> + <td>{{ field }} <small>{{ field.help_text }}</small></td> + </tr> + {% endfor %} + </table> + </div> + </center> + <br> + <center> + <button class="btn btn-success btn-lg" type="submit"> + Change + </button> + <a href="{% url 'workshop_app:index' %}" class="btn btn-primary btn-lg"> + Cancel + </a> + </center> +</form> +<script type="text/javascript"> + $(document).ready(function() + { + $("#id_old_password").addClass("form-control"); + $("#id_new_password1").addClass("form-control"); + $("#id_new_password2").addClass("form-control"); + }); +</script> +{% endblock content %} diff --git a/workshop_app/templates/workshop_app/base.html b/workshop_app/templates/workshop_app/base.html index ba968ba..95f5fa0 100644 --- a/workshop_app/templates/workshop_app/base.html +++ b/workshop_app/templates/workshop_app/base.html @@ -97,6 +97,9 @@ </a> <div class="dropdown-menu" aria-labelledby="navbarDropdown"> <a class="dropdown-item" href="{% url 'workshop_app:view_own_profile' %}">Profile</a> + <a class="dropdown-item" href="{% url 'password_change' %}"> + Change Password + </a> <a class="dropdown-item" href="{% url 'workshop_app:logout' %}">Logout</a> </div> </li> diff --git a/workshop_app/templates/workshop_app/view_profile.html b/workshop_app/templates/workshop_app/view_profile.html index 5cb5c36..041d6ac 100644 --- a/workshop_app/templates/workshop_app/view_profile.html +++ b/workshop_app/templates/workshop_app/view_profile.html @@ -1,51 +1,49 @@ {% extends 'workshop_app/base.html' %} -{% block title %} - Coordinator Profile -{% endblock %} +{% block title %} Profile {% endblock %} {% csrf_token %} {% block content %} <div class="container"> - <table class="table table-bordered"> - <tr> - <th><label for="id_first_name"><h5>First name:</h5></label></th> - <th><label for="id_first_name"><h5>{{ coordinator_profile.user.first_name }}</h5></label></th> - </tr> - <tr> - <th><label for="id_last_name"><h5>Last name:</h5></label></th> - <th><label for="id_last_name"><h5>{{ coordinator_profile.user.last_name }}</h5></label></th> - </tr> - <tr> - <th><label for="id_email"><h5>Email:</h5></label></th> - <th><label for="id_email"><h5>{{ coordinator_profile.user.email }}</h5></label></th> - </tr> - <tr> - <th><label for="id_institute"><h5>Institute:</h5></label></th> - <th><label for="id_institute"><h5>{{ coordinator_profile.user.profile.institute }}</h5></label></th> - </tr> - <tr> - <th><label for="id_phone_number"><h5>Phone Number:</h5></label></th> - <th><label for="id_phone_number"><h5>{{ coordinator_profile.user.profile.phone_number }}</h5></label> - </th> - </tr> - <tr> - <th><label for="id_department"><h5>Department:</h5></label></th> - <th><label for="id_department"><h5>{{ coordinator_profile.user.profile.department }}</h5></label></th> - </tr> - <tr> - <th><label for="id_location"><h5>Location:</h5></label></th> - <th><label for="id_location"><h5>{{ coordinator_profile.user.profile.location }}</h5></label></th> - </tr> - <tr> - <th><label for="id_position"><h5>Position:</h5></label></th> - <th><label for="id_position"><h5>{{ coordinator_profile.user.profile.position }}</h5></label></th> - </tr> - </table> - <br> - {% if Workshops %} + <table class="table table-bordered"> + <tr> + <th><label for="id_first_name"><h5>First name:</h5></label></th> + <th><label for="id_first_name"><h5>{{ coordinator_profile.user.first_name }}</h5></label></th> + </tr> + <tr> + <th><label for="id_last_name"><h5>Last name:</h5></label></th> + <th><label for="id_last_name"><h5>{{ coordinator_profile.user.last_name }}</h5></label></th> + </tr> + <tr> + <th><label for="id_email"><h5>Email:</h5></label></th> + <th><label for="id_email"><h5>{{ coordinator_profile.user.email }}</h5></label></th> + </tr> + <tr> + <th><label for="id_institute"><h5>Institute:</h5></label></th> + <th><label for="id_institute"><h5>{{ coordinator_profile.user.profile.institute }}</h5></label></th> + </tr> + <tr> + <th><label for="id_phone_number"><h5>Phone Number:</h5></label></th> + <th><label for="id_phone_number"><h5>{{ coordinator_profile.user.profile.phone_number }}</h5></label> + </th> + </tr> + <tr> + <th><label for="id_department"><h5>Department:</h5></label></th> + <th><label for="id_department"><h5>{{ coordinator_profile.user.profile.department }}</h5></label></th> + </tr> + <tr> + <th><label for="id_location"><h5>Location:</h5></label></th> + <th><label for="id_location"><h5>{{ coordinator_profile.user.profile.location }}</h5></label></th> + </tr> + <tr> + <th><label for="id_position"><h5>Position:</h5></label></th> + <th><label for="id_position"><h5>{{ coordinator_profile.user.profile.position }}</h5></label></th> + </tr> + </table> + <br> + <div class="container"> <h2>Workshop Details</h2> <table class="table table-bordered"> @@ -77,6 +75,55 @@ </table> </div> <br><br> + {% else %} + <form action="" method="post"> + {% csrf_token %} + <div class="row justify-content-center form-group"> + <div class="col-md-6"> + <form action="" method="post"> + <fieldset> + {% csrf_token %} + {% if form.errors %} + {% for field in form %} + {% for error in field.errors %} + <div class="alert alert-dismissible alert-danger"> + <button type="button" class="close" data-dismiss="alert"> + <i class="fa fa-close"></i> + </button> + <strong>{{field.label}} : {{ error|escape }}</strong> + </div> + {% endfor %} + {% endfor %} + {% for error in form.non_field_errors %} + <div class="alert alert-dismissible alert-danger"> + <button type="button" class="close" data-dismiss="alert"> + <i class="fa fa-close"></i> + </button> + <strong>{{field.label}} : {{ error|escape }}</strong> + </div> + {% endfor %} + {% endif %} + <table class="table table-responsive-sm"> + <tr><td>{{form.title}}</td></tr> + <tr><td>{{form.first_name}}</td></tr> + <tr><td>{{form.last_name}}</td></tr> + <tr><td>{{form.phone_number}}</td></tr> + <tr><td>{{form.institute}}</td></tr> + <tr><td>{{form.department}}</td></tr> + <tr><td>{{form.position}}</td></tr> + <tr><td>{{form.location}}</td></tr> + <tr><td>{{form.state}}</td></tr> + </table> + <br> + </fieldset> + <button class="btn btn-success btn-lg" type="submit"> + <i class="fa fa-pencil-square-o"></i> Update</button> + <a href="{% url 'workshop_app:index' %}" class="btn btn-primary btn-lg">Cancel + </a> + </form> + </div> + </div> + </form> {% endif %} </div> {% endblock %} diff --git a/workshop_app/urls.py b/workshop_app/urls.py index b83e5cc..59e5ca5 100644 --- a/workshop_app/urls.py +++ b/workshop_app/urls.py @@ -25,7 +25,6 @@ urlpatterns = [ url(r'^activate_user/$', views.activate_user), url(r'^login/$', views.user_login, name="login"), url(r'^logout/$', views.user_logout, name="logout"), - url(r'^edit_profile/$', views.edit_profile), url(r'^status$', views.workshop_status_coordinator, name='workshop_status_coordinator'), url(r'^dashboard$', views.workshop_status_instructor, diff --git a/workshop_app/views.py b/workshop_app/views.py index 7be17d9..d59603d 100644 --- a/workshop_app/views.py +++ b/workshop_app/views.py @@ -165,43 +165,6 @@ def user_register(request): return render(request, "workshop_app/register.html", {"form": form}) -@login_required -def view_profile(request): - """ view instructor and coordinator profile """ - user = request.user - if user.is_superuser: - return redirect('/admin') - return render(request, "workshop_app/view_profile.html") - - -@login_required -def edit_profile(request): - """ edit profile details facility for instructor and coordinator """ - - user = request.user - if user.is_superuser: - return redirect('/admin') - - if request.method == 'POST': - form = ProfileForm(request.POST, user=user, instance=user.profile) - if form.is_valid(): - form_data = form.save(commit=False) - form_data.user = user - form_data.user.first_name = request.POST['first_name'] - form_data.user.last_name = request.POST['last_name'] - form_data.user.save() - form_data.save() - messages.add_message(request, messages.SUCCESS, "Profile updated.") - return redirect(reverse("workshop_app:view_own_profile")) - else: - messages.add_message( - request, messages.ERROR, "Profile update failed!" - ) - else: - form = ProfileForm(user=user, instance=user.profile) - return render(request, 'workshop_app/edit_profile.html', {'form': form}) - - # Workshop views @login_required @@ -514,7 +477,26 @@ def view_profile(request, user_id): def view_own_profile(request): """User can view own profile """ user = request.user - coordinator_profile = Profile.objects.get(user=user) + if user.is_superuser: + return redirect("admin") + profile = user.profile + if request.method == 'POST': + form = ProfileForm(request.POST, user=user, instance=profile) + if form.is_valid(): + form_data = form.save(commit=False) + form_data.user = user + form_data.user.first_name = request.POST['first_name'] + form_data.user.last_name = request.POST['last_name'] + form_data.user.save() + form_data.save() + messages.add_message(request, messages.SUCCESS, "Profile updated.") + return redirect(reverse("workshop_app:view_own_profile")) + else: + messages.add_message( + request, messages.ERROR, "Profile update failed!" + ) + else: + form = ProfileForm(user=user, instance=profile) return render(request, "workshop_app/view_profile.html", - {"coordinator_profile": coordinator_profile, "Workshops": None}) + {"profile": profile, "Workshops": None, "form": form}) |