From e1f735e04aa8dee1fb2d40c595d735133da681a3 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 7 Jun 2017 13:29:58 +0100 Subject: [PATCH 1/6] use strict --- sourcing/static/js/doc.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sourcing/static/js/doc.js b/sourcing/static/js/doc.js index c0a90a2..d59d667 100644 --- a/sourcing/static/js/doc.js +++ b/sourcing/static/js/doc.js @@ -1,3 +1,5 @@ +'use strict'; + $(function() { $("div#right").hide(); /* $("button#add-new-span").click(function() { From a571f97ac8f886ab5b426e34bb498ae5992ed001 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 7 Jun 2017 13:30:10 +0100 Subject: [PATCH 2/6] use strict --- sourcing/static/js/sourcedoc.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sourcing/static/js/sourcedoc.js b/sourcing/static/js/sourcedoc.js index cf2e711..2929929 100644 --- a/sourcing/static/js/sourcedoc.js +++ b/sourcing/static/js/sourcedoc.js @@ -1,3 +1,5 @@ +'use strict'; + function add_message() { $("div#messages").text("whatever"); } From 4897d0a7d6d61c877df4d35fa4bebe519a89b50a Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 7 Jun 2017 13:30:30 +0100 Subject: [PATCH 3/6] add tether, required for bootstrap --- sourcing/templates/base.html | 1 + 1 file changed, 1 insertion(+) diff --git a/sourcing/templates/base.html b/sourcing/templates/base.html index 3f217b4..0756ab2 100644 --- a/sourcing/templates/base.html +++ b/sourcing/templates/base.html @@ -27,6 +27,7 @@ + {% block scripts %} From 95c196076becb0c1ba23a93171e0c25497ba107c Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 7 Jun 2017 13:30:56 +0100 Subject: [PATCH 4/6] add title method --- sourcing/view.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sourcing/view.py b/sourcing/view.py index 1b16e79..b50d58e 100644 --- a/sourcing/view.py +++ b/sourcing/view.py @@ -199,6 +199,14 @@ def fulfil(username, hashid): item=item, doc=fulfil_edl_with_sources(item.text)) +@bp.route('///add_title', methods=['POST']) +def add_title(username, hashid): + item = get_item(username, hashid) + title = request.form['title'] + item.add_title(title, current_user) + flash('title added') + return redirect(item.url) + @bp.route('//') def view_item(username, hashid, raw=False): if ',' in hashid: From 511eea5bdfdabdeb1dc61ee9588995b015bc63b1 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 7 Jun 2017 13:31:29 +0100 Subject: [PATCH 5/6] refactor --- sourcing/model.py | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/sourcing/model.py b/sourcing/model.py index 8ff3ec4..8c55023 100644 --- a/sourcing/model.py +++ b/sourcing/model.py @@ -123,21 +123,22 @@ class User(TimeStampedModel, UserMixin): return user class Item(TimeStampedModel): - __versioned__ = {} __tablename__ = 'item' + __versioned__ = {'base_classes': (TimeStampedModel,)} id = Column(Integer, primary_key=True) user_id = Column(Integer, ForeignKey('user.id')) published = Column(DateTime) - type = Column(Enum('sourcedoc', 'xanadoc', 'xanalink', name='item_type'), nullable=False) + type = Column(Enum('sourcedoc', 'xanadoc', 'xanalink', name='item_type'), + nullable=False) filename = Column(Unicode) text = Column(UnicodeText) user = relationship('User', backref='items') __mapper_args__ = { - 'polymorphic_identity': 'item', 'polymorphic_on': type, + 'with_polymorphic': '*', } @property @@ -179,11 +180,34 @@ class Item(TimeStampedModel): def edit_url(self): return url_for('.edit_item', username=self.user.username, hashid=self.hashid) + @property + def add_title_url(self): + return url_for('.add_title', username=self.user.username, hashid=self.hashid) + def title(self, titles=None): if not titles: titles = XanaLink.get_all_titles() return self.type + ": " + titles.get(self, self.hashid) + def has_title(self): + titles = XanaLink.get_all_titles() + print(titles) + return self in titles + + def add_title(self, title, user): + title_source_doc = SourceDoc(text=title, user=user) + session.add(title_source_doc) + session.commit() + link_text = '''type=title + +facet= +sourcedoc: {} +facet= +span: {},start=0,length={}'''.format(self.external_url, title_source_doc.external_url, len(title)) + title_link = XanaLink(text=link_text, user=user) + session.add(title_link) + session.commit() + @classmethod def from_external(cls, url): home = url_for('.home', _external=True) @@ -200,16 +224,16 @@ class Item(TimeStampedModel): class XanaDoc(Item): __tablename__ = 'xanadoc' - id = Column(Integer, ForeignKey('item.id'), primary_key=True) - __mapper_args__ = {'polymorphic_identity': 'xanadoc'} + id = Column(Integer, ForeignKey(Item.id), primary_key=True) + class XanaLink(Item): __tablename__ = 'xanalink' - id = Column(Integer, ForeignKey('item.id'), primary_key=True) - __mapper_args__ = {'polymorphic_identity': 'xanalink'} + id = Column(Integer, ForeignKey(Item.id), primary_key=True) + def parse(self): return parse_link(self.text) @@ -250,7 +274,9 @@ class XanaLink(Item): class SourceDoc(Item): __tablename__ = 'sourcedoc' - id = Column(Integer, ForeignKey('item.id'), primary_key=True) + __mapper_args__ = {'polymorphic_identity': 'sourcedoc'} + + id = Column(Integer, ForeignKey(Item.id), primary_key=True) db_price_per_character = Column(Integer) db_document_price = Column(Integer) @@ -262,7 +288,6 @@ class SourceDoc(Item): def price_per_character(self): return self.db_price_per_character or self.db_document_price / len(self.text) - __mapper_args__ = {'polymorphic_identity': 'sourcedoc'} configure_mappers() From 8a60c1000b4a74c3e538dc88aa2881c30f346452 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 7 Jun 2017 13:31:49 +0100 Subject: [PATCH 6/6] add title modal --- sourcing/templates/view.html | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/sourcing/templates/view.html b/sourcing/templates/view.html index 1e14187..98b1b05 100644 --- a/sourcing/templates/view.html +++ b/sourcing/templates/view.html @@ -4,6 +4,29 @@ {% block content %} + + -

{{ self.title() }}

+

{{ self.title() }} + {% if current_user.is_authenticated and doc.user == current_user and not doc.has_title() %} + + {% endif %} +

{% if version %}

Revision as of {{ version.modified.strftime('%H:%M, %d %B %Y') }}

{% endif %}