summaryrefslogtreecommitdiff
path: root/tbc
diff options
context:
space:
mode:
authorhardythe12014-12-23 13:32:13 +0530
committerhardythe12014-12-23 13:32:13 +0530
commit9b40244be612a6be04d4e337dc1c9862d059ef06 (patch)
tree85c017332e6bc3a21d79ec51be4c78f961ec8f65 /tbc
parent56138a036de7a9dee3cd3a786148752f443cb541 (diff)
downloadPython-TBC-Interface-9b40244be612a6be04d4e337dc1c9862d059ef06.tar.gz
Python-TBC-Interface-9b40244be612a6be04d4e337dc1c9862d059ef06.tar.bz2
Python-TBC-Interface-9b40244be612a6be04d4e337dc1c9862d059ef06.zip
added chapter links for old books & corrected a minor error for approving old books
Diffstat (limited to 'tbc')
-rw-r--r--tbc/templates/tbc/upload-content-old.html23
-rw-r--r--tbc/templates/tbc/upload-content.html2
-rwxr-xr-xtbc/views.py23
3 files changed, 38 insertions, 10 deletions
diff --git a/tbc/templates/tbc/upload-content-old.html b/tbc/templates/tbc/upload-content-old.html
index 8b3c692..5922082 100644
--- a/tbc/templates/tbc/upload-content-old.html
+++ b/tbc/templates/tbc/upload-content-old.html
@@ -41,6 +41,14 @@ function validate_content()
return true;
}
</script>
+<script>
+$(document).ready(function() {
+ $(".chapters").on('change', function() {
+ var str = "option[id='image_"+$(this).attr('id')+"']";
+ $(str).text($(this).val());
+ });
+});
+</script>
{% endblock %}
{% block content %}
@@ -55,16 +63,21 @@ function validate_content()
<form action="/submit-code-old/{{ curr_book.id }}" method=POST enctype="multipart/form-data">
{% csrf_token %}
{% for i in no_notebooks %}
- <input type=text id=chapter{{i}} name=chapter{{i}} placeholder="Chapter {{ forloop.counter }} name">
+ <input class="chapters" type=text id=chapter{{i}} name=chapter{{i}} placeholder="Chapter {{ forloop.counter }} name">
<input type=file id=notebook{{i}} name=notebook{{i}}>
{% endfor %}
<br>
<hr>
- <p>Upload screenshots of Plots/Graphs/Charts(if any) "that you have plotted" and not from the textbook itself from any cahpter. If there are no plots/graphs/charts, then upload a screenshot of any chapter. Give proper caption for the screen shots. Only .png files are acceptable.</p>
- {% for i in no_images %}
- <input type=text id=caption{{i}} name=caption{{i}} placeholder="Caption {{ forloop.counter }}">
- <input type=file id=image{{i}} name=image{{i}}>
+ <p>Upload screenshots of Plots/Graphs/Charts(if any) "that you have plotted" and not from the textbook itself from any chapter. If there are no plots/graphs/charts, then upload a screenshot of any chapter. Give proper caption for the screen shots. Only .png files are acceptable.</p>
+ {% for i in no_images %}
+ <input type=text id=caption{{i}} name=caption{{i}} placeholder="Caption {{ forloop.counter }}">
+ <label class="label label-info" for="chapter_image{{i}}">Select Chapter: </label><select id=chapter_image{{i}} name=chapter_image{{i}}>
+ {% for i in no_notebooks %}
+ <option name=image_chapter{{i}} id=image_chapter{{i}} value = chapter{{i}}>chapter {{i}}</option>
{% endfor %}
+ </select>
+ <input type=file id=image{{i}} name=image{{i}}>
+ {% endfor %}
<br><br>
<center><input class="btn btn-primary" type=submit value=submit onClick="return validate_content();"></center>
</form>
diff --git a/tbc/templates/tbc/upload-content.html b/tbc/templates/tbc/upload-content.html
index 0c187d9..56dfb69 100644
--- a/tbc/templates/tbc/upload-content.html
+++ b/tbc/templates/tbc/upload-content.html
@@ -67,7 +67,7 @@ function validate_content()
{% endfor %}
<br>
<hr>
- <p>Upload screenshots of Plots/Graphs/Charts(if any) "that you have plotted" and not from the textbook itself from any cahpter. If there are no plots/graphs/charts, then upload a screenshot of any chapter. Give proper caption for the screen shots. Only .png files are acceptable.</p>
+ <p>Upload screenshots of Plots/Graphs/Charts(if any) "that you have plotted" and not from the textbook itself from any chapter. If there are no plots/graphs/charts, then upload a screenshot of any chapter. Give proper caption for the screen shots. Only .png files are acceptable.</p>
{% for i in no_images %}
<input type=text id=caption{{i}} name=caption{{i}} placeholder="Caption {{ forloop.counter }}">
<label class="label label-info" for="chapter_image{{i}}">Select Chapter: </label><select id=chapter_image{{i}} name=chapter_image{{i}}>
diff --git a/tbc/views.py b/tbc/views.py
index 5b43585..ef389aa 100755
--- a/tbc/views.py
+++ b/tbc/views.py
@@ -335,11 +335,13 @@ def SubmitCodeOld(request, book_id=None):
user = request.user
curr_profile = Profile.objects.get(user=user)
context = {}
+ dict = {}
curr_book = Book.objects.get(id=book_id)
if request.method == 'POST':
for i in range(1, curr_book.no_chapters+1):
chapter = Chapters()
chapter.name = request.POST['chapter'+str(i)]
+ dict['chapter'+str(i)] = chapter.name
chapter.notebook = request.FILES['notebook'+str(i)]
chapter.book = curr_book
chapter.save()
@@ -349,6 +351,10 @@ def SubmitCodeOld(request, book_id=None):
screenshot.image = request.FILES['image'+str(i)]
screenshot.book = curr_book
screenshot.save()
+ chapter_image = request.POST['chapter_image'+str(i)]
+ chapter = list(Chapters.objects.filter(name=dict[chapter_image]))[-1]
+ chapter.screen_shots.add(screenshot)
+ chapter.save()
subject = "Python-TBC: Book Submission"
message = "Hi "+curr_book.reviewer.name+",\n"+\
"A book has been submitted on the Python TBC interface.\n"+\
@@ -954,9 +960,18 @@ def ApproveBook(request, book_id=None):
book = Book.objects.get(id=book_id)
book.approved = True
book.save()
- proposal = Proposal.objects.get(accepted=book)
- proposal.status = "book completed"
- proposal.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/"
@@ -990,7 +1005,7 @@ def ApproveBook(request, book_id=None):
"IIT Bombay, Powai, Mumbai - 400076\n"+\
"Kindly, write Python Texbook Companion on top of the envelope.\n\n\n"+\
"Regards,\n"+"Python TBC,\n"+"FOSSEE, IIT - Bombay"
- add_log(user, book, CHANGE, 'Book approved', proposal.id,
+ add_log(user, book, CHANGE, msg, proposal.id,
chat=subject + '\n' + message)
email_send(book.reviewer.email, subject, message)
context['user'] = user