diff options
Diffstat (limited to 'tbc')
-rw-r--r-- | tbc/forms.py | 31 | ||||
-rw-r--r-- | tbc/models.py | 25 | ||||
-rw-r--r-- | tbc/views.py | 48 |
3 files changed, 77 insertions, 27 deletions
diff --git a/tbc/forms.py b/tbc/forms.py index 685b04f..b55bc5d 100644 --- a/tbc/forms.py +++ b/tbc/forms.py @@ -7,10 +7,23 @@ from tbc.models import * class UserProfileForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super(UserProfileForm, self).__init__(*args, **kwargs) + self.fields['about'].label = "About Yourself" + self.fields['insti_org'].label = "Institute/Organizaiton" + self.fields['dept_desg'].label = "Department/Branch/Designation" + self.fields['phone_no'].label = "Mobile No" + self.fields['about_proj'].label = "How did you come to know about the project" class Meta: model = Profile exclude = ('user') - + widgets = { + 'about':forms.TextInput(attrs={'placeholder':'Tell us about yourself'}), + 'insti_org':forms.TextInput(attrs={'placeholder':'Name of University/Organizaiton(if corporate)'}), + 'dept_desg':forms.TextInput(attrs={'placeholder':'Name of the Department/Branch or your designation'}), + 'phone_no':forms.TextInput(attrs={'placeholder':'Phone Number Please'}), + } + class UserRegisterForm(UserCreationForm): class Meta: @@ -29,6 +42,22 @@ class UserLoginForm(forms.Form): class BookForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super(BookForm, self).__init__(*args, **kwargs) + self.fields['publisher_place'].label = "Publisher with Place" + self.fields['isbn'].label = "ISBN No." + self.fields['edition'].label = "Book Edition" + self.fields['year_of_pub'].label = "Year of Publication" + self.fields['no_chapters'].label = "Number of Chapter" class Meta: model = Book exclude = ('contributor') + widgets = { + 'title':forms.TextInput(attrs={'placeholder':'Title of the Book'}), + 'author':forms.TextInput(attrs={'placeholder':'Author of the Book'}), + 'publisher_place':forms.TextInput(attrs={'placeholder':'Name of the Publisher with Place'}), + 'isbn':forms.TextInput(attrs={'placeholder':'Valid ISBN no. of the Book'}), + 'edition':forms.TextInput(attrs={'placeholder':'Edition of the Book'}), + 'year_of_pub':forms.TextInput(attrs={'placeholder':'Year when the Book was published'}), + 'no_chapters':forms.TextInput(attrs={'placeholder':'Total number of chapters in the Book'}), + } diff --git a/tbc/models.py b/tbc/models.py index 2749a8f..0a2d50c 100644 --- a/tbc/models.py +++ b/tbc/models.py @@ -14,6 +14,23 @@ CATEGORY = (("computer science", "Computer Science"), GENDER = (("male", "Male"), ("female", "Female")) +COURSES = (("mtech", "Mtech"), + ("me", "ME"), + ("msc", "MSc"), + ("mscit", "MScIT"), + ("mca", "MCA"), + ("be", "BE"), + ("bca", "BCA"), + ("bscit", "BScIt"), + ("others", "Others")) + +ABOUT_PROJ = (("pythontbc website", "PythonTBC Website"), + ("through friend", "Through Friend"), + ("through prof/teacher", "Through Prof/Teacher"), + ("through mailing list", "Through Mailing List"), + ("through posters in college", "Through Posters in College"), + ("others", "Others")) + def get_notebook_dir(instance, filename): return '%s/%s/%s' % (instance.book.contributor, instance.book.name, filename) @@ -27,10 +44,12 @@ class Profile(models.Model): user = models.ForeignKey(User) about = models.CharField(max_length=256) insti_org = models.CharField(max_length=128) + course = models.CharField(max_length=10, choices=COURSES) dept_desg = models.CharField(max_length=32) dob = models.DateField() gender = models.CharField(max_length=10, choices=GENDER) phone_no = models.CharField(max_length=15) + about_proj = models.CharField(max_length=50, choices=ABOUT_PROJ) def __unicode__(self): name = self.user.first_name or 'Profile' return '%s'%(name) @@ -45,11 +64,13 @@ class Reviewer(models.Model): class Book(models.Model): """Model to store the book details""" - name = models.CharField(max_length=32) + title = models.CharField(max_length=32) author = models.CharField(max_length=32) category = models.CharField(max_length=32, choices=CATEGORY) - publisher = models.CharField(max_length=50) + publisher_place = models.CharField(max_length=50) isbn = models.CharField(max_length=20) + edition = models.CharField(max_length=15) + year_of_pub = models.CharField(max_length=4) no_chapters = models.IntegerField(max_length=2) contributor = models.ForeignKey(Profile) reviewer = models.ForeignKey(Reviewer) diff --git a/tbc/views.py b/tbc/views.py index c75f095..2ac4847 100644 --- a/tbc/views.py +++ b/tbc/views.py @@ -26,7 +26,6 @@ def email_send(to,subject,msg): s.quit() - def Home(request): context = {} images = [] @@ -88,12 +87,6 @@ def UserRegister(request): context['form'] = form return render_to_response('tbc/register.html', context) -def UserLogout(request): - user = request.user - if user.is_authenticated() and user.is_active: - logout(request) - return redirect('/') - def UserProfile(request): user = request.user @@ -119,25 +112,14 @@ def UserProfile(request): return render_to_response('tbc/profile.html', context) else: return HttpResponse('invalid user') + - -def ChapterUpload(request): +def UserLogout(request): user = request.user - curr_book = Book.objects.order_by("-id")[0] - if request.method == 'POST': - for i in range(1, curr_book.no_chapters+1): - chapter = Chapters() - chapter.name = request.POST['chapter'+str(i)] - chapter.notebook = request.FILES['notebook'+str(i)] - chapter.book = curr_book - chapter.save() - return HttpResponseRedirect('/upload-images') - context = {} - context.update(csrf(request)) - context['user'] = user - context['no_notebooks'] = [i for i in range(1, curr_book.no_chapters+1)] - return render_to_response('tbc/upload-chapters.html', context) - + if user.is_authenticated() and user.is_active: + logout(request) + return redirect('/') + def SubmitBook(request): curr_user = request.user @@ -163,6 +145,24 @@ def SubmitBook(request): return render_to_response('tbc/submit-book.html', context) +def ChapterUpload(request): + user = request.user + curr_book = Book.objects.order_by("-id")[0] + if request.method == 'POST': + for i in range(1, curr_book.no_chapters+1): + chapter = Chapters() + chapter.name = request.POST['chapter'+str(i)] + chapter.notebook = request.FILES['notebook'+str(i)] + chapter.book = curr_book + chapter.save() + return HttpResponseRedirect('/upload-images') + context = {} + context.update(csrf(request)) + context['user'] = user + context['no_notebooks'] = [i for i in range(1, curr_book.no_chapters+1)] + return render_to_response('tbc/upload-chapters.html', context) + + def ImageUpload(request): user = request.user curr_book = Book.objects.order_by("-id")[0] |