diff options
Diffstat (limited to 'tbc')
-rw-r--r-- | tbc/templates/tbc/brokenbooks.html | 24 | ||||
-rw-r--r-- | tbc/templates/tbc/link_image.html | 47 | ||||
-rw-r--r-- | tbc/urls.py | 2 | ||||
-rwxr-xr-x | tbc/views.py | 51 |
4 files changed, 124 insertions, 0 deletions
diff --git a/tbc/templates/tbc/brokenbooks.html b/tbc/templates/tbc/brokenbooks.html new file mode 100644 index 0000000..07cfebb --- /dev/null +++ b/tbc/templates/tbc/brokenbooks.html @@ -0,0 +1,24 @@ +{% extends 'base.html' %} +{% load static %} + +{% block script %} +<script type="text/javascript"> +function submitBook() +{ + document.forms.brokenbooks.submit(); +} +</script> + +{% endblock %} +{% block content %} +<center><h4>Select any book from the drop down below to fix the broken link:</h4></center> +<form name="brokenbooks" action="/brokenbooks/" method=POST enctype="multipart/form-data"> +{% csrf_token %} +<center> + <select style="border-color:black" name="books" id="books" onchange="submitBook()"> + <option value=0>Select Book</option> + {% for book in books_to_link %} + <option value={{ book.id }}>{{ book }}</option> + {% endfor %} + </select> +{% endblock %} diff --git a/tbc/templates/tbc/link_image.html b/tbc/templates/tbc/link_image.html new file mode 100644 index 0000000..befa301 --- /dev/null +++ b/tbc/templates/tbc/link_image.html @@ -0,0 +1,47 @@ +{% extends 'base.html' %} +{% block content %} + + <center><font color='blue'><b> + {% if success %} + Thank you for your contribution.<br> + Click <a href={% url 'tbc:brokenbooks' %}>Broken Books</a> to contribute further.<br> + {% else %} + Link image for the book + {{ book.title }} by {{ book.author }}.<br> + Select an appropriate chapter from the dropdown for the corresponding image.<br> + You can verify using the chapters link given at the bottom.<br> + Once you are sure, click on Submit button. + </font></b> + </center> + <hr> + <form action="/link-image/" method=POST enctype="multipart/form-data"> + {% csrf_token %} + <input type="hidden" name="book" value={{book.id}}> + <div class ="row-fluid"> + {% for screenshot in screenshots %} + <!--<a href="/static/uploads/{{ screenshot.image }}" target="_blank">{{ screenshot }}</a>--> + <div class ="module-list"> + <img src="/static/uploads/{{ screenshot.image }}"> + <br> + <select style="border-color:black" name="chapters{{screenshot.id}}" id="chapters{{screenshot.id}}"> + {% for chapter in chapters %} + <option value={{ chapter.id }}>{{ chapter }}</option> + {% endfor %} + </select> + <hr> + </div> + {% endfor %} + </div> + <br> + <div > + <b><u> Below are the links to the chapters:</u></b><br> + + {% for chapter in chapters %} + <a href="{% url 'tbc:ConvertNotebook' chapter.notebook %}" target="_blank">{{ chapter }}</a> + <br> + {% endfor %} + </div> + <center><input class="btn btn-primary" type=submit value=submit></center> + </form> +{% endif %} +{% endblock %} diff --git a/tbc/urls.py b/tbc/urls.py index c558b6e..747a77d 100644 --- a/tbc/urls.py +++ b/tbc/urls.py @@ -49,6 +49,8 @@ urlpatterns = patterns('', 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'), + url(r'^brokenbooks/$', 'tbc.views.get_broken_books', name='brokenbooks'), + url(r'^link-image/$', 'tbc.views.link_image', name='link_image'), # ajax urls url(r'^ajax/matching-books/$', 'tbc.views.ajax_matching_books', name='AjaxMatchingBooks'), diff --git a/tbc/views.py b/tbc/views.py index 6955b8f..c161fb5 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -7,6 +7,7 @@ from django.core.context_processors import csrf from django.contrib.auth import authenticate, login, logout from django.contrib.admin.models import CHANGE from django.contrib.auth.decorators import login_required +from django.template import RequestContext from models import * from tbc.forms import * import local @@ -1362,3 +1363,53 @@ def ajax_matching_books(request): 'flag': flag } return render_to_response('tbc/ajax-matching-books.html', context) + + +def get_broken_books(request): + context = {} + ci = RequestContext(request) + if request.method == 'POST': + _book_id = request.POST["books"] + try: + book = Book.objects.get(id=_book_id) + except Book.DoesNotExist: + pass + else: + chapters = Chapters.objects.filter(book_id=_book_id) + screenshots = ScreenShots.objects.filter(book_id=_book_id) + context['book'] = book + context['chapters'] = chapters + context['screenshots'] = screenshots + return render_to_response('tbc/link_image.html', context, + context_instance = ci) + books = Book.objects.all() + broken_books = [] + for book in books: + chapters = Chapters.objects.filter(book=book) + screenshots = ScreenShots.objects.filter(book=book) + try: + if screenshots and chapters: + for screenshot in screenshots: + screenshot.chapters_set.get() + except Chapters.MultipleObjectsReturned: + pass + except Chapters.DoesNotExist: + broken_books.append(book) + context = {'books_to_link': broken_books} + return render_to_response('tbc/brokenbooks.html', context, context_instance=ci) + + +def link_image(request): + context = {} + context['success'] = False + ci = RequestContext(request) + if request.method == 'POST': + _book_id = request.POST["book"] + screenshots = ScreenShots.objects.filter(book_id=_book_id) + for screenshot in screenshots: + chapter_id = request.POST["chapters{0}".format(screenshot.id)] + chapter = Chapters.objects.get(id=chapter_id) + chapter.screen_shots.add(screenshot) + chapter.save() + context['success'] = True + return render_to_response('tbc/link_image.html', context, context_instance=ci) |