Beispiel #1
0
def cards_per_day(cards, date_from, date_to, column_from, column_to):
    date_from = HelperClass.get_si_date(date_from)
    date_to = HelperClass.get_si_date(date_to)
    date = date_from

    dates = {}
    column_from = models.Column.objects.get(id=column_from)
    column_to = models.Column.objects.get(id=column_to)
    between = columns_between(column_from, column_to)[::-1]

    while date <= date_to:
        tmp = {}
        for col in between:
            tmp[col.name] = 0

        for card in cards:
            columns = column_at_date(card, date.date())
            for column in columns:
                if column in between:
                    tmp[column.name] += 1

        dates[HelperClass.to_si_date(date)] = tmp
        date += datetime.timedelta(days=1)

    return dates
Beispiel #2
0
 def resolve_wip_logs(self, info, project_id, creation_start, creation_end, done_start, done_end, dev_start, \
                      dev_end, estimate_from, estimate_to, card_type, date_from=None, date_to=None):
     cards = filter_cards(project_id, creation_start, creation_end, done_start, done_end, dev_start, \
                          dev_end, estimate_from, estimate_to, card_type)
     logs = models.CardLog.objects.filter(action__isnull=False, card__in=cards)
     if date_from:
         start = HelperClass.get_si_date(date_from)
         logs = logs.filter(timestamp__gte=start)
     if date_to:
         end = HelperClass.get_si_date(date_to)
         logs = logs.filter(timestamp__lte=end + datetime.timedelta(days=1))
     if not logs:
         return []
     columns = models.Column.objects.filter(board=logs.first().to_column.board, parent=None)
     return sorted(logs, key=lambda k: get_columns_absolute(columns, []).index(k.to_column))
Beispiel #3
0
    def generate_report(self):
        for km in self.fuckton_dict:
            self.reports_txt[
                km] = "Dragi %s,\n\nSpodaj so napisane vse tabele in projekti, kjer bodo kartice kmalu potekle.\n\n----------------------------\n" % km.first_name
            self.reports_html[km] = "<p>" + self.reports_txt[km]
            for board in self.fuckton_dict[km]:
                self.reports_txt[km] += "Tabela %s:\n" % board.name
                self.reports_html[km] += "<p>" + "Tabela %s:\n" % board.name
                for proj in self.fuckton_dict[km][board]:
                    self.reports_txt[km] += "Projekt %s:\n" % proj.name
                    self.reports_html[km] += "<p>" + insert_tab() + "Projekt %s:\n" % proj.name
                    for card in self.fuckton_dict[km][board][proj]:
                        self.reports_txt[km] += "Kartica #%d %s:\n" % (card.card_number, card.name)
                        self.reports_txt[km] += "Rok: %s\n\n" % HelperClass.to_si_date(card.expiration)
                        self.reports_html[km] += "<p>" + insert_tab() + insert_tab() + "Kartica #%d %s:\n" % (
                            card.card_number,
                            card.name) + insert_tab() + insert_tab() + "Rok: %s\n\n" % HelperClass.to_si_date(
                            card.expiration) + "</p>"
                        if km in self.km_cards.keys():
                            cards = self.km_cards[km]
                            cards.append(card)
                            self.km_cards[km] = cards
                        else:
                            self.km_cards[km] = [card]
                    self.reports_html[km] + "</p>"
                self.reports_html[km] += "</p>"

            self.reports_txt[km] += "\nLep pozdrav, \n\n Emineo"
            self.reports_html[km] += "\nLep pozdrav, \n\n Emineo"+"</p>"
