Beispiel #1
0
def group_list():
    """
    View which combines a list of quick summaries concerning the goings-on
    for each of your groups.
    """
    # First, grab all of the User's Groups via the list of their Memberships.
    groups = helper.get_groups_from_user(current_user)

    # Then get the relevant information from each group and puts it into the content object
    content = {"groups": []}
    for group in groups:
        content["groups"].append(
            {
                "human_name": group.human_name,
                "code_name": group.code_name,
                "byline": group.byline,
                "description": group.description,
            }
        )

    # Lastly, pass in the "infonav" object used to build the sidebar navigation.
    infonav = groupbot.views.build_infonav("user")
    return render_template("pages/groups/list.html", content=content, infonav=infonav)
Beispiel #2
0
def build_infonav(level, current_group=None, member=None):
    """
    This function produces the information required to construct the (now simplified) navbar.  The level
    parameter determines whether we should be passing in the list of groups (for the top-level dashboard view)
    or instead be passing in the information required to show one group (for the group detail view).

    :param level:
    :return infonav:
    """

    # First, make our infonav object
    infonav = {}

    # If we're at the user level, we just need the sidebar to list each of the user's groups
    if level == "user":
        infonav["parent"] = {"name": current_user.codename, "view": "group_list"}
        user_groups = helper.get_groups_from_user(current_user)
        infonav["pages"] = []
        for each_group in user_groups:
            infonav["pages"].append({"name": each_group.code_name, "view": "group_list"})

    # At the group level, however, we want to list all the vital information from each group.
    # Namely, we need links to Tasks, Events, Roles, and Members.  Tasks and Events have the five
    # upcoming objects as children along with a link to the actual List page, Role and Member
    # have no children -- just a link to the list page.
    elif level == "group":
        # First off, make sure the group is defined -- otherwise we're borked!
        if current_group == None:
            raise Exception("No Group supplied to create infonav!")
        else:
            # Assuming it's defined, get the parent listing set up
            infonav["parent"] = {
                "name": current_group.code_name,
                "view": "group_detail",
                "args": {"group_id": current_group.group_id},
            }

            # Now the fun part.  First, add the links for Members and Roles
            infonav["pages"] = []
            infonav["pages"].append({"name": "Members", "view": "member_list"})
            infonav["pages"].append({"name": "Roles", "view": "role_list"})

            # Now, make the objects required to populate Tasks and its children
            task_view = {"name": "Tasks", "view": "task_list"}
            upcoming_tasks = m.Task.query.filter_by(group_id=current_group.id).order_by(m.Task.deadline).limit(5)
            task_view["children"] = []
            for each_task in upcoming_tasks:
                task_view["children"].append(
                    {"name": each_task.name, "view": "task_detail", "args": {"task_id": each_task.task_id}}
                )
            infonav["pages"].append(task_view)

            # Same story, but now with the Group's Events
            event_view = {"name": "Events", "view": "event_list"}
            upcoming_events = m.Event.query.filter_by(group_id=current_group.id).order_by(m.Event.start_time).limit(5)
            for each_event in upcoming_events:
                event_view["children"].append(
                    {"name": each_event.name, "view": "event_detail", "args": {"event_id": each_event.event_id}}
                )
            infonav["pages"].append(event_view)

    return infonav