Example #1
0
def elem2rec_detailed(ar,elem,**rec):
    """
    Adds additional information for this record, used only by detail views.
    
    The "navigation information" is a set of pointers to the next, previous, 
    first and last record relative to this record in this report. 
    (This information can be relatively expensive for records that are towards 
    the end of the report. 
    See `/blog/2010/0716`,
    `/blog/2010/0721`,
    `/blog/2010/1116`,
    `/blog/2010/1207`.)
    
    recno 0 means "the requested element exists but is not contained in the requested queryset".
    This can happen after changing the quick filter (search_change) of a detail view.
    
    """
    rh = ar.ah
    rec = elem2rec1(ar,rh,elem,**rec)
    if ar.actor.hide_top_toolbar:
        rec.update(title=ar.get_detail_title(elem))
    else:
        #~ print(ar.get_title())
        #~ print(dd.obj2str(elem))
        #~ print(repr(unicode(elem)))
        if True:  # before 20131017
            rec.update(title=ar.get_title() + u" » " + ar.get_detail_title(elem))
        else: # todo
            rec.update(title=E.tostring(ar.href_to_request(ar)) + u" » " + ar.get_detail_title(elem))
    rec.update(id=elem.pk)
    rec.update(disable_delete=rh.actor.disable_delete(elem,ar))
    if rh.actor.show_detail_navigator:
        rec.update(navinfo=navinfo(ar.data_iterator,elem))
    return rec
Example #2
0
    def as_html(self,ar,pk):
        ah = ar.ah
        ba = ar.bound_action
        rpt = ar.actor

        
        navigator = None
        if pk and pk != '-99999' and pk != '-99998':
            elem = ar.get_row_by_pk(pk)
            if elem is None:
                raise http.Http404("%s has no row with primary key %r" % (rpt,pk))
                #~ raise Exception("20120327 %s.get_row_by_pk(%r)" % (rpt,pk))
            if ar.actor.show_detail_navigator:
              
                ni = navinfo(ar.data_iterator,elem)
                if ni:
                    buttons = []
                    #~ buttons.append( ('*',_("Home"), '/' ))
                    
                    buttons.append( ('<<',_("First page"), ar.pk2url(ni['first']) ))
                    buttons.append( ('<',_("Previous page"), ar.pk2url(ni['prev']) ))
                    buttons.append( ('>',_("Next page"), ar.pk2url(ni['next']) ))
                    buttons.append( ('>>',_("Last page"), ar.pk2url(ni['last']) ))
                        
                    #~ chunks = []
                    #~ for text,title,url in buttons:
                        #~ chunks.append('[')
                        #~ if url:
                            #~ chunks.append(E.a(text,href=url,title=title))
                        #~ else:
                            #~ chunks.append(text)
                        #~ chunks.append('] ')
                    #~ navigator = E.p(*chunks)
                    navigator = buttons2pager(buttons)
                else:
                    navigator = E.p("No navinfo")
        else:
            elem = None
        
        
        wl = ar.bound_action.get_window_layout()
        #~ print 20120901, wl.main
        lh = wl.get_layout_handle(settings.SITE.ui)
        
        #~ items = list(render_detail(ar,elem,lh.main))
        items = list(lh.main.as_plain_html(ar,elem))
        if navigator: items.insert(0,navigator)
        #~ print E.tostring(E.div())
        #~ if len(items) == 0: return ""
        main = E.form(*items)
        #~ print 20120901, lh.main.__html__(ar)
        """
        The method="html" argument isn't available in Python 2.6, only 2.7
        It is useful to avoid side effects in case of empty elements:
        the default method (xml) writes an empty E.div() as "<div/>"
        while in HTML5 it must be "<div></div>" (the ending / is ignored)
        """
        #~ return E.tostring(main,method="html")
        #~ return E.tostring(main)
        return main
Example #3
0
 def swap_seqno(self, ar, offset):
     """
     Move this row "up or down" within its siblings
     """
     #~ qs = self.get_siblings()
     qs = ar.data_iterator
     if qs is None:
         return
     nav = AttrDict(**navinfo(qs, self))
     if not nav.recno:
         return
     new_recno = nav.recno + offset
     if new_recno <= 0:
         return
     if new_recno > qs.count():
         return
     other = qs[new_recno - 1]
     prev_seqno = other.seqno
     other.seqno = self.seqno
     self.seqno = prev_seqno
     self.save()
     other.save()