diff options
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/forms.py | 89 | ||||
-rw-r--r-- | yaksh/views.py | 18 |
2 files changed, 88 insertions, 19 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index 57140bc..aa4d7b9 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -55,6 +55,9 @@ attempts = [(i, i) for i in range(1, 6)] attempts.append((-1, 'Infinite')) days_between_attempts = ((j, j) for j in range(401)) +# Add bootstrap class separated by space +form_input_class = "form-control" + def get_object_form(model, exclude_fields=None): model_class = get_model_class(model) @@ -72,25 +75,51 @@ class UserRegisterForm(forms.Form): a new user to the system""" username = forms.CharField(max_length=30, help_text='Letters, digits,\ - period and underscores only.') - email = forms.EmailField() - password = forms.CharField(max_length=30, widget=forms.PasswordInput()) + period and underscores only.', + widget=forms.TextInput( + {'class': form_input_class, 'placeholder': "Username"}) + ) + email = forms.EmailField(widget=forms.TextInput( + {'class': form_input_class, 'placeholder': "Email"} + )) + password = forms.CharField(max_length=30, + widget=forms.PasswordInput( + {'class': form_input_class, 'placeholder': "Password"})) confirm_password = forms.CharField( - max_length=30, widget=forms.PasswordInput()) - first_name = forms.CharField(max_length=30) - last_name = forms.CharField(max_length=30) + max_length=30, widget=forms.PasswordInput( + {'class': form_input_class, 'placeholder': "Confirm Password"} + )) + first_name = forms.CharField(max_length=30, widget=forms.TextInput( + {'class': form_input_class, 'placeholder': "First Name"} + )) + last_name = forms.CharField(max_length=30, widget=forms.TextInput( + {'class': form_input_class, 'placeholder': "Last Name"} + )) roll_number = forms.CharField( - max_length=30, help_text="Use a dummy if you don't have one.") + max_length=30, help_text="Use a dummy if you don't have one.", + widget=forms.TextInput( + {'class': form_input_class, 'placeholder': "Roll Number"} + )) institute = forms.CharField( - max_length=128, help_text='Institute/Organization') + max_length=128, help_text='Institute/Organization', + widget=forms.TextInput( + {'class': form_input_class, 'placeholder': "Institute"} + )) department = forms.CharField( - max_length=64, help_text='Department you work/study at') + max_length=64, help_text='Department you work/study at', + widget=forms.TextInput( + {'class': form_input_class, 'placeholder': "Department"} + )) position = forms.CharField( max_length=64, - help_text='Student/Faculty/Researcher/Industry/Fellowship/etc.') + help_text='Student/Faculty/Researcher/Industry/Fellowship/etc.', + widget=forms.TextInput( + {'class': form_input_class, 'placeholder': "Position"} + )) timezone = forms.ChoiceField( choices=[(tz, tz) for tz in pytz.common_timezones], - help_text='Course timings are shown based on the selected timezone', + help_text='All timings are shown based on the selected timezone', + widget=forms.Select({'class': 'custom-select'}), initial=pytz.country_timezones['IN'][0]) def clean_username(self): @@ -158,8 +187,18 @@ class UserRegisterForm(forms.Form): class UserLoginForm(forms.Form): """Creates a form which will allow the user to log into the system.""" - username = forms.CharField(max_length=30) - password = forms.CharField(max_length=30, widget=forms.PasswordInput()) + username = forms.CharField( + max_length=30, + widget=forms.TextInput( + attrs={'class': form_input_class, 'placeholder': 'Username'} + ) + ) + password = forms.CharField( + max_length=30, + widget=forms.PasswordInput( + attrs={'class': form_input_class, 'placeholder': 'Password'} + ) + ) def clean(self): super(UserLoginForm, self).clean() @@ -297,8 +336,10 @@ class ProfileForm(forms.ModelForm): fields = ['first_name', 'last_name', 'institute', 'department', 'roll_number', 'position', 'timezone'] - first_name = forms.CharField(max_length=30) - last_name = forms.CharField(max_length=30) + first_name = forms.CharField(max_length=30, widget=forms.TextInput( + {'class': form_input_class, 'placeholder': "First Name"})) + last_name = forms.CharField(max_length=30, widget=forms.TextInput( + {'class': form_input_class, 'placeholder': "Last Name"})) def __init__(self, *args, **kwargs): if 'user' in kwargs: @@ -306,7 +347,23 @@ class ProfileForm(forms.ModelForm): super(ProfileForm, self).__init__(*args, **kwargs) self.fields['first_name'].initial = user.first_name self.fields['last_name'].initial = user.last_name - + self.fields['institute'].widget.attrs.update( + {'class': form_input_class} + ) + self.fields['department'].widget.attrs.update( + {'class': form_input_class} + ) + self.fields['roll_number'].widget.attrs.update( + {'class': form_input_class} + ) + self.fields['position'].widget.attrs.update( + {'class': form_input_class} + ) + self.fields['timezone'] = forms.ChoiceField( + choices=[(tz, tz) for tz in pytz.common_timezones], + help_text='All timings are shown based on the selected timezone', + widget=forms.Select({'class': 'custom-select'}) + ) class UploadFileForm(forms.Form): file = forms.FileField() diff --git a/yaksh/views.py b/yaksh/views.py index 0bf91eb..78b30bf 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -14,6 +14,7 @@ from django.utils import timezone from django.core.exceptions import ( MultipleObjectsReturned, ObjectDoesNotExist ) +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from taggit.models import Tag import json import six @@ -395,8 +396,19 @@ def prof_manage(request, msg=None): return my_redirect('/exam/login') if not is_moderator(user): return my_redirect('/exam/') - courses = Course.objects.filter(Q(creator=user) | Q(teachers=user), - is_trial=False).distinct() + courses = Course.objects.get_queryset().filter( + Q(creator=user) | Q(teachers=user), + is_trial=False).distinct().order_by("-id") + paginator = Paginator(courses, 10) + page = request.GET.get('page') + try: + courses = paginator.page(page) + except PageNotAnInteger: + # If page is not an integer, deliver first page. + courses = paginator.page(1) + except EmptyPage: + # If page is out of range (e.g. 9999), deliver last page of results. + courses = paginator.page(paginator.num_pages) trial_paper = AnswerPaper.objects.filter( user=user, question_paper__quiz__is_trial=True, course__is_trial=True @@ -416,7 +428,7 @@ def prof_manage(request, msg=None): else: answerpaper.delete() - context = {'user': user, 'courses': courses, + context = {'user': user, 'objects': courses, 'trial_paper': trial_paper, 'msg': msg } return my_render_to_response( |