diff options
author | prathamesh | 2014-08-18 12:47:27 +0530 |
---|---|---|
committer | prathamesh | 2014-08-18 12:47:27 +0530 |
commit | 7137c7e70624ea37656f905032cfb02726306af8 (patch) | |
tree | 267433b1db01d870fb2ec970a45a2d67cd228fcc /tbc | |
parent | 60a93ffd5a9aa7abb0a4f09c5de4374b77b2cae8 (diff) | |
download | Python-TBC-Interface-7137c7e70624ea37656f905032cfb02726306af8.tar.gz Python-TBC-Interface-7137c7e70624ea37656f905032cfb02726306af8.tar.bz2 Python-TBC-Interface-7137c7e70624ea37656f905032cfb02726306af8.zip |
Modification to proposal and sample notebook flow
After the proposal is rejected, user will again submit the proposal.
So the proposal form is filled with the initial values of the rejected
proposal.
Sample notebook can be submitted only if the proposal is approved else
will display a message saying 'not permitted'
User after sample notebook submission can anytime edit it.
Modified the template for the reviewer to see the new and old proposal.
Since the ids where same for the collapse element in the loop so there
was problem in javascript.
Profile view modified.
First checks for the user profile. If exists then updates or else
creates a new profile for the user. This will prevent multiple profile
for a single user.[Alternatively, we can give one-to-one relation between
user and profile in models]
Diffstat (limited to 'tbc')
-rwxr-xr-x | tbc/templates/base.html | 9 | ||||
-rw-r--r-- | tbc/templates/tbc/review-proposal.html | 16 | ||||
-rw-r--r-- | tbc/templates/tbc/submit-sample.html | 2 | ||||
-rwxr-xr-x | tbc/views.py | 46 |
4 files changed, 56 insertions, 17 deletions
diff --git a/tbc/templates/base.html b/tbc/templates/base.html index 9708a53..ab79738 100755 --- a/tbc/templates/base.html +++ b/tbc/templates/base.html @@ -206,6 +206,15 @@ </center> <div class="clearfix"></div> {% endif %} + {% if cannot_submit_sample %} + <center> + <div class="alert" style="width:400px;height:25px;"> + <a class="close" data-dismiss="alert" href="#">×</a> + <p>You have not been permitted to send sample notebook.</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 a71ebfc..c0ea983 100644 --- a/tbc/templates/tbc/review-proposal.html +++ b/tbc/templates/tbc/review-proposal.html @@ -8,16 +8,16 @@ {% endif %} <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="accordion{{ forloop.counter }}"> + <li><h4>Proposal from {{ proposal.user.user.first_name }} {{ proposal.user.user.last_name }}</h4></li> + <div class="accordion" id="accordion1{{ forloop.parentloop.counter }}{{ 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="#accordion{{ forloop.counter }}" href="#collapse{{forloop.counter}}"> + <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1{{ forloop.parentloop.counter }}{{ forloop.counter }}" href="#collapse1{{ forloop.parentloop.counter }}{{forloop.counter}}"> Book Preference {{ forloop.counter }} - {{ textbook.title }} </a> </div> - <div id="collapse{{forloop.counter}}" class="accordion-body collapse"> + <div id="collapse1{{ forloop.parentloop.counter }}{{forloop.counter}}" class="accordion-body collapse"> <div class="accordion-inner"> Author: {{ textbook.author}}<br> Edition: {{ textbook.edition }}<br> @@ -40,16 +40,16 @@ <hr> <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="accordion{{ forloop.counter }}"> + <h4><li>Proposal from {{ proposal.proposal.user.user.first_name }} {{ proposal.proposal.user.user.last_name }}</h4></li> + <div class="accordion" id="accordion2{{ 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="#accordion{{ forloop.counter }}" href="#collapse{{forloop.counter}}"> + <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2{{ forloop.parentloop.counter }}{{ forloop.counter }}" href="#collapse2{{ forloop.parentloop.counter }}{{forloop.counter}}"> Book Preference {{ forloop.counter }} - {{ textbook.title }} </a> </div> - <div id="collapse{{forloop.counter}}" class="accordion-body collapse"> + <div id="collapse2{{ forloop.parentloop.counter }}{{forloop.counter}}" class="accordion-body collapse"> <div class="accordion-inner"> Author: {{ textbook.author}}<br> Edition: {{ textbook.edition }}<br> diff --git a/tbc/templates/tbc/submit-sample.html b/tbc/templates/tbc/submit-sample.html index f259ffc..96f1209 100644 --- a/tbc/templates/tbc/submit-sample.html +++ b/tbc/templates/tbc/submit-sample.html @@ -29,7 +29,7 @@ function validate_content() {% 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=text id=ch_name_old name=ch_name_old value="{{ old_notebook.name }}"> <input type=file id=old_notebook name=old_notebook> <br> <hr> diff --git a/tbc/views.py b/tbc/views.py index a504628..d50beb8 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -90,6 +90,8 @@ def Home(request): context['no_book_alloted'] = True if 'sample_notebook' in request.GET: context['sample_notebook'] = True + if 'cannot_submit_sample' in request.GET: + context['cannot_submit_sample'] =True books = Book.objects.filter(approved=True).order_by("-id")[0:6] for book in books: @@ -166,7 +168,11 @@ def UserProfile(request): user = request.user if user.is_authenticated(): if request.method == 'POST': - form = UserProfileForm(request.POST) + user_profile = Profile.objects.filter(user=user) + if user_profile.exists(): + form = UserProfileForm(request.POST, instance=user_profile[0]) + else: + form = UserProfileForm(request.POST) if form.is_valid(): data = form.save(commit=False) data.user = request.user @@ -305,12 +311,16 @@ def SubmitProposal(request): context = {} context.update(csrf(request)) context['user'] = curr_user - user_proposals = Proposal.objects.filter(user=user_profile) - can_submit_new = True + user_proposals = list(Proposal.objects.filter(user=user_profile)) + proposal_id = None + can_submit_new = False matching_books = [] - for proposal in user_proposals: - if proposal.status is not "book completed": - can_submit_new = False + if user_proposals: + if user_proposals[-1].status == 'rejected': + can_submit_new = True + proposal_id = user_proposals[-1].id + else: + can_submit_new = True if can_submit_new: if request.method == 'POST': book_titles = request.POST.getlist('title') @@ -342,6 +352,18 @@ def SubmitProposal(request): book_forms = [] for i in range(3): form = BookForm() + if proposal_id: + proposal = Proposal.objects.get(id=proposal_id) + textbooks = proposal.textbooks.all() + form.initial['title'] = textbooks[i].title + form.initial['author'] = textbooks[i].author + form.initial['category'] = textbooks[i].category + form.initial['publisher_place'] = textbooks[i].publisher_place + form.initial['isbn'] = textbooks[i].isbn + form.initial['edition'] = textbooks[i].edition + form.initial['year_of_pub'] = textbooks[i].year_of_pub + form.initial['no_chapters'] = textbooks[i].no_chapters + book_forms.append(form) context['book_forms'] = book_forms return render_to_response('tbc/submit-proposal.html', context) @@ -447,7 +469,12 @@ def SubmitSample(request, proposal_id=None, old_notebook_id=None): if request.method == "POST": curr_proposal = Proposal.objects.get(id=proposal_id) if old_notebook_id: - pass + old_notebook = SampleNotebook.objects.get(id=old_notebook_id) + old_notebook.proposal = curr_proposal + old_notebook.name = request.POST.get('ch_name_old') + old_notebook.sample_notebook = request.FILES['old_notebook'] + old_notebook.save() + return HttpResponseRedirect('/?sample_notebook=done') else: sample_notebook = SampleNotebook() sample_notebook.proposal = curr_proposal @@ -457,7 +484,10 @@ def SubmitSample(request, proposal_id=None, old_notebook_id=None): return HttpResponseRedirect('/?sample_notebook=done') else: profile = Profile.objects.get(user=request.user) - proposal = Proposal.objects.get(user=profile, status='samples') + try: + proposal = Proposal.objects.get(user=profile, status='samples') + except Proposal.DoesNotExist: + return HttpResponseRedirect('/?cannot_submit_sample=True') try: old_notebook = SampleNotebook.objects.get(proposal=proposal) context['has_old'] = True |