summaryrefslogtreecommitdiff
path: root/tbc
diff options
context:
space:
mode:
authorHardik Ghaghada2015-03-13 15:28:12 +0530
committerHardik Ghaghada2015-03-13 15:28:12 +0530
commit8fc4844775edd500fd11508043d284048e1add96 (patch)
tree68aa99bd49bd0923c88fed10f263338ed33baff7 /tbc
parentcb03fbb819a28ef464c9d47b7f01d59b3119571d (diff)
parent707af515ef317adc74d6ad9f0c912eb598c5ff9f (diff)
downloadPython-TBC-Interface-8fc4844775edd500fd11508043d284048e1add96.tar.gz
Python-TBC-Interface-8fc4844775edd500fd11508043d284048e1add96.tar.bz2
Python-TBC-Interface-8fc4844775edd500fd11508043d284048e1add96.zip
Merge pull request #15 from FOSSEE/CleanURL
Clean url
Diffstat (limited to 'tbc')
-rw-r--r--tbc/models.py4
-rwxr-xr-xtbc/templates/base.html2
-rw-r--r--tbc/templates/tbc/book-details.html4
-rw-r--r--tbc/templates/tbc/book-review-details.html4
-rwxr-xr-xtbc/views.py51
5 files changed, 29 insertions, 36 deletions
diff --git a/tbc/models.py b/tbc/models.py
index 5c052a1..74419e4 100644
--- a/tbc/models.py
+++ b/tbc/models.py
@@ -56,11 +56,11 @@ BOOK_PREFERENCE = (("book1","1st Book"),
def get_notebook_dir(instance, filename):
- return '%s/%s/%s' % (instance.book.contributor, instance.book.title.replace(' ', '_'), filename.replace(' ', '_'))
+ return '%s/%s' % (instance.book.title.replace(' ', '_'), filename.replace(' ', '_'))
def get_image_dir(instance, filename):
- return '%s/%s/screenshots/%s' % (instance.book.contributor, instance.book.title.replace(' ', '_'), filename.replace(' ', '_'))
+ return '%s/screenshots/%s' % (instance.book.title.replace(' ', '_'), filename.replace(' ', '_'))
def get_sample_dir(instance, filename):
diff --git a/tbc/templates/base.html b/tbc/templates/base.html
index d246436..ca7bfc0 100755
--- a/tbc/templates/base.html
+++ b/tbc/templates/base.html
@@ -295,7 +295,7 @@
<div style="clear:both;"></div>
{% for item in items %}
<div class ="module-list">
- <a href="{% url 'tbc:BookDetails' item.book.id %}"><img src="{% static 'uploads/' %}{{ item.image.image }}"></a>
+ <a href="{% url 'tbc:BookDetails' item.book.id %}"><img src="{% static 'Python-Textbook-Companions/' %}{{ item.image.image }}"></a>
<center><a href="{% url 'tbc:BookDetails' item.book.id %}">{{ item.book.title }}</a></center>
</div>
{% endfor %}
diff --git a/tbc/templates/tbc/book-details.html b/tbc/templates/tbc/book-details.html
index dc8c272..99c8ba6 100644
--- a/tbc/templates/tbc/book-details.html
+++ b/tbc/templates/tbc/book-details.html
@@ -20,9 +20,9 @@ function redirectToIpynb(notebook)
{% for image in images %}
<div class ="module-list">
{% if image.chapters_set.get.notebook %}
- <a href="{% url 'tbc:ConvertNotebook' image.chapters_set.get.notebook %}"><img src="{% static 'uploads/' %}{{ image.image }}"></a>
+ <a href="{% url 'tbc:ConvertNotebook' image.chapters_set.get.notebook %}"><img src="{% static 'Python-Textbook-Companions/' %}{{ image.image }}"></a>
{% else %}
- <img src="{% static 'uploads/' %}{{ image.image }}">
+ <img src="{% static 'Python-Textbook-Companions/' %}{{ image.image }}">
{% endif %}
<center><p style="margin-top:30px;">{{ image.caption }}</p></center>
</div>
diff --git a/tbc/templates/tbc/book-review-details.html b/tbc/templates/tbc/book-review-details.html
index e546220..33401d5 100644
--- a/tbc/templates/tbc/book-review-details.html
+++ b/tbc/templates/tbc/book-review-details.html
@@ -6,9 +6,9 @@
{% for image in images %}
<div class ="module-list">
{% if image.chapters_set.get.notebook %}
- <a href="{% url 'tbc:ConvertNotebook' image.chapters_set.get.notebook %}"><img src="{% static 'uploads/' %}{{ image.image }}"></a>
+ <a href="{% url 'tbc:ConvertNotebook' image.chapters_set.get.notebook %}"><img src="{% static 'Python-Textbook-Companions/' %}{{ image.image }}"></a>
{% else %}
- <img src="{% static 'uploads/' %}{{ image.image }}">
+ <img src="{% static 'Python-Textbook-Companions/' %}{{ image.image }}">
{% endif %}
<center><p style="margin-top:30px;">{{ image.caption }}</p></center>
</div>
diff --git a/tbc/views.py b/tbc/views.py
index deb5123..5b2802c 100755
--- a/tbc/views.py
+++ b/tbc/views.py
@@ -9,6 +9,7 @@ from django.contrib.admin.models import CHANGE
from django.contrib.auth.decorators import login_required
from models import *
from tbc.forms import *
+import local
import os
import zipfile
import StringIO
@@ -1028,29 +1029,11 @@ def ApproveBook(request, book_id=None):
if is_reviewer(request.user):
if request.method == 'POST' and request.POST['approve_notify'] == "approve":
book = Book.objects.get(id=book_id)
- book.approved = True
- book.save()
- try:
- proposal = Proposal.objects.get(accepted=book)
- proposal.status = "book completed"
- proposal.save()
- msg = "Book Approved"
- except Proposal.DoesNotExist:
- proposal = Proposal()
- proposal.user = book.contributor
- proposal.accepted = book
- proposal.status = "book completed"
- proposal.save()
- msg = "Old Book Approved"
- file_path = os.path.abspath(os.path.dirname(__file__))
- copy_path = "/".join(file_path.split("/")[1:-2])
- copy_path = "/"+copy_path+"/Python-Textbook-Companions/"
- file_path = file_path+"/static/uploads/"
- directory = file_path+book.contributor.user.first_name
- os.chmod(directory, 0777)
- os.chdir(directory)
+ file_path = local.path
book_title = book.title.replace(" ", "_")
- fp = open(book_title+"/README.txt", 'w')
+ directory = file_path+book_title
+ os.chdir(directory)
+ fp = open(directory+"/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")
@@ -1062,7 +1045,20 @@ def ApproveBook(request, book_id=None):
fp.write("Isbn: "+book.isbn+"\n")
fp.write("Edition: "+book.edition)
fp.close()
- os.popen("cp -r '"+book_title+"' '"+copy_path+"'")
+ try:
+ proposal = Proposal.objects.get(accepted=book)
+ proposal.status = "book completed"
+ proposal.save()
+ msg = "Book Approved"
+ except Proposal.DoesNotExist:
+ proposal = Proposal()
+ proposal.user = book.contributor
+ proposal.accepted = book
+ proposal.status = "book completed"
+ proposal.save()
+ msg = "Old Book Approved"
+ book.approved = True
+ book.save()
subject = "Python-TBC: Book Completion"
message = """Hi """+book.contributor.user.first_name+""",\n
Congratulations !\nThe book - """+book.title+""" is now complete & published.\nPlease visit the link given below to download the forms to be filled to complete the formalities.\nhttp://tbc-python.fossee.in/internship-forms\nThe forms should be duly filled (fill only the sections which are applicable) & submitted at the following address:\nDr. Prabhu Ramachandran,\nDepartment of Aerospace Engineering,\nIIT Bombay, Powai, Mumbai - 400076\nKindly write Python Textbook Companion on top of the envelope.\nIf you already sent the forms then you may kindly ignore this mail.\n\nThank You for your contribution !\nRegards,\n Python TBC Team,\nFOSSEE - IIT Bombay"""
@@ -1151,8 +1147,7 @@ def BrowseBooks(request):
def ConvertNotebook(request, notebook_path=None):
context = {}
- path = os.path.abspath(os.path.dirname(__file__))
- path = path+"/static/uploads/"
+ path = local.path
path = path+notebook_path
notebook_name = path.split("/")[-1:]
notebook_name = notebook_name[0].split(".")[0]
@@ -1160,13 +1155,11 @@ def ConvertNotebook(request, notebook_path=None):
path = "/".join(path)+"/"
os.chdir(path)
try:
- template = path.split("/")[8:]
- template = "/".join(template)+notebook_name+".html"
+ template = path+notebook_name+".html"
return render_to_response(template, {})
except:
os.popen("ipython nbconvert --to html \""+path+notebook_name+".ipynb\"")
- template = path.split("/")[8:]
- template = "/".join(template)+notebook_name+".html"
+ template = path+notebook_name+".html"
return render_to_response(template, {})