def get(self, request, app_label=None, rptname=None, fldname=None, **kw): """If `fldname` is specified, return a JSON object with two attributes `count` and `rows`, where `rows` is a list of `(display_text, value)` tuples. Used by ComboBoxes or similar widgets. If `fldname` is not specified, returns the choices for the `record_selector` widget. """ rpt = requested_actor(app_label, rptname) emptyValue = None if fldname is None: ar = rpt.request(request=request) qs = ar.data_iterator def row2dict(obj, d): d[constants.CHOICES_TEXT_FIELD] = str(obj) # getattr(obj,'pk') d[constants.CHOICES_VALUE_FIELD] = obj.pk return d else: # NOTE: if you define a *parameter* with the same name as # some existing *data element* name, then the parameter # will override the data element here in choices view. field = rpt.get_param_elem(fldname) if field is None: field = rpt.get_data_elem(fldname) if field.blank: # logger.info("views.Choices: %r is blank",field) emptyValue = '<br/>' ar = rpt.request(request=request) qs, row2dict = choices_for_field(ar, rpt, field) return choices_response(rpt, request, qs, row2dict, emptyValue)
def get(self, request, app_label=None, actor=None, an=None, field=None, **kw): actor = requested_actor(app_label, actor) ba = actor.get_url_action(an) if ba is None: raise Exception("Unknown action %r for %s" % (an, actor)) field = ba.action.get_param_elem(field) qs, row2dict = choices_for_field(ba.request(request=request), ba.action, field) if field.blank: emptyValue = '<br/>' else: emptyValue = None return choices_response(actor, request, qs, row2dict, emptyValue)
def get(self, request, app_label=None, rptname=None, fldname=None, **kw): """ Return a JSON object with two attributes `count` and `rows`, where `rows` is a list of `(display_text,value)` tuples. Used by ComboBoxes or similar widgets. If `fldname` is not specified, returns the choices for the `record_selector` widget. """ rpt = requested_actor(app_label, rptname) emptyValue = None if fldname is None: ar = rpt.request(request=request) # ,rpt.default_action) # ~ rh = rpt.get_handle(self) # ~ ar = ViewReportRequest(request,rh,rpt.default_action) # ~ ar = dbtables.TableRequest(self,rpt,request,rpt.default_action) # ~ rh = ar.ah # ~ qs = ar.get_data_iterator() qs = ar.data_iterator # ~ qs = rpt.request(self).get_queryset() def row2dict(obj, d): d[constants.CHOICES_TEXT_FIELD] = str(obj) # getattr(obj,'pk') d[constants.CHOICES_VALUE_FIELD] = obj.pk return d else: """ NOTE: if you define a *parameter* with the same name as some existing *data element* name, then the parameter will override the data element. At least here in choices view. """ # ~ field = find_field(rpt.model,fldname) field = rpt.get_param_elem(fldname) if field is None: field = rpt.get_data_elem(fldname) if field.blank: # ~ logger.info("views.Choices: %r is blank",field) emptyValue = '' qs, row2dict = choices_for_field(rpt.request(request=request), rpt, field) return choices_response(rpt, request, qs, row2dict, emptyValue)