Beispiel #4
0
    def mutate(root, info, card=None, ok=False, card_data=None):
        if card_data.owner_userteam_id is None:
            owner = None
        else:
            owner = models.UserTeam.objects.get(id=card_data.owner_userteam_id)

        card = models.Card.objects.get(id=card_data.id)

        # zbrišemo vse taske ker jih kasneje na novo dodamo not
        models.Task.objects.filter(card=card).delete()

        card.column = models.Column.objects.get(id=card_data.column_id)
        card.type = models.CardType.objects.get(id=card_data.type_id)
        card.description = card_data.description
        card.name = card_data.name
        card.estimate = card_data.estimate
        card.project = models.Project.objects.get(id=card_data.project_id)
        old_expiration = card.expiration

        card.expiration = HelperClass.get_si_date(card_data.expiration).date()
        card.save()
        if card.expiration != old_expiration:
            card.was_mail_send = False
            if card.does_card_expire_soon(card.project.board.days_to_expire):
                projects_on_board = models.Project.objects.filter(board=card.project.board)
                for project in projects_on_board:
                    cards = models.Card.objects.filter(project=project)
                    for card in cards:
                        card.was_mail_send = False
                        card.save()
        card.owner = owner
        card.priority = card_data.priority
        card.save()

        # first delete all tasks assigned to card
        # for task in tasks:#
        #    task.delete()

        for task in card_data.tasks:
            if task.assignee_userteam_id is None:
                assignee = None
            else:
                assignee = models.UserTeam.objects.get(id=task.assignee_userteam_id)

            task_entity = models.Task(card=card, description=task.description, done=task.done, assignee=assignee, hours=task.hours)
            task_entity.save()

        return EditCard(ok=True, card=card)
Beispiel #5
0
def filter_cards(project_id, creation_start, creation_end, done_start, done_end, dev_start, dev_end, \
                 estimate_from, estimate_to, card_type):
    cards = models.Card.objects.all()
    if project_id:
        project = models.Project.objects.get(id=project_id)
        cards = cards.filter(project=project)
    if creation_start:
        start = HelperClass.get_si_date(creation_start)
        cards = cards.filter(date_created__gte=start)
    if creation_end:
        end = HelperClass.get_si_date(creation_end)
        cards = cards.filter(date_created__lte=end + datetime.timedelta(days=1))
    if done_start:
        start = HelperClass.get_si_date(done_start)
        done_column = get_done_column(project.board)
        valid_cards = models.CardLog.objects.filter(to_column=done_column, timestamp__gte=start).values_list('card',
                                                                                                             flat=True)
        cards = cards.filter(pk__in=[c for c in valid_cards])
    if done_end:
        end = HelperClass.get_si_date(done_end)
        done_column = get_done_column(project.board)
        valid_cards = models.CardLog.objects.filter(to_column=done_column,
                                                    timestamp__lt=end + datetime.timedelta(days=1)).values_list('card',
                                                                                                                flat=True)
        cards = cards.filter(pk__in=[c for c in valid_cards])
    if dev_start:
        start = HelperClass.get_si_date(dev_start)
        left, _ = get_boundary_columns(project.board)
        valid_cards = models.CardLog.objects.filter(to_column=left, timestamp__gte=start).values_list('card', flat=True)
        cards = cards.filter(pk__in=[c for c in valid_cards])
    if dev_end:
        end = HelperClass.get_si_date(dev_end)
        left, _ = get_boundary_columns(project.board)
        valid_cards = models.CardLog.objects.filter(to_column=left,
                                                    timestamp__lt=end + datetime.timedelta(days=1)).values_list('card',
                                                                                                                flat=True)
        cards = cards.filter(pk__in=[c for c in valid_cards])
    if estimate_from:
        cards = cards.filter(estimate__gte=estimate_from)
    if estimate_to:
        cards = cards.filter(estimate__lte=estimate_to)
    if card_type:
        type_ids = [t.split('_')[1] for t in card_type if t]
        if type_ids: cards = cards.filter(reduce(lambda x, y: x | y, [Q(type__id=id) for id in type_ids]))
    return cards.filter(is_deleted=False)
Beispiel #6
0
    def validate(self, attrs):
        credentials = {
            self.username_field: attrs.get(self.username_field),
            'password': attrs.get('password')
        }

        if all(credentials.values()):
            request = self.context['request']
            user = authenticate(request=request, **credentials)

            ip_login = HelperClass.get_client_ip(request)
            attempt, created = LoginAttempt.objects.get_or_create(ip=ip_login)

            if attempt.can_login():
                if user:
                    if not user.is_active:
                        msg = 'Uporabnik ni aktiven.'
                        raise serializers.ValidationError(msg)

                    payload = jwt_payload_handler(user)
                    user_logged_in.send(sender=user.__class__,
                                        request=request,
                                        user=user)
                    attempt.success()

                    return {'user': user, 'token': jwt_encode_handler(payload)}
                else:
                    attempt.fail()
                    msg = 'Napačen vnos podatkov.'
                    raise serializers.ValidationError(msg)
            else:
                msg = 'Vaš IP naslov je trenutno blokiran (preveč neveljavnih poskusov).'
                raise serializers.ValidationError(msg)
        else:
            msg = 'Must include "{username_field}" and "password".'
            msg = msg.format(username_field=self.username_field)
            raise serializers.ValidationError(msg)
