Пример #1
0
def getDocumentList():
    """

    Gets a slice of a document list. Uses URL arguments:

      page: mandatory, page to present
      search: optional, search criteria
      orderbyfield: optional, set by default to title
      orderbyorder: optional, asc / desc, set by default to asc

    TODO: modify data validation

    """
    m = DocumentModel()
    out = []

    search = request.args["search"] if "search" in request.args else None
    orderbyfield = "last_edit_time"
    orderbyorder = "desc"

    totalSize = m.getDocumentListSize(search=search)
    docs = m.getDocumentList(request.args["page"], cons.backend["DocumentListLength"], \
                             search=search, orderByField=orderbyfield, orderByOrder=orderbyorder)

    for doc in docs:
        thisDoc = dict()
        thisDoc["id"] = doc["id"]
        thisDoc["english"]=False
        thisDoc["spanish"]=False
        
        if doc["title_en"]!="" and doc["theme_en"]!="" and doc["description_en"]!="":
            thisDoc["english"]=True
            
        if doc["title_es"]!="" and doc["theme_es"]!="" and doc["description_es"]!="":
            thisDoc["spanish"]=True

        thisDoc["title"] = doc["title"]
        thisDoc["time"] = str(doc["publishing_date"].isoformat())
        thisDoc["edit_time"] = doc["time"].isoformat()
        thisDoc["published"] = doc["published"]

        thisDoc["authors"] = m.getDocumentAuthors(doc["id"])
        thisDoc["attachments"] = False
        if len(m.getDocumentPdf(doc["id"]))>0:
            thisDoc["attachments"] = True

        thisDoc["links"] = False
        if doc["link_es"]!=None or doc["link_en"]!=None:
            thisDoc["links"] = True

        out.append(thisDoc)

    return(jsonify({"results": {"listSize": totalSize, "page": int(request.args["page"]), \
                                "data": out}}))