annotate MoinMoin/items/ticket.py @ 2713:c9baa61473a9

Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
author Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
date Sun, 10 Aug 2014 01:59:26 +0530
parents c05ad337ac22
children 8bdd34c2cb74
rev   line source
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
1 # Copyright: 2012 MoinMoin:CheerXiao
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
2 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
3
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
4 """
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
5 MoinMoin - Ticket itemtype
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
6 """
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
7
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
8
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
9 from __future__ import absolute_import, division
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
10
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
11 import time
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
12
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
13 from flask import request, abort, redirect, url_for
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
14 from flask import g as flaskg
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
15
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
16 from jinja2 import Markup
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
17
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
18 from whoosh.query import Term
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
19
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
20 from MoinMoin.i18n import L_
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
21 from MoinMoin.themes import render_template
1988
490c13d072f2 remove Submit widget
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1975
diff changeset
22 from MoinMoin.forms import (Form, OptionalText, OptionalMultilineText, SmallNatural, Tags,
2627
8f93193cfd9b Added +tickets view having list of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2614
diff changeset
23 Reference, BackReference, SelectSubmit, Text)
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
24 from MoinMoin.storage.middleware.protecting import AccessDenied
2159
246904e49804 change simple occurences of subscribed_items to subscriptions
Ana Balica <ana.balica@gmail.com>
parents: 2123
diff changeset
25 from MoinMoin.constants.keys import (ITEMTYPE, CONTENTTYPE, ITEMID, CURRENT,
2614
9d04f5a42445 Removed pep-8 error from MoinMoin/items/ticket.py
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2613
diff changeset
26 SUPERSEDED_BY, SUBSCRIPTIONS, DEPENDS_ON, NAME, SUMMARY)
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
27 from MoinMoin.constants.contenttypes import CONTENTTYPE_USER
2713
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2656
diff changeset
28 from MoinMoin.items import Item, Contentful, register, BaseModifyForm, get_itemtype_specific_tags
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
29 from MoinMoin.items.content import NonExistentContent
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
30
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
31
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
32 ITEMTYPE_TICKET = u'ticket'
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
33
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
34 USER_QUERY = Term(CONTENTTYPE, CONTENTTYPE_USER)
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
35 TICKET_QUERY = Term(ITEMTYPE, ITEMTYPE_TICKET)
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
36
2634
4cc1d15c203c Added tags filter option
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2627
diff changeset
37 Rating = SmallNatural.using(optional=True).with_properties(lower=1, upper=5)
2613
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
38
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
39
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
40 def get_itemid_short_summary(rev):
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
41 return '{itemid} ({summary})'.format(itemid=rev.meta[ITEMID][:4], summary=rev.meta[SUMMARY][:50])
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
42
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
43
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
44 def get_name(rev):
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
45 return rev.meta[NAME][0]
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
46
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
47
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
48 OptionalTicketReference = Reference.to(
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
49 TICKET_QUERY,
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
50 ).using(
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
51 optional=True,
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
52 ).with_properties(
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
53 label_getter=get_itemid_short_summary,
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
54 )
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
55 OptionalUserReference = Reference.to(
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
56 USER_QUERY,
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
57 ).using(
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
58 optional=True,
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
59 ).with_properties(
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
60 empty_label='(Nobody)',
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
61 label_getter=get_name,
f0cc5ebc5192 Now summary is also shown along with itemid initials in dropdown lists of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2612
diff changeset
62 )
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
63
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1963
diff changeset
64
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
65 class TicketMetaForm(Form):
2627
8f93193cfd9b Added +tickets view having list of tickets
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2614
diff changeset
66 summary = Text.using(label=L_("Summary")).with_properties(placeholder=L_("One-line summary of the item"))
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
67 effort = Rating.using(label=L_("Effort"))
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
68 difficulty = Rating.using(label=L_("Difficulty"))
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
69 severity = Rating.using(label=L_("Severity"))
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
70 priority = Rating.using(label=L_("Priority"))
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
71 tags = Tags.using(optional=True)
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
72 assigned_to = OptionalUserReference.using(label=L_("Assigned To"))
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
73 superseded_by = OptionalTicketReference.using(label=L_("Superseded By"))
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
74 depends_on = OptionalTicketReference.using(label=L_("Depends On"))
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
75
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1963
diff changeset
76
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
77 class TicketBackRefForm(Form):
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
78 supersedes = BackReference.using(label=L_("Supersedes"))
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
79 required_by = BackReference.using(label=L_("Required By"))
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
80 subscribers = BackReference.using(label=L_("Subscribers"))
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
81
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
82 def _load(self, item):
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
83 id_ = item.meta[ITEMID]
2108
55694eb202a3 use constants for ticket meta keys in items/ticket.py too
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2094
diff changeset
84 self['supersedes'].set(Term(SUPERSEDED_BY, id_))
55694eb202a3 use constants for ticket meta keys in items/ticket.py too
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2094
diff changeset
85 self['required_by'].set(Term(DEPENDS_ON, id_))
2159
246904e49804 change simple occurences of subscribed_items to subscriptions
Ana Balica <ana.balica@gmail.com>
parents: 2123
diff changeset
86 self['subscribers'].set(Term(SUBSCRIPTIONS, id_))
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
87
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1963
diff changeset
88
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
89 class TicketForm(BaseModifyForm):
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
90 meta = TicketMetaForm
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
91 backrefs = TicketBackRefForm
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
92 message = OptionalMultilineText.using(label=L_("Message")).with_properties(rows=8, cols=80)
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
93
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
94 def _load(self, item):
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
95 meta = item.prepare_meta_for_modify(item.meta)
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
96 self['meta'].set(meta, 'duck')
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
97 # XXX need a more explicit way to test for item creation/modification
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
98 if ITEMID in item.meta:
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
99 self['backrefs']._load(item)
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
100
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
101
2018
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
102 class TicketSubmitForm(TicketForm):
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
103 submit_label = L_("Submit ticket")
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
104
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
105 def _dump(self, item):
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
106 # initial metadata for Ticket-itemtyped item
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
107 meta = {
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
108 ITEMTYPE: item.itemtype,
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
109 # XXX support other markups
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
110 CONTENTTYPE: 'text/x.moin.wiki;charset=utf-8',
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
111 'closed': False,
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
112 }
2092
f8570c669184 Fix setting metadata property on ticket creation.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2040
diff changeset
113 meta.update(self['meta'].value)
2018
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
114 return meta, message_markup(self['message'].value)
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
115
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
116
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
117 class TicketUpdateForm(TicketForm):
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
118 submit = SelectSubmit.valued('update', 'update_negate_status')
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
119
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
120 def _load(self, item):
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
121 super(TicketUpdateForm, self)._load(item)
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
122 self['submit'].properties['labels'] = {
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
123 'update': L_('Update ticket'),
2040
d47f2665684a make pep8 checker happy
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2018
diff changeset
124 'update_negate_status': (L_('Update & reopen ticket') if item.meta.get('closed')
d47f2665684a make pep8 checker happy
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2018
diff changeset
125 else L_('Update & close ticket'))
2018
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
126 }
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
127
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
128 def _dump(self, item):
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
129 # Since the metadata form for tickets is an incomplete one, we load the
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
130 # original meta and update it with those from the metadata editor
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
131 meta = item.meta_filter(item.prepare_meta_for_modify(item.meta))
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
132 meta.update(self['meta'].value)
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
133 if self['submit'].value == 'update_negate_status':
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
134 meta['closed'] = not meta.get('closed')
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
135
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
136 data = item.content.data_storage_to_internal(item.content.data)
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
137 message = self['message'].value
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
138 if message:
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
139 data += message_markup(message)
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
140
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
141 return meta, data
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
142
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
143
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
144 # XXX Ideally we should generate DOM instead of moin wiki source. But
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
145 # currently this is not very useful, since
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
146 # * DOM cannot be stored directly, it has to be converted to some markup first
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
147 # * DOM -> markup conversion is only available for moinwiki
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
148
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
149 # XXX How to do i18n on this?
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
150
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
151 def message_markup(message):
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
152 return u'''{{{{{{#!wiki tip
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
153 %(author)s wrote on <<DateTime(%(timestamp)d)>>:
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
154
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
155 %(message)s
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
156 }}}}}}
2094
ce4cce38fe51 Use name[0] in Reference element and generated ticket comment
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2092
diff changeset
157 ''' % dict(author=flaskg.user.name[0], timestamp=time.time(), message=message)
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
158
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
159
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
160 @register
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
161 class Ticket(Contentful):
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
162 itemtype = ITEMTYPE_TICKET
1815
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1678
diff changeset
163 display_name = L_('Ticket')
a38ad19c9e7c Replace ITEMTYPES with information collected in item_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1678
diff changeset
164 description = L_('Ticket item')
2123
6b640b54adde split ticket.html into ticket/{base,submit,modify}.html
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2108
diff changeset
165 submit_template = 'ticket/submit.html'
6b640b54adde split ticket.html into ticket/{base,submit,modify}.html
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2108
diff changeset
166 modify_template = 'ticket/modify.html'
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
167
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
168 def do_show(self, revid):
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
169 if revid != CURRENT:
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
170 # TODO When requesting a historical version, show a readonly view
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
171 abort(403)
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
172 else:
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
173 return self.do_modify()
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
174
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
175 def do_modify(self):
1990
22441b6366e6 improve use of is_new in Ticket.do_modify a bit
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1988
diff changeset
176 is_new = isinstance(self.content, NonExistentContent)
2018
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
177 closed = self.meta.get('closed')
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
178
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
179 Form = TicketSubmitForm if is_new else TicketUpdateForm
1990
22441b6366e6 improve use of is_new in Ticket.do_modify a bit
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1988
diff changeset
180
1963
f05af7eb6f50 fix handling of HEAD requests
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1815
diff changeset
181 if request.method in ['GET', 'HEAD']:
2018
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
182 form = Form.from_item(self)
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
183 elif request.method == 'POST':
2018
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
184 form = Form.from_request(request)
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
185 if form.validate():
2018
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
186 meta, data = form._dump(self)
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
187 try:
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
188 self.modify(meta, data)
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
189 except AccessDenied:
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
190 abort(403)
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
191 else:
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
192 return redirect(url_for('.show_item', item_name=self.name))
2018
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
193
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
194 # XXX When creating new item, suppress the "foo doesn't exist. Create it?" dummy content
7ae56d378f15 support close/reopen ticket
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1990
diff changeset
195 data_rendered = None if is_new else Markup(self.content._render_data())
1678
51e1e8b0b7f2 Implement Ticket item as 'ticket' itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents:
diff changeset
196
2713
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2656
diff changeset
197 suggested_tags = get_itemtype_specific_tags(ITEMTYPE_TICKET)
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2656
diff changeset
198
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2656
diff changeset
199 return render_template(self.submit_template if is_new else self.modify_template,
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2656
diff changeset
200 is_new=is_new,
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2656
diff changeset
201 closed=closed,
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2656
diff changeset
202 item_name=self.name,
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2656
diff changeset
203 data_rendered=data_rendered,
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2656
diff changeset
204 form=form,
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2656
diff changeset
205 suggested_tags=suggested_tags,
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2656
diff changeset
206 item=self,
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2656
diff changeset
207 )