Exemple #1
0
def prepare_filters(doctype, controller, kwargs):
    for key in kwargs.keys():
        try:
            kwargs[key] = json.loads(kwargs[key])
        except ValueError:
            pass
    filters = frappe._dict(kwargs)
    meta = frappe.get_meta(doctype)

    if hasattr(controller,
               'website') and controller.website.get('condition_field'):
        filters[controller.website['condition_field']] = 1

    if filters.pathname:
        # resolve additional filters from path
        resolve_path(filters.pathname)
        for key, val in frappe.local.form_dict.items():
            if key not in filters and key != 'flags':
                filters[key] = val

    # filter the filters to include valid fields only
    for fieldname, val in list(filters.items()):
        if not meta.has_field(fieldname):
            del filters[fieldname]

    return filters
Exemple #2
0
def get(doctype, txt=None, limit_start=0, **kwargs):
	"""Returns processed HTML page for a standard listing."""
	limit_start = cint(limit_start)
	limit_page_length = 20
	next_start = limit_start + limit_page_length

	filters = frappe._dict(kwargs)
	if filters.pathname:
		# resolve additional filters from path
		resolve_path(filters.pathname)
		for key, val in frappe.local.form_dict.items():
			if key in ("cmd", "pathname", "doctype", "txt", "limit_start"):
				if key in filters:
					del filters[key]

			elif key not in filters:
				filters[key] = val

	meta = frappe.get_meta(doctype)
	list_context = get_list_context({}, doctype)

	if list_context.filters:
		filters.update(list_context.filters)

	_get_list = list_context.get_list or get_list

	raw_result = _get_list(doctype=doctype, txt=txt, filters=filters,
		limit_start=limit_start, limit_page_length=limit_page_length)

	show_more = (_get_list(doctype=doctype, txt=txt, filters=filters,
		limit_start=next_start, limit_page_length=1) and True or False)

	if txt:
		list_context.default_subtitle = _('Filtered by "{0}"').format(txt)

	result = []
	row_template = list_context.row_template or "templates/includes/list/row_template.html"
	for doc in raw_result:
		doc.doctype = doctype
		new_context = { "doc": doc, "meta": meta }
		if not frappe.flags.in_test:
			new_context["pathname"] = frappe.local.request.path.strip("/ ")
		new_context.update(list_context)
		rendered_row = frappe.render_template(row_template, new_context, is_path=True)
		result.append(rendered_row)

	return {
		"result": result,
		"show_more": show_more,
		"next_start": next_start
	}
Exemple #3
0
def prepare_filters(doctype, kwargs):
	filters = frappe._dict(kwargs)
	meta = frappe.get_meta(doctype)

	if filters.pathname:
		# resolve additional filters from path
		resolve_path(filters.pathname)
		for key, val in frappe.local.form_dict.items():
			if key not in filters and key != 'flags':
				filters[key] = val

	# filter the filters to include valid fields only
	for fieldname, val in filters.items():
		if not meta.has_field(fieldname):
			del filters[fieldname]

	return filters
Exemple #4
0
def prepare_filters(kwargs):
    filters = frappe._dict(kwargs)

    if filters.pathname:
        # resolve additional filters from path
        resolve_path(filters.pathname)
        for key, val in frappe.local.form_dict.items():
            if key in ("cmd", "pathname", "doctype", "txt", "limit_start"):
                if key in filters:
                    del filters[key]

            elif key not in filters:
                filters[key] = val

    if "is_web_form" in filters:
        del filters["is_web_form"]

    return filters
Exemple #5
0
def prepare_filters(kwargs):
	filters = frappe._dict(kwargs)

	if filters.pathname:
		# resolve additional filters from path
		resolve_path(filters.pathname)
		for key, val in frappe.local.form_dict.items():
			if key in ("cmd", "pathname", "doctype", "txt", "limit_start"):
				if key in filters:
					del filters[key]

			elif key not in filters:
				filters[key] = val

	if "is_web_form" in filters:
		del filters["is_web_form"]

	return filters
Exemple #6
0
def prepare_filters(doctype, controller, kwargs):
	filters = frappe._dict(kwargs)
	meta = frappe.get_meta(doctype)

	if hasattr(controller, 'website') and controller.website.get('condition_field'):
		filters[controller.website['condition_field']] = 1

	if filters.pathname:
		# resolve additional filters from path
		resolve_path(filters.pathname)
		for key, val in frappe.local.form_dict.items():
			if key not in filters and key != 'flags':
				filters[key] = val

	# filter the filters to include valid fields only
	for fieldname, val in list(filters.items()):
		if not meta.has_field(fieldname):
			del filters[fieldname]

	return filters
Exemple #7
0
def get(doctype, txt=None, limit_start=0, **kwargs):
    """Returns processed HTML page for a standard listing."""
    limit_start = cint(limit_start)
    limit_page_length = 20
    next_start = limit_start + limit_page_length

    filters = frappe._dict(kwargs)
    if filters.pathname:
        # resolve additional filters from path
        resolve_path(filters.pathname)
        for key, val in frappe.local.form_dict.items():
            if key in ("cmd", "pathname", "doctype", "txt", "limit_start"):
                if key in filters:
                    del filters[key]

            elif key not in filters:
                filters[key] = val

    meta = frappe.get_meta(doctype)
    list_context = get_list_context({}, doctype)

    if list_context.filters:
        filters.update(list_context.filters)

    _get_list = list_context.get_list or get_list

    raw_result = _get_list(doctype=doctype,
                           txt=txt,
                           filters=filters,
                           limit_start=limit_start,
                           limit_page_length=limit_page_length)

    show_more = (_get_list(doctype=doctype,
                           txt=txt,
                           filters=filters,
                           limit_start=next_start,
                           limit_page_length=1) and True or False)

    if txt:
        list_context.default_subtitle = _('Filtered by "{0}"').format(txt)

    result = []
    row_template = list_context.row_template or "templates/includes/list/row_template.html"
    for doc in raw_result:
        doc.doctype = doctype
        new_context = {
            "doc": doc,
            "meta": meta,
            "pathname": frappe.local.request.path.strip("/ ")
        }
        new_context.update(list_context)
        result.append(
            frappe.render_template(row_template, new_context, is_path=True))

    list_context.update({
        "result": result,
        "show_more": show_more,
        "next_start": next_start
    })

    return list_context