Beispiel #1
0
def render_cms_events(listid, resource, rfields, record, **attr):
    """
        Custom dataList item renderer for 'Events' on the Home page

        @param listid: the HTML ID for this list
        @param resource: the S3Resource to render
        @param rfields: the S3ResourceFields to render
        @param record: the record as dict
        @param attr: additional HTML attributes for the item
    """

    T = current.T
    pkey = "cms_post.id"

    # Construct the item ID
    if pkey in record:
        record_id = record[pkey]
        item_id = "%s-%s" % (listid, record_id)
    else:
        # template
        item_id = "%s-[id]" % listid

    item_class = "thumbnail"

    raw = record._row
    series = "Event"
    date = record["cms_post.date"]
    body = record["cms_post.body"]
    location = record["cms_post.location_id"]
    location_id = raw["cms_post.location_id"]
    location_url = URL(c="gis", f="location", args=[location_id])
    author = record["cms_post.created_by"]
    author_id = raw["cms_post.created_by"]
    organisation = record["auth_user.organisation_id"]
    organisation_id = raw["auth_user.organisation_id"]
    org_url = URL(c="org", f="organisation", args=[organisation_id, "profile"])
    # @ToDo: Optimise by not doing DB lookups (especially duplicate) within render, but doing these in the bulk query
    avatar = s3_avatar_represent(author_id,
                                 _class="media-object",
                                 _style="width:50px;padding:5px;padding-top:0px;")
    db = current.db
    ltable = current.s3db.pr_person_user
    ptable = db.pr_person
    query = (ltable.user_id == author_id) & \
            (ltable.pe_id == ptable.pe_id)
    row = db(query).select(ptable.id,
                           limitby=(0, 1)
                           ).first()
    if row:
        person_url = URL(c="hrm", f="person", args=[row.id])
    else:
        person_url = "#"
    author = A(author,
               _href=person_url,
               )
    avatar = A(avatar,
               _href=person_url,
               _class="pull-left",
               )

    # Edit Bar
    permit = current.auth.s3_has_permission
    table = db.cms_post
    if permit("update", table, record_id=record_id):
        edit_btn = A(I(" ", _class="icon icon-edit"),
                     _href=URL(c="cms", f="post",
                               args=[record_id, "update.popup"],
                               vars={"refresh": listid,
                                     "record": record_id}),
                     _class="s3_modal",
                     _title=T("Edit Event"),
                     )
    else:
        edit_btn = ""
    if permit("delete", table, record_id=record_id):
        delete_btn = A(I(" ", _class="icon icon-remove-sign"),
                       _class="dl-item-delete",
                       )
    else:
        delete_btn = ""
    edit_bar = DIV(edit_btn,
                   delete_btn,
                   _class="edit-bar fright",
                   )

    # Dropdown of available documents
    documents = raw["doc_document.file"]
    if documents:
        if not isinstance(documents, list):
            documents = [documents]
        doc_list = UL(_class="dropdown-menu",
                      _role="menu",
                      )
        retrieve = db.doc_document.file.retrieve
        for doc in documents:
            try:
                doc_name = retrieve(doc)[0]
            except IOError:
                doc_name = current.messages["NONE"]
            doc_url = URL(c="default", f="download",
                          args=[doc])
            doc_item = LI(A(I(_class="icon-file"),
                            " ",
                            doc_name,
                            _href=doc_url,
                            ),
                          _role="menuitem",
                          )
            doc_list.append(doc_item)
        docs = DIV(A(I(_class="icon-paper-clip"),
                     SPAN(_class="caret"),
                     _class="btn dropdown-toggle",
                     _href="#",
                     **{"_data-toggle": "dropdown"}
                     ),
                   doc_list,
                   _class="btn-group attachments dropdown pull-right",
                   )
    else:
        docs = ""

    # Render the item
    item = DIV(DIV(I(SPAN(" %s" % T("Event"),
                          _class="card-title",
                          ),
                     _class="icon icon-%s" % series.lower().replace(" ", "_"),
                     ),
                   SPAN(A(location,
                          _href=location_url,
                          ),
                        _class="location-title",
                        ),
                   SPAN(date,
                        _class="date-title",
                        ),
                   edit_bar,
                   _class="card-header",
                   ),
               DIV(avatar,
                   DIV(DIV(body,
                           DIV(author,
                               " - ",
                               A(organisation,
                                 _href=org_url,
                                 _class="card-organisation",
                                 ),
                               docs,
                               _class="card-person",
                               ),
                           _class="media",
                           ),
                       _class="media-body",
                       ),
                   _class="media",
                   ),
               _class=item_class,
               _id=item_id,
               )

    return item
