from models import Patch, MailThread
from lookups import UserLookup
+from widgets import ThreadPickWidget
from ajax import _archivesAPI
class PatchForm(forms.ModelForm):
self.fields['committer'].label_from_instance = lambda x: '%s %s (%s)' % (x.user.first_name, x.user.last_name, x.user.username)
+class NewPatchForm(forms.ModelForm):
+ 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
+ exclude = ('commitfests', 'mailthreads', 'modified', 'authors', 'reviewers', 'committer', 'wikilink', 'gitlink', )
+
def _fetch_thread_choices(patch):
for mt in patch.mailthread_set.order_by('-latestmessage'):
ti = sorted(_archivesAPI('/message-id.json/%s' % mt.messageid), key=lambda x: x['date'], reverse=True)
from mailqueue.util import send_mail
from models import CommitFest, Patch, PatchOnCommitFest, PatchHistory, Committer
-from forms import PatchForm, CommentForm
+from forms import PatchForm, NewPatchForm, CommentForm
def home(request):
commitfests = CommitFest.objects.all()
@transaction.commit_on_success
def patchform(request, cfid, patchid):
cf = get_object_or_404(CommitFest, pk=cfid)
-
- if patchid == 'new':
- patch = Patch()
- else:
- #XXX: also filter that it exists on this cf!
- patch = get_object_or_404(Patch, pk=patchid)
+ patch = get_object_or_404(Patch, pk=patchid, commitfests=cf)
if request.method == 'POST':
form = PatchForm(data=request.POST, instance=patch)
r.set_modified()
r.save()
- if patchid == 'new':
- poc = PatchOnCommitFest(patch=r, commitfest=cf, enterdate=datetime.today())
- poc.save()
form.save_m2m()
return HttpResponseRedirect('../../%s/' % r.pk)
# Else fall through and render the page again
else:
form = PatchForm(instance=patch)
- if patchid=='new':
- title = 'New patch'
- breadcrumbs = [{'title': cf.name, 'href': '/%s/' % cf.pk},]
- else:
- title = 'Edit patch'
- breadcrumbs = [{'title': cf.name, 'href': '/%s/' % cf.pk},
- {'title': 'View patch', 'href': '/%s/%s/' % (cf.pk, patch.pk)}]
-
return render_to_response('base_form.html', {
'cf': cf,
'form': form,
'patch': patch,
- 'title': title,
- 'breadcrumbs': breadcrumbs,
- }, context_instance=RequestContext(request))
+ 'title': 'Edit patch',
+ 'breadcrumbs': [{'title': cf.name, 'href': '/%s/' % cf.pk},
+ {'title': 'View patch', 'href': '/%s/%s/' % (cf.pk, patch.pk)}],
+ }, context_instance=RequestContext(request))
+
+@login_required
+@transaction.commit_on_success
+def newpatch(request, cfid):
+ cf = get_object_or_404(CommitFest, pk=cfid)
+ if request.method == 'POST':
+ form = NewPatchForm(data=request.POST)
+ if form.is_valid():
+ raise Exception("Do something")
+ else:
+ form = NewPatchForm()
+
+ return render_to_response('base_form.html', {
+ 'form': form,
+ 'title': 'New patch',
+ 'breadcrumbs': [{'title': cf.name, 'href': '/%s/' % cf.pk},],
+ 'savebutton': 'Create patch',
+ 'threadbrowse': True,
+ }, context_instance=RequestContext(request))
def _review_status_string(reviewstatus):
if '0' in reviewstatus:
url(r'^$', 'commitfest.views.home'),
url(r'^(\d+)/$', 'commitfest.views.commitfest'),
url(r'^(\d+)/(\d+)/$', 'commitfest.views.patch'),
- url(r'^(\d+)/(\d+|new)/edit/$', 'commitfest.views.patchform'),
+ url(r'^(\d+)/(\d+)/edit/$', 'commitfest.views.patchform'),
+ url(r'^(\d+)/new/$', 'commitfest.views.newpatch'),
url(r'^(\d+)/(\d+)/status/(review|author|committer)/$', 'commitfest.views.status'),
url(r'^(\d+)/(\d+)/close/(reject|feedback|committed)/$', 'commitfest.views.close'),
url(r'^(\d+)/(\d+)/reviewer/(become|remove)/$', 'commitfest.views.reviewer'),