Beispiel #7
0
 def resolve_all_paginated_users(self, info, page, page_size):
     p_size = page_size
     qs = models.User.objects.all()
     return HelperClass.get_paginator(qs, p_size, page, UserPaginatedType)
Beispiel #8
0
    def mutate(root, info, card=None, ok=False, card_data=None, board_id=None, user_id=None):
        if card_data.owner_userteam_id is None:
            owner = None
        else:
            owner = models.UserTeam.objects.get(id=card_data.owner_userteam_id)

        board = models.Board.objects.get(id=board_id)
        if card_data.column_id is None:
            if card_data.type_id == 0:
                column_id = models.Column.objects.get(board=board, position=0, parent=None).id
            else:
                column_id = models.Column.objects.get(board=board, priority=True).id

        if card_data.type_id == 1:
            column_id = models.Column.objects.get(board=board, priority=True).id
            silver_bullet_cards = models.Card.objects.filter(column=models.Column.objects.get(id=column_id),
                                                             type=models.CardType.objects.get(id=1),
                                                             project=models.Project.objects.get(id=card_data.project_id))
            if len(silver_bullet_cards) != 0:
                raise GraphQLError("V stolpcu z najvišjo prioriteto je lahko samo ena nujna zahteva.")
        else:
            column_id = card_data.column_id

        project = models.Project.objects.get(id=card_data.project_id)
        cards = models.Card.objects.filter(project=project)

        card = models.Card(column=models.Column.objects.get(id=column_id),
                           type=models.CardType.objects.get(id=card_data.type_id),
                           card_number=len(cards) + 1,
                           description=card_data.description,
                           name=card_data.name,
                           estimate=card_data.estimate,
                           project=models.Project.objects.get(id=card_data.project_id),
                           expiration=HelperClass.get_si_date(card_data.expiration).date(),
                           owner=owner,
                           priority=card_data.priority)
        card.save()

        # to reset was mail send for whole board
        projects_on_board = models.Project.objects.filter(board=project.board)
        if card.does_card_expire_soon(card.project.board.days_to_expire):
            for project in projects_on_board:
                cards = models.Card.objects.filter(project=project)
                for card in cards:
                    card.was_mail_send = False
                    card.save()

        for task in card_data.tasks:
            if task.assignee_userteam_id is None:
                assignee = None
            else:
                assignee = models.UserTeam.objects.get(id=task.assignee_userteam_id)

            task_entity = models.Task(card=card, description=task.description, done=task.done, assignee=assignee, hours=task.hours)
            task_entity.save()

        # kreacija kartice
        models.CardLogCreateDelete(card=card, action=0).save()

        cards = models.Card.objects.filter(column=models.Column.objects.get(id=column_id))

        log_action = None
        if (len(cards) > models.Column.objects.get(id=column_id).wip) and (
                models.Column.objects.get(id=column_id).wip != 0):
            log_action = "Presežena omejitev wip ob kreaciji."

        user_teams = models.UserTeam.objects.filter(
            member=models.User.objects.get(id=user_id), team=card.project.team)
        user_team = None
        if len(user_teams) > 1:
            for user_t in user_teams:
                if user_t.role != models.TeamRole.objects.get(id=4):
                    user_team = user_t
                    break

        if user_team is None:
            user_team = user_teams[0]

        models.CardLog(card=card, from_column=None, to_column=models.Column.objects.get(id=column_id),
                       action=log_action, user_team=user_team).save()

        return AddCard(ok=True, card=card)
Beispiel #9
0
 def resolve_si_timestamp(instance, info):
     return HelperClass.to_si_timestamp(instance.timestamp)