aboutsummaryrefslogtreecommitdiff
path: root/src/web/controllers/bookmark.py
blob: c842341428d5657fad2d5cad6a73a71389a2d6db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import logging
import itertools
from datetime import datetime, timedelta

from bootstrap import db
from web.models import Bookmark
from .abstract import AbstractController
from .tag import BookmarkTagController

logger = logging.getLogger(__name__)


class BookmarkController(AbstractController):
    _db_cls = Bookmark

    def count_by_href(self, **filters):
        return self._count_by(Bookmark.href, filters)

    def update(self, filters, attrs):
        BookmarkTagController(self.user_id) \
                                .read(**{'bookmark_id': filters["id"]}) \
                                .delete()

        for tag in attrs['tags']:
            BookmarkTagController(self.user_id) \
                        .update({'id': tag.id}, {'bookmark_id': filters["id"]})

        del attrs['tags']
        return super().update(filters, attrs)
bgstack15