summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhardythe12014-07-30 17:13:02 +0530
committerhardythe12014-07-30 17:13:02 +0530
commit250fc9e92257994e5610892be40ab62939fbcbac (patch)
tree04290874702f299584ee821d20c0e8d7af482724
parentf71c45f91d582375643de198880b87e994300596 (diff)
downloadPython-TBC-Interface-250fc9e92257994e5610892be40ab62939fbcbac.tar.gz
Python-TBC-Interface-250fc9e92257994e5610892be40ab62939fbcbac.tar.bz2
Python-TBC-Interface-250fc9e92257994e5610892be40ab62939fbcbac.zip
added changes to check matching books while submitting proposal
-rwxr-xr-xtbc/templates/base.html4
-rw-r--r--tbc/templates/tbc/ajax-matching-books.html24
-rw-r--r--tbc/templates/tbc/submit-proposal.html63
-rw-r--r--tbc/urls.py4
-rwxr-xr-xtbc/views.py31
5 files changed, 116 insertions, 10 deletions
diff --git a/tbc/templates/base.html b/tbc/templates/base.html
index d0c8708..91e8454 100755
--- a/tbc/templates/base.html
+++ b/tbc/templates/base.html
@@ -64,8 +64,6 @@
</style>
{% endblock %}
- {% block script %}
- {% endblock %}
</head>
<body>
@@ -230,6 +228,8 @@
ga('send', 'pageview');
</script>
<!-- / google analytics -->
+ {% block script %}
+ {% endblock %}
</body>
</html>
diff --git a/tbc/templates/tbc/ajax-matching-books.html b/tbc/templates/tbc/ajax-matching-books.html
new file mode 100644
index 0000000..c5fbfa8
--- /dev/null
+++ b/tbc/templates/tbc/ajax-matching-books.html
@@ -0,0 +1,24 @@
+<html>
+<body>
+<div>
+ <span id="flag">{% if flag %}match exists{% endif %}</span>
+ <div id="matches">
+ <center><h5>The books you have proposed may already be <b>under progress</b> or <b>completed</b> by some other contributor. Kindly verify and submit the proposal.</h5></center>
+ <hr>
+ {% for match in matches %}
+ {% if match %}
+ <b><h5>Potential matching books for your book preference {{ forloop.counter }}</h5></b>
+ {% else %}
+ <h5>No matching books found for book preference {{ forloop.counter }}</h5>
+ {% endif %}
+ <ul>
+ {% for book in match %}
+ <li>{{ book.title }} by {{ book.author }}</li>
+ {% endfor %}
+ </ul>
+ <hr>
+ {% endfor %}
+ </div>
+</div>
+</body>
+</html>
diff --git a/tbc/templates/tbc/submit-proposal.html b/tbc/templates/tbc/submit-proposal.html
index 1f091bb..1da0e22 100644
--- a/tbc/templates/tbc/submit-proposal.html
+++ b/tbc/templates/tbc/submit-proposal.html
@@ -1,14 +1,73 @@
{% extends 'base.html' %}
{% block content %}
<div id="content-wrap" style="max-width:600px;">
- <form action="/submit-proposal/" method=POST enctype="multipart/form-data">
+ <form id="proposal-form" action="/submit-proposal/" method=POST enctype="multipart/form-data">
{% csrf_token %}
{% for form in book_forms %}
<h4>Book Preference {{ forloop.counter }}</h4>
{{ form.as_p }}
{% endfor %}
<hr>
- <input class="btn btn-primary" type=submit value=submit>
+ <input id="proposal-form-submit" class="btn btn-primary" type=submit value=submit>
</form>
</div>
+
+
+<!-- Button to trigger modal -->
+<!-- Modal -->
+<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
+ <h3 id="myModalLabel">Potential Matching Books</h3>
+ </div>
+ <div class="modal-body">
+ <p>One fine body…</p>
+ </div>
+ <div class="modal-footer">
+ <button class="btn btn-primary" data-dismiss="modal">Go Back</button>
+ <button id="modal-submit-proposal" class="btn btn-danger">Submit Proposal</button>
+ </div>
+</div>
+{% endblock %}
+
+{% block script %}
+ <script>
+ $(document).ready(function() {
+ $("#proposal-form-submit").click(function(e) {
+ var i = 0;
+ var titles = [];
+ $titles = $("input[name='title']");
+ $titles = $("input[name='title']");
+ $titles.each(function(index, value) {
+ titles[i] = $(this).val();
+ ++i;
+ });
+ titles = JSON.stringify(titles);
+
+ $.ajax({
+ url: "/ajax/matching-books/",
+ type: "POST",
+ dataType: "html",
+ data: {
+ titles: titles
+ },
+ success: function(output) {
+ console.log(output);
+ var $output = $(output);
+ if($output.find("#flag").html() == "") {
+ $("#proposal-form").submit();
+ } else {
+ $(".modal-body").html($output.find("#matches").html());
+ $("#myModal").modal();
+ }
+ }
+ });
+ e.preventDefault();
+ });
+ $("#modal-submit-proposal").click(function(e){
+ $("#proposal-form").submit();
+ e.preventDefault();
+ });
+ });
+ </script>
{% endblock %}
diff --git a/tbc/urls.py b/tbc/urls.py
index 57a2ddd..74c3c2e 100644
--- a/tbc/urls.py
+++ b/tbc/urls.py
@@ -36,4 +36,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'),
+
+ # 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 c2356c7..49505bc 100755
--- a/tbc/views.py
+++ b/tbc/views.py
@@ -1,5 +1,6 @@
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response, redirect
+from django.views.decorators.csrf import csrf_exempt
from django.core.context_processors import csrf
from django.contrib.auth import authenticate, login, logout
from models import *
@@ -11,6 +12,7 @@ import smtplib
import shutil
import string
import random
+import json
from email.mime.text import MIMEText
@@ -314,12 +316,6 @@ def SubmitProposal(request):
book_editions = request.POST.getlist('edition')
book_years = request.POST.getlist('year_of_pub')
book_chapters = request.POST.getlist('no_chapters')
- """for title in book_titles:
- temp_books = Book.objects.filter(title__icontains=title)
- for book in temp_books:
- matching_books.append(book)
- matching_books = set(matching_books)
- return HttpResponse(matching_books)"""
for item in range(3):
tempbook = TempBook()
tempbook.title = book_titles[item]
@@ -776,3 +772,26 @@ def ConvertNotebook(request, notebook_path=None):
template = path.split("/")[8:]
template = "/".join(template)+notebook_name+".html"
return render_to_response(template, {})
+
+
+# ajax views
+@csrf_exempt
+def ajax_matching_books(request):
+ titles = request.POST["titles"]
+ titles = json.loads(titles)
+ matches = []
+ i = 1
+ flag = None
+ for title in titles:
+ if title:
+ match = TempBook.objects.filter(title__icontains=title)
+ if match:
+ flag = True
+ matches.append(match)
+ else:
+ matches.append(None)
+ context = {
+ 'matches': matches,
+ 'flag': flag
+ }
+ return render_to_response('tbc/ajax-matching-books.html', context)