Beispiel #1
0
class Comment(db.BaseDocument):
    comment = db.StringField()
    who = db.ReferenceField('User', reverse_delete_rule=db.NULLIFY)
    ticket = db.ReferenceField('Ticket', reverse_delete_rule=db.CASCADE)

    @classmethod
    def get_by_ticket(cls, ticket_pk):
        return cls.objects(ticket=ticket_pk).order_by('-created_on')
Beispiel #2
0
class SprintTicketOrder(db.BaseDocument):
    ticket = db.ReferenceField(Ticket, reverse_delete_rule=db.CASCADE)
    ticket_repr = db.DictField()
    order = db.IntField()
    sprint = db.ReferenceField(Sprint, reverse_delete_rule=db.CASCADE)
    active = db.BooleanField(default=True)

    @classmethod
    def get_active_sprint_ticket(cls, sprint_pk, ticket_pk):
        try:
            spo = cls.objects(sprint=sprint_pk, ticket=ticket_pk,
                              active=True).first()
        except cls.DoesNotExits:
            spo = None
        return spo

    @classmethod
    def get_active_ticket(cls, ticket_pk):
        try:
            spo = cls.objects(ticket=ticket_pk, active=True).first()
        except cls.DoesNotExits:
            spo = None
        return spo

    @classmethod
    def get_active_sprint(cls, sprint_pk):
        try:
            spo = cls.objects(sprint=sprint_pk, active=True)
        except cls.DoesNotExits:
            spo = None
        return spo

    @classmethod
    def get_next_order_index(cls, sprint_pk):
        return cls.objects(sprint=sprint_pk, active=True).count()

    @classmethod
    def inactivate_spo(cls, sprint_pk, ticket_pk):
        cls.objects(sprint=sprint_pk, ticket=ticket_pk,
                    active=True).update_one(set__active=False)

    @classmethod
    def list_spo(cls, sprint_pk, tickets_ids):
        return cls.objects(ticket__nin=tickets_ids,
                           sprint=sprint_pk,
                           active=True)

    @classmethod
    def inactivate_list_spo(cls, sprint_pk, tickets_ids):
        cls.list_spo(sprint_pk, tickets_ids).update(set__active=False)

    @classmethod
    def order_items(cls, ordered_ids, sprint):
        for index, s in enumerate(ordered_ids):
            item = cls.get_active_sprint_ticket(sprint, s)
            if item:
                item.order = index
                item.save()
Beispiel #3
0
class Ticket(db.BaseDocument):
    title = db.StringField(max_length=200, required=True)
    description = db.StringField()
    labels = db.ListField(db.StringField())
    number = db.IntField()
    project = db.ReferenceField('Project', reverse_delete_rule=db.CASCADE)
    order = db.IntField()
    points = db.IntField()
    type = db.StringField(max_length=1, choices=TICKET_TYPE)
    files = db.ListField(db.ReferenceField('Attachment'))
    assigned_to = db.ListField(db.ReferenceField('ProjectMember'))
    closed = db.BooleanField(default=False)
    related_tickets = db.ListField(db.ReferenceField('TicketDependency'))

    @classmethod
    def get_last_ticket(cls, project_pk):
        return cls.objects(project=project_pk).order_by('-number').first()

    @classmethod
    def get_tickets_backlog(cls, project_pk, not_tickets):
        tickets = Ticket.objects(
            Q(project=project_pk) & Q(id__nin=not_tickets)
            & (Q(closed=False) | Q(closed__exists=False))).order_by('order')
        return tickets

    @classmethod
    def get_next_order_index(cls, project_pk):
        return cls.objects(project=project_pk).count()

    @classmethod
    def remove_attachment(cls, tkt_id, att):
        cls.objects(pk=tkt_id).update_one(pull__files=att)

    @classmethod
    def remove_member(cls, tkt_id, project_member_id):
        cls.objects(pk=tkt_id).update_one(pull__assigned_to=project_member_id)

    @classmethod
    def remove_related_ticket(cls, tkt_id, related_tkt_id):
        cls.objects(pk=tkt_id).update_one(pull__related_tickets=related_tkt_id)

    @classmethod
    def search(cls, query, projects):
        return cls.objects((Q(title__icontains=query)
                            | Q(description__icontains=query))
                           & Q(project__in=projects))

    @classmethod
    def get_closed_tickets(cls, project_pk):
        return cls.objects(project=project_pk, closed=True)

    @classmethod
    def close_tickets(cls, tickets_ids):
        cls.objects(pk__in=tickets_ids).update(set__closed=True)
