Rename XanaDoc to XanaPage.

This commit is contained in:
Edward Betts 2019-04-25 13:19:38 +01:00
parent 28a85e8cd5
commit d7f51b0982
16 changed files with 54 additions and 54 deletions

View file

@ -60,19 +60,19 @@ def populate_references():
database.session.add(ref)
seen.add(as_tuple)
for xanadoc in model.XanaDoc.query:
doc_edl = edl.parse_edl(xanadoc.text)
for xanapage in model.XanaPage.query:
doc_edl = edl.parse_edl(xanapage.text)
if 'spans' not in doc_edl or not doc_edl['spans']:
continue
for url, start, length in doc_edl['spans']:
src_doc = model.Item.from_external(url, home=home)
if not src_doc.id:
continue
print(xanadoc.id, '->', src_doc.id)
as_tuple = (xanadoc.id, src_doc.id)
print(xanapage.id, '->', src_doc.id)
as_tuple = (xanapage.id, src_doc.id)
if as_tuple in seen:
continue
ref = model.Reference(subject_id=xanadoc.id, object_id=src_doc.id)
ref = model.Reference(subject_id=xanapage.id, object_id=src_doc.id)
database.session.add(ref)
seen.add(as_tuple)

View file

@ -1,5 +1,5 @@
from .url import get_url, get_text
from .parse import get_span, parse_span, parse_link, parse_sourcedoc_facet, xanadoc_span_html, span_html, get_urls
from .parse import get_span, parse_span, parse_link, parse_sourcedoc_facet, xanapage_span_html, span_html, get_urls
from collections import defaultdict
from html import escape
from .utils import protect_start_spaces
@ -100,14 +100,14 @@ def fulfil_edl_with_links(edl, doc_num='', links=None, hide_all_transclusions=Fa
break
if link_end < start:
continue
cls = 'xanadoclink link'
cls = 'xanapagelink link'
link_span = (f'<span class="{cls}" id="link{facet_num}_{link_num}">' +
escape(span_text[link_start:link_end]) +
'</span>')
new_text += escape(span_text[pos:link_start]) + link_span
pos = link_end
new_text += escape(span_text[pos:start + length])
cur = xanadoc_span_html(num, new_text, url, start, length, highlight=highlight)
cur = xanapage_span_html(num, new_text, url, start, length, highlight=highlight)
doc_spans.append(cur)
doc = ''.join(doc_spans)

View file

@ -141,7 +141,7 @@ class Item(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'),
type = Column(Enum('sourcedoc', 'xanapage', 'xanalink', name='item_type'),
nullable=False)
filename = Column(Unicode)
text = Column(UnicodeText)
@ -262,9 +262,9 @@ span: {},start=0,length={}'''.format(self.external_url, title_source_doc.externa
q = cls.query.filter(User.username == username, cls.id == item_id)
return q.one_or_none()
class XanaDoc(Item):
__tablename__ = 'xanadoc'
__mapper_args__ = {'polymorphic_identity': 'xanadoc'}
class XanaPage(Item):
__tablename__ = 'xanapage'
__mapper_args__ = {'polymorphic_identity': 'xanapage'}
id = Column(Integer, ForeignKey(Item.id), primary_key=True)

View file

@ -49,10 +49,10 @@ def find_min_max(spans, source):
def span_html(span_type, num):
return '<span class="{span_type} sourcedoc{span_type}" id="{span_type}{num}">'.format(num=num, span_type=span_type)
def xanadoc_span_html(num, text, url, start, length, highlight=True, censor=False):
def xanapage_span_html(num, text, url, start, length, highlight=True, censor=False):
cls = []
if highlight:
cls = ['xanadoctransclusion', 'transclusion']
cls = ['xanapagetransclusion', 'transclusion']
html_class = ' class="{}"'.format(' '.join(cls)) if cls else ''
html = '<span id="span{}"{} data-url="{}" data-start="{}" data-length="{}">{}</span>'.format(num, html_class, escape(url), start, length, text)

View file

@ -13,7 +13,7 @@
background-color: #ffe;
}
.xanadoc {
.xanapage {
background-color: #eef;
}

View file

@ -195,7 +195,7 @@ function new_document(doc) {
var w = document.documentElement.clientWidth;
var h = document.documentElement.clientHeight;
if (doc.doctype == 'xanadoc') {
if (doc.doctype == 'xanapage') {
var x = (w / 2) - 400;
var y = (h / 2) - 400;
} else {
@ -316,9 +316,9 @@ function fulfil() {
new_document(doc);
}
});
new_document({'heading': 'xanadoc',
new_document({'heading': 'xanapage',
'text': doc.doc,
'doctype': 'xanadoc'});
'doctype': 'xanapage'});
update();
@ -338,7 +338,7 @@ function fulfil() {
hover_link_bridge(this, false);
});
$('.xanadoclink').click(function(e) {
$('.xanapagelink').click(function(e) {
var num = get_end_number(this.id);
var source = $('#link' + num).closest( ".sourcedoc" );
@ -357,7 +357,7 @@ function fulfil() {
update();
});
$('.xanadoctransclusion').click(function(e) {
$('.xanapagetransclusion').click(function(e) {
var num = get_end_number(this.id);
var source = $('#transclusion' + num).closest( ".sourcedoc" );

View file

@ -194,7 +194,7 @@ function new_document(doc) {
var w = document.documentElement.clientWidth;
var h = document.documentElement.clientHeight;
if (doc.doctype == 'xanadoc') {
if (doc.doctype == 'xanapage') {
element.css('height', (h - 100) + 'px');
var ratio = (doc.index + 1) / (doc.doc_count + 1)
@ -285,7 +285,7 @@ function fulfil(doc, index, doc_count, heading) {
new_document({'heading': heading,
'text': doc.doc,
'doctype': 'xanadoc',
'doctype': 'xanapage',
'index': index,
'doc_count': doc_count});
@ -299,7 +299,7 @@ function size_svg() {
}
function add_handlers() {
$('.xanadoclink').click(function(e) {
$('.xanapagelink').click(function(e) {
var num = get_end_number(this.id);
var bridge = document.getElementById('linkbridge' + num);
@ -311,11 +311,11 @@ function add_handlers() {
update();
});
$('.xanadoclink').bind('mouseover', function(e) {
$('.xanapagelink').bind('mouseover', function(e) {
hover_link_bridge(this, true);
});
$('.xanadoclink').bind('mouseout', function(e) {
$('.xanapagelink').bind('mouseout', function(e) {
hover_link_bridge(this, false);
});

View file

@ -15,7 +15,7 @@
<li class="nav-item">
<a class="nav-link" href="{{ doc.url }}">View</a>
</li>
{% if doc.type == 'xanadoc' %}
{% if doc.type == 'xanapage' %}
<li class="nav-item">
<a class="nav-link" href="{{ doc.url }}/fulfil">Fulfil</a>
</li>

View file

@ -8,7 +8,7 @@
<li class="nav-item">
<a class="nav-link" href="{{ doc.url }}">View</a>
</li>
{% if doc.type == 'xanadoc' %}
{% if doc.type == 'xanapage' %}
<li class="nav-item">
<a class="nav-link" href="{{ doc.url }}/fulfil">Fulfil</a>
</li>

View file

@ -4,7 +4,7 @@
<p>
<a href="{{ url_for('.new_sourcedoc') }}" class="btn btn-primary">new source document</a>
<a href="{{ url_for('.new_xanalink') }}" class="btn btn-primary">new xanalink</a>
<a href="{{ url_for('.new_xanadoc') }}" class="btn btn-primary">new xanadoc</a>
<a href="{{ url_for('.new_xanapage') }}" class="btn btn-primary">new xanapage</a>
</p>
{% endmacro %}
@ -22,7 +22,7 @@
<div class="col-md-2">
<form>
<h5>item type</h5>
{% for item_type in 'xanadoc', 'xanalink', 'sourcedoc' %}
{% for item_type in 'xanapage', 'xanalink', 'sourcedoc' %}
<div class="form-check">
<input class="form-check-input facet_type" type="checkbox" checked="checked" id="type_{{ item_type }}">
<label class="form-check-label" for="type_{{ item_type }}"> {{ item_type }}</label>

View file

@ -8,7 +8,7 @@
<li class="nav-item">
<a class="nav-link" href="{{ doc.url }}">View</a>
</li>
{% if doc.type == 'xanadoc' %}
{% if doc.type == 'xanapage' %}
<li class="nav-item">
<a class="nav-link" href="{{ doc.url }}/fulfil">In view</a>
</li>

View file

@ -67,7 +67,7 @@
<li class="nav-item">
<a class="nav-link active" href="{{ doc.url }}">View</a>
</li>
{% if doc.type == 'xanadoc' %}
{% if doc.type == 'xanapage' %}
<li class="nav-item">
<a class="nav-link" href="{{ doc.url }}/fulfil">In view</a>
</li>
@ -106,7 +106,7 @@
<div class="row">
<div class="col-md-8" id="main">
{% if doc.type == 'xanadoc' %}
{% if doc.type == 'xanapage' %}
<h4>Edit Decision List (EDL)</h4>
{% endif %}
<div class="card" id="text">
@ -129,7 +129,7 @@
{%- for start, line in iter_lines(text) if line != '\r\n' -%}
{# <p data-start="{{ start }}">{% if line != "\n" and line != "\r\n" %}{{ line }}{% else %}&nbsp;{% endif
%}</p>#}
<p class="card-text{% if doc.type != 'xanadoc' or line.startswith('-') %} margin-bottom-zero{% endif %}" data-start="{{ start }}">{{ nbsp_at_start(line) }}</p>
<p class="card-text{% if doc.type != 'xanapage' or line.startswith('-') %} margin-bottom-zero{% endif %}" data-start="{{ start }}">{{ nbsp_at_start(line) }}</p>
{%- endfor -%}
{% endif %}
</div>
@ -142,7 +142,7 @@
<p id="span-selector" class="d-none">span: <span id="span"></span></p>
{% endif %}
{% if doc.type == 'xanadoc' %}
{% if doc.type == 'xanapage' %}
<p class="my-3">
<a class="btn btn-primary" href="{{ doc.edit_url }}" role="button">Edit EDL</a>

View file

@ -7,7 +7,7 @@
<title>{{ title | default("Xanadu") }}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='bootstrap4/css/bootstrap.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/xanadoc.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/xanapage.css') }}">
</head>
<body>

View file

@ -7,7 +7,7 @@
<title>{{ title | default("Xanadu") }}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='bootstrap4/css/bootstrap.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/xanadoc.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/xanapage.css') }}">
</head>
<body>

View file

@ -7,7 +7,7 @@
<h1 class="mt-3">{{ doc.title() }}</h1>
<p><a href="{{ doc.url }}">view xanadoc (cancel edit)</a></p>
<p><a href="{{ doc.url }}">view xanapage (cancel edit)</a></p>
<form method="POST" action="{{ doc.view_url('finish_xanaedit') }}">
<input type="hidden" name="edits" id="edits" value=""/>

View file

@ -5,7 +5,7 @@ from flask_login import (login_user, current_user, logout_user,
from .forms import (LoginForm, SignupForm, AccountSettingsForm,
UploadSourceDocForm, SourceDocForm, ItemForm,
ForgotPasswordForm, PasswordForm)
from .model import User, SourceDoc, Item, XanaDoc, XanaLink, Reference
from .model import User, SourceDoc, Item, XanaPage, XanaLink, Reference
from .parse import parse_xanapage_facet, parse_link
from .url import get_url
from .mail import send_mail
@ -199,11 +199,11 @@ def get_source_doc(username, hashid):
doc = None
return doc if doc else abort(404)
def get_xanadoc(username, hashid):
def get_xanapage(username, hashid):
doc = Item.get_by_hashid(hashid)
if doc and doc.user.username != username:
doc = None
return doc if doc and doc.type == 'xanadoc' else abort(404)
return doc if doc and doc.type == 'xanapage' else abort(404)
def get_item(username, hashid):
doc = Item.get_by_hashid(hashid)
@ -213,7 +213,7 @@ def get_item(username, hashid):
@bp.route('/<username>/<hashid>/edl')
def view_edl(username, hashid):
item = get_xanadoc(username, hashid)
item = get_xanapage(username, hashid)
return render_template('view.html',
doc=item,
@ -222,7 +222,7 @@ def view_edl(username, hashid):
@bp.route('/<username>/<hashid>/realize')
def realize_edl(username, hashid):
item = get_xanadoc(username, hashid)
item = get_xanapage(username, hashid)
spans = list(fulfil_edl(item.text))
doc_text = ''.join(span['text'] for span in spans)
@ -246,7 +246,7 @@ def fulfil_xanaflight(item):
all_links = []
for facet in facets:
xanapage = Item.from_external(parse_xanapage_facet(facet))
assert xanapage.type == 'xanadoc'
assert xanapage.type == 'xanapage'
edl = parse_edl(xanapage.text)
edl_list.append((xanapage, edl))
all_links += [parse_link(link['text']) for link in edl['links']]
@ -268,8 +268,8 @@ def fulfil_xanaflight(item):
def fulfil(username, hashid):
item = get_item(username, hashid)
if item.type == 'xanadoc':
return render_template('view/xanadoc.html',
if item.type == 'xanapage':
return render_template('view/xanapage.html',
item=item,
doc=fulfil_edl_with_sources(item.text))
if item.type == 'xanalink' and item.text.startswith('type=flight'):
@ -379,7 +379,7 @@ def view_item(username, hashid, raw=False):
version = None
text = item.text
if item.type == 'xanadoc':
if item.type == 'xanapage':
spans = list(fulfil_edl(item.text))
doc_text = ''.join(span['text'] for span in spans)
else:
@ -403,7 +403,7 @@ def history(username, hashid):
@bp.route('/<username>/<hashid>/xanaedit')
def xanaedit_item(username, hashid):
doc = get_xanadoc(username, hashid)
doc = get_xanapage(username, hashid)
spans = list(fulfil_edl(doc.text))
doc_text = ''.join(span['text'] for span in spans)
@ -412,13 +412,13 @@ def xanaedit_item(username, hashid):
@bp.route('/<username>/<hashid>/xanaedit', methods=['POST'])
def save_xanaedit(username, hashid):
# doc = get_xanadoc(username, hashid)
# doc = get_xanapage(username, hashid)
edits = json.loads(request.form['edits'])
return jsonify(edits=edits)
@bp.route('/<username>/<hashid>/finish', methods=['POST'])
def finish_xanaedit(username, hashid):
doc = get_xanadoc(username, hashid)
doc = get_xanapage(username, hashid)
current_edl = parse_edl(doc.text)
spans = [Span(*span) for span in current_edl['spans']]
@ -505,18 +505,18 @@ def new_xanalink():
flash('New xanalink saved.')
return jsonify(url=obj.url)
@bp.route('/new/xanadoc', methods=['GET', 'POST'])
@bp.route('/new/xanapage', methods=['GET', 'POST'])
@login_required
def new_xanadoc():
def new_xanapage():
form = ItemForm()
if form.validate_on_submit():
obj = XanaDoc(user=current_user)
obj = XanaPage(user=current_user)
form.populate_obj(obj)
session.add(obj)
session.commit()
flash('New xanadoc saved.')
flash('New xanapage saved.')
return redirect(obj.url)
return render_template('new.html', form=form, item_type='xanadoc')
return render_template('new.html', form=form, item_type='xanapage')
@bp.route('/edit/<filename>', methods=['GET', 'POST'])
@login_required