Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Card.py 3.58 KiB
Newer Older
from multipledispatch import dispatch
# from library.leankit.models.User import User


class CardConnection():
    parents: list
    children: list

    def __iter__(self):
        yield 'parents', self.parents
        yield 'children', self.children


class CardExternalLink():
    label: str
    url: str

    def __iter__(self):
        yield 'label', self.label
        yield 'url', self.url


class CardCustomField(object):
    fieldId: str
    value: str

    def __iter__(self):
        yield 'fieldId', self.fieldId
        yield 'value', self.value


class Card(object):
    boardId: str
    title: str
    typeId: str
    assignedUserIds: list
    description: str
    size: int
    laneId: str
    connections: dict
    mirrorSourceCardId: str
    copiedFromCardId: str
    blockReason: str
    priority: str
    customIconId: str
    customId: str
    externalLink: list
    index: int
    plannedStart: str
    plannedFinish: str
    tags: list
    wipOverrideComment: str
    customFields: list

    @dispatch()
    def __init__(self):
        """parameterless constructor for json deserialization support"""
        pass

    @dispatch(str, str)
    def __init__(self, boardId: str, title: str):
        self.boardId = boardId
        self.title = title

    def __iter__(self):
        for attr_name in dir(self):
            if not attr_name.startswith("__"):
                print(attr_name)
                yield attr_name, getattr(self, attr_name)

    # @dispatch(User)
    # def assign_user(self, user: User):
    #     self.assign_user(user.id)

    @dispatch(str)
    def assign_user(self, userid: str):
        if userid not in self.assignedUserIds:
            self.assignedUserIds.append(userid)

    # @dispatch(User)
    # def unassign_user(self, user: User):
    #     self.unassign_user(user.id)

    @dispatch(str)
    def unassign_user(self, userid: str):
        if userid in self.assignedUserIds:
            self.assignedUserIds.remove(userid)

# def card_decoder(obj):
#     if 'boardId' in obj and 'title' in obj:
#         new_card = Card(obj['boardId'], obj['title'])
#         if 'typeId' in obj:
#             new_card['typeId'] = obj['typeId']
#
#         if 'assignedUserIds' in obj:
#             new_card['assignedUserIds'] = obj['assignedUserIds']
#
#         # TODO set others, or generate using inspection/reflection
#         return new_card
#     return obj

# cardObj = json.loads('{"__type__": "Card", "rollNumber":1, "name": "Ault kelly", "marks": 78}', object_hook=studentDecoder)
# {
#     "boardId": "944576308",
#     "title": "The title of the card",
#     "typeId": "944576314",
#     "assignedUserIds": [ "478440842" ],
#     "description": "The card description",
#     "size": 1,
#     "laneId": "944576326",
#     "connections": {
#       "parents": ["945202295"],
#       "children": ["945250930"]
#     },
#     "mirrorSourceCardId": "945202295",
#     "copiedFromCardId": "945261794",
#     "blockReason": "The block reason",
#     "priority": "normal",
#     "customIconId": "944576317",
#     "customId": "Card header text",
#     "externalLink": {
#         "label": "The link label",
#         "url": "https://www.leankit.com"
#     },
#     "index": 1,
#     "plannedStart": "2020-01-20",
#     "plannedFinish": "2020-02-01",
#     "tags": [
#         "tagOne",
#         "tagTwo"
#     ],
#     "wipOverrideComment": "The override reason",
#     "customFields": [ {
#       "fieldId": "945250752",
#       "value": "This is the field value"
#     } ]
# }