Esempio n. 1
0
def task_movements_by_member(request, movement_type="forward", board=None):
    if movement_type != "forward" and movement_type != "backward":
        raise ValueError(
            "{0} is not recognized as a valid movement type".format(
                movement_type))

    # Caching
    chart_uuid = "members.task_movements_by_member-{0}-{1}".format(
        movement_type,
        board.id if board else "user-{0}".format(request.user.id))
    chart = CachedChart.get(board=board, uuid=chart_uuid)
    if chart:
        return chart

    chart_title = u"Task {0} movements as of {1}".format(
        movement_type, timezone.now())
    if board:
        chart_title += u" for board {0}".format(board.name)

    member_chart = pygal.HorizontalBar(title=chart_title,
                                       legend_at_bottom=True,
                                       print_values=True,
                                       print_zeroes=False,
                                       human_readable=True)

    card_movement_filter = {"type": movement_type}
    if board:
        card_movement_filter["board_id"] = board.id

    # If this user is a member, include it in the developers list at the front
    if user_is_member(request.user):
        members = [request.user.member] + list(
            Member.get_user_team_mates(request.user))
    else:
        members = Member.get_user_team_mates(request.user)

    for member_i in members:
        member_name = member_i.external_username
        num_card_movements = member_i.card_movements.filter(
            **card_movement_filter).count()
        if num_card_movements > 0:
            member_chart.add(u"{0}".format(member_name), num_card_movements)

    chart = CachedChart.make(board=board,
                             uuid=chart_uuid,
                             svg=member_chart.render(is_unicode=True))
    return chart.render_django_response()
Esempio n. 2
0
def index(request):
    member = None
    boards = []
    member_multiboards = []
    team_mates = []
    current_user = request.user
    if user_is_member(current_user):
        member = current_user.member
        member_multiboards = member.multiboards. \
            filter(show_in_index=True, is_archived=False). \
            order_by("order", "name")

    lists = []
    if current_user.is_authenticated():
        team_mates = Member.get_user_team_mates(request.user)
        boards = get_user_boards(current_user).filter(
            is_archived=False).order_by("name")

    now = timezone.now()
    today = now.date()
    week_of_year = get_week_of_year(today)

    weeks_of_year = get_weeks_of_year_since_one_year_ago()

    replacements = {
        "any_card_has_value":
        Card.objects.filter(board__in=boards, value__isnull=False).exists(),
        "has_noise_measurements":
        NoiseMeasurement.objects.filter(
            Q(member__in=team_mates) | Q(member=member)).exists(),
        "weeks_of_year":
        weeks_of_year,
        "lists":
        lists,
        "boards":
        boards,
        "week_of_year":
        week_of_year,
        "member":
        member,
        "multiboards":
        member_multiboards,
        "developers":
        [member] + (list(member.team_mates.filter(
            is_developer=True)) if member else list(team_mates)),
        "downtime_developers": ([
            dev for dev in member.team_members.filter(is_developer=True)
            if dev.is_in_downtime
        ]) if member else [],
        "pending_red_cards":
        Card.objects.filter(board__in=boards,
                            list__type="ready_to_develop",
                            is_closed=False,
                            labels__color="red").order_by(
                                "board__name", "name"),
        "pending_orange_cards":
        Card.objects.filter(board__in=boards,
                            list__type="ready_to_develop",
                            is_closed=False,
                            labels__color="orange").order_by(
                                "board__name", "name"),
        "pending_yellow_cards":
        Card.objects.filter(board__in=boards,
                            list__type="ready_to_develop",
                            is_closed=False,
                            labels__color="yellow").order_by(
                                "board__name", "name")
    }
    return render(request, "index/index.html", replacements)