Beispiel #2
0
def render_homepage_posts(rfields, record, **attr):
    """
        Custom dataList item renderer for CMS Posts on the Homepage

        @param rfields: the S3ResourceFields to render
        @param record: the record as dict
        @param attr: additional HTML attributes for the item
    """
    
    pkey = "cms_post.id"

    # Construct the item ID
    listid = "datalist"
    if pkey in record:
        record_id = record[pkey]
        item_id = "%s-%s" % (listid, record_id)
    else:
        # template
        item_id = "%s-[id]" % listid

    item_class = "thumbnail"

    db = current.db

    raw = record._row
    series = record["cms_post.series_id"]
    date = record["cms_post.created_on"]
    body = record["cms_post.body"]
    location = record["cms_post.location_id"]
    location_id = raw["cms_post.location_id"]
    location_url = URL(c="gis", f="location", args=[location_id])

    # Attachment(s)?
    document = raw["doc_document.file"]
    if document:
        doc_url = URL(c="default", f="download",
                      args=[document]
                      )
        doc_link = A(I(_class="icon icon-paper-clip fright"),
                     _href=doc_url)
    else:
        doc_link = ""

    if series not in ("News", "Twitter", "Ushahidi", "YouTube"):
        # We expect an Author
        author = record["cms_post.created_by"]
        author_id = raw["cms_post.created_by"]
        organisation = record["auth_user.organisation_id"]
        organisation_id = raw["auth_user.organisation_id"]
        org_url = URL(c="org", f="organisation", args=[organisation_id])
        # @ToDo: Optimise by not doing DB lookups (especially duplicate) within render, but doing these in the bulk query
        avatar = s3_avatar_represent(author_id,
                                     _class="media-object",
                                     _style="width:50px;padding:5px;padding-top:0px;")
        s3db = current.s3db
        ltable = s3db.pr_person_user
        ptable = db.pr_person
        query = (ltable.user_id == author_id) & \
                (ltable.pe_id == ptable.pe_id)
        row = db(query).select(ptable.id,
                               limitby=(0, 1)
                               ).first()
        if row:
            person_url = URL(c="hrm", f="person", args=[row.id])
        else:
            person_url = "#"
        author = A(author,
                   _href=person_url,
                   )
        avatar = A(avatar,
                   _href=person_url,
                   _class="pull-left",
                   )
        card_person = DIV(author,
                          " - ",
                          A(organisation,
                            _href=org_url,
                            _class="card-organisation",
                            ),
                          doc_link,
                          _class="card-person",
                          )
    else:
        # No Author
        card_person = DIV(doc_link,
                          _class="card-person",
                          )
        avatar = None
        if series == "News":
            icon = URL(c="static", f="img",
                       args=["markers", "gis_marker.image.News.png"])
        elif series == "Twitter":
            icon = URL(c="static", f="img", args=["social", "twitter.png"])
        elif series == "Ushahidi":
            icon = URL(c="static", f="img",
                       args=["markers", "gis_marker.image.Ushahidi.png"])
        elif series == "YouTube":
            #icon = URL(c="static", f="img", args=["social", "YouTube.png"])
            avatar = DIV(IFRAME(_width=320,
                                _height=180,
                                _src=raw["cms_post.comments"],
                                _frameborder=0),
                         _class="pull-left"
                         )
        if not avatar:
            avatar = DIV(IMG(_src=icon,
                             _class="media-object",
                             _style="width:50px;padding:5px;padding-top:0px;",
                             ),
                         _class="pull-left")

    # Edit Bar
    permit = current.auth.s3_has_permission
    table = db.cms_post
    if permit("update", table, record_id=record_id):
        edit_btn = A(I(" ", _class="icon icon-edit"),
                     _href=URL(c="cms", f="post", args=[record_id, "update"]),
                     )
    else:
        edit_btn = ""
    if permit("delete", table, record_id=record_id):
        delete_btn = A(I(" ", _class="icon icon-remove-sign"),
                       _href=URL(c="cms", f="post",
                                 args=[record_id, "delete"]),
                       )
    else:
        delete_btn = ""
    edit_bar = DIV(edit_btn,
                   delete_btn,
                   _class="edit-bar fright",
                   )

    if series == "Alert":
        item_class = "%s disaster" % item_class

    # Overall layout
    item = DIV(DIV(I(SPAN(" %s" % current.T(series),
                          _class="card-title",
                          ),
                     _class="icon icon-%s" % series.lower(),
                     ),
                   SPAN(A(location,
                          _href=location_url,
                          ),
                        _class="location-title",
                        ),
                   SPAN(date,
                        _class="date-title",
                        ),
                   edit_bar,
                   _class="card-header",
                   ),
               DIV(avatar,
                   DIV(DIV(body,
                           card_person,
                           _class="media",
                           ),
                       _class="media-body",
                       ),
                   _class="media",
                   ),
               _class=item_class,
               _id=item_id,
               )

    return item
