def do_project_issues(request, **kw): session = Session.get_session(request) if session: values = {"user": '******' % encode_html(session.user.name)} else: values = {"user": '******'} pid = request.normpath.split("/")[2] prj = issuebase.projects.query_one(project_id=pid) values["project_id"] = prj.project_id values["project_name"] = prj.name values["project_description"] = prj.description ilist = "" for issue in issuebase.issues.query_iter(project_id=prj.pid): if issue.creator_id is not None: creator = issuebase.users[issue.creator_id].name else: creator = "unknown" shorttitle = re.sub("[^A-Za-z0-9\s/]", "", issue.title) shorttitle = re.sub("\s+", "_", shorttitle) ilist += """<tr><td class="number">#%i</td><td class="info"> <div><b><a href="/issues/%i/%s">%s</a></b>%s <p class="subinfo">by %s at %s</p> </td></tr>""" % ( issue.iid, issue.iid, shorttitle, issue.title, "<span class='pull-right label label-warning'>new</span>" if issue.bug_status == "unconfirmed" else "", creator, issue.creation_date, ) values["issues"] = ilist return TemplateResponse("templates/project_issues.html", values)
def do_mylyn_buglist(request, **kw): session=Session.get_session(request) if session is None: return "<html><head><title>Log in to Bugzilla</title></head><body>Not logged in!</body></html>" print kw host=request.headers.getheader('host') buglist=ET.Element(XMLNS_rdf+'result', attrib={XMLNS_rdf+'about':host+request.path}) installation=ET.SubElement(buglist, XMLNS_bz+'installation', attrib={XMLNS_rdf+'about':host}) ET.SubElement(installation,XMLNS_bz+'query_timestamp').text=str(datetime.datetime.now()) bugs=ET.SubElement(buglist,XMLNS_bz+'bugs') seq=ET.SubElement(bugs,XMLNS_rdf+'Seq') if 'bug_id' in kw: cvars=[int(x) for x in (','.join(kw['bug_id'])).split(',') if x] cond=['bug_id in (%s)'%(','.join('?'*len(cvars)))] if 'chfieldfrom' in kw: cvars.append(re.sub(r'[+-]\d+$','',kw['chfieldfrom'][-1])) cond.append('datetime(modification_date)>=datetime(?)') if 'chfieldto' in kw: cvars.append(re.sub(r'[+-]\d+$','',kw['chfieldto'][-1])) cond.append('datetime(modification_date)<=datetime(?)') for bug in issuebase.select_sql(' and '.join(cond),cvars): ET.SubElement(seq,XMLNS_rdf+'li').append(bug.to_short_xml(host)) else: make_search(kw) for bug in issuebase.issues: ET.SubElement(seq,XMLNS_rdf+'li').append(bug.to_short_xml(host)) return RDFResponse(buglist)
def do_mylyn_index(request, Bugzilla_login=None, **kw): if Bugzilla_login: try: session=Session(request) except (KeyError, AssertionError): return "<html><body>Wrong login/password</body></html>" else: session=Session.get_session(request) if session is None: return "<html><head><title>Log in to Bugzilla</title></head><body>Not logged in!</body></html>" return "<html><body>MyLyn-Interface</body></html>"
def do_mylyn_show_bug(request, ctype=None, id=None, excludefield=(), **kw): session=Session.get_session(request) if session is None: return "<html><head><title>Log in to Bugzilla</title></head><body>Not logged in!</body></html>" print kw,excludefield if True or ctype[-1]=='xml': result=ET.Element('bugzilla',version="4.3") for ii in id: issue=issuebase.issues[int(ii)] result.append(issue.to_xml(request.headers.getheader('host'),excludefield)) return XMLResponse(result) return "xxx"
def do_project_browse(request, **kw): pid = request.normpath.split("/")[2] session = Session.get_session(request) if session is None: raise RedirectLocation("/login.html?hint=2&project=%s" % pid) prj = issuebase.projects.query_one(project_id=pid) values = {"user": '******' % encode_html(session.user.name)} values["project_id"] = prj.project_id values["project_name"] = prj.name values["project_description"] = prj.description values["title"] = kw.get("title", "") values["comment"] = kw.get("comment", "") return TemplateResponse("templates/project_browse.html", values)
def do_project_newissue(request, submit=None, **kw): pid = request.normpath.split("/")[2] session = Session.get_session(request) if session is None: raise RedirectLocation("/login.html?hint=2&project=%s" % pid) prj = issuebase.projects.query_one(project_id=pid) values = {"user": '******' % encode_html(session.user.name)} values["project_id"] = prj.project_id values["project_name"] = prj.name values["project_description"] = prj.description values["title"] = kw.get("title", "") values["comment"] = kw.get("comment", "") if submit == "submit": script = "" if not kw.get("title"): script += """ $('#title').parent().parent().addClass('error') $('#title').after('<span class="help-inline">no title given</span>') """ if not script: try: iss = issuebase.issues.new() iss.creator_id = session.user.uid iss.creation_date = str(datetime.datetime.now()).split(".")[0] iss.modification_date = str(datetime.datetime.now()).split(".")[0] iss.project_id = prj.pid iss.title = kw["title"] iss.bug_status = "unconfirmed" iss.assignee_id = prj.creator_id iss.bug_severity = kw.get("severity", "normal") iss.priority = kw.get("priority", "medium") iss.commit() if kw["comment"]: cmt = issuebase.comments.new() cmt.issue_id = iss._rowid cmt.is_private = 0 cmt.creator_id = session.user.uid cmt.creation_date = str(datetime.datetime.now()).split(".")[0] cmt.text = kw["comment"] cmt.commit() if kw.get("notify") == "notify": no = issuebase.notify.new() no.issue_id = iss._rowid no.user_id = session.user.uid no.commit() except Exception, e: print type(e), e raise RedirectLocation("/projects/%s/issues.html" % prj.project_id) values["script"] = script
def do_project_summary(request, **kw): session = Session.get_session(request) if session: values = {"user": '******' % encode_html(session.user.name)} else: values = {"user": '******'} pid = request.normpath.split("/")[2] prj = issuebase.projects.query_one(project_id=pid) values["project_id"] = prj.project_id values["project_name"] = prj.name dd = prj.description.split("\n") values["project_description"] = "<p><b>%s</b></p><p>%s</p>" % ( encode_html(dd[0]), "</p><p>".join(map(encode_html, dd[1:])), ) return TemplateResponse("templates/project_summary.html", values)
def do_upload(request, **kw): session = Session.get_session(request) if session is None: raise RedirectLocation("/login.html") print kw["icon"][:3], len(kw["icon"][3]) if kw["icon"][3]: att = issuebase.attachments.new() att.issue_id = -1 att.creator_id = session.user.uid if session else None att.creation_date = str(datetime.datetime.now()).split(".")[0] att.modifier_id = session.user.uid if session else None att.modification_date = str(datetime.datetime.now()).split(".")[0] att.mimetype = kw.get("contenttypeentry", kw.get("icon")[1]) att.filename = kw.get("icon")[0] att.data = buffer(kw.get("icon")[3]) att.commit() print att._rowid return MimeResponse(str(att._rowid), "text/plain")
def do_mylyn_attachment(request, Bugzilla_login=None, action=None,**kw): if Bugzilla_login: try: session=Session(request) except (KeyError, AssertionError): return "<html><body>Wrong login/password</body></html>" else: session=Session.get_session(request) print session,action,kw if action=='insert': if session is None: return "<html><head><title>Log in to Bugzilla</title></head><body>Not logged in!</body></html>" cmt=issuebase.attachments.new() cmt.issue_id=int(kw['bugid']) cmt.is_patch=int(kw.get('ispatch',0)) cmt.is_obsolete=int(kw.get('isobsolete',0)) cmt.creator_id=session.user.uid if session else None cmt.creation_date=str(datetime.datetime.now()).split('.')[0] cmt.modifier_id=session.user.uid if session else None cmt.modification_date=str(datetime.datetime.now()).split('.')[0] cmt.description=kw.get('description') cmt.comment=kw.get('comment') cmt.mimetype=kw.get('contenttypeentry',kw.get('data')[1]) cmt.filename=kw.get('data')[0] cmt.data=buffer(kw.get('data')[3]) cmt.commit() elif action=='update': if session is None: return "<html><head><title>Log in to Bugzilla</title></head><body>Not logged in!</body></html>" cmt=issuebase.attachments[int(kw['id'])] cmt.modifier_id=session.user.uid if session else None cmt.modification_date=str(datetime.datetime.now()).split('.')[0] if 'ispatch' in kw: cmt.is_patch=int(kw['ispatch']) if 'isobsolete' in kw: cmt.is_obsolete=int(kw['isobsolete']) if 'description' in kw: cmt.is_description=kw['description'] if 'comment' in kw: cmt.comment=kw['comment'] if 'contenttypeentry' in kw: cmt.mimetype=kw['contenttypeentry'] if 'filename' in kw: cmt.filenamekw['filename'] cmt.commit() else: cmt=issuebase.attachments[int(kw['id'])] request.add_headers['Content-disposition']='inline; filename="%s"'%cmt.filename return MimeResponse(str(cmt.data),cmt.mimetype) return """<html><head><title>Bug %s processed</title></head></html>"""%int(kw['bugid'])
def do_mylyn_post_bug(request, **kw): session=Session.get_session(request) if session is None: return "<html><head><title>Log in to Bugzilla</title></head><body>Not logged in!</body></html>" print kw iss=issuebase.issues.new() iss.creator_id=session.user.uid if session else None iss.creation_date=str(datetime.datetime.now()).split('.')[0] iss.modification_date=str(datetime.datetime.now()).split('.')[0] ass=issuebase.users.query_one(login=kw.get('assigned_to')) if ass is not None: iss.assignee_id=ass.uid pro=issuebase.projects.query_one(name=kw.get('product')) if pro is not None: iss.project_id=pro.pid if kw.get('short_desc'): iss.title = kw['short_desc'] for elem in ('bug_status','resolution','bug_file_loc','status_whiteboard','priority','bug_severity'): if elem in kw: setattr(iss,elem,kw[elem]) iss.commit() if 'new_comment' in kw and kw['new_comment'].strip(): cmt=issuebase.comments.new() cmt.issue_id=iss._rowid cmt.is_private=0 cmt.creator_id=session.user.uid if session else None cmt.creation_date=str(datetime.datetime.now()).split('.')[0] cmt.text=kw['new_comment'] cmt.commit() print kw for elem in ( # used 'bug_id','id','assigned_to','product','short_desc','new_comment', 'bug_status','resolution','bug_file_loc','status_whiteboard','priority','bug_severity', # ignored 'classification_id','classification','rep_platform','cclist_accessible', 'reporter_accessible','form_name','op_sys','version','keywords','blocked', 'everconfirmed','delta_ts','dependson','assigned_to_name','component', ): if elem in kw: kw.pop(elem) print kw return """<html><head><title>Bug %s processed</title></head></html>"""%iss._rowid
def do_newproject(request, create=None, **kw): session = Session.get_session(request) if session is None: raise RedirectLocation("/login.html?hint=1") print create, kw.keys() values = { "user": session.user.name, "pid": kw.get("pid", ""), "name": kw.get("name", ""), "descr": kw.get("descr", ""), } if create == "create": script = "" if not re.match(r"^[A-Za-z0-9_]+$", kw["pid"]): script += """ $('#pid').parent().parent().addClass('error') $('#pid').after('<span class="help-inline">only letters and numbers allowed</span>') """ elif issuebase.projects.query_one(project_id=kw["pid"]): script += """ $('#pid').parent().parent().addClass('error') $('#pid').after('<span class="help-inline">project with this id already exists</span>') """ if not kw["name"]: script += """ $('#name').parent().parent().addClass('error') $('#name').after('<span class="help-inline">no name given</span>') """ if not script: try: prj = issuebase.projects.new() prj.creator = session.user.uid prj.creation_date = str(datetime.datetime.now()).split(".")[0] prj.project_id = kw["pid"] prj.name = kw["name"] prj.description = kw["descr"] print re.sub("[^0-9]*", "", kw["icon_nr"]), kw["icon_nr"] prj.icon = re.sub("[^0-9]*", "", kw["icon_nr"]) prj.commit() except Exception, e: print type(e), e raise RedirectLocation("/index.html") values["script"] = script
def do_list(request, **kw): session = Session.get_session(request) if session: values = {"user": '******' % encode_html(session.user.name)} else: values = {"user": '******'} list = "" for prj in issuebase.projects: list += """<li class="span4"> <a class="thumbnail" href="/projects/%s/"> <table><tr><td valign="top"><img src="/projects/%s/icon.jpg" width='64' height='64' alt=""></td><td style="padding-left:5px;color:black"> <h5>%s</h5> <p>%s</p> </td></tr></table></a> </li>""" % ( prj.project_id, prj.project_id, encode_html(prj.name), encode_html(prj.description.split("\n")[0]), ) values["list"] = list return TemplateResponse("templates/list.html", values)
def do_issue(request, **kw): iid = request.normpath.split("/")[2] session = Session.get_session(request) if session: values = {"user": '******' % encode_html(session.user.name)} else: values = {"user": '******'} print kw iss = issuebase.issues[int(iid)] if kw.get("submit") == "submit" and session: iss.modification_date = str(datetime.datetime.now()).split(".")[0] ass = issuebase.users.query_one(login=kw.get("assigned_to")) if ass is not None: iss.assignee_id = ass.uid if kw.get("title"): iss.title = kw["title"] for elem in ("bug_status", "resolution", "priority", "bug_severity", "bug_file_loc", "status_whiteboard"): if elem in kw: setattr(iss, elem, kw[elem]) iss.commit() if kw.get("new_comment", "").strip(): cmt = issuebase.comments.new() cmt.issue_id = iss._rowid cmt.is_private = 0 cmt.creator_id = session.user.uid if session else None cmt.creation_date = str(datetime.datetime.now()).split(".")[0] cmt.text = kw["new_comment"] cmt.commit() pass no = issuebase.notify.query_one(issue_id=iss._rowid, user_id=session.user.uid) print no if kw.get("notify") == "notify": if no is None: no = issuebase.notify.new() no.issue_id = iss._rowid no.user_id = session.user.uid no.commit() elif no: no.delete() prj = issuebase.projects[iss.project_id] values["project_id"] = prj.project_id values["project_name"] = encode_html(prj.name) values["iid"] = iid values["creator_name"] = issuebase.users[iss.creator_id].name values["creation_date"] = iss.creation_date values["title"] = iss.title print iss.assignee_id values["assigned_to"] = issuebase.users[iss.assignee_id].name if iss.assignee_id else "unassigned" values["s_" + (iss.bug_severity or "normal")] = 'selected="selected"' values["s_" + (iss.priority or "medium")] = 'selected="selected"' values["s_" + (re.sub("[^a-z]", "", iss.bug_status or "unconfirmed"))] = 'selected="selected"' values["s_" + (re.sub("[^a-z]", "", iss.resolution or "none"))] = 'selected="selected"' comments = "" for cmm in issuebase.comments.query_iter(issue_id=iid): try: cc = encode_html(issuebase.users[cmm.creator_id].name) except: cc = "unknown" comments += "<div><h5>by %s at %s</h5><p><pre>%s</pre></p></div>" % ( cc, cmm.creation_date, encode_html(cmm.text), ) values["comments"] = comments or '<span class="help-block">none</span>' if session: no = issuebase.notify.query_one(issue_id=iss._rowid, user_id=session.user.uid) if no: values["notify"] = 'checked="checked"' return TemplateResponse( "templates/project_issue.html" if session else "templates/project_issue_disabled.html", values )