diff options
-rw-r--r-- | tbc/models.py | 1 | ||||
-rw-r--r-- | tbc/templates/tbc/book-details.html | 6 | ||||
-rw-r--r-- | tbc/templates/tbc/book-review-details.html | 6 | ||||
-rw-r--r-- | tbc/templates/tbc/update-code.html | 27 | ||||
-rw-r--r-- | tbc/templates/tbc/upload-content.html | 14 | ||||
-rwxr-xr-x | tbc/views.py | 14 |
6 files changed, 60 insertions, 8 deletions
diff --git a/tbc/models.py b/tbc/models.py index 67a6d09..bd06c93 100644 --- a/tbc/models.py +++ b/tbc/models.py @@ -109,6 +109,7 @@ class Chapters(models.Model): name = models.CharField(max_length=200) notebook = models.FileField(upload_to=get_notebook_dir) book = models.ForeignKey(Book) + screen_shots = models.ManyToManyField('ScreenShots') def __unicode__(self): name = self.name or 'Chapter' return '%s'%(name) diff --git a/tbc/templates/tbc/book-details.html b/tbc/templates/tbc/book-details.html index 415666d..dc8c272 100644 --- a/tbc/templates/tbc/book-details.html +++ b/tbc/templates/tbc/book-details.html @@ -19,7 +19,11 @@ function redirectToIpynb(notebook) <div class="row-fluid"> {% for image in images %} <div class ="module-list"> - <img src="{% static 'uploads/' %}{{ image.image }}"> + {% if image.chapters_set.get.notebook %} + <a href="{% url 'tbc:ConvertNotebook' image.chapters_set.get.notebook %}"><img src="{% static 'uploads/' %}{{ image.image }}"></a> + {% else %} + <img src="{% static 'uploads/' %}{{ image.image }}"> + {% endif %} <center><p style="margin-top:30px;">{{ image.caption }}</p></center> </div> {% endfor %} diff --git a/tbc/templates/tbc/book-review-details.html b/tbc/templates/tbc/book-review-details.html index 1aa888c..e546220 100644 --- a/tbc/templates/tbc/book-review-details.html +++ b/tbc/templates/tbc/book-review-details.html @@ -5,7 +5,11 @@ <div class="row-fluid"> {% for image in images %} <div class ="module-list"> - <img src="{% static 'uploads/' %}{{ image.image }}"> + {% if image.chapters_set.get.notebook %} + <a href="{% url 'tbc:ConvertNotebook' image.chapters_set.get.notebook %}"><img src="{% static 'uploads/' %}{{ image.image }}"></a> + {% else %} + <img src="{% static 'uploads/' %}{{ image.image }}"> + {% endif %} <center><p style="margin-top:30px;">{{ image.caption }}</p></center> </div> {% endfor %} diff --git a/tbc/templates/tbc/update-code.html b/tbc/templates/tbc/update-code.html index cce2038..ee1d5b5 100644 --- a/tbc/templates/tbc/update-code.html +++ b/tbc/templates/tbc/update-code.html @@ -1,4 +1,15 @@ {% extends 'base.html' %} +{% block script %} +<script src="/static/js/jquery.js" type="text/javascript"></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 %} <div id="content-wrap" style="max-width:600px;"> <p>You are updating codes for the book {{ book.title }} by {{ book.author }}</p> @@ -6,17 +17,23 @@ <form action="/submit-code/" method=POST enctype="multipart/form-data"> {% csrf_token %} {% for chapter in chapters %} - <input type=text name=chapter{{forloop.counter}} value="{{ chapter.name }}"> - <input type=file name=notebook{{forloop.counter}}> + <input class="chapters" type=text id=chapter{{forloop.counter}} name=chapter{{forloop.counter}} value="{{ chapter.name }}"> + <input type=file name=notebook{{forloop.counter}}> {% endfor %} <br> <hr> <p>Upload 3 screenshots from any 3 random chapters and give proper captions</p> {% for screenshot in screenshots %} <input type=text name=caption{{forloop.counter}} value="{{ screenshot.caption }}"> - <input type=file name=image{{forloop.counter}}> - {% endfor %} - <center><input type=submit value=submit></center> + <label class="label label-info" for="chapter_image{{forloop.counter}}">Select Chapter: </label><select id=chapter_image{{forloop.counter}} name=chapter_image{{forloop.counter}}> + {% for chapter in chapters %} + <option name=image_chapter{{forloop.counter}} id=image_chapter{{forloop.counter}} value = chapter{{forloop.counter}} >{{ chapter.name}}</option> + {% endfor %} + </select> + <input type=file id=image{{forloop.counter}} name=image{{forloop.counter}}> + {% endfor %} + <br><br> + <center><input class="btn btn-primary" type=submit value=submit></center> </form> </div> {% endblock %} diff --git a/tbc/templates/tbc/upload-content.html b/tbc/templates/tbc/upload-content.html index 2423bd4..0c187d9 100644 --- a/tbc/templates/tbc/upload-content.html +++ b/tbc/templates/tbc/upload-content.html @@ -1,7 +1,14 @@ {% extends 'base.html' %} {% block script %} +<script src="/static/js/jquery.js" type="text/javascript"></script> <script> +$(document).ready(function() { + $(".chapters").on('change', function() { + var str = "option[id='image_"+$(this).attr('id')+"']"; + $(str).text($(this).val()); + }); +}); function validate_content() { no_notebooks = {{ no_notebooks }}.length; @@ -55,7 +62,7 @@ function validate_content() <form action="/submit-code/" 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> @@ -63,6 +70,11 @@ function validate_content() <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 }}"> + <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> diff --git a/tbc/views.py b/tbc/views.py index 049f838..930deb0 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -727,6 +727,7 @@ def SubmitCode(request): curr_book = curr_proposal.accepted except: return HttpResponseRedirect('/?no_book_alloted=true') + dict = {} if curr_proposal.status == "codes disapproved": if request.method == 'POST': chapters = Chapters.objects.filter(book=curr_book) @@ -735,6 +736,8 @@ def SubmitCode(request): for chapter in chapters: chapter.name = request.POST['chapter'+str(counter)] chapter.notebook = request.FILES['notebook'+str(counter)] + dict['chapter'+str(counter)] = chapter.name + chapter.screen_shots.clear() chapter.save() counter += 1 counter = 1 @@ -742,6 +745,12 @@ def SubmitCode(request): screenshot.caption = request.POST['caption'+str(counter)] screenshot.image = request.FILES['image'+str(counter)] screenshot.save() + chapter_image = request.POST['chapter_image'+str(counter)] + # if chapter name is unique then no need to convert the query + # set to list. Instead of filter get can be used then. + chapter = list(Chapters.objects.filter(name=dict[chapter_image]))[-1] + chapter.screen_shots.add(screenshot) + chapter.save() counter += 1 curr_proposal.status = "codes submitted" curr_proposal.save() @@ -752,6 +761,7 @@ def SubmitCode(request): 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() @@ -761,6 +771,10 @@ def SubmitCode(request): 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() book = Book.objects.order_by("-id")[0] proposal = Proposal.objects.get(accepted=book) proposal.status = "codes submitted" |