Beispiel #3
0
def render_homepage_posts(list_id, item_id, resource, rfields, record):
    """
        Custom dataList item renderer for CMS Posts on the Homepage

        @param list_id: the HTML ID of the list
        @param item_id: the HTML ID of the item
        @param resource: the S3Resource to render
        @param rfields: the S3ResourceFields to render
        @param record: the record as dict
    """

    record_id = record["cms_post.id"]
    item_class = "thumbnail"

    db = current.db

    raw = record._row
    series = record["cms_post.series_id"]
    date = record["cms_post.created_on"]
    body = record["cms_post.body"]
    location = record["cms_post.location_id"]
    location_id = raw["cms_post.location_id"]
    location_url = URL(c="gis", f="location", args=[location_id])

    # Attachment(s)?
    document = raw["doc_document.file"]
    if document:
        doc_url = URL(c="default", f="download", args=[document])
        doc_link = A(I(_class="icon icon-paper-clip fright"), _href=doc_url)
    else:
        doc_link = ""

    if series not in ("News", "Twitter", "Ushahidi", "YouTube"):
        # We expect an Author
        author = record["cms_post.created_by"]
        author_id = raw["cms_post.created_by"]
        organisation = record["auth_user.organisation_id"]
        organisation_id = raw["auth_user.organisation_id"]
        org_url = URL(c="org", f="organisation", args=[organisation_id])
        # @ToDo: Optimise by not doing DB lookups (especially duplicate) within render, but doing these in the bulk query
        avatar = s3_avatar_represent(
            author_id,
            _class="media-object",
            _style="width:50px;padding:5px;padding-top:0px;")
        s3db = current.s3db
        ltable = s3db.pr_person_user
        ptable = db.pr_person
        query = (ltable.user_id == author_id) & \
                (ltable.pe_id == ptable.pe_id)
        row = db(query).select(ptable.id, limitby=(0, 1)).first()
        if row:
            person_url = URL(c="hrm", f="person", args=[row.id])
        else:
            person_url = "#"
        author = A(
            author,
            _href=person_url,
        )
        avatar = A(
            avatar,
            _href=person_url,
            _class="pull-left",
        )
        card_person = DIV(
            author,
            " - ",
            A(
                organisation,
                _href=org_url,
                _class="card-organisation",
            ),
            doc_link,
            _class="card-person",
        )
    else:
        # No Author
        card_person = DIV(
            doc_link,
            _class="card-person",
        )
        avatar = None
        if series == "News":
            icon = URL(c="static",
                       f="img",
                       args=["markers", "gis_marker.image.News.png"])
        elif series == "Twitter":
            icon = URL(c="static", f="img", args=["social", "twitter.png"])
        elif series == "Ushahidi":
            icon = URL(c="static",
                       f="img",
                       args=["markers", "gis_marker.image.Ushahidi.png"])
        elif series == "YouTube":
            #icon = URL(c="static", f="img", args=["social", "YouTube.png"])
            avatar = DIV(IFRAME(_width=320,
                                _height=180,
                                _src=raw["cms_post.comments"],
                                _frameborder=0),
                         _class="pull-left")
        if not avatar:
            avatar = DIV(IMG(
                _src=icon,
                _class="media-object",
                _style="width:50px;padding:5px;padding-top:0px;",
            ),
                         _class="pull-left")

    # Edit Bar
    permit = current.auth.s3_has_permission
    table = db.cms_post
    if permit("update", table, record_id=record_id):
        edit_btn = A(
            I(" ", _class="icon icon-edit"),
            _href=URL(c="cms", f="post", args=[record_id, "update"]),
        )
    else:
        edit_btn = ""
    if permit("delete", table, record_id=record_id):
        delete_btn = A(
            I(" ", _class="icon icon-remove-sign"),
            _href=URL(c="cms", f="post", args=[record_id, "delete"]),
        )
    else:
        delete_btn = ""
    edit_bar = DIV(
        edit_btn,
        delete_btn,
        _class="edit-bar fright",
    )

    if series == "Alert":
        item_class = "%s disaster" % item_class

    # Overall layout
    item = DIV(
        DIV(
            I(
                SPAN(
                    " %s" % current.T(series),
                    _class="card-title",
                ),
                _class="icon icon-%s" % series.lower(),
            ),
            SPAN(
                A(
                    location,
                    _href=location_url,
                ),
                _class="location-title",
            ),
            SPAN(
                date,
                _class="date-title",
            ),
            edit_bar,
            _class="card-header",
        ),
        DIV(
            avatar,
            DIV(
                DIV(
                    body,
                    card_person,
                    _class="media",
                ),
                _class="media-body",
            ),
            _class="media",
        ),
        _class=item_class,
        _id=item_id,
    )

    return item
