Skip to content

Commit fc16044

Browse files
committed
Default author to self when adding a new patch (#26)
People sometimes forget to configure the author field when adding a patch to the commitfest. It's also kinda silly to always have to search for your own name. In the cases that people add commitfest entries for patches of others, removing themselves and adding the other person is only a backspace presses away. Apart from that this also updates the patch creation form to include all the fields from the patch edit form. Instead of having the patch creation submit button redirect to the patch edit page. Fixes #14
1 parent e5a137e commit fc16044

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

pgcommitfest/commitfest/forms.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,19 @@ def __init__(self, *args, **kwargs):
7171
self.fields[field].label_from_instance = lambda u: '{} ({})'.format(u.username, u.get_full_name())
7272

7373

74-
class NewPatchForm(forms.ModelForm):
74+
class NewPatchForm(PatchForm):
75+
# Put threadmsgid first
76+
field_order = ['threadmsgid']
77+
7578
threadmsgid = forms.CharField(max_length=200, required=True, label='Specify thread msgid', widget=ThreadPickWidget)
76-
# 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.')
7779

78-
class Meta:
79-
model = Patch
80-
fields = ('name', 'topic', )
80+
def __init__(self, *args, **kwargs):
81+
request = kwargs.pop('request', None)
82+
super(NewPatchForm, self).__init__(*args, **kwargs)
83+
84+
if request:
85+
self.fields['authors'].queryset = User.objects.filter(pk=request.user.id)
86+
self.fields['authors'].initial = [request.user.id]
8187

8288
def clean_threadmsgid(self):
8389
try:

pgcommitfest/commitfest/views.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def newpatch(request, cfid):
440440
# Now add the thread
441441
try:
442442
doAttachThread(cf, patch, form.cleaned_data['threadmsgid'], request.user)
443-
return HttpResponseRedirect("/patch/%s/edit/" % (patch.id,))
443+
return HttpResponseRedirect("/patch/%s/" % (patch.id,))
444444
except Http404:
445445
# Thread not found!
446446
# This is a horrible breakage of API layers
@@ -451,13 +451,14 @@ def newpatch(request, cfid):
451451
# not happen very often. If we successfully attached to it, we will have already returned.
452452
patch.delete()
453453
else:
454-
form = NewPatchForm()
454+
form = NewPatchForm(request=request)
455455

456456
return render(request, 'base_form.html', {
457457
'form': form,
458458
'title': 'New patch',
459459
'breadcrumbs': [{'title': cf.title, 'href': '/%s/' % cf.pk}, ],
460460
'savebutton': 'Create patch',
461+
'selectize_multiple_fields': form.selectize_multiple_fields.items(),
461462
'threadbrowse': True,
462463
})
463464

0 commit comments

Comments
 (0)