Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use form for search_submission #8065

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ietf/submit/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,13 @@ def __init__(self, *args, **kwargs):
self.fields['frm'].label='From'
self.fields['frm'].widget.attrs['readonly'] = True
self.fields['reply_to'].widget.attrs['readonly'] = True


class SubmissionSearchForm(forms.Form):
"""Form used for search_submission"""

name = forms.CharField(max_length=255, required=True, label="I-D name")

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["name"].widget.attrs["placeholder"] = "draft-..."
93 changes: 66 additions & 27 deletions ietf/submit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,47 @@
from ietf.ietfauth.utils import has_role, role_required
from ietf.mailtrigger.utils import gather_address_lists
from ietf.person.models import Email
from ietf.submit.forms import (SubmissionAutoUploadForm, AuthorForm, SubmitterForm, EditSubmissionForm,
PreapprovalForm, ReplacesForm, SubmissionManualUploadForm)
from ietf.submit.forms import (
SubmissionAutoUploadForm,
AuthorForm,
SubmitterForm,
EditSubmissionForm,
PreapprovalForm,
ReplacesForm,
SubmissionManualUploadForm,
SubmissionSearchForm,
)
from ietf.submit.mail import send_full_url, send_manual_post_request
from ietf.submit.models import (Submission, Preapproval, SubmissionExtResource,
DraftSubmissionStateName )
from ietf.submit.tasks import process_uploaded_submission_task, process_and_accept_uploaded_submission_task, poke
from ietf.submit.utils import ( approvable_submissions_for_user, preapprovals_for_user,
recently_approved_by_user, validate_submission, create_submission_event, docevent_from_submission,
post_submission, cancel_submission, rename_submission_files, remove_submission_files,
get_submission, save_files, clear_existing_files, accept_submission, accept_submission_requires_group_approval,
accept_submission_requires_prev_auth_approval, update_submission_external_resources)
from ietf.submit.models import (
Submission,
Preapproval,
SubmissionExtResource,
DraftSubmissionStateName,
)
from ietf.submit.tasks import (
process_uploaded_submission_task,
process_and_accept_uploaded_submission_task,
poke,
)
from ietf.submit.utils import (
approvable_submissions_for_user,
preapprovals_for_user,
recently_approved_by_user,
validate_submission,
create_submission_event,
docevent_from_submission,
post_submission,
cancel_submission,
rename_submission_files,
remove_submission_files,
get_submission,
save_files,
clear_existing_files,
accept_submission,
accept_submission_requires_group_approval,
accept_submission_requires_prev_auth_approval,
update_submission_external_resources,
)
from ietf.stats.utils import clean_country_name
from ietf.utils.accesstoken import generate_access_token
from ietf.utils.log import log
Expand Down Expand Up @@ -195,24 +225,33 @@ def api_submit_tombstone(request):
def tool_instructions(request):
return render(request, 'submit/tool_instructions.html', {'selected': 'instructions'})


def search_submission(request):
error = None
name = None
if request.method == 'POST':
name = request.POST.get('name', '')
submission = Submission.objects.filter(name=name).order_by('-pk').first()
if submission:
return redirect(submission_status, submission_id=submission.pk)
else:
if re.search(r'-\d\d$', name):
submission = Submission.objects.filter(name=name[:-3]).order_by('-pk').first()
if submission:
return redirect(submission_status, submission_id=submission.pk)
error = 'No valid submission found for %s' % name
return render(request, 'submit/search_submission.html',
{'selected': 'status',
'error': error,
'name': name})
if request.method == "POST":
form = SubmissionSearchForm(request.POST)
if form.is_valid():
name = form.cleaned_data["name"]
submission = Submission.objects.filter(name=name).order_by("-pk").first()
if submission:
return redirect(submission_status, submission_id=submission.pk)
else:
if re.search(r"-\d\d$", name):
submission = (
Submission.objects.filter(name=name[:-3])
.order_by("-pk")
.first()
)
if submission:
return redirect(submission_status, submission_id=submission.pk)
form.add_error(None, f"No valid submission found for {name}")
else:
form = SubmissionSearchForm()
return render(
request,
"submit/search_submission.html",
{"selected": "status", "form": form},
)


def can_edit_submission(user, submission, access_token):
key_matched = access_token and submission.access_token() == access_token
Expand Down
8 changes: 1 addition & 7 deletions ietf/templates/submit/search_submission.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@
<form method="post">
{% csrf_token %}
<div class="mb-3">
<label class="form-label" for="name">I-D name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="draft-..." required>
{% bootstrap_form form %}
</div>
{% if error %}
<p class="alert alert-danger my-3">
{{ error }}
</p>
{% endif %}
<button class="btn btn-primary" type="submit">See status</button>
</form>
{% endblock %}
Loading