def new_view(request): if request.method == "GET": form = NewIssueForm() else: assert request.method == "POST" form = NewIssueForm(data=request.POST) if form.is_valid(): product = form.cleaned_data["product"] summary = form.cleaned_data["summary"] description = form.cleaned_data["description"] who = Profiles.objects.get(login_name=request.user.username) b = Bugs() b.short_desc = summary b.alias = None b.product = product # get the first row in the Versions table by default: b.version = product.versions_set.all()[0].value # get the first row in the Milestones table by default: b.target_milestone = product.milestones_set.all()[0].value try: b.component = Components.objects.filter(product=b.product).get(name="core") except Components.DoesNotExist: b.component = Components.objects.filter(product=b.product).all()[0] b.op_sys = OpSys.objects.get(value="All").value b.rep_platform = RepPlatform.objects.get(value="All").value b.priority = "Medium" b.bug_severity = "Minor" b.bug_status = "NEW" b.everconfirmed = 1 # NEW is a confirmed status b.assigned_to = who b.delta_ts = datetime.datetime.today() b.creation_ts = datetime.datetime.today() b.reporter = who b.votes = 0 b.reporter_accessible = 1 b.cclist_accessible = 1 b.estimated_time = 0 b.remaining_time = 0 b.keywords = "s" b.save() l = Longdescs(bug=b, who=who) l.thetext = description l.bug_when = datetime.datetime.today() l.work_time = 0 l.isprivate = 0 l.already_wrapped = 0 l.type = 0 l.save() redirect_to = "/bugs-ui/bug/%s/" % b.bug_id return HttpResponseRedirect(redirect_to) return render_to_response("new.html", { "new_issue_form": form, }, context_instance=RequestContext(request))
def bug_view(request, bug_id): error_msg = "" bug = Bugs.objects.get(bug_id=bug_id) if request.method == "POST" and request.user.is_authenticated(): comment_form = CommentForm(request.POST, request.FILES) if comment_form.is_valid(): text = comment_form.cleaned_data["comment_text"] attachment = request.FILES.get("attachment", None) labels = extract_labels(request.POST) if update_labels(bug, labels): ok = True else: ok = False error_msg = "Unknown label" if ok and text != "" or attachment is not None: who = Profiles.objects.get(login_name=request.user.username) l = Longdescs(bug=bug, who=who) if attachment: #text += "Got attachment: %s\n" % attachment a = Attachments(bug=bug, submitter=who) a.filename = attachment.name a.description = attachment.name a.creation_ts = datetime.datetime.today() a.modification_time = datetime.datetime.today() a.isobsolete = 0 a.isprivate = 0 a.isurl = 0 a.save() d = AttachData(id=a) d.thedata = attachment.read() d.save() l.thetext = text l.bug_when = datetime.datetime.today() l.work_time = 0 l.isprivate = 0 l.already_wrapped = 0 l.type = 0 l.save() return HttpResponseRedirect("/bugs-ui/bug/%s/" % bug_id) comment_form = CommentForm() prev_bug = int(bug_id)-1 if len(Bugs.objects.filter(bug_id=prev_bug)) == 0: prev_bug = "" next_bug = int(bug_id)+1 if len(Bugs.objects.filter(bug_id=next_bug)) == 0: next_bug = "" comments = bug.longdescs_set.all() if len(comments) > 0: comments_first = comments[0] else: comments_first = None comments_other = comments[1:] attachments = bug.attachments_set.all() keywords = bug.kws.all() from django import forms class LabelChoiceField(object): def __init__(self, id, queryset=None, initial=None, html_class="label_in_field"): self.id = id self.initial = initial self.html_class = html_class self.queryset = queryset def __unicode__(self): div = """ <div class="menu"> <ul id="menu_%d" class="menu">""" % self.id for q in self.queryset: div += "<li>%s</li>" % q.name div += "</ul></div>" return mark_safe(u'<input type="text" name="label_%d" id="label_%d" class="%s" value="%s"/>%s' % (self.id, self.id, self.html_class, self.convert(self.initial), div)) def convert(self, obj): if obj: return self.label_from_instance(obj) else: return "" def label_from_instance(self, obj): return obj.name keywords_fields = [LabelChoiceField(id, queryset=Keyworddefs.objects.all(), initial=kw) for id, kw in enumerate(keywords)] keywords_fields.append(LabelChoiceField(len(keywords), queryset=Keyworddefs.objects.all())) return render_to_response("bug.html", { "bug": bug, "comments_first": comments_first, "comments_other": comments_other, "comment_form": comment_form, "prev_bug": prev_bug, "next_bug": next_bug, "attachments": attachments, "keywords_fields": keywords_fields, "keywords": keywords, "error_msg": error_msg, }, context_instance=RequestContext(request))