summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhardythe12015-08-14 08:50:35 +0530
committerhardythe12015-08-14 08:50:35 +0530
commit1c72a02860e8d4cb3333384d55f8c7c92c476ebe (patch)
tree4152f0cae7e604c7de41662b5c32a5a85b8714a0
parente89be11e0a16c52b9fb643f22e9d6b83f784ba40 (diff)
parent4ec13d0acd72e1a4a26abe98d6c5b8b1812a3658 (diff)
downloadPython-TBC-Interface-1c72a02860e8d4cb3333384d55f8c7c92c476ebe.tar.gz
Python-TBC-Interface-1c72a02860e8d4cb3333384d55f8c7c92c476ebe.tar.bz2
Python-TBC-Interface-1c72a02860e8d4cb3333384d55f8c7c92c476ebe.zip
Merge branch 'master' of https://github.com/FOSSEE/Python-TBC-Interface
-rw-r--r--tbc/templates/tbc/brokenbooks.html24
-rw-r--r--tbc/templates/tbc/link_image.html47
-rw-r--r--tbc/urls.py2
-rwxr-xr-xtbc/views.py51
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..03cdcec
--- /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/Python-Textbook-Companions/{{ 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)