def get(self, request, app_label=None, actor=None, pk=None): ar = action_request(app_label, actor, request, request.GET, False) ar.renderer = settings.SITE.plugins.bootstrap3.renderer 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" % (ar.actor, 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: # m = elem.__class__ 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']))) navigator = buttons2pager(buttons) else: navigator = E.p("No navinfo") else: elem = None main = layout2html(ar, elem) # 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>" # (and the ending / is ignored). #~ return tostring(main, method="html") #~ return tostring(main) # return main context = dict( title=ar.get_action_title(), obj=elem, form=main, navigator=navigator, ) #~ template = web.jinja_env.get_template('detail.html') context.update(ar=ar) return http_response(ar, ar.actor.detail_html_template, context)
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()
def save_new_instance(self, ar, elem): elem.save_new_instance(ar) ar.success(_("%s has been created.") % obj2unicode(elem)) # print(19062017, "Ticket 1910") if ar.actor.handle_uploaded_files is None: # The `rows` can contain complex strings which cause # decoding problems on the client when responding to a # file upload ar.set_response(rows=[ar.ah.store.row2list(ar, elem)]) ar.set_response(navinfo=navinfo(ar.data_iterator, elem)) else: # Must set text/html for file uploads, otherwise the # browser adds a <PRE></PRE> tag around the AJAX response. ar.set_content_type('text/html') # if ar.actor.stay_in_grid and ar.requesting_panel: if ar.actor.stay_in_grid: # do not open a detail window on the new instance return ar.goto_instance(elem)
def elem2rec_detailed(ar, elem, with_navinfo=True, **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 queryset. 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 = ar.elem2rec1(rh, elem, **rec) if ar.actor.hide_top_toolbar or ar.bound_action.action.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=tostring(ar.href_to_request(ar)) + u" » " + ar.get_detail_title(elem)) rec.update(id=elem.pk) if ar.actor.editable: rec.update(disable_delete=rh.actor.disable_delete(elem, ar)) if rh.actor.show_detail_navigator and with_navinfo: rec.update(navinfo=navinfo(ar.data_iterator, elem)) return rec
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 queryset. 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 = ar.elem2rec1(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) if ar.actor.editable: 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