Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def getit():
if ar.request is None:
columns = None
else:
data = getrqdata(ar.request)
columns = [
str(x) for x in
data.getlist(constants.URL_PARAM_COLUMNS)]
if columns:
all_widths = data.getlist(constants.URL_PARAM_WIDTHS)
hiddens = [(x == 'true') for x in data.getlist(
constants.URL_PARAM_HIDDENS)]
fields = []
widths = []
ah = ar.actor.get_handle()
for i, cn in enumerate(columns):
col = None
for e in ah.list_layout.main.columns:
if e.name == cn:
col = e
break
if col is None:
raise Exception("No column named %r in %s" %
(cn, ar.ah.list_layout.main.columns))
# ba = tbl.get_url_action(tbl.default_elem_action_name)
# 20120202
if tbl.master_field is not None:
from django.contrib.contenttypes.models import ContentType
rqdata = getrqdata(ar.request)
if tbl.master is not None:
master = tbl.master
else:
mt = rqdata.get(constants.URL_PARAM_MASTER_TYPE)
# ContentType = rt.models.contenttypes.ContentType
try:
master = ContentType.objects.get(pk=mt).model_class()
except ContentType.DoesNotExist:
master = None
pk = rqdata.get(constants.URL_PARAM_MASTER_PK, None)
if pk and master:
try:
kw[tbl.master_field.name] = master.objects.get(pk=pk)
except ValueError:
raise Exception(
"Invalid primary key %r for %s", pk, master.__name__)
except master.DoesNotExist:
raise Exception("There's no %s with primary key %r" %
(master.__name__, pk))
for k, v in list(ar.request.GET.items()):
kw[str(k)] = v
# logger.info(
# "20130513 get_request_choices(%r) -> %r",
# tbl, kw)
if isinstance(e, GridElement):
yield "%s.on_master_changed();" % e.as_ext()
elif isinstance(e, HtmlBoxElement):
yield "%s.refresh();" % e.as_ext()
elif isinstance(e, FieldElement):
if not panel.layout_handle.layout.editable:
return
holder = panel.layout_handle.layout.get_chooser_holder()
chooser = holder.get_chooser_for_field(e.field.name)
if not chooser:
return
for f in chooser.context_fields:
if master_field and master_field.name == f.name:
yield "var bp = this.get_base_params();"
yield "%s.setContextValue('%s',bp['%s']);" % (
e.as_ext(), constants.URL_PARAM_MASTER_PK,
constants.URL_PARAM_MASTER_PK)
yield "%s.setContextValue('%s',bp['%s']);" % (
e.as_ext(), constants.URL_PARAM_MASTER_TYPE,
constants.URL_PARAM_MASTER_TYPE)
else:
yield (
"%s.setContextValue('%s', record ? record."
"data['%s'] : undefined);" % (
e.as_ext(), f.name, form_field_name(f)))
def get_request_url(self, ar, *args, **kw):
if ar.actor.__name__ == "Main":
return self.front_end.build_plain_url(*args, **kw)
st = ar.get_status()
kw.update(st['base_params'])
add_user_language(kw, ar)
if ar.offset is not None:
kw.setdefault(ext_requests.URL_PARAM_START, ar.offset)
if ar.limit is not None:
kw.setdefault(ext_requests.URL_PARAM_LIMIT, ar.limit)
if ar.order_by is not None:
sc = ar.order_by[0]
if sc.startswith('-'):
sc = sc[1:]
kw.setdefault(ext_requests.URL_PARAM_SORTDIR, 'DESC')
kw.setdefault(ext_requests.URL_PARAM_SORT, sc)
#~ print '20120901 TODO get_request_url'
return self.front_end.build_plain_url(
ar.actor.app_label, ar.actor.__name__, *args, **kw)
else:
return '-' + k
sort_dir = rqdata.get(constants.URL_PARAM_SORTDIR, 'ASC')
if sort_dir == 'DESC':
sort = [si(k) for k in sort]
# sort = ['-' + k for k in sort]
# print("20171123", sort)
kw.update(order_by=sort)
try:
offset = rqdata.get(constants.URL_PARAM_START, None)
if offset:
kw.update(offset=int(offset))
limit = rqdata.get(
constants.URL_PARAM_LIMIT, self.actor.preview_limit)
if limit:
kw.update(limit=int(limit))
except ValueError:
# Example: invalid literal for int() with base 10:
# 'fdpkvcnrfdybhur'
raise SuspiciousOperation("Invalid value for limit or offset")
kw = self.actor.parse_req(request, rqdata, **kw)
# print("20171123 %s.parse_req() --> %s" % (self, kw))
return kw
"""
:param actor: requesting Actor
:param request: web request
:param qs: list of django model QS,
:param row2dict: function for converting data set into a dict for json
:param emptyValue: The Text value to represent None in the choice-list
:return: json web responce
Filters data-set acording to quickseach
Counts total rows in the set,
Calculates offset and limit
Adds None value
returns
"""
quick_search = request.GET.get(constants.URL_PARAM_FILTER, None)
offset = request.GET.get(constants.URL_PARAM_START, None)
limit = request.GET.get(constants.URL_PARAM_LIMIT, None)
if isinstance(qs, models.QuerySet):
qs = qs.filter(qs.model.quick_search_filter(quick_search)) if quick_search else qs
count = qs.count()
if offset:
qs = qs[int(offset):]
# ~ kw.update(offset=int(offset))
if limit:
# ~ kw.update(limit=int(limit))
qs = qs[:int(limit)]
rows = [row2dict(row, {}) for row in qs]
else:
def get_field_options(self, **kw):
kw = FieldElement.get_field_options(self, **kw)
# When used as editor of an EditorGridPanel, don't set the name attribute
# because it is not needed for grids and might conflict with fields of a
# surronding detail form. See ticket #38 (`/blog/2011/0408`).
# Also, Comboboxes with simple values may never have a hiddenName
# option.
if not isinstance(self.layout_handle.layout, ColumnsLayout) \
and not isinstance(self, SimpleRemoteComboFieldElement):
kw.update(hiddenName=self.field.name +
constants.CHOICES_HIDDEN_SUFFIX)
return kw
using a HttpRequest to build the context.
"""
kw = {
"ar": ar,
}
# kw = {}
# ba = tbl.get_url_action(tbl.default_elem_action_name)
# 20120202
if tbl.master_field is not None:
from django.contrib.contenttypes.models import ContentType
rqdata = getrqdata(ar.request)
if tbl.master is not None:
master = tbl.master
else:
mt = rqdata.get(constants.URL_PARAM_MASTER_TYPE)
# ContentType = rt.models.contenttypes.ContentType
try:
master = ContentType.objects.get(pk=mt).model_class()
except ContentType.DoesNotExist:
master = None
pk = rqdata.get(constants.URL_PARAM_MASTER_PK, None)
if pk and master:
try:
kw[tbl.master_field.name] = master.objects.get(pk=pk)
except ValueError:
raise Exception(
"Invalid primary key %r for %s", pk, master.__name__)
except master.DoesNotExist:
raise Exception("There's no %s with primary key %r" %
(master.__name__, pk))
from lino.core.store import ParameterStore
self.params_store = ParameterStore(lh, self.url_param_name)
class ActionParamsLayout(ParamsLayout):
"""
A Layout description for an action parameter panel.
Lino instantiates this for every :attr:`params_layout
` of a custom action.
A subclass of :class:`ParamsLayout`.
"""
join_str = "\n"
window_size = (50, 'auto')
url_param_name = constants.URL_PARAM_FIELD_VALUES
def setup_element(self, lh, e):
from lino.utils import jsgen
e.declare_type = jsgen.DECLARE_THIS
def get_choices_url(self, ui, field, **kw):
return settings.SITE.kernel.default_ui.build_plain_url(
"apchoices",
self._datasource.defining_actor.app_label,
self._datasource.defining_actor.__name__,
self._datasource.action_name,
field.name, **kw)
:param actor: requesting Actor
:param request: web request
:param qs: list of django model QS,
:param row2dict: function for converting data set into a dict for json
:param emptyValue: The Text value to represent None in the choice-list
:return: json web responce
Filters data-set acording to quickseach
Counts total rows in the set,
Calculates offset and limit
Adds None value
returns
"""
quick_search = request.GET.get(constants.URL_PARAM_FILTER, None)
offset = request.GET.get(constants.URL_PARAM_START, None)
limit = request.GET.get(constants.URL_PARAM_LIMIT, None)
if isinstance(qs, models.QuerySet):
qs = qs.filter(qs.model.quick_search_filter(quick_search)) if quick_search else qs
count = qs.count()
if offset:
qs = qs[int(offset):]
# ~ kw.update(offset=int(offset))
if limit:
# ~ kw.update(limit=int(limit))
qs = qs[:int(limit)]
rows = [row2dict(row, {}) for row in qs]
else:
rows = [row2dict(row, {}) for row in qs]