|
1 | 1 | # Copyright The IETF Trust 2007, All Rights Reserved |
| 2 | +from django.conf import settings |
2 | 3 | from django.core.urlresolvers import reverse |
3 | 4 | from django.http import HttpResponseRedirect, Http404 |
4 | 5 | from django.shortcuts import get_object_or_404 |
5 | 6 | from django.shortcuts import render_to_response |
6 | 7 | from django.template import RequestContext |
| 8 | +from django.core.exceptions import ObjectDoesNotExist |
7 | 9 |
|
8 | | -from ietf.submit.models import IdSubmissionDetail |
| 10 | +from ietf.submit.models import IdSubmissionDetail, IdApprovedDetail |
9 | 11 | from ietf.submit.forms import UploadForm, AutoPostForm, MetaDataForm |
10 | | -from ietf.submit.utils import (DraftValidation, UPLOADED, WAITING_AUTHENTICATION, CANCELED, |
11 | | - perform_post) |
| 12 | +from ietf.submit.utils import (DraftValidation, perform_post, |
| 13 | + UPLOADED, WAITING_AUTHENTICATION, CANCELED, INITIAL_VERSION_APPROVAL_REQUESTED) |
| 14 | +from ietf.utils.mail import send_mail |
| 15 | + |
12 | 16 |
|
13 | 17 |
|
14 | 18 | def submit_index(request): |
@@ -53,12 +57,33 @@ def draft_status(request, submission_id, message=None): |
53 | 57 | message=('error', 'This submission has been canceled, modification is no longer possible') |
54 | 58 | status = detail.status |
55 | 59 | allow_edit = None |
| 60 | + |
56 | 61 | if request.method=='POST' and allow_edit: |
57 | 62 | if request.POST.get('autopost', False): |
58 | | - auto_post_form = AutoPostForm(draft=detail, validation=validation, data=request.POST) |
59 | | - if auto_post_form.is_valid(): |
60 | | - auto_post_form.save(request) |
61 | | - return HttpResponseRedirect(reverse(draft_status, None, kwargs={'submission_id': detail.submission_id})) |
| 63 | + try: |
| 64 | + approved_detail = IdApprovedDetail.objects.get(filename=detail.filename) |
| 65 | + except ObjectDoesNotExist: |
| 66 | + approved_detail = None |
| 67 | + detail.status_id = INITIAL_VERSION_APPROVAL_REQUESTED |
| 68 | + detail.save() |
| 69 | + |
| 70 | + if detail.revision == '00' and not approved_detail: |
| 71 | + subject = 'New draft waiting for approval: %s' % detail.filename |
| 72 | + from_email = settings.IDST_FROM_EMAIL |
| 73 | + to_email = [] |
| 74 | + if detail.group_acronym: |
| 75 | + to_email += [i.person.email()[1] for i in detail.group_acronym.wgchair_set.all()] |
| 76 | + to_email = list(set(to_email)) |
| 77 | + if to_email: |
| 78 | + metadata_form = MetaDataForm(draft=detail, validation=validation) |
| 79 | + send_mail(request, to_email, from_email, subject, 'submit/manual_post_mail.txt', |
| 80 | + {'form': metadata_form, 'draft': detail}) |
| 81 | + else: |
| 82 | + auto_post_form = AutoPostForm(draft=detail, validation=validation, data=request.POST) |
| 83 | + if auto_post_form.is_valid(): |
| 84 | + auto_post_form.save(request) |
| 85 | + return HttpResponseRedirect(reverse(draft_status, None, kwargs={'submission_id': detail.submission_id})) |
| 86 | + |
62 | 87 | else: |
63 | 88 | return HttpResponseRedirect(reverse(draft_edit, None, kwargs={'submission_id': detail.submission_id})) |
64 | 89 | else: |
@@ -114,3 +139,12 @@ def draft_confirm(request, submission_id, auth_key): |
114 | 139 | message = ('success', 'Authorization key accepted. Auto-Post complete') |
115 | 140 | perform_post(detail) |
116 | 141 | return draft_status(request, submission_id, message) |
| 142 | + |
| 143 | + |
| 144 | +def draft_approve(request, submission_id): |
| 145 | + detail = get_object_or_404(IdSubmissionDetail, submission_id=submission_id) |
| 146 | + if detail.status_id == INITIAL_VERSION_APPROVAL_REQUESTED: |
| 147 | + validation = DraftValidation(detail) |
| 148 | + approved_detail = IdApprovedDetail() |
| 149 | + perform_post(detail) |
| 150 | + return HttpResponseRedirect(reverse(draft_status, None, kwargs={'submission_id': submission_id})) |
0 commit comments