summaryrefslogtreecommitdiff
path: root/tbc
diff options
context:
space:
mode:
authorhardythe12013-11-11 16:28:10 +0530
committerhardythe12013-11-11 16:28:10 +0530
commitacd1e3c64ebaa4b3c08758e40b5e9b8486fbd7a5 (patch)
treee77aff1b3667c6ffa752285b26fe3e8c16f01984 /tbc
parent5c96aba148286bb3989592701dc47d3c46563891 (diff)
downloadPython-TBC-Interface-acd1e3c64ebaa4b3c08758e40b5e9b8486fbd7a5.tar.gz
Python-TBC-Interface-acd1e3c64ebaa4b3c08758e40b5e9b8486fbd7a5.tar.bz2
Python-TBC-Interface-acd1e3c64ebaa4b3c08758e40b5e9b8486fbd7a5.zip
approve and push the repo
Diffstat (limited to 'tbc')
-rw-r--r--tbc/templates/tbc/book-review-details.html10
-rw-r--r--tbc/urls.py4
-rw-r--r--tbc/views.py55
3 files changed, 52 insertions, 17 deletions
diff --git a/tbc/templates/tbc/book-review-details.html b/tbc/templates/tbc/book-review-details.html
index f7c0d0e..704441f 100644
--- a/tbc/templates/tbc/book-review-details.html
+++ b/tbc/templates/tbc/book-review-details.html
@@ -17,10 +17,14 @@
{% endfor %}
</ol>
<hr>
-<form action="/approve-book/{{ book.id }}" method=POST enctype="multipart/form-data">
+<form action="/approve-book/{{ book.id }}" method="POST">
{% csrf_token %}
-<center><input type=submit name=approve value="Approve & Push">
-<input type=submit name=sendmail value="Notify for changes"></center>
+<select name=approve_notify>
+ <option value=none>Select an Action</option>
+ <option value="approve">Approve</option>
+ <option value="notify">Notify Changes</option>
+</select>
+<input type=submit value=GO>
</form>
<table>
<tr><td>Author: &nbsp;&nbsp;<td>{{ book.author }}
diff --git a/tbc/urls.py b/tbc/urls.py
index 4e75389..6ced6f9 100644
--- a/tbc/urls.py
+++ b/tbc/urls.py
@@ -11,11 +11,11 @@ urlpatterns = patterns('',
url(r'^submit-book/$', 'tbc.views.SubmitBook', name='SubmitBook'),
url(r'^upload-content/$', 'tbc.views.ContentUpload', name='ContentUpload'),
url(r'^get-zip/(?P<book_id>\d+)$', 'tbc.views.GetZip', name='GetZip'),
- #url(r'^upload-images/$', 'tbc.views.ImageUpload', name='ImageUpload'),
url(r'^browse-books/$', 'tbc.views.BrowseBooks', name='BrowseBooks'),
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'^book-details/(?P<book_id>\d+)/$', 'tbc.views.BookDetails', name='BookDetails'),
)
diff --git a/tbc/views.py b/tbc/views.py
index 8c22325..b229856 100644
--- a/tbc/views.py
+++ b/tbc/views.py
@@ -185,10 +185,9 @@ def ContentUpload(request):
context['user'] = user
context['no_images'] = [i for i in range(1, 4)]
return render_to_response('tbc/upload-images.html', context)"""
-
-def GetZip(request, book_id=None):
- user = request.user
+
+def generateZip(book_id):
book = Book.objects.get(id=book_id)
files_to_zip = []
file_path = os.path.abspath(os.path.dirname(__file__))
@@ -205,6 +204,12 @@ def GetZip(request, book_id=None):
zip_path = os.path.join(book.title, fname)
zip_file.write(fpath, zip_path)
zip_file.close()
+ return s, zipfile_name
+
+
+def GetZip(request, book_id=None):
+ user = request.user
+ s, zipfile_name = generateZip(book_id)
resp = HttpResponse(s.getvalue(), mimetype = "application/x-zip-compressed")
resp['Content-Disposition'] = 'attachment; filename=%s' % zipfile_name
return resp
@@ -233,27 +238,53 @@ def BookReview(request, book_id=None):
context['images'] = images
#context['user'] = user
context['book'] = book
+ 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.update(csrf(request))
return render_to_response('tbc/book-review.html', context)
def ApproveBook(request, book_id=None):
user = request.user
context = {}
- if method == 'POST' and request.POST.get('approve') == "approve":
- #book = Books.objects.get(id=book_id)
- #book.approved = True
- context.update(csrf(request))
+ if request.method == 'POST' and request.POST['approve_notify'] == "approve":
+ book = Book.objects.get(id=book_id)
+ book.approved = True
+ file_path = os.path.abspath(os.path.dirname(__file__))
+ zip_path = "/".join(file_path.split("/")[1:-2])
+ zip_path = "/"+zip_path+"/Python-Textbook-Companions/"
+ file_path = file_path+"/static/uploads/"
+ directory = file_path+book.contributor.user.first_name
+ os.chdir(directory)
+ fp = open(book.title+"/README.txt", 'w')
+ fp.write("Contributed By: "+book.contributor.user.first_name+" "+book.contributor.user.last_name+"\n")
+ fp.write("Course: "+book.contributor.course+"\n")
+ fp.write("College/Institute/Organization: "+book.contributor.insti_org+"\n")
+ fp.write("Department/Designation: "+book.contributor.dept_desg+"\n")
+ fp.write("Book Title: "+book.title+"\n")
+ fp.write("Author: "+book.author+"\n")
+ fp.write("Publisher: "+book.publisher_place+"\n")
+ fp.write("Year of publication: "+book.year_of_pub+"\n")
+ fp.write("Isbn: "+book.isbn+"\n")
+ fp.write("Edition: "+book.edition)
+ fp.close()
+ os.popen("cp -r "+book.title+" "+zip_path)
+ os.chdir(zip_path)
+ os.popen("git add .")
+ commit_msg = "adding "+book.title
+ os.popen("git commit -m "+commit_msg)
+ os.popen("git push")
context['user'] = user
- return render_to_response("Book Approved", context)
- elif method == 'POST' and request.POST.get('sendmail') == "sendmail":
- context.update(csrf(request))
+ return HttpResponse("worked")
+ elif request.method == 'POST' and request.POST['approve_notify'] == "notify":
context['user'] = user
- return render_to_response("Mail Sent", context)
-
+ return HttpResponse("Mail Sent")
+ else:
+ context['user'] = user
+ return HttpResponseRedirect("/book-review/"+book_id)
def BrowseBooks(request):
context = {}