Beispiel #4
0
def render_cms_events(list_id, item_id, resource, rfields, record):
    """
        Custom dataList item renderer for 'Events' on the Home page

        @param list_id: the HTML ID of the list
        @param item_id: the HTML ID of the item
        @param resource: the S3Resource to render
        @param rfields: the S3ResourceFields to render
        @param record: the record as dict
    """

    record_id = record["cms_post.id"]
    item_class = "thumbnail"

    T = current.T

    raw = record._row
    series = "Event"
    date = record["cms_post.date"]
    body = record["cms_post.body"]
    location = record["cms_post.location_id"]
    location_id = raw["cms_post.location_id"]
    location_url = URL(c="gis", f="location", args=[location_id])
    author = record["cms_post.created_by"]
    author_id = raw["cms_post.created_by"]
    organisation = record["auth_user.organisation_id"]
    organisation_id = raw["auth_user.organisation_id"]
    org_url = URL(c="org", f="organisation", args=[organisation_id, "profile"])
    # @ToDo: Optimise by not doing DB lookups (especially duplicate) within render, but doing these in the bulk query
    avatar = s3_avatar_represent(
        author_id,
        _class="media-object",
        _style="width:50px;padding:5px;padding-top:0;")
    db = current.db
    ltable = current.s3db.pr_person_user
    ptable = db.pr_person
    query = (ltable.user_id == author_id) & \
            (ltable.pe_id == ptable.pe_id)
    row = db(query).select(ptable.id, limitby=(0, 1)).first()
    if row:
        person_url = URL(c="hrm", f="person", args=[row.id])
    else:
        person_url = "#"
    author = A(
        author,
        _href=person_url,
    )
    avatar = A(
        avatar,
        _href=person_url,
        _class="pull-left",
    )

    # Edit Bar
    permit = current.auth.s3_has_permission
    table = db.cms_post
    if permit("update", table, record_id=record_id):
        edit_btn = A(
            I(" ", _class="icon icon-edit"),
            _href=URL(c="cms",
                      f="post",
                      args=[record_id, "update.popup"],
                      vars={
                          "refresh": list_id,
                          "record": record_id
                      }),
            _class="s3_modal",
            _title=T("Edit Event"),
        )
    else:
        edit_btn = ""
    if permit("delete", table, record_id=record_id):
        delete_btn = A(
            I(" ", _class="icon icon-remove-sign"),
            _class="dl-item-delete",
        )
    else:
        delete_btn = ""
    edit_bar = DIV(
        edit_btn,
        delete_btn,
        _class="edit-bar fright",
    )

    # Dropdown of available documents
    documents = raw["doc_document.file"]
    if documents:
        if not isinstance(documents, list):
            documents = [documents]
        doc_list = UL(
            _class="dropdown-menu",
            _role="menu",
        )
        retrieve = db.doc_document.file.retrieve
        for doc in documents:
            try:
                doc_name = retrieve(doc)[0]
            except IOError:
                doc_name = current.messages["NONE"]
            doc_url = URL(c="default", f="download", args=[doc])
            doc_item = LI(
                A(
                    I(_class="icon-file"),
                    " ",
                    doc_name,
                    _href=doc_url,
                ),
                _role="menuitem",
            )
            doc_list.append(doc_item)
        docs = DIV(
            A(I(_class="icon-paper-clip"),
              SPAN(_class="caret"),
              _class="btn dropdown-toggle",
              _href="#",
              **{"_data-toggle": "dropdown"}),
            doc_list,
            _class="btn-group attachments dropdown pull-right",
        )
    else:
        docs = ""

    # Render the item
    item = DIV(
        DIV(
            I(
                SPAN(
                    " %s" % T("Event"),
                    _class="card-title",
                ),
                _class="icon icon-%s" % series.lower().replace(" ", "_"),
            ),
            SPAN(
                A(
                    location,
                    _href=location_url,
                ),
                _class="location-title",
            ),
            SPAN(
                date,
                _class="date-title",
            ),
            edit_bar,
            _class="card-header",
        ),
        DIV(
            avatar,
            DIV(
                DIV(
                    body,
                    DIV(
                        author,
                        " - ",
                        A(
                            organisation,
                            _href=org_url,
                            _class="card-organisation",
                        ),
                        docs,
                        _class="card-person",
                    ),
                    _class="media",
                ),
                _class="media-body",
            ),
            _class="media",
        ),
        _class=item_class,
        _id=item_id,
    )

    return item
