diff options
-rw-r--r-- | yaksh/forms.py | 40 | ||||
-rw-r--r-- | yaksh/templates/yaksh/course_detail.html | 9 | ||||
-rw-r--r-- | yaksh/views.py | 41 |
3 files changed, 48 insertions, 42 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index f4d1b02..54eb21f 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -140,7 +140,6 @@ class QuizForm(forms.ModelForm): self.fields['course'] = forms.ModelChoiceField( queryset=Course.objects.filter(creator=user)) - class Meta: model = Quiz fields = '__all__' @@ -188,26 +187,27 @@ class CourseForm(forms.ModelForm): model = Course fields = ['name', 'active', 'enrollment'] -class EditProfile(forms.Form): +class EditProfile(forms.ModelForm): """ edit profile form for students and moderators """ + class Meta: + model = Profile + fields = ['first_name', 'last_name', 'institute', 'department', 'roll_number', 'position'] + first_name = forms.CharField(max_length=30) last_name = forms.CharField(max_length=30) - institute = forms.CharField\ - (max_length=128) - department = forms.CharField\ - (max_length=64) - roll_number = forms.CharField\ - (max_length=30) - position = forms.CharField\ - (max_length=64) - - def save(self, user): - user.first_name = self.cleaned_data['first_name'] - user.last_name = self.cleaned_data['last_name'] - user.profile.department = self.cleaned_data['department'] - user.profile.institute = self.cleaned_data['institute'] - user.profile.roll_number = self.cleaned_data['roll_number'] - user.profile.position = self.cleaned_data['position'] - user.save() - user.profile.save() + + def __init__(self, user, *args, **kwargs): + initial = '' + if 'instance' in kwargs: + initial = kwargs["instance"] + if 'user' in kwargs: + user = kwargs["user"] + del kwargs["user"] + super(EditProfile, self).__init__(*args, **kwargs) + self.fields['first_name'].initial = user.first_name + self.fields['last_name'].initial = user.last_name + self.fields['roll_number'].initial = user.profile.roll_number + self.fields['department'].initial = user.profile.department + self.fields['institute'].initial = user.profile.institute + self.fields['position'].initial = user.profile.position diff --git a/yaksh/templates/yaksh/course_detail.html b/yaksh/templates/yaksh/course_detail.html index 0c37375..c771cc7 100644 --- a/yaksh/templates/yaksh/course_detail.html +++ b/yaksh/templates/yaksh/course_detail.html @@ -24,7 +24,8 @@ <div class="well"> <div class="row"> <div class="span3" style="padding-top:10px"> - <input type="checkbox" name="check" value="{{ request.id }}"> <a href="#" data-toggle="tooltip" title=" Full Name: {{ request.get_full_name }}
Institute: {{ request.profile.institute }}
Department: {{ request.profile.department}}
Roll Number: {{ request.profile.roll_number }}"> {{ request.username }}</a> + <input type="checkbox" name="check" value="{{ request.id }}"> + <a href="#" data-toggle="tooltip" title=" Full Name: {{ request.get_full_name }}
Institute: {{ request.profile.institute }}
Department: {{ request.profile.department}}
Roll Number: {{ request.profile.roll_number }}"> {{ request.username }}</a> </div> <a class="btn success" href="{{URL_ROOT}}/exam/manage/enroll/{{ course.id }}/{{ request.id }}/"> Enroll </a> <a class="btn danger" href="{{URL_ROOT}}/exam/manage/reject/{{ course.id }}/{{ request.id }}/"> Reject </a> </div> @@ -46,7 +47,8 @@ <div class="well"> <div class="row"> <div class="span4" style="padding-top:10px"> - <input type="checkbox" name="check" value="{{ rejected.id }}"> {{ rejected.username }} + <input type="checkbox" name="check" value="{{ rejected.id }}"> + <a href="#" data-toggle="tooltip" title=" Full Name: {{ rejected.get_full_name }}
Institute: {{ rejected.profile.institute }}
Department: {{ rejected.profile.department}}
Roll Number: {{ rejected.profile.roll_number }}"> {{ rejected.username }}</a> </div> <a class="btn success" href="{{URL_ROOT}}/exam/manage/enroll/rejected/{{ course.id }}/{{ rejected.id }}/"> Enroll </a> </div> @@ -71,7 +73,8 @@ <div class="well"> <div class="row"> <div class="span4" style="padding-top:10px"> - <input type="checkbox" name="check" value="{{ enrolled.id }}"> {{ enrolled.username }} + <input type="checkbox" name="check" value="{{ enrolled.id }}"> + <a href="#" data-toggle="tooltip" title=" Full Name: {{ enrolled.get_full_name }}
Institute: {{ enrolled.profile.institute }}
Department: {{ enrolled.profile.department}}
Roll Number: {{ enrolled.profile.roll_number }}"> {{ enrolled.username }}</a> </div> <a class="btn danger" href="{{URL_ROOT}}/exam/manage/enrolled/reject/{{ course.id }}/{{ enrolled.id }}/"> Reject </a> </div> diff --git a/yaksh/views.py b/yaksh/views.py index 8001520..1e4abcf 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -626,6 +626,9 @@ def enroll(request, course_id, user_id=None, was_rejected=False): else: enroll_users = User.objects.filter(id__in=enroll_ids) course.enroll(was_rejected, *enroll_users) + elif user_id is None: + return my_render_to_response('yaksh/course_detail.html', {'course': course}, + context_instance=ci) else: user = get_object_or_404(User, pk=user_id) course.enroll(was_rejected, user) @@ -635,6 +638,7 @@ def enroll(request, course_id, user_id=None, was_rejected=False): @login_required def reject(request, course_id, user_id=None, was_enrolled=False): user = request.user + ci = RequestContext(request) if not is_moderator(user): raise Http404('You are not allowed to view this page') course = get_object_or_404(Course, creator=user, pk=course_id) @@ -646,6 +650,9 @@ def reject(request, course_id, user_id=None, was_enrolled=False): else: reject_users = User.objects.filter(id__in=reject_ids) course.reject(was_enrolled, *reject_users) + elif user_id is None: + return my_render_to_response('yaksh/course_detail.html', {'course': course}, + context_instance=ci) else: user = get_object_or_404(User, pk=user_id) course.reject(was_enrolled, user) @@ -981,12 +988,8 @@ def view_profile(request): """ view moderators and users profile """ user = request.user - ci = RequestContext(request) - if not user.is_authenticated(): - raise Http404('You are not allowed to view this page!') - else: - return my_render_to_response('yaksh/view_profile.html', - context_instance=ci) + #ci = RequestContext(request) + return my_render_to_response('yaksh/view_profile.html', {'user':user}) @login_required def edit_profile(request): @@ -995,14 +998,20 @@ def edit_profile(request): context = {} user = request.user ci = RequestContext(request) - data = {} - if not user.is_authenticated(): - raise Http404('You are not allowed to view this page!') + profile = Profile.objects.get(user_id=user.id) if request.method == 'POST': - form = EditProfile(request.POST) + form = EditProfile(user, request.POST) if form.is_valid(): - data = form.cleaned_data - form.save(user) + user.first_name = request.POST['first_name'] + user.last_name = request.POST['last_name'] + profile.department = request.POST['department'] + profile.institute = request.POST['institute'] + profile.roll_number = request.POST['roll_number'] + profile.position = request.POST['position'] + user.save() + form_data = form.save(commit=False) + form_data.user_id = user.id + profile.save() return my_render_to_response('yaksh/profile_updated.html', context_instance=ci) else: @@ -1010,13 +1019,7 @@ def edit_profile(request): return my_render_to_response('yaksh/editprofile.html', context, context_instance=ci) else: - data['first_name'] = user.first_name - data['last_name'] = user.last_name - data['institute'] = user.profile.institute - data['department'] = user.profile.department - data['roll_number'] = user.profile.roll_number - data['position'] = user.profile.position - form = EditProfile(initial=data) + form = EditProfile(user=user) context['form'] = form return my_render_to_response('yaksh/editprofile.html', context, context_instance=ci) |