diff options
Diffstat (limited to 'tbc')
-rw-r--r-- | tbc/admin.py | 1 | ||||
-rw-r--r-- | tbc/models.py | 3 | ||||
-rwxr-xr-x | tbc/templates/base.html | 20 | ||||
-rw-r--r-- | tbc/templates/tbc/review-proposal.html | 8 | ||||
-rw-r--r-- | tbc/templates/tbc/submit-sample.html | 27 | ||||
-rw-r--r-- | tbc/templates/tbc/upload-content.html | 8 | ||||
-rw-r--r-- | tbc/urls.py | 3 | ||||
-rwxr-xr-x | tbc/views.py | 60 |
8 files changed, 97 insertions, 33 deletions
diff --git a/tbc/admin.py b/tbc/admin.py index 2a82b76..9983e27 100644 --- a/tbc/admin.py +++ b/tbc/admin.py @@ -8,3 +8,4 @@ admin.site.register(Chapters) admin.site.register(ScreenShots) admin.site.register(TempBook) admin.site.register(Proposal) +admin.site.register(SampleNotebook) diff --git a/tbc/models.py b/tbc/models.py index a1f2408..4b474f2 100644 --- a/tbc/models.py +++ b/tbc/models.py @@ -146,3 +146,6 @@ class SampleNotebook(models.Model): proposal = models.ForeignKey(Proposal) name = models.CharField(max_length=40) sample_notebook = models.FileField(upload_to=get_sample_dir) + def __unicode__(self): + notebook = self.proposal.accepted.title or 'notebook' + return '%s'%(notebook) diff --git a/tbc/templates/base.html b/tbc/templates/base.html index 91e8454..9708a53 100755 --- a/tbc/templates/base.html +++ b/tbc/templates/base.html @@ -94,7 +94,7 @@ <ul class="dropdown-menu"> <li><a href="{% url 'tbc:SubmitProposal' %}">Submit Proposal</a></li> <li><a href="{% url 'tbc:SubmitSample' %}">Submit Sample Notebook</a></li> - <li><a href="{% url 'tbc:SubmitBook' %}">Submit Book</a></li> + <li><a href="{% url 'tbc:SubmitCode' %}">Submit Codes</a></li> <li><a href="{% url 'tbc:UpdateBook' %}">Update Submission</a></li> <li><a href="{% url 'tbc:UpdatePassword' %}">Update Password</a></li> <li><a href="{% url 'tbc:UserLogout' %}">Logout</a></li> @@ -188,6 +188,24 @@ </center> <div class="clearfix"></div> {% endif %} + {% if no_book_alloted %} + <center> + <div class="alert" style="width:400px;height:25px;"> + <a class="close" data-dismiss="alert" href="#">×</a> + <p>There is no book alloted to you. You cannot submit codes.</p> + </div> + </center> + <div class="clearfix"></div> + {% endif %} + {% if sample_notebook %} + <center> + <div class="alert" style="width:550px;height:40px;"> + <a class="close" data-dismiss="alert" href="#">×</a> + <p>Sample notebook has been submitted successfully. Please be patient while the reviewer reviews your codes & get backs to you.</p> + </div> + </center> + <div class="clearfix"></div> + {% endif %} <div class="row-fluid"> <center><h3>Recent Submissions</h3></center> {% for item in items %} diff --git a/tbc/templates/tbc/review-proposal.html b/tbc/templates/tbc/review-proposal.html index 98c26a1..a71ebfc 100644 --- a/tbc/templates/tbc/review-proposal.html +++ b/tbc/templates/tbc/review-proposal.html @@ -9,11 +9,11 @@ <ol> {% for proposal in proposals %} <li><h4>Propsal from {{ proposal.user.user.first_name }} {{ proposal.user.user.last_name }}</h4></li> - <div class="accordion" id="accordion2"> + <div class="accordion" id="accordion{{ forloop.counter }}"> {% for textbook in proposal.textbooks.all %} <div class="accordion-group"> <div class="accordion-heading"> - <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapse{{forloop.counter}}"> + <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion{{ forloop.counter }}" href="#collapse{{forloop.counter}}"> Book Preference {{ forloop.counter }} - {{ textbook.title }} </a> </div> @@ -41,11 +41,11 @@ <ol> {% for proposal in old_proposals %} <h4><li>Propsal from {{ proposal.proposal.user.user.first_name }} {{ proposal.proposal.user.user.last_name }}</h4></li> - <div class="accordion" id="accordion2"> + <div class="accordion" id="accordion{{ forloop.counter }}"> {% for textbook in proposal.proposal.textbooks.all %} <div class="accordion-group"> <div class="accordion-heading"> - <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapse{{forloop.counter}}"> + <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion{{ forloop.counter }}" href="#collapse{{forloop.counter}}"> Book Preference {{ forloop.counter }} - {{ textbook.title }} </a> </div> diff --git a/tbc/templates/tbc/submit-sample.html b/tbc/templates/tbc/submit-sample.html index b26e8ae..f259ffc 100644 --- a/tbc/templates/tbc/submit-sample.html +++ b/tbc/templates/tbc/submit-sample.html @@ -26,13 +26,24 @@ function validate_content() <div id="content-wrap" style="max-width:600px;"> <h5>You are uploading sample notebook for the book {{ proposal.accepted }} by {{ proposal.accepted.author }}</h5> <p>Only .ipynb files are acceptable</p> - <form action="/submit-sample/{{ proposal.id }}" method=POST enctype="multipart/form-data" onSubmit="return validate_content();"> - {% csrf_token %} - <input type=text id=ch_name name=ch_name placeholder="Name of the chapter you coded the solved example from"> - <input type=file id=sample_notebook name=sample_notebook> - <br> - <hr> - <center><input class="btn btn-primary" type=submit value=submit></center> - </form> + {% if has_old %} + <form action="/submit-sample/{{ proposal.id }}/{{ old_notebook.id }}" name="with-old" method=POST enctype="multipart/form-data" onSubmit="return validate_content();"> + {% csrf_token %} + <input type=text id=ch_name_old name=ch_name_old placeholder="{{ old_notebook.title }}"> + <input type=file id=old_notebook name=old_notebook> + <br> + <hr> + <center><input class="btn btn-primary" type=submit value=submit></center> + </form> + {% else %} + <form action="/submit-sample/{{ proposal.id }}" name="without-old" method=POST enctype="multipart/form-data" onSubmit="return validate_content();"> + {% csrf_token %} + <input type=text id=ch_name name=ch_name placeholder="Name of the chapter you coded the solved example from"> + <input type=file id=sample_notebook name=sample_notebook> + <br> + <hr> + <center><input class="btn btn-primary" type=submit value=submit></center> + </form> + {% endif %} </div> {% endblock %} diff --git a/tbc/templates/tbc/upload-content.html b/tbc/templates/tbc/upload-content.html index 01bb584..1b73691 100644 --- a/tbc/templates/tbc/upload-content.html +++ b/tbc/templates/tbc/upload-content.html @@ -44,10 +44,15 @@ function validate_content() {% endblock %} {% block content %} +<center> + <h4>Submitting code for the book </h4> + <h4> {{ curr_book.title }} by {{ curr_book.author }}</h4> +</center> +<hr> <div id="content-wrap" style="max-width:600px;"> <p>Upload chapters as individual IPython notebooks. Please do not use spaces to name your Ipython Notebook files. For ex. use "chapter1.ipynb instead of chapter 1.ipynb"</p> - <form action="/upload-content/{{ curr_book.id }}" method=POST enctype="multipart/form-data"> + <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"> @@ -60,6 +65,7 @@ function validate_content() <input type=text id=caption{{i}} name=caption{{i}} placeholder="Caption {{ forloop.counter }}"> <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> </div> diff --git a/tbc/urls.py b/tbc/urls.py index 74c3c2e..f3f9aa4 100644 --- a/tbc/urls.py +++ b/tbc/urls.py @@ -17,8 +17,9 @@ urlpatterns = patterns('', url(r'^submit-book/$', 'tbc.views.SubmitBook', name='SubmitBook'), url(r'^submit-sample/$', 'tbc.views.SubmitSample', name='SubmitSample'), url(r'^submit-sample/(?P<proposal_id>\d+)$', 'tbc.views.SubmitSample', name='SubmitSample'), + url(r'^submit-sample/(?P<proposal_id>\d+)/(?P<old_notebook_id>\d+)$', 'tbc.views.SubmitSample', name='SubmitSample'), url(r'^update-book/$', 'tbc.views.UpdateBook', name='UpdateBook'), - url(r'^upload-content/(?P<book_id>\d+)$', 'tbc.views.ContentUpload', name='ContentUpload'), + url(r'^submit-code/$', 'tbc.views.SubmitCode', name='SubmitCode'), url(r'^update-content/(?P<book_id>\d+)$', 'tbc.views.UpdateContent', name='UpdateContent'), url(r'^get-zip/(?P<book_id>\d+)$', 'tbc.views.GetZip', name='GetZip'), url(r'^browse-books/$', 'tbc.views.BrowseBooks', name='BrowseBooks'), diff --git a/tbc/views.py b/tbc/views.py index 49505bc..a504628 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -86,6 +86,11 @@ def Home(request): context['proposal_submitted'] = True if 'proposal_pending' in request.GET: context['proposal_pending'] = True + if 'no_book_alloted' in request.GET: + context['no_book_alloted'] = True + if 'sample_notebook' in request.GET: + context['sample_notebook'] = True + books = Book.objects.filter(approved=True).order_by("-id")[0:6] for book in books: images.append(ScreenShots.objects.filter(book=book)[0]) @@ -347,6 +352,7 @@ def SubmitProposal(request): def ReviewProposals(request, proposal_id=None, textbook_id=None): context = {} if is_reviewer(request.user): + context['reviewer'] = request.user if proposal_id: proposal = Proposal.objects.get(id=proposal_id) accepted_book = TempBook.objects.get(id=textbook_id) @@ -385,6 +391,8 @@ def ReviewProposals(request, proposal_id=None, textbook_id=None): context['proposals'] = new_proposals context['old_proposals'] = old_proposals return render_to_response('tbc/review-proposal.html', context) + else: + return HttpResponse("not allowed") def DisapproveProposal(request, proposal_id=None): @@ -433,22 +441,32 @@ def RejectProposal(request, proposal_id=None): return render_to_response('tbc/reject-proposal.html', context) -def SubmitSample(request, proposal_id=None): +def SubmitSample(request, proposal_id=None, old_notebook_id=None): context = {} context.update(csrf(request)) if request.method == "POST": curr_proposal = Proposal.objects.get(id=proposal_id) - sample_notebook = SampleNotebook() - sample_notebook.proposal = curr_proposal - sample_notebook.name = request.POST.get('ch_name') - sample_notebook.sample_notebook = request.FILES['sample_notebook'] - sample_notebook.save() - return HttpResponse("done") + if old_notebook_id: + pass + else: + sample_notebook = SampleNotebook() + sample_notebook.proposal = curr_proposal + sample_notebook.name = request.POST.get('ch_name') + sample_notebook.sample_notebook = request.FILES['sample_notebook'] + sample_notebook.save() + return HttpResponseRedirect('/?sample_notebook=done') else: profile = Profile.objects.get(user=request.user) proposal = Proposal.objects.get(user=profile, status='samples') - context['proposal'] = proposal - return render_to_response('tbc/submit-sample.html', context) + try: + old_notebook = SampleNotebook.objects.get(proposal=proposal) + context['has_old'] = True + context['old_notebook'] = old_notebook + context['proposal'] = proposal + return render_to_response('tbc/submit-sample.html', context) + except: + context['proposal'] = proposal + return render_to_response('tbc/submit-sample.html', context) def UpdateBook(request): @@ -492,9 +510,14 @@ def UpdateBook(request): return render_to_response('tbc/update-book.html', context) -def ContentUpload(request, book_id=None): +def SubmitCode(request): user = request.user - curr_book = Book.objects.get(id=book_id) + curr_profile = Profile.objects.get(user=user) + try: + curr_proposal = Proposal.objects.get(user=curr_profile, status='book alloted') + curr_book = curr_proposal.accepted + except: + return HttpResponseRedirect('/?no_book_alloted=true') if request.method == 'POST': for i in range(1, curr_book.no_chapters+1): chapter = Chapters() @@ -522,13 +545,14 @@ def ContentUpload(request, book_id=None): "http://tbc-python.fossee.in/book-review/"+str(curr_book.id) email_send(book.reviewer.email, subject, message) return HttpResponseRedirect('/?up=done') - context = {} - context.update(csrf(request)) - context['user'] = user - context['curr_book'] = curr_book - context['no_notebooks'] = [i for i in range(1, curr_book.no_chapters+1)] - context['no_images'] = [i for i in range(1, 4)] - return render_to_response('tbc/upload-content.html', context) + else: + context = {} + context.update(csrf(request)) + context['user'] = user + context['curr_book'] = curr_book + context['no_notebooks'] = [i for i in range(1, curr_book.no_chapters+1)] + context['no_images'] = [i for i in range(1, 4)] + return render_to_response('tbc/upload-content.html', context) def UpdateContent(request, book_id=None): |