Beispiel #5
0
    def custom_postp(r, output):
        if r.representation == "plain" and \
           r.method != "search":
            # Map Popups - styled like dataList
            auth = current.auth
            db = current.db
            record = r.record
            record_id = record.id

            item_class = "thumbnail"
            item_id = "popup-%s" % record_id

            table = s3db.cms_post
            series = table.series_id.represent(record.series_id)
            date = S3DateTime.date_represent(record.created_on, utc=True)
            body = record.body
            location_id = record.location_id
            location = table.location_id.represent(location_id)
            location_url = URL(c="gis", f="location", args=[location_id])

            # Attachment(s)?
            table = s3db.doc_document
            row = db(table.doc_id == record.doc_id).select(
                table.file, limitby=(0, 1)).first()
            if row:
                doc_url = URL(c="default", f="download", args=[row.file])
                doc_link = A(I(_class="icon icon-paper-clip fright"),
                             _href=doc_url)
            else:
                doc_link = ""

            if series not in ("News", "Twitter", "Ushahidi", "YouTube"):
                # We expect an Author
                author_id = record.created_by
                author = table.created_by.represent(author_id)
                utable = auth.settings.table_user
                user = db(utable.id == author_id).select(
                    utable.organisation_id, limitby=(0, 1)).first()
                organisation_id = user.organisation_id
                organisation = s3db.org_organisation_id.attr["represent"](
                    organisation_id)
                org_url = URL(c="org",
                              f="organisation",
                              args=[organisation_id])
                # @ToDo: Optimise by not doing DB lookups (especially duplicate) within render, but doing these in the bulk query
                avatar = s3_avatar_represent(
                    author_id,
                    _class="media-object",
                    _style="width:50px;padding:5px;padding-top:0px;")
                ltable = s3db.pr_person_user
                ptable = db.pr_person
                query = (ltable.user_id == author_id) & \
                        (ltable.pe_id == ptable.pe_id)
                row = db(query).select(ptable.id, limitby=(0, 1)).first()
                if row:
                    person_url = URL(c="hrm", f="person", args=[row.id])
                else:
                    person_url = "#"
                author = A(
                    author,
                    _href=person_url,
                )
                avatar = A(
                    avatar,
                    _href=person_url,
                    _class="pull-left",
                )
                card_person = DIV(
                    author,
                    " - ",
                    A(
                        organisation,
                        _href=org_url,
                        _class="card-organisation",
                    ),
                    doc_link,
                    _class="card-person",
                )
            else:
                # No Author
                card_person = DIV(
                    doc_link,
                    _class="card-person",
                )
                avatar = None
                if series == "News":
                    icon = URL(c="static",
                               f="img",
                               args=["markers", "gis_marker.image.News.png"])
                elif series == "Twitter":
                    icon = URL(c="static",
                               f="img",
                               args=["social", "twitter.png"])
                elif series == "Ushahidi":
                    icon = URL(
                        c="static",
                        f="img",
                        args=["markers", "gis_marker.image.Ushahidi.png"])
                elif series == "YouTube":
                    #icon = URL(c="static", f="img", args=["social", "YouTube.png"])
                    avatar = DIV(IFRAME(_width=320,
                                        _height=180,
                                        _src=record.comments,
                                        _frameborder=0),
                                 _class="pull-left")
                if not avatar:
                    avatar = DIV(IMG(
                        _src=icon,
                        _class="media-object",
                        _style="width:50px;padding:5px;padding-top:0px;",
                    ),
                                 _class="pull-left")

            # Edit Bar
            permit = auth.s3_has_permission
            if permit("update", table, record_id=record_id):
                edit_btn = A(
                    I(" ", _class="icon icon-edit"),
                    _href=URL(c="cms", f="post", args=[record_id, "update"]),
                )
            else:
                edit_btn = ""
            # delete_btn looks too much like popup close!
            #if permit("delete", table, record_id=record_id):
            #    delete_btn = A(I(" ", _class="icon icon-remove-sign"),
            #                   _href=URL(c="cms", f="post",
            #                   args=[record_id, "delete"]),
            #                   )
            #else:
            delete_btn = ""
            edit_bar = DIV(
                edit_btn,
                delete_btn,
                _class="edit-bar fright",
            )

            # Overall layout
            output = DIV(
                DIV(
                    I(
                        SPAN(
                            " %s" % T(series),
                            _class="card-title",
                        ),
                        _class="icon icon-%s" % series.lower(),
                    ),
                    SPAN(
                        A(
                            location,
                            _href=location_url,
                        ),
                        _class="location-title",
                    ),
                    SPAN(
                        date,
                        _class="date-title",
                    ),
                    edit_bar,
                    _class="card-header",
                ),
                DIV(
                    avatar,
                    DIV(
                        DIV(
                            body,
                            card_person,
                            _class="media",
                        ),
                        _class="media-body",
                    ),
                    _class="media",
                ),
                _class=item_class,
                _id=item_id,
            )
        elif callable(standard_postp):
            # Call standard postp
            output = standard_postp(r, output)
        return output
