Commits

xiaq committed 1417016

Separate +show view for tickets

  • Participants
  • Parent commits 75e91cd

Comments (0)

Files changed (2)

File MoinMoin/items/ticket.py

         self['subscribers'].set(Term(SUBSCRIBED_ITEMS, id_))
 
 
-class TicketForm(BaseModifyForm):
-    meta = TicketMetaForm
+class TicketBaseForm(BaseModifyForm):
     backrefs = TicketBackRefForm
     message = OptionalMultilineText.using(label=L_("Message")).with_properties(rows=8, cols=80)
 
     def _load(self, item):
-        meta = item.prepare_meta_for_modify(item.meta)
-        self['meta'].set(meta, 'duck')
         # XXX need a more explicit way to test for item creation/modification
         if ITEMID in item.meta:
             self['backrefs']._load(item)
 
 
-class TicketSubmitForm(TicketForm):
+class TicketModifyForm(TicketBaseForm):
+    meta = TicketMetaForm
+
+    def _load(self, item):
+        super(TicketModifyForm, self)._load(item)
+        meta = item.prepare_meta_for_modify(item.meta)
+        self['meta'].set(meta, 'duck')
+
+
+class TicketSubmitForm(TicketModifyForm):
     submit_label = L_("Submit ticket")
 
     def _dump(self, item):
         return meta, message_markup(self['message'].value)
 
 
-class TicketUpdateForm(TicketForm):
+class TicketUpdateForm(TicketModifyForm):
     submit = SelectSubmit.valued('update', 'update_negate_status')
 
     def _load(self, item):
         return meta, data
 
 
+class TicketShowForm(TicketBaseForm):
+    """
+    Form used for the +show view of a ticket.
+
+    No TicketMetaForm here, since the +show view doesn't allow modifying metadata.
+    """
+
+
 # XXX Ideally we should generate DOM instead of moin wiki source. But
 # currently this is not very useful, since
 # * DOM cannot be stored directly, it has to be converted to some markup first
     itemtype = ITEMTYPE_TICKET
     display_name = L_('Ticket')
     description = L_('Ticket item')
+    show_template = 'ticket/show.html'
     submit_template = 'ticket/submit.html'
     modify_template = 'ticket/modify.html'
 
-    def do_show(self, revid):
-        if revid != CURRENT:
-            # TODO When requesting a historical version, show a readonly view
-            abort(403)
-        else:
-            return self.do_modify()
-
-    def do_modify(self):
+    def _do_show_or_modify(self, show):
         is_new = isinstance(self.content, NonExistentContent)
         closed = self.meta.get('closed')
 
-        Form = TicketSubmitForm if is_new else TicketUpdateForm
+        if show:
+            Form = TicketShowForm
+            template = self.show_template
+        else:
+            Form = TicketSubmitForm if is_new else TicketUpdateForm
+            template = self.submit_template if is_new else self.modify_template
 
         if request.method in ['GET', 'HEAD']:
             form = Form.from_item(self)
         # XXX When creating new item, suppress the "foo doesn't exist. Create it?" dummy content
         data_rendered = None if is_new else Markup(self.content._render_data())
 
-        return render_template(self.submit_template if is_new else self.modify_template,
+        return render_template(template,
                                is_new=is_new,
                                closed=closed,
                                item_name=self.name,
                                data_rendered=data_rendered,
                                form=form,
+                               item=self,
+                               display_fields=display_fields,
                               )
 
+    def do_show(self, revid):
+        if revid != CURRENT:
+            # TODO When requesting a historical version, show a readonly view
+            abort(403)
+        else:
+            return self._do_show_or_modify(show=True)
+
+    def do_modify(self):
+        return self._do_show_or_modify(show=False)
+
 
 ITEMTYPE_TICKET_INDEX = u'ticketindex'
 

File MoinMoin/templates/ticket/show.html

+{% extends "ticket/base.html" %}
+{% from "display_widgets.html" import render %}
+
+{% block title_text %}
+  {{ _("Ticket: '%(item_name)s'", item_name=item_name) }}
+{% endblock %}
+
+{% block form_controls %}
+  <h2>{{ _("Add comment") }}</h2>
+  <dl>
+    {{ forms.render(form['message']) }}
+  </dl>
+
+  <h2>{{ _("Metadata") }}</h2>
+  <dl>
+    {% for field in display_fields %}
+      <dt>{{ field.label }}</dt>
+      <dd>{{ render(item.meta[field.name], field.widget) }}</dd>
+    {% endfor %}
+  </dl>
+
+  <h2>{{ _("Back references") }}</h2>
+  <dl>
+    {{ render_backref() }}
+  </dl>
+{% endblock %}