[notification view] consider row/col
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 30 Jul 2009 15:19:29 +0200
changeset 2572 58556f9317c9
parent 2568 87f99ad0d3a8
child 2573 9c414dbc76da
[notification view] consider row/col
sobjects/notification.py
web/views/editforms.py
--- a/sobjects/notification.py	Thu Jul 30 11:30:06 2009 +0200
+++ b/sobjects/notification.py	Thu Jul 30 15:19:29 2009 +0200
@@ -134,14 +134,14 @@
       override call)
     """
     msgid_timestamp = True
-
+    # XXX refactor to work with len(rset) > 1
     def recipients(self):
         finder = self.vreg.select('components', 'recipients_finder', self.req,
                                   rset=self.rset)
         return finder.recipients()
 
     def subject(self):
-        entity = self.entity(0, 0)
+        entity = self.entity(self.row or 0, self.col or 0)
         subject = self.req._(self.message)
         etype = entity.dc_type()
         eid = entity.eid
@@ -154,7 +154,7 @@
         return self.req.actual_session().user.login
 
     def context(self, **kwargs):
-        entity = self.entity(0, 0)
+        entity = self.entity(self.row or 0, self.col or 0)
         for key, val in kwargs.iteritems():
             if val and isinstance(val, unicode) and val.strip():
                kwargs[key] = self.req._(val)
@@ -185,7 +185,7 @@
             lang = self.vreg.property_value('ui.language')
             recipients = zip(recipients, repeat(lang))
         if self.rset is not None:
-            entity = self.entity(0, 0)
+            entity = self.entity(self.row or 0, self.col or 0)
             # if the view is using timestamp in message ids, no way to reference
             # previous email
             if not self.msgid_timestamp:
@@ -282,7 +282,7 @@
 """
 
     def context(self, **kwargs):
-        entity = self.entity(0, 0)
+        entity = self.entity(self.row or 0, self.col or 0)
         content = entity.printable_value(self.content_attr, format='text/plain')
         if content:
             contentformat = getattr(entity, self.content_attr + '_format', 'text/rest')
@@ -290,7 +290,7 @@
         return super(ContentAddedView, self).context(content=content, **kwargs)
 
     def subject(self):
-        entity = self.entity(0, 0)
+        entity = self.entity(self.row or 0, self.col or 0)
         return  u'%s #%s (%s)' % (self.req.__('New %s' % entity.e_schema),
                                   entity.eid, self.user_login())
 
--- a/web/views/editforms.py	Thu Jul 30 11:30:06 2009 +0200
+++ b/web/views/editforms.py	Thu Jul 30 15:19:29 2009 +0200
@@ -43,7 +43,31 @@
         js, nodeid, label)
 
 
-class DeleteConfForm(FormViewMixIn, EntityView):
+class DeleteConfForm(forms.CompositeForm):
+    id = 'deleteconf'
+    __select__ = non_final_entity()
+
+    domid = 'deleteconf'
+    copy_nav_params = True
+    form_buttons = [Button(stdmsgs.YES, cwaction='delete'),
+                    Button(stdmsgs.NO, cwaction='cancel')]
+    @property
+    def action(self):
+        return self.build_url('edit')
+
+    def __init__(self, *args, **kwargs):
+        super(DeleteConfForm, self).__init__(*args, **kwargs)
+        done = set()
+        for entity in self.rset.entities():
+            if entity.eid in done:
+                continue
+            done.add(entity.eid)
+            subform = self.vreg.select('forms', 'base', self.req, entity=entity,
+                                       mainform=False)
+            self.form_add_subform(subform)
+
+
+class DeleteConfFormView(FormViewMixIn, EntityView):
     """form used to confirm deletion of some entities"""
     id = 'deleteconf'
     title = _('delete')
@@ -59,20 +83,9 @@
           % _('this action is not reversible!'))
         # XXX above message should have style of a warning
         w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s) ?'))
-        form = self.vreg.select('forms', 'composite', req, domid='deleteconf',
-                                copy_nav_params=True,
-                                action=self.build_url('edit'), onsubmit=onsubmit,
-                                form_buttons=[Button(stdmsgs.YES, cwaction='delete'),
-                                              Button(stdmsgs.NO, cwaction='cancel')])
-        done = set()
+        form = self.vreg.select('forms', 'composite', req, onsubmit=onsubmit)
         w(u'<ul>\n')
         for entity in self.rset.entities():
-            if entity.eid in done:
-                continue
-            done.add(entity.eid)
-            subform = self.vreg.select('forms', 'base', req, entity=entity,
-                                       mainform=False)
-            form.form_add_subform(subform)
             # don't use outofcontext view or any other that may contain inline edition form
             w(u'<li>%s</li>' % tags.a(entity.view('textoutofcontext'),
                                       href=entity.absolute_url()))