コード例 #1
0
ファイル: api.py プロジェクト: esimorre/openplm
def search(request, editable_only="true", with_file_only="true"):
    """
    Returns all objects matching a query.

    :param editable_only: if ``"true"`` (the default), returns only editable objects
    :param with_file_only: if ``"true"`` (the default), returns only documents with 
                           at least one file

    :implements: :func:`http_api.search`
    """
    if request.GET and "type" in request.GET:
        attributes_form = forms.TypeForm(request.GET)
        if attributes_form.is_valid():
            query_dict = {}
            cls = models.get_all_plmobjects()[attributes_form.cleaned_data["type"]]
            extra_attributes_form = forms.get_search_form(cls, request.GET)
            results = cls.objects.all()
            if extra_attributes_form.is_valid():
                results = extra_attributes_form.search(results)
                objects = []
                for res in results:
                    if editable_only == "false" or res.is_editable:
                        if with_file_only == "true" and hasattr(res, "files") \
                           and not bool(res.files):
                            continue
                        if editable_only == "true":
                            obj = DocumentController(res, request.user)
                            if not obj.check_permission("owner", False):
                                continue
                        objects.append(object_to_dict(res))
                return {"objects" : objects} 
    return {"result": "error"}
コード例 #2
0
ファイル: api.py プロジェクト: esimorre/openplm
def get_search_fields(request, typename):
    """
    Returns search fields associated to *typename*.

    :implements: :func:`http_api.search_fields`
    """
    try:
        form = forms.get_search_form(models.get_all_plmobjects()[typename])
    except KeyError:
        return {"result" : "error", "fields" : []}
    return {"fields" : get_fields_from_form(form)}