Beispiel #6
0
def render_profile_posts(listid, resource, rfields, record, **attr):
    """
        Custom dataList item renderer for CMS Posts on the Profile pages

        @param listid: the HTML ID for this list
        @param resource: the S3Resource to render
        @param rfields: the S3ResourceFields to render
        @param record: the record as dict
        @param attr: additional HTML attributes for the item
    """

    pkey = "cms_post.id"

    # Construct the item ID
    if pkey in record:
        record_id = record[pkey]
        item_id = "%s-%s" % (listid, record_id)
    else:
        # template
        item_id = "%s-[id]" % listid

    item_class = "thumbnail"

    raw = record._row
    series = record["cms_post.series_id"]
    date = record["cms_post.created_on"]
    body = record["cms_post.body"]
    location = record["cms_post.location_id"]
    location_id = raw["cms_post.location_id"]
    location_url = URL(c="gis", f="location", args=[location_id])
    author = record["cms_post.created_by"]
    author_id = raw["cms_post.created_by"]
    organisation = record["auth_user.organisation_id"]
    organisation_id = raw["auth_user.organisation_id"]
    org_url = URL(c="org", f="organisation", args=[organisation_id])
    # @ToDo: Optimise by not doing DB lookups (especially duplicate) within render, but doing these in the bulk query
    avatar = s3_avatar_represent(author_id,
                                 _class="media-object")
    db = current.db
    s3db = current.s3db
    ltable = s3db.pr_person_user
    ptable = db.pr_person
    query = (ltable.user_id == author_id) & \
            (ltable.pe_id == ptable.pe_id)
    row = db(query).select(ptable.id,
                           limitby=(0, 1)
                           ).first()
    if row:
        person_url = URL(c="hrm", f="person", args=[row.id])
    else:
        person_url = "#"
    author = A(author,
               _href=person_url,
               )
    avatar = A(avatar,
               _href=person_url,
               _class="pull-left",
               )
    permit = current.auth.s3_has_permission
    table = db.cms_post
    if permit("update", table, record_id=record_id):
        edit_btn = A(I(" ", _class="icon icon-edit"),
                     _href=URL(c="cms", f="post",
                               args=[record_id, "update.popup"],
                               vars={"refresh": listid,
                                     "record": record_id}),
                     _class="s3_modal",
                     _title=current.response.s3.crud_strings.cms_post.title_update,
                     )
    else:
        edit_btn = ""
    if permit("delete", table, record_id=record_id):
        #delete_btn = A(I(" ", _class="icon icon-remove-sign"),
                       #_href=URL(c="cms", f="post", args=[record_id, "delete"]),
                       #)
        delete_btn = A(I(" ", _class="icon icon-remove-sign"),
                       _class="dl-item-delete",
                      )
    else:
        delete_btn = ""
    edit_bar = DIV(edit_btn,
                   delete_btn,
                   _class="edit-bar fright",
                   )
    document = raw["doc_document.file"]
    if document:
        doc_url = URL(c="default", f="download",
                      args=[document]
                      )
        doc_link = A(I(_class="icon icon-paper-clip fright"),
                     _href=doc_url)
    else:
        doc_link = ""

    # Render the item
    class SMALL(DIV):
        tag = "small"

    item = DIV(DIV(DIV(avatar,
                       P(SMALL(" ", author, " ",
                               A(organisation,
                                 _href=org_url,
                                 _class="card-organisation",
                                 ),
                               ),
                         _class="citation"),
                       _class="span1"),
                   DIV(SPAN(A(location,
                              _href=location_url,
                              ),
                            _class="location-title"),
                        " ",
                        SPAN(date,
                             _class="date-title"),
                        edit_bar,
                        P(body,
                          _class="card_comments"),
                        doc_link,
                       _class="span5 card-details"),
                   _class="row",
                   ),
               _class=item_class,
               _id=item_id,
               )

    return item
Beispiel #7
0
    def custom_postp(r, output):
        if r.representation == "plain" and \
           r.method != "search":
            # Map Popups - styled like dataList
            auth = current.auth
            db = current.db
            record = r.record
            record_id = record.id

            item_class = "thumbnail"
            item_id = "popup-%s" % record_id

            table = s3db.cms_post
            series = table.series_id.represent(record.series_id)
            date = S3DateTime.date_represent(record.created_on, utc=True)
            body = record.body
            location_id = record.location_id
            location = table.location_id.represent(location_id)
            location_url = URL(c="gis", f="location", args=[location_id])

            # Attachment(s)?
            table = s3db.doc_document
            row = db(table.doc_id == record.doc_id).select(table.file,
                                                           limitby=(0, 1)
                                                           ).first()
            if row:
                doc_url = URL(c="default", f="download",
                              args=[row.file]
                              )
                doc_link = A(I(_class="icon icon-paper-clip fright"),
                             _href=doc_url)
            else:
                doc_link = ""

            if series not in ("News", "Twitter", "Ushahidi", "YouTube"):
                # We expect an Author
                author_id = record.created_by
                author = table.created_by.represent(author_id)
                utable = auth.settings.table_user
                user = db(utable.id == author_id).select(utable.organisation_id,
                                                         limitby=(0, 1)
                                                         ).first()
                organisation_id = user.organisation_id
                organisation = s3db.org_organisation_id.attr["represent"](organisation_id)
                org_url = URL(c="org", f="organisation", args=[organisation_id])
                # @ToDo: Optimise by not doing DB lookups (especially duplicate) within render, but doing these in the bulk query
                avatar = s3_avatar_represent(author_id,
                                             _class="media-object",
                                             _style="width:50px;padding:5px;padding-top:0px;")
                ltable = s3db.pr_person_user
                ptable = db.pr_person
                query = (ltable.user_id == author_id) & \
                        (ltable.pe_id == ptable.pe_id)
                row = db(query).select(ptable.id,
                                       limitby=(0, 1)
                                       ).first()
                if row:
                    person_url = URL(c="hrm", f="person", args=[row.id])
                else:
                    person_url = "#"
                author = A(author,
                           _href=person_url,
                           )
                avatar = A(avatar,
                           _href=person_url,
                           _class="pull-left",
                           )
                card_person = DIV(author,
                                  " - ",
                                  A(organisation,
                                    _href=org_url,
                                    _class="card-organisation",
                                    ),
                                  doc_link,
                                  _class="card-person",
                                  )
            else:
                # No Author
                card_person = DIV(doc_link,
                                  _class="card-person",
                                  )
                avatar = None
                if series == "News":
                    icon = URL(c="static", f="img",
                               args=["markers", "gis_marker.image.News.png"])
                elif series == "Twitter":
                    icon = URL(c="static", f="img", args=["social", "twitter.png"])
                elif series == "Ushahidi":
                    icon = URL(c="static", f="img",
                               args=["markers", "gis_marker.image.Ushahidi.png"])
                elif series == "YouTube":
                    #icon = URL(c="static", f="img", args=["social", "YouTube.png"])
                    avatar = DIV(IFRAME(_width=320,
                                        _height=180,
                                        _src=record.comments,
                                        _frameborder=0),
                                 _class="pull-left"
                                 )
                if not avatar:
                    avatar = DIV(IMG(_src=icon,
                                     _class="media-object",
                                     _style="width:50px;padding:5px;padding-top:0px;",
                                     ),
                                 _class="pull-left")

            # Edit Bar
            permit = auth.s3_has_permission
            if permit("update", table, record_id=record_id):
                edit_btn = A(I(" ", _class="icon icon-edit"),
                             _href=URL(c="cms", f="post",
                             args=[record_id, "update"]),
                             )
            else:
                edit_btn = ""
            # delete_btn looks too much like popup close!
            #if permit("delete", table, record_id=record_id):
            #    delete_btn = A(I(" ", _class="icon icon-remove-sign"),
            #                   _href=URL(c="cms", f="post",
            #                   args=[record_id, "delete"]),
            #                   )
            #else:
            delete_btn = ""
            edit_bar = DIV(edit_btn,
                           delete_btn,
                           _class="edit-bar fright",
                           )

            # Overall layout
            output = DIV(DIV(I(SPAN(" %s" % T(series),
                                    _class="card-title",
                                    ),
                               _class="icon icon-%s" % series.lower(),
                               ),
                             SPAN(A(location,
                                    _href=location_url,
                                    ),
                                  _class="location-title",
                                  ),
                             SPAN(date,
                                  _class="date-title",
                                  ),
                             edit_bar,
                             _class="card-header",
                             ),
                         DIV(avatar,
                             DIV(DIV(body,
                                     card_person,
                                     _class="media",
                                     ),
                                 _class="media-body",
                                 ),
                             _class="media",
                             ),
                         _class=item_class,
                         _id=item_id,
                         )
        elif callable(standard_postp):
            # Call standard postp
            output = standard_postp(r, output)
        return output
