From b13f51268caacf987365c3cda89b812d9d1b2255 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Tue, 11 Aug 2015 17:34:38 +0530 Subject: interface to fix broken books. --- tbc/templates/tbc/brokenbooks.html | 24 ++++++++++++++++++ tbc/templates/tbc/link_image.html | 47 +++++++++++++++++++++++++++++++++++ tbc/urls.py | 2 ++ tbc/views.py | 51 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 tbc/templates/tbc/brokenbooks.html create mode 100644 tbc/templates/tbc/link_image.html (limited to 'tbc') 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 %} + + +{% endblock %} +{% block content %} +

Select any book from the drop down below to fix the broken link:

+
+{% csrf_token %} +
+ +{% 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 %} + +
+ {% if success %} + Thank you for your contribution.
+ Click Broken Books to contribute further.
+ {% else %} + Link image for the book + {{ book.title }} by {{ book.author }}.
+ Select an appropriate chapter from the dropdown for the corresponding image.
+ You can verify using the chapters link given at the bottom.
+ Once you are sure, click on Submit button. +
+
+
+ + {% csrf_token %} + +
+ {% for screenshot in screenshots %} + +
+ +
+ +
+
+ {% endfor %} +
+
+
+ Below are the links to the chapters:
+ + {% for chapter in chapters %} + {{ chapter }} +
+ {% endfor %} +
+
+ +{% 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\d+)$', 'tbc.views.BookReview', name='BookReview'), url(r'^approve-book/(?P\d+)$', 'tbc.views.ApproveBook', name='ApproveBook'), url(r'^notify-changes/(?P\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) -- cgit