コード例 #1
0
ファイル: views.py プロジェクト: csdl/makahiki
def supply(request, page_name):
    """Supplies view_objects for education widget."""
    _ = page_name

    user = request.user
    completed = []
    available = {'activity': [], 'commitment': [], 'event': [], }
    pending = []
    for member in ActionMember.objects.filter(user=user):
        if member.approval_status == 'approved':
            completed.append(member.action)
        elif member.approval_status == 'pending':
            pending.append(member.action)
    for grid in Grid.objects.all():
        action = grid.action
        if smartgrid.is_unlock(user, action) and not action in pending and not action in completed:
            if smartgrid.availablity(action) == 0:
                available[action.type].append(action)

    return {
            'completed': completed,
            'pending': pending,
            'available_activities': available['activity'],
            'available_commitments': available['commitment'],
            'available_events': available['event'],
            }
コード例 #2
0
def supply(request, page_name):
    """Supplies view_objects for education widget."""
    _ = page_name

    user = request.user
    completed = []
    available = {
        'activity': [],
        'commitment': [],
        'event': [],
    }
    pending = []
    for member in ActionMember.objects.filter(user=user):
        if member.approval_status == 'approved':
            completed.append(member.action)
        elif member.approval_status == 'pending':
            pending.append(member.action)
    for grid in Grid.objects.all():
        action = grid.action
        if smartgrid.is_unlock(
                user,
                action) and not action in pending and not action in completed:
            if smartgrid.availablity(action) == 0:
                available[action.type].append(action)

    return {
        'completed': completed,
        'pending': pending,
        'available_activities': available['activity'],
        'available_commitments': available['commitment'],
        'available_events': available['event'],
    }
コード例 #3
0
ファイル: views.py プロジェクト: gregorylburgess/makahiki
def view_action(request, action_type, slug):
    """individual action page"""
    action = smartgrid.get_action(slug=slug)
    user = request.user
    team = user.get_profile().team
    view_objects = {}

    if not smartgrid.is_unlock(user, action):
        response = HttpResponseRedirect(reverse("learn_index", args=()))
        response.set_cookie("task_unlock_condition", action.unlock_condition_text)
        return response

    action = smartgrid.annotate_action_details(user, action)
    completed_members = smartgrid.get_action_members(action)
    completed_count = completed_members.count()
    team_members = completed_members.select_related('user__profile').filter(
        user__profile__team=team)

    if action_type == "commitment":
        form = view_commitments.view(request, action)
    elif action_type == "activity":
        form = view_activities.view(request, action)

        # if there is embedded widget, get the supplied objects
        if action.embedded_widget:
            view_module_name = 'apps.widgets.' + action.embedded_widget + '.views'
            view_objects[action.embedded_widget] = importlib.import_module(
                view_module_name).supply(request, None)
            view_objects['embedded_widget_template'] = "widgets/" + \
                action.embedded_widget + "/templates/index.html"
    elif action.type in ("event", "excursion"):  # action.event:
        form = view_events.view(request, action)
        # calculate available seat
        action.available_seat = action.event.event_max_seat - completed_count
    elif action_type == "filler":
        response = HttpResponseRedirect(reverse("learn_index", args=()))
        return response

    user_reminders = view_reminders.load_reminders(action, user)
    try:
        feedback = ActionFeedback.objects.get(user=user.pk, action=action.pk)
    except ObjectDoesNotExist:
        feedback = None

    view_objects['quests'] = get_quests(user)

    return render_to_response("task.html", {
        "action": action,
        "form": form,
        "completed_count": completed_count,
        "team_members": team_members,
        "display_form": True if "display_form" in request.GET else False,
        "reminders": user_reminders,
        "view_objects": view_objects,
        "feedback_p": feedback,
        }, context_instance=RequestContext(request))