Beispiel #8
0
def render_profile_posts(listid, resource, rfields, record, **attr):
    """
        Custom dataList item renderer for CMS Posts on the Profile pages

        @param listid: the HTML ID for this list
        @param resource: the S3Resource to render
        @param rfields: the S3ResourceFields to render
        @param record: the record as dict
        @param attr: additional HTML attributes for the item
    """

    pkey = "cms_post.id"

    # Construct the item ID
    if pkey in record:
        record_id = record[pkey]
        item_id = "%s-%s" % (listid, record_id)
    else:
        # template
        item_id = "%s-[id]" % listid

    item_class = "thumbnail"

    raw = record._row
    series = record["cms_post.series_id"]
    date = record["cms_post.created_on"]
    body = record["cms_post.body"]
    event_id = raw["event_event_post.event_id"]
    location = record["cms_post.location_id"]
    location_id = raw["cms_post.location_id"]
    location_url = URL(c="gis", f="location", args=[location_id])
    author = record["cms_post.created_by"]
    author_id = raw["cms_post.created_by"]
    organisation = record["auth_user.organisation_id"]
    organisation_id = raw["auth_user.organisation_id"]
    org_url = URL(c="org", f="organisation", args=[organisation_id])
    # @ToDo: Optimise by not doing DB lookups (especially duplicate) within render, but doing these in the bulk query
    avatar = s3_avatar_represent(author_id, _class="media-object")
    db = current.db
    s3db = current.s3db
    ltable = s3db.pr_person_user
    ptable = db.pr_person
    query = (ltable.user_id == author_id) & \
            (ltable.pe_id == ptable.pe_id)
    row = db(query).select(ptable.id, limitby=(0, 1)).first()
    if row:
        person_url = URL(c="hrm", f="person", args=[row.id])
    else:
        person_url = "#"
    author = A(
        author,
        _href=person_url,
    )
    avatar = A(
        avatar,
        _href=person_url,
        _class="pull-left",
    )
    permit = current.auth.s3_has_permission
    table = db.cms_post
    if permit("update", table, record_id=record_id):
        vars = {
            "refresh": listid,
            "record": record_id,
            "~.series_id$name": series,
        }
        f = current.request.function
        if f == "event" and event_id:
            vars["(event)"] = event_id
        if f == "location" and location_id:
            vars["(location)"] = location_id
        edit_btn = A(
            I(" ", _class="icon icon-edit"),
            _href=URL(c="cms",
                      f="post",
                      args=[record_id, "update.popup"],
                      vars=vars),
            _class="s3_modal",
            _title=current.response.s3.crud_strings.cms_post.title_update,
        )
    else:
        edit_btn = ""
    if permit("delete", table, record_id=record_id):
        delete_btn = A(
            I(" ", _class="icon icon-remove-sign"),
            _class="dl-item-delete",
        )
    else:
        delete_btn = ""
    edit_bar = DIV(
        edit_btn,
        delete_btn,
        _class="edit-bar fright",
    )
    document = raw["doc_document.file"]
    if document:
        doc_url = URL(c="default", f="download", args=[document])
        doc_link = A(I(_class="icon icon-paper-clip fright"), _href=doc_url)
    else:
        doc_link = ""

    # Render the item
    class SMALL(DIV):
        tag = "small"

    item = DIV(
        DIV(
            DIV(avatar,
                P(SMALL(
                    " ",
                    author,
                    " ",
                    A(
                        organisation,
                        _href=org_url,
                        _class="card-organisation",
                    ),
                ),
                  _class="citation"),
                _class="span1"),
            DIV(SPAN(A(
                location,
                _href=location_url,
            ),
                     _class="location-title"),
                " ",
                SPAN(date, _class="date-title"),
                edit_bar,
                P(body, _class="card_comments"),
                doc_link,
                _class="span5 card-details"),
            _class="row",
        ),
        _class=item_class,
        _id=item_id,
    )

    return item
