Beispiel #1
0
def add_attachment(request, board_id, card_id):
    if request.method != "POST":
        return JsonResponseMethodNotAllowed(
            {"message": "HTTP method not allowed."})

    member = request.user.member
    try:
        board = get_user_boards(request.user).get(id=board_id)
        card = board.cards.get(id=card_id)
    except (Board.DoesNotExist, Card.DoesNotExist) as e:
        return JsonResponseNotFound({"message": "Not found."})

    uploaded_file_content = request.body
    if uploaded_file_content is None:
        return JsonResponseNotFound({"message": "No file sent."})

    with tempfile.TemporaryFile() as uploaded_file:
        uploaded_file.write(uploaded_file_content)
        uploaded_file_name = request.GET.get("uploaded_file_name",
                                             custom_uuid())
        attachment = card.add_new_attachment(member, uploaded_file,
                                             uploaded_file_name)

    serializer = Serializer(board=card.board)
    return JsonResponse(serializer.serialize_card_attachment(attachment))
Beispiel #2
0
 def new_list(self, new_list):
     new_list.uuid = custom_uuid()
     # Calculation of position is a bit tricky:
     # As position of the new list doesn't really matter, and
     # we don't want to block some tuples of the database, we get the max position
     # and add a random offset.
     random_offset = random.randrange(0, 1000)
     position = 0
     if new_list.board.lists.all().exists():
         position = new_list.board.lists.aggregate(
             max=Max("position"))["max"]
     new_list.position = position + random_offset
     now = timezone.now()
     new_list.creation_datetime = now
     new_list.last_activity_datetime = now
     return new_list
Beispiel #3
0
    def new_card(self, card, labels=None, position="bottom"):
        # Card attribute assignment
        card.uuid = custom_uuid()
        card.short_url = reverse("boards:view_card_short_url",
                                 args=(card.board_id, card.uuid))
        card.url = reverse("boards:view_card_short_url",
                           args=(card.board_id, card.uuid))
        # Position is a bit more difficult
        cards = card.list.active_cards.all()
        if not cards.exists():
            position = 100000
        else:
            if position == "top":
                position = cards.order_by("position")[0].position - 1000
            elif position == "bottom":
                position = cards.order_by("-position")[0].position + 1000

        card.position = position
        card.creation_datetime = timezone.now()
        card.last_activity_datetime = timezone.now()
        return card
Beispiel #4
0
 def new_label(self, label):
     label.uuid = custom_uuid()
     return label
Beispiel #5
0
 def new_board(self, board):
     board.uuid = custom_uuid()
     board.has_to_be_fetched = False
     board.last_activity_datetime = timezone.now()
     return board
Beispiel #6
0
 def add_comment_to_card(self, card, comment):
     comment.uuid = custom_uuid()
     comment.last_edition_datetime = None
     return comment
Beispiel #7
0
 def add_attachment_to_card(self, card, attachment):
     attachment.card = card
     attachment.uuid = custom_uuid()
     attachment.creation_datetime = timezone.now()
     return attachment