diff options
author | hardythe1 | 2013-11-22 17:46:50 +0530 |
---|---|---|
committer | hardythe1 | 2013-11-22 17:46:50 +0530 |
commit | cc4922f209ac8fdb5930bdcef91b11e606a75af2 (patch) | |
tree | 4c44c41b846de110e3007ee61ddb24f3e5fc25b1 | |
parent | c55a9304cac3dfc0f8ad77e19086136397f783f0 (diff) | |
download | Python-TBC-Interface-cc4922f209ac8fdb5930bdcef91b11e606a75af2.tar.gz Python-TBC-Interface-cc4922f209ac8fdb5930bdcef91b11e606a75af2.tar.bz2 Python-TBC-Interface-cc4922f209ac8fdb5930bdcef91b11e606a75af2.zip |
changes to redirect reviewer to resp. interface & notify user about chages required
-rw-r--r-- | tbc/models.py | 8 | ||||
-rwxr-xr-x | tbc/templates/base.html | 45 | ||||
-rw-r--r-- | tbc/templates/tbc/notify-changes.html | 16 | ||||
-rw-r--r-- | tbc/urls.py | 2 | ||||
-rw-r--r-- | tbc/views.py | 132 |
5 files changed, 143 insertions, 60 deletions
diff --git a/tbc/models.py b/tbc/models.py index 5fe993b..7defae8 100644 --- a/tbc/models.py +++ b/tbc/models.py @@ -64,11 +64,11 @@ class Reviewer(models.Model): class Book(models.Model): """Model to store the book details""" - title = models.CharField(max_length=32) - author = models.CharField(max_length=32) + title = models.CharField(max_length=500) + author = models.CharField(max_length=300) category = models.CharField(max_length=32, choices=CATEGORY) - publisher_place = models.CharField(max_length=50) - isbn = models.CharField(max_length=20) + publisher_place = models.CharField(max_length=150) + isbn = models.CharField(max_length=50) edition = models.CharField(max_length=15) year_of_pub = models.CharField(max_length=4) no_chapters = models.IntegerField(max_length=2) diff --git a/tbc/templates/base.html b/tbc/templates/base.html index 9a47446..73ccc32 100755 --- a/tbc/templates/base.html +++ b/tbc/templates/base.html @@ -51,22 +51,35 @@ </ul> </li> </ul> - {% if not user %} - <form action="" method="post" class="navbar-form pull-right"> - <button type="button" class="btn" onclick='location.replace("{% url 'tbc:UserLogin' %}");'>Login</button> - <button type="button" class="btn" onclick='location.replace("{% url 'tbc:UserRegister' %}");'>Sign Up</button> - </form> - {% else %} - <div class="btn-group pull-right"> - <button class="btn">{{ user.first_name }} {{ user.last_name }}</button> - <button class="btn dropdown-toggle" data-toggle="dropdown"> - <span class="caret"></span> - </button> - <ul class="dropdown-menu"> - <li><a href="{% url 'tbc:SubmitBook' %}">Submit Book</a></li> - <li><a href="{% url 'tbc:UserLogout' %}">Logout</a></li> - </ul> - </div> + {% if user %} + <div class="btn-group pull-right"> + <button class="btn">{{ user.first_name }} {{ user.last_name }}</button> + <button class="btn dropdown-toggle" data-toggle="dropdown"> + <span class="caret"></span> + </button> + <ul class="dropdown-menu"> + <li><a href="{% url 'tbc:SubmitBook' %}">Submit Book</a></li> + <li><a href="{% url 'tbc:UserLogout' %}">Logout</a></li> + </ul> + </div> + {% endif %} + {% if reviewer %} + <div class="btn-group pull-right"> + <button class="btn">{{ reviewer.first_name }} {{ reviewer.last_name }}</button> + <button class="btn dropdown-toggle" data-toggle="dropdown"> + <span class="caret"></span> + </button> + <ul class="dropdown-menu"> + <li><a href="{% url 'tbc:BookReview' %}">Review Books</a></li> + <li><a href="{% url 'tbc:UserLogout' %}">Logout</a></li> + </ul> + </div> + {% endif %} + {% if anonymous %} + <form action="" method="post" class="navbar-form pull-right"> + <button type="button" class="btn" onclick='location.replace("{% url 'tbc:UserLogin' %}");'>Login</button> + <button type="button" class="btn" onclick='location.replace("{% url 'tbc:UserRegister' %}");'>Sign Up</button> + </form> {% endif %} </div><!--/.nav-collapse --> diff --git a/tbc/templates/tbc/notify-changes.html b/tbc/templates/tbc/notify-changes.html new file mode 100644 index 0000000..ffb2199 --- /dev/null +++ b/tbc/templates/tbc/notify-changes.html @@ -0,0 +1,16 @@ +{% extends 'base.html' %} +{% load static %} +{% block content %} +<center><h3>Notify Changes</h3></center> +<p>Notifing Chages for book {{ book.title }} to {{ book.contributor.user.first_name }} {{ book.contributor.user.last_name }} +<form action="/notify-changes/{{ book_id }}" method=POST enctype="multipart/form-data"> +{% csrf_token %} + <table> + <tr><td>To</td></tr> + <tr><td><input type="text" value="{{ mailto }}" readonly></td></tr> + <tr><td>Changes Required</td></tr> + <tr><td><textarea rows="5" cols="100" name="changes_required"></textarea></td></tr> + <tr><td><input type="submit" value="Send"></td></tr> + </table> +</form> +{% endblock %} diff --git a/tbc/urls.py b/tbc/urls.py index 6ced6f9..5eae31c 100644 --- a/tbc/urls.py +++ b/tbc/urls.py @@ -15,7 +15,9 @@ urlpatterns = patterns('', url(r'^browse-books/(?P<category>.+)$', 'tbc.views.BrowseBooks', name='BrowseBooks'), url(r'^book-details/(?P<book_id>\d+)/$', 'tbc.views.BookDetails', name='BookDetails'), + url(r'^book-review/$', 'tbc.views.BookReview', name='BookReview'), url(r'^book-review/(?P<book_id>\d+)$', 'tbc.views.BookReview', name='BookReview'), url(r'^approve-book/(?P<book_id>\d+)$', 'tbc.views.ApproveBook', name='ApproveBook'), + url(r'^notify-changes/(?P<book_id>\d+)$', 'tbc.views.NotifyChanges', name='NotifyChanges'), ) diff --git a/tbc/views.py b/tbc/views.py index 7c3f43b..59de552 100644 --- a/tbc/views.py +++ b/tbc/views.py @@ -24,20 +24,24 @@ def email_send(to,subject,msg): smtpObj.sendmail(mail_from, to, message.as_string()) except SMTPException: return HttpResponse("Error:unable to send email") + + +def is_reviewer(user): + if user.groups.filter(name='reviewer').count() == 1: + return True + def Home(request): context = {} images = [] if request.user.is_anonymous(): - context['user'] = None + context['anonymous'] = True else: - context['user'] = request.user + if is_reviewer(request.user): + context['reviewer'] = request.user + else: + context['user'] = request.user books = Book.objects.filter(approved=True)[0:6] - """if len(books)>=6: - context['books'] = books - else: - books = Book.objects.all() - context['books'] = books""" for book in books: images.append(ScreenShots.objects.filter(book=book)[0]) context['images'] = images @@ -50,19 +54,24 @@ def Home(request): def UserLogin(request): + context = {} if request.method == 'POST': username = request.POST['username'] password = request.POST['password'] curr_user = authenticate(username=username, password=password) login(request, curr_user) - try: - Profile.objects.get(user=curr_user) - return HttpResponseRedirect("/") - except: - return HttpResponseRedirect("/profile") + if curr_user.groups.filter(name='reviewer').count() == 1: + context['reviewer'] = curr_user + return HttpResponseRedirect("/book-review") + else: + context['user'] = curr_user + try: + Profile.objects.get(user=curr_user) + return HttpResponseRedirect("/") + except: + return HttpResponseRedirect("/profile") else: form = UserLoginForm() - context = {} context.update(csrf(request)) context['form'] = form return render_to_response('tbc/login.html', context) @@ -122,6 +131,7 @@ def UserLogout(request): def SubmitBook(request): curr_user = request.user + context = {} if request.method == 'POST': form = BookForm(request.POST) if form.is_valid(): @@ -129,15 +139,15 @@ def SubmitBook(request): profile = Profile.objects.get(user=request.user.id) data.contributor = profile data.save() + context['user'] = curr_user return HttpResponseRedirect('/upload-content') else: - context = {} context.update(csrf(request)) context['form'] = form + context['user'] = curr_user return render_to_response('tbc/submit-book.html', context) else: form = BookForm() - context = {} context.update(csrf(request)) context['form'] = form context['user'] = curr_user @@ -213,9 +223,12 @@ def GetZip(request, book_id=None): def BookDetails(request, book_id=None): context = {} if request.user.is_anonymous(): - context['user'] = None + context['anonymous'] = True else: - context['user'] = request.user + if is_reviewer(request.user): + context['reviewer'] = request.user + else: + context['user'] = request.user book = Book.objects.get(id=book_id) chapters = Chapters.objects.filter(book=book) images = ScreenShots.objects.filter(book=book) @@ -227,21 +240,25 @@ def BookDetails(request, book_id=None): def BookReview(request, book_id=None): context = {} - if book_id: - book = Book.objects.get(id=book_id) - chapters = Chapters.objects.filter(book=book) - images = ScreenShots.objects.filter(book=book) - context['chapters'] = chapters - context['images'] = images - #context['user'] = user - context['book'] = book - context.update(csrf(request)) - return render_to_response('tbc/book-review-details.html', context) + if is_reviewer(request.user): + if book_id: + book = Book.objects.get(id=book_id) + chapters = Chapters.objects.filter(book=book) + images = ScreenShots.objects.filter(book=book) + context['chapters'] = chapters + context['images'] = images + context['book'] = book + context['reviewer'] = request.user + context.update(csrf(request)) + return render_to_response('tbc/book-review-details.html', context) + else: + books = Book.objects.filter(approved=False) + context['books'] = books + context['reviewer'] = request.user + context.update(csrf(request)) + return render_to_response('tbc/book-review.html', context) else: - books = Book.objects.filter(approved=False) - context['books'] = books - context.update(csrf(request)) - return render_to_response('tbc/book-review.html', context) + return HttpResponse("You are not allowed to view this page.") def ApproveBook(request, book_id=None): @@ -271,26 +288,61 @@ def ApproveBook(request, book_id=None): fp.write("Edition: "+book.edition) fp.close() x = shutil.copytree(book.title, zip_path+book.title) + subject = "Python-TBC: Book Completion" + message = "Hi "+book.contributor.user.first_name+",\n"+\ + "Congratulations !\n"+\ + "The book - "+book.title+" is now complete.\n"+\ + "Please visit the below given link to download the forms to be filled to complete the formalities.\n"+\ + "http://dev.fossee.in/internship-forms"+"\n"+\ + "The forms should be duly filled(fill only sections which are applicable) & submit at the following address:\n"+\ + "Dr. Prabhu Ramachandran, \n"+\ + "Department of Aerospace Engineering,\n"+\ + "IIT Bombay, Powai, Mumbai - 400076\n"+\ + "Kindly, write Python Texbook Companion on top of the envelope.\n\n\n"+\ + "Regards,\n"+"Python TBC,\n"+"FOSSEE, IIT - Bombay" + return HttpResponse(message) + email_send(book.reviewer.email, subject, message) context['user'] = user return HttpResponseRedirect("/book-review") elif request.method == 'POST' and request.POST['approve_notify'] == "notify": - context['user'] = user - book = Book.objects.get(id=book_id) - subject = "Python-TBC: Book Submission" - message = "Hi "+Book.reviewer.name+",\n"\ - "A book has been submitted on the interface.\n"\ - "" - return HttpResponse("Mail Sent") + return HttpResponseRedirect("/notify-changes/"+book_id) else: context['user'] = user return HttpResponseRedirect("/book-review/"+book_id) + + +def NotifyChanges(request, book_id=None): + context = {} + if is_reviewer(request.user): + book = Book.objects.get(id=book_id) + if request.method == 'POST': + changes_required = request.POST['changes_required'] + subject = "Python-TBC: Corrections Required" + message = "Hi, "+book.contributor.user.first_name+",\n"+\ + "Book titled, "+book.title+" requires following changes: \n"+\ + changes_required + context.update(csrf(request)) + email_send(book.contributor.user.email, subject, message) + else: + context['book'] = book + context['book_id'] = book_id + context['mailto'] = book.contributor.user.email + context['reviewer'] = request.user + context.update(csrf(request)) + return render_to_response('tbc/notify-changes.html', context) + else: + return HttpResponse('invalid user') + def BrowseBooks(request): context = {} if request.user.is_anonymous(): - context['user'] = None + context['anonymous'] = True else: - context['user'] = request.user + if is_reviewer(request.user): + context['reviewer'] = request.user + else: + context['user'] = request.user images = [] if request.method == 'POST': category = request.POST['category'] |