Beispiel #9
0
def render_homepage_posts(listid, resource, rfields, record, **attr):
    """
        Custom dataList item renderer for CMS Posts on the Homepage

        @param listid: the HTML ID for this list
        @param resource: the S3Resource to render
        @param rfields: the S3ResourceFields to render
        @param record: the record as dict
        @param attr: additional HTML attributes for the item
    """

    pkey = "cms_post.id"

    # Construct the item ID
    if pkey in record:
        record_id = record[pkey]
        item_id = "%s-%s" % (listid, record_id)
    else:
        # template
        item_id = "%s-[id]" % listid

    item_class = "thumbnail"

    raw = record._row
    series = record["cms_post.series_id"]
    date = record["cms_post.created_on"]
    body = record["cms_post.body"]
    location = record["cms_post.location_id"]
    location_id = raw["cms_post.location_id"]
    location_url = URL(c="gis", f="location", args=[location_id])
    author = record["cms_post.created_by"]
    author_id = raw["cms_post.created_by"]
    organisation = record["auth_user.organisation_id"]
    organisation_id = raw["auth_user.organisation_id"]
    org_url = URL(c="org", f="organisation", args=[organisation_id, "profile"])
    # @ToDo: Optimise by not doing DB lookups (especially duplicate) within render, but doing these in the bulk query
    avatar = s3_avatar_represent(author_id,
                                 _class="media-object",
                                 _style="width:50px;padding:5px;padding-top:0px;")
    db = current.db
    s3db = current.s3db
    ltable = s3db.pr_person_user
    ptable = db.pr_person
    query = (ltable.user_id == author_id) & \
            (ltable.pe_id == ptable.pe_id)
    row = db(query).select(ptable.id,
                           limitby=(0, 1)
                           ).first()
    if row:
        person_url = URL(c="hrm", f="person", args=[row.id])
    else:
        person_url = "#"
    author = A(author,
               _href=person_url,
               )
    avatar = A(avatar,
               _href=person_url,
               _class="pull-left",
               )
    permit = current.auth.s3_has_permission
    table = db.cms_post
    if permit("update", table, record_id=record_id):
        edit_btn = A(I(" ", _class="icon icon-edit"),
                     _href=URL(c="cms", f="post",
                               args=[record_id, "update.popup"],
                               vars={"refresh": listid,
                                     "record": record_id}),
                     _class="s3_modal",
                     _title=current.response.s3.crud_strings.cms_post.title_update,
                     )
    else:
        edit_btn = ""
    if permit("delete", table, record_id=record_id):
        delete_btn = A(I(" ", _class="icon icon-remove-sign"),
                       _class="dl-item-delete",
                      )
    else:
        delete_btn = ""
    edit_bar = DIV(edit_btn,
                   delete_btn,
                   _class="edit-bar fright",
                   )
    # @ToDo: Dropdown of available documents
    document = raw["doc_document.file"]
    if document:
        doc_url = URL(c="default", f="download",
                      args=[document]
                      )
        doc_link = A(I(_class="icon icon-paper-clip fright"),
                     _href=doc_url)
    else:
        doc_link = ""

    if series == "Alert":
        item_class = "%s disaster" % item_class

    # Render the item
    item = DIV(DIV(I(SPAN(" %s" % current.T(series),
                          _class="card-title",
                          ),
                     _class="icon icon-%s" % series.lower().replace(" ", "_"),
                     ),
                   SPAN(A(location,
                          _href=location_url,
                          ),
                        _class="location-title",
                        ),
                   SPAN(date,
                        _class="date-title",
                        ),
                   edit_bar,
                   _class="card-header",
                   ),
               DIV(avatar,
                   DIV(DIV(body,
                           DIV(author,
                               " - ",
                               A(organisation,
                                 _href=org_url,
                                 _class="card-organisation",
                                 ),
                               doc_link,
                               _class="card-person",
                               ),
                           _class="media",
                           ),
                       _class="media-body",
                       ),
                   _class="media",
                   ),
               _class=item_class,
               _id=item_id,
               )

    return item