diff --git a/pgcommitfest/commitfest/forms.py b/pgcommitfest/commitfest/forms.py index ec0c62ae..50141e03 100644 --- a/pgcommitfest/commitfest/forms.py +++ b/pgcommitfest/commitfest/forms.py @@ -71,13 +71,19 @@ def __init__(self, *args, **kwargs): self.fields[field].label_from_instance = lambda u: '{} ({})'.format(u.username, u.get_full_name()) -class NewPatchForm(forms.ModelForm): +class NewPatchForm(PatchForm): + # Put threadmsgid first + field_order = ['threadmsgid'] + threadmsgid = forms.CharField(max_length=200, required=True, label='Specify thread msgid', widget=ThreadPickWidget) -# patchfile = forms.FileField(allow_empty_file=False, max_length=50000, label='or upload patch file', required=False, help_text='This may be supported sometime in the future, and would then autogenerate a mail to the hackers list. At such a time, the threadmsgid would no longer be required.') - class Meta: - model = Patch - fields = ('name', 'topic', ) + def __init__(self, *args, **kwargs): + request = kwargs.pop('request', None) + super(NewPatchForm, self).__init__(*args, **kwargs) + + if request: + self.fields['authors'].queryset = User.objects.filter(pk=request.user.id) + self.fields['authors'].initial = [request.user.id] def clean_threadmsgid(self): try: diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py index 83288a81..89fbd175 100644 --- a/pgcommitfest/commitfest/views.py +++ b/pgcommitfest/commitfest/views.py @@ -440,7 +440,7 @@ def newpatch(request, cfid): # Now add the thread try: doAttachThread(cf, patch, form.cleaned_data['threadmsgid'], request.user) - return HttpResponseRedirect("/patch/%s/edit/" % (patch.id,)) + return HttpResponseRedirect("/patch/%s/" % (patch.id,)) except Http404: # Thread not found! # This is a horrible breakage of API layers @@ -451,13 +451,14 @@ def newpatch(request, cfid): # not happen very often. If we successfully attached to it, we will have already returned. patch.delete() else: - form = NewPatchForm() + form = NewPatchForm(request=request) return render(request, 'base_form.html', { 'form': form, 'title': 'New patch', 'breadcrumbs': [{'title': cf.title, 'href': '/%s/' % cf.pk}, ], 'savebutton': 'Create patch', + 'selectize_multiple_fields': form.selectize_multiple_fields.items(), 'threadbrowse': True, })