def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        _id = self.id.data
        link = self.link.data
        title = self.title.data
        description = self.description.data
        tags = map(lambda x: {'name': x.strip()}, self.tags.data.split(','))

        if _id is None or _id == '' or int(_id) < 1:
            self.bookmark = ItemBookmark(tags=tags,
                                         link=link,
                                         title=title,
                                         description=description)
        else:
            self.bookmark = get_bookmark_by_id(_id)
            if self.bookmark is None:
                abort(404)
            self.bookmark.title = title
            self.bookmark.description = description
            self.bookmark.set_tags(tags)

        return True
class BookmarkForm(AjaxForm):
    id = HiddenField(u'Id')
    link = URLField(u'Link',
                    validators=[
                        validators.required(),
                        validators.url(),
                    ])
    title = TextField(u'Title', validators=[
        validators.required(),
    ])
    description = TextAreaField(u'Description')
    tags = TextField(u'Tags')
    submit = SubmitField(u'Add')
    edit = SubmitField(u'Edit')

    def __init__(self, formdata=None, *args, **kwargs):
        self.id.data = kwargs.get('id', None)
        super(BookmarkForm, self).__init__(formdata, *args, **kwargs)

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        _id = self.id.data
        link = self.link.data
        title = self.title.data
        description = self.description.data
        tags = map(lambda x: {'name': x.strip()}, self.tags.data.split(','))

        if _id is None or _id == '' or int(_id) < 1:
            self.bookmark = ItemBookmark(tags=tags,
                                         link=link,
                                         title=title,
                                         description=description)
        else:
            self.bookmark = get_bookmark_by_id(_id)
            if self.bookmark is None:
                abort(404)
            self.bookmark.title = title
            self.bookmark.description = description
            self.bookmark.set_tags(tags)

        return True
Exemple #3
0
def reset_all(json_file):
    db.drop_all()
    db.create_all()

    items = json.loads(open(json_file).read())
    for item in items['bookmarks']:
        i = ItemBookmark(**item)
        add_bookmark(i)
    for item in items['users']:
        i = User(**item)
        add_user(i)
Exemple #4
0
def reset_all(json_file):
    db.drop_all()
    db.create_all()

    items = json.loads(open(json_file).read())
    for item in items:
        i = ItemBookmark(ptags=item['tags'],
                         plink=item['link'],
                         ptitle=item['title'],
                         pdescription=item['description'],
                         json=True)
        add_bookmark(i)
def get_bookmark_by_id(id):
    bookmark = Bookmark.query.get(id)

    ret = ItemBookmark()

    ret._id = bookmark.id
    ret.tags = ", ".join([x.name for x in bookmark.tags])
    ret.title = bookmark.title
    ret.description = bookmark.description
    ret.link = bookmark.link
    return ret
class BookmarkForm(AjaxForm):
    id = HiddenField(u'Id')
    link = URLField(u'Link', validators=[validators.required(),
        validators.url(), ])
    title = TextField(u'Title', validators=[validators.required(), ])
    description = TextAreaField(u'Description')
    tags = TextField(u'Tags')
    submit = SubmitField(u'Add')
    edit = SubmitField(u'Edit')

    def __init__(self, formdata=None, *args, **kwargs):
        self.id.data = kwargs.get('id', None)
        super(BookmarkForm, self).__init__(formdata, *args, **kwargs)

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        _id = self.id.data
        link = self.link.data
        title = self.title.data
        description = self.description.data
        tags = map(lambda x: {'name': x.strip()}, self.tags.data.split(','))

        if _id is None or _id == '' or int(_id) < 1:
            self.bookmark = ItemBookmark(tags=tags, link=link, title=title,
                description=description)
        else:
            self.bookmark = get_bookmark_by_id(_id)
            if self.bookmark is None:
                abort(404)
            self.bookmark.title = title
            self.bookmark.description = description
            self.bookmark.set_tags(tags)

        return True
Exemple #7
0
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        link = self.link.data
        title = self.title.data
        description = self.description.data
        tags = map(lambda x: {'name': x.strip()}, self.tags.data.split(','))

        # TODO : add id control if create is False (modification mode need a
        # valid bookmark id)
        self.bookmark = ItemBookmark(ptags=tags, plink=link, ptitle=title,
            pdescription=description, json=True)
        return True
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        _id = self.id.data
        link = self.link.data
        title = self.title.data
        description = self.description.data
        tags = map(lambda x: {'name': x.strip()}, self.tags.data.split(','))

        if _id is None or _id == '' or int(_id) < 1:
            self.bookmark = ItemBookmark(tags=tags, link=link, title=title,
                description=description)
        else:
            self.bookmark = get_bookmark_by_id(_id)
            if self.bookmark is None:
                abort(404)
            self.bookmark.title = title
            self.bookmark.description = description
            self.bookmark.set_tags(tags)

        return True
Exemple #9
0
import argparse
from lxml.html.soupparser import fromstring
from bookmark.blueprint.api.item.Bookmark import ItemBookmark
from bookmark.service import add_bookmark

parser = argparse.ArgumentParser(description='Delicious bookmark import')
parser.add_argument('path', type=str, help='path to delicious.html file')

args = parser.parse_args()
path = args.path

content = open(path).read()
xml = fromstring(content)

for link in xml.xpath("/html/dl/dt/a"):
    item = {
        "title": link.text,
        "link": link.get("href"),
        "description": "",
        "tags": [{
            "name": x.strip(),
        } for x in link.get("tags").split(',')]
    }
    i = ItemBookmark(**item)
    add_bookmark(i)