Beispiel #4
0
class TicketColumnTransition(db.BaseDocument):
    ticket = db.ReferenceField(Ticket, reverse_delete_rule=db.CASCADE)
    column = db.ReferenceField(Column, reverse_delete_rule=db.CASCADE)
    sprint = db.ReferenceField(Sprint, reverse_delete_rule=db.CASCADE)
    order = db.IntField()
    who = db.ReferenceField(User, reverse_delete_rule=db.NULLIFY)
    latest_state = db.BooleanField(default=True)

    @classmethod
    def get_latest_transition(cls, ticket_pk, sprint=None, **kwargs):
        filters = dict(ticket=ticket_pk, latest_state=True)
        if sprint:
            filters.update(dict(sprint=sprint))
        filters.update(kwargs)
        return cls.objects(**filters).first()

    @classmethod
    def get_transitions_in_cols(cls, columns_ids):
        return cls.objects(column__in=columns_ids, latest_state=True)

    @classmethod
    def get_transitions_for_sprint(cls, sprint):
        return cls.objects(sprint=sprint, latest_state=True)

    @classmethod
    def get_next_order_index(cls, col):
        return cls.objects(column=col).count()

    @classmethod
    def order_items(cls, ordered_ids, sprint=None, **kwargs):
        for index, s in enumerate(ordered_ids):
            item = cls.get_latest_transition(ticket_pk=s,
                                             sprint=sprint,
                                             **kwargs)
            if item:
                item.order = index
                item.save()
Beispiel #5
0
class Sprint(db.BaseDocument):
    name = db.StringField(max_length=100, required=True)
    start_date = db.DateTimeField()
    end_date = db.DateTimeField()
    project = db.ReferenceField(Project, reverse_delete_rule=db.CASCADE)
    order = db.IntField(min_value=0)
    started = db.BooleanField(default=False)
    finalized = db.BooleanField(default=False)
    total_points_when_started = db.IntField()

    @classmethod
    def get_by_project(cls, project_pk):
        try:
            instances = cls.objects(project=project_pk).order_by('order')
        except cls.DoesNotExtis:
            instances = []
        return instances

    @classmethod
    def get_by_project_not_finalized(cls, project_pk):
        try:
            instances = cls.objects(project=project_pk,
                                    finalized=False).order_by('order')
        except cls.DoesNotExtis:
            instances = []
        return instances

    @classmethod
    def get_active_sprint(cls, project_pk):
        try:
            instance = cls.objects.get(project=project_pk,
                                       started=True,
                                       finalized=False)
        except cls.DoesNotExtis:
            instance = None
        return instance

    @classmethod
    def get_archived_sprints(cls, project_pk):
        return cls.objects(project=project_pk,
                           finalized=True).order_by('order')
Beispiel #6
0
class TicketDependency(db.BaseDocument):
    ticket = db.ReferenceField('Ticket')
    type = db.StringField(choices=DEPENDENCY_TYPE, max_length=2)
Beispiel #7
0
class UserNotification(db.BaseDocument):
    activity = db.ReferenceField(UserActivity, reverse_delete_rule=db.CASCADE)
    user = db.ReferenceField(User)
    viewed = db.BooleanField(default=False)
Beispiel #8
0
class UserActivity(db.BaseDocument):
    project = db.ReferenceField(Project)
    verb = db.StringField()
    author = db.ReferenceField(User)
    data = db.DictField()
    to = db.ReferenceField(User)