Merge branch 'master' of /home/edward/git/sourcing
This commit is contained in:
commit
469ec90d16
|
@ -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()
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
$(function() {
|
||||
$("div#right").hide();
|
||||
/* $("button#add-new-span").click(function() {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
function add_message() {
|
||||
$("div#messages").text("whatever");
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
</div>
|
||||
|
||||
<script src="{{ url_for('static', filename='jquery/jquery.js') }}"></script>
|
||||
<script src="https://npmcdn.com/tether@1.2.4/dist/js/tether.min.js"></script>
|
||||
<script src="{{ url_for('static', filename='bootstrap4/js/bootstrap.js') }}"></script>
|
||||
|
||||
{% block scripts %}
|
||||
|
|
|
@ -4,6 +4,29 @@
|
|||
|
||||
{% block content %}
|
||||
|
||||
<div class="modal fade" id="title-modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">set {{ doc.type }} title</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form method="POST" action="{{ doc.add_title_url }}">
|
||||
<div class="modal-body">
|
||||
<label for="form-title">title</label>
|
||||
<input name="title" id="form-title" class="form-control">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-primary">Add title</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="{{ doc.url }}">View</a>
|
||||
|
@ -24,7 +47,11 @@
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<h1 class="mt-3">{{ self.title() }}</h1>
|
||||
<h1 class="mt-3">{{ self.title() }}
|
||||
{% if current_user.is_authenticated and doc.user == current_user and not doc.has_title() %}
|
||||
<button class="btn btn-primary" data-toggle="modal" data-target="#title-modal">add title</button>
|
||||
{% endif %}
|
||||
</h1>
|
||||
{% if version %}
|
||||
<p>Revision as of {{ version.modified.strftime('%H:%M, %d %B %Y') }}</p>
|
||||
{% endif %}
|
||||
|
|
|
@ -199,6 +199,14 @@ def fulfil(username, hashid):
|
|||
item=item,
|
||||
doc=fulfil_edl_with_sources(item.text))
|
||||
|
||||
@bp.route('/<username>/<hashid>/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('/<username>/<hashid>')
|
||||
def view_item(username, hashid, raw=False):
|
||||
if ',' in hashid:
|
||||
|
|
Loading…
Reference in a new issue