aboutsummaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2017-02-13 15:27:13 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2017-02-13 15:27:13 +0100
commit879427aa740f399aecd31c0e12909e6f39705f5e (patch)
tree5bb2d792e7211c763db550eaf8f0c676e37aa25a /src/web
parentMerge branch 'master' of github.com:newspipe/newspipe into bookmark (diff)
downloadnewspipe-879427aa740f399aecd31c0e12909e6f39705f5e.tar.gz
newspipe-879427aa740f399aecd31c0e12909e6f39705f5e.tar.bz2
newspipe-879427aa740f399aecd31c0e12909e6f39705f5e.zip
wip
Diffstat (limited to 'src/web')
-rw-r--r--src/web/controllers/abstract.py1
-rw-r--r--src/web/controllers/bookmark.py2
-rw-r--r--src/web/forms.py2
-rw-r--r--src/web/models/__init__.py2
-rw-r--r--src/web/models/article.py8
-rw-r--r--src/web/models/bookmark.py9
-rw-r--r--src/web/models/tag.py50
-rw-r--r--src/web/templates/bookmarks.html2
-rw-r--r--src/web/templates/edit_bookmark.html8
-rw-r--r--src/web/views/bookmark.py16
10 files changed, 48 insertions, 52 deletions
diff --git a/src/web/controllers/abstract.py b/src/web/controllers/abstract.py
index 8563d5f2..074ce24c 100644
--- a/src/web/controllers/abstract.py
+++ b/src/web/controllers/abstract.py
@@ -100,6 +100,7 @@ class AbstractController:
def update(self, filters, attrs, return_objs=False, commit=True):
assert attrs, "attributes to update must not be empty"
+ print(attrs)
result = self._get(**filters).update(attrs, synchronize_session=False)
if commit:
db.session.flush()
diff --git a/src/web/controllers/bookmark.py b/src/web/controllers/bookmark.py
index cf7815a8..f7dab9d8 100644
--- a/src/web/controllers/bookmark.py
+++ b/src/web/controllers/bookmark.py
@@ -16,5 +16,5 @@ class BookmarkController(AbstractController):
return self._count_by(Bookmark.href, filters)
def update(self, filters, attrs, *args, **kwargs):
- self.tags = attrs['tags']
+ #self.tag_objs = attrs['tags']
return super().update(filters, attrs, *args, **kwargs)
diff --git a/src/web/forms.py b/src/web/forms.py
index 5957ceef..4d44f379 100644
--- a/src/web/forms.py
+++ b/src/web/forms.py
@@ -206,8 +206,8 @@ class CategoryForm(Form):
class BookmarkForm(Form):
href = TextField(lazy_gettext("URL"))
+ title = TextField(lazy_gettext("Title"))
description = TextField(lazy_gettext("Description"))
- extended = TextField(lazy_gettext("Description long"))
tags = TextField(lazy_gettext("Tags"))
to_read = BooleanField(lazy_gettext("To read"), default=False)
shared = BooleanField(lazy_gettext("Shared"), default=False)
diff --git a/src/web/models/__init__.py b/src/web/models/__init__.py
index c8fc1aef..229a99e5 100644
--- a/src/web/models/__init__.py
+++ b/src/web/models/__init__.py
@@ -32,7 +32,7 @@ from .user import User
from .article import Article
from .icon import Icon
from .category import Category
-from .tag import Tag
+#from .tag import Tag
from .tag import BookmarkTag
from .tag import ArticleTag
from .bookmark import Bookmark
diff --git a/src/web/models/article.py b/src/web/models/article.py
index 923d6869..6245b10e 100644
--- a/src/web/models/article.py
+++ b/src/web/models/article.py
@@ -34,6 +34,8 @@ from sqlalchemy.ext.associationproxy import association_proxy
from web.models.right_mixin import RightMixin
+
+
class Article(db.Model, RightMixin):
"Represent an article from a feed."
id = db.Column(db.Integer(), primary_key=True)
@@ -53,9 +55,9 @@ class Article(db.Model, RightMixin):
# relationships
tag_objs = db.relationship('ArticleTag', back_populates='article',
- cascade='all,delete-orphan',
- lazy=False,
- foreign_keys='[ArticleTag.article_id]')
+ cascade='all,delete-orphan',
+ lazy=False,
+ foreign_keys='[ArticleTag.article_id]')
tags = association_proxy('tag_objs', 'text')
# index
diff --git a/src/web/models/bookmark.py b/src/web/models/bookmark.py
index a796cffa..b62285b7 100644
--- a/src/web/models/bookmark.py
+++ b/src/web/models/bookmark.py
@@ -34,14 +34,15 @@ from sqlalchemy.ext.associationproxy import association_proxy
from web.models.right_mixin import RightMixin
+
class Bookmark(db.Model, RightMixin):
"""
Represent a bookmark.
"""
id = db.Column(db.Integer(), primary_key=True)
href = db.Column(db.String(), default="")
+ title = db.Column(db.String(), default="")
description = db.Column(db.String(), default="FR")
- extended = db.Column(db.String())
shared = db.Column(db.Boolean(), default=False)
to_read = db.Column(db.Boolean(), default=False)
time = db.Column(db.DateTime(), default=datetime.utcnow)
@@ -49,9 +50,9 @@ class Bookmark(db.Model, RightMixin):
# relationships
tag_objs = db.relationship('BookmarkTag', back_populates='bookmark',
- cascade='all,delete-orphan',
- lazy=False,
- foreign_keys='[BookmarkTag.bookmark_id]')
+ cascade='all,delete-orphan',
+ lazy=False,
+ foreign_keys='[BookmarkTag.bookmark_id]')
tags = association_proxy('tag_objs', 'text')
diff --git a/src/web/models/tag.py b/src/web/models/tag.py
index d43ce300..28727dbf 100644
--- a/src/web/models/tag.py
+++ b/src/web/models/tag.py
@@ -1,50 +1,34 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
-from sqlalchemy import Column, ForeignKey, Integer, String
-from sqlalchemy.orm import relationship
-
from bootstrap import db
-class Tag(db.Model):
- id = db.Column(db.Integer(), primary_key=True)
- text = Column(String, unique=False)
- obj = db.Column(db.String, default='article')
- user_id = db.Column(db.Integer(), db.ForeignKey('user.id'), nullable=False)
+class ArticleTag(db.Model):
+ text = db.Column(db.String, primary_key=True, unique=False)
- __mapper_args__ = {
- 'polymorphic_on': obj
- }
+ # foreign keys
+ article_id = db.Column(db.Integer, db.ForeignKey('article.id', ondelete='CASCADE'),
+ primary_key=True)
+ # relationships
+ article = db.relationship('Article', back_populates='tag_objs',
+ foreign_keys=[article_id])
def __init__(self, text):
self.text = text
-class ArticleTag(Tag):
- __mapper_args__ = {
- 'polymorphic_identity': 'article'
- }
- id = db.Column(db.Integer, db.ForeignKey('tag.id', ondelete='CASCADE'),
- primary_key=True)
-
- # relationships
- article_id = Column(Integer, ForeignKey('article.id', ondelete='CASCADE'),
- nullable=False)
- article = relationship('Article', back_populates='tag_objs',
- foreign_keys=[article_id])
-
+class BookmarkTag(db.Model):
+ text = db.Column(db.String, primary_key=True, unique=False)
-class BookmarkTag(Tag):
- __mapper_args__ = {
- 'polymorphic_identity': 'bookmark'
- }
- id = db.Column(db.Integer, db.ForeignKey('tag.id', ondelete='CASCADE'),
- primary_key=True)
+ # foreign keys
+ bookmark_id = db.Column(db.Integer, db.ForeignKey('bookmark.id', ondelete='CASCADE'),
+ primary_key=True)
# relationships
- bookmark_id = Column(Integer, ForeignKey('bookmark.id', ondelete='CASCADE'),
- nullable=False)
- bookmark = relationship('Bookmark', back_populates='tag_objs',
+ bookmark = db.relationship('Bookmark', back_populates='tag_objs',
foreign_keys=[bookmark_id])
+
+ def __init__(self, text):
+ self.text = text
diff --git a/src/web/templates/bookmarks.html b/src/web/templates/bookmarks.html
index 9e6f0ab1..fc0e3aaa 100644
--- a/src/web/templates/bookmarks.html
+++ b/src/web/templates/bookmarks.html
@@ -6,7 +6,7 @@
{% for bookmark in bookmarks %}
<li class="list-group-item">
<a href="{{ bookmark.href }}">{{ bookmark.href }}</a>&nbsp;
- <a href="{{ bookmark.href }}">{{ ", ".join(bookmark.tags) }}</a>&nbsp;
+ <a href="{{ bookmark.href }}">{{ bookmark.tags }}</a>&nbsp;
<a href="{{ url_for('bookmark.form', bookmark_id=bookmark.id) }}">edit</a>
</li>
{% endfor %}
diff --git a/src/web/templates/edit_bookmark.html b/src/web/templates/edit_bookmark.html
index 8dc0cba3..384e641c 100644
--- a/src/web/templates/edit_bookmark.html
+++ b/src/web/templates/edit_bookmark.html
@@ -14,6 +14,14 @@
</div>
<div class="form-group">
+ <label for="{{ form.title.id }}" class="col-sm-3 control-label">{{ form.title.label }}</label>
+ <div class="col-sm-9">
+ {{ form.title(class_="form-control", size="100%") }}
+ </div>
+ {% for error in form.title.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
+ </div>
+
+ <div class="form-group">
<label for="{{ form.description.id }}" class="col-sm-3 control-label">{{ form.description.label }}</label>
<div class="col-sm-9">
{{ form.description(class_="form-control", size="100%") }}
diff --git a/src/web/views/bookmark.py b/src/web/views/bookmark.py
index d780a3ae..c2fdc597 100644
--- a/src/web/views/bookmark.py
+++ b/src/web/views/bookmark.py
@@ -10,6 +10,7 @@ import conf
from bootstrap import db
from web.forms import BookmarkForm
from web.controllers import BookmarkController
+from web.models.tag import BookmarkTag
logger = logging.getLogger(__name__)
bookmarks_bp = Blueprint('bookmarks', __name__, url_prefix='/bookmarks')
@@ -38,7 +39,7 @@ def form(bookmark_id=None):
action = gettext('Edit bookmark')
head_titles = [action]
form = BookmarkForm(obj=bookmark)
- form.tags.data = ", ".join(bookmark.tags)
+ form.tags.data = bookmark.tags
return render_template('edit_bookmark.html', action=action,
head_titles=head_titles, bookmark=bookmark,
form=form)
@@ -57,18 +58,17 @@ def process_form(bookmark_id=None):
# Edit an existing bookmark
bookmark_attr = {'href': form.href.data,
'description': form.description.data,
- 'extended': form.extended.data,
+ 'title': form.title.data,
'tags': [tag.strip() for tag in form.tags.data.split(',')],
'shared': form.shared.data,
'to_read': form.to_read.data}
if bookmark_id is not None:
- bookmark = BookmarkController(current_user.id).get(id=bookmark_id)
- form.populate_obj(bookmark)
- bookmark.tags = [tag.strip() for tag in form.tags.data.split(',')]
- db.session.commit()
-
- #bookmark_contr.update({'id': bookmark_id}, bookmark_attr)
+ # bookmark = BookmarkController(current_user.id).get(id=bookmark_id)
+ # form.populate_obj(bookmark)
+ # bookmark.tags = [tag.strip() for tag in form.tags.data.split(',')],
+ # db.session.commit()
+ bookmark_contr.update({'id': bookmark_id}, bookmark_attr)
flash(gettext('Bookmark successfully updated.'), 'success')
return redirect(url_for('bookmark.form', bookmark_id=bookmark_id))
bgstack15