Added edit comments, user contributions and improved history page
This commit is contained in:
parent
f4d536dc47
commit
d2cef14c38
6 changed files with 80 additions and 23 deletions
43
app.py
43
app.py
|
|
@ -21,8 +21,8 @@ from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
from werkzeug.routing import BaseConverter
|
from werkzeug.routing import BaseConverter
|
||||||
from peewee import *
|
from peewee import *
|
||||||
from playhouse.db_url import connect as dbconnect
|
from playhouse.db_url import connect as dbconnect
|
||||||
import csv, datetime, hashlib, html, importlib, json, markdown, os, random, \
|
import datetime, hashlib, html, importlib, json, markdown, os, random, \
|
||||||
re, sys, uuid, warnings
|
re, sys, warnings
|
||||||
from functools import lru_cache, partial
|
from functools import lru_cache, partial
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
@ -250,7 +250,7 @@ class PageText(BaseModel):
|
||||||
|
|
||||||
class PageRevision(BaseModel):
|
class PageRevision(BaseModel):
|
||||||
page = FK(Page, backref='revisions', index=True)
|
page = FK(Page, backref='revisions', index=True)
|
||||||
user = ForeignKeyField(User, null=True)
|
user = ForeignKeyField(User, backref='contributions', null=True)
|
||||||
comment = CharField(1024, default='')
|
comment = CharField(1024, default='')
|
||||||
textref = FK(PageText)
|
textref = FK(PageText)
|
||||||
pub_date = DateTimeField(index=True)
|
pub_date = DateTimeField(index=True)
|
||||||
|
|
@ -439,7 +439,7 @@ forbidden_urls = [
|
||||||
'create', 'edit', 'p', 'ajax', 'history', 'manage', 'static', 'media',
|
'create', 'edit', 'p', 'ajax', 'history', 'manage', 'static', 'media',
|
||||||
'accounts', 'tags', 'init-config', 'upload', 'upload-info', 'about',
|
'accounts', 'tags', 'init-config', 'upload', 'upload-info', 'about',
|
||||||
'stats', 'terms', 'privacy', 'easter', 'search', 'help', 'circles',
|
'stats', 'terms', 'privacy', 'easter', 'search', 'help', 'circles',
|
||||||
'protect', 'kt', 'embed', 'backlinks'
|
'protect', 'kt', 'embed', 'backlinks', 'u'
|
||||||
]
|
]
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
@ -541,6 +541,7 @@ def savepoint(form, is_preview=False, pageobj=None):
|
||||||
pl_title=form['title'],
|
pl_title=form['title'],
|
||||||
pl_text=form['text'],
|
pl_text=form['text'],
|
||||||
pl_tags=form['tags'],
|
pl_tags=form['tags'],
|
||||||
|
pl_comment=form['comment'],
|
||||||
pl_enablemath='enablemath' in form,
|
pl_enablemath='enablemath' in form,
|
||||||
pl_is_locked='lockpage' in form,
|
pl_is_locked='lockpage' in form,
|
||||||
pl_owner_is_current_user=pageobj.is_owned_by(current_user) if pageobj else True,
|
pl_owner_is_current_user=pageobj.is_owned_by(current_user) if pageobj else True,
|
||||||
|
|
@ -596,7 +597,8 @@ def create():
|
||||||
"url": request.args.get("url"),
|
"url": request.args.get("url"),
|
||||||
"title": "",
|
"title": "",
|
||||||
"text": "",
|
"text": "",
|
||||||
"tags": ""
|
"tags": "",
|
||||||
|
"comment": get_string(g.lang, "page-created")
|
||||||
})
|
})
|
||||||
|
|
||||||
@app.route('/edit/<int:id>/', methods=['GET', 'POST'])
|
@app.route('/edit/<int:id>/', methods=['GET', 'POST'])
|
||||||
|
|
@ -632,22 +634,24 @@ def edit(id):
|
||||||
p.is_locked = 'lockpage' in request.form
|
p.is_locked = 'lockpage' in request.form
|
||||||
p.save()
|
p.save()
|
||||||
p.change_tags(p_tags)
|
p.change_tags(p_tags)
|
||||||
pr = PageRevision.create(
|
if request.form['text'] != p.latest.text:
|
||||||
page=p,
|
pr = PageRevision.create(
|
||||||
user_id=current_user.id,
|
page=p,
|
||||||
comment='',
|
user_id=current_user.id,
|
||||||
textref=PageText.create_content(request.form['text']),
|
comment=request.form["comment"],
|
||||||
pub_date=datetime.datetime.now(),
|
textref=PageText.create_content(request.form['text']),
|
||||||
length=len(request.form['text'])
|
pub_date=datetime.datetime.now(),
|
||||||
)
|
length=len(request.form['text'])
|
||||||
PageLink.parse_links(p, request.form['text'])
|
)
|
||||||
|
PageLink.parse_links(p, request.form['text'])
|
||||||
return redirect(p.get_url())
|
return redirect(p.get_url())
|
||||||
|
|
||||||
form = {
|
form = {
|
||||||
"url": p.url,
|
"url": p.url,
|
||||||
"title": p.title,
|
"title": p.title,
|
||||||
"text": p.latest.text,
|
"text": p.latest.text,
|
||||||
"tags": ','.join(x.name for x in p.tags)
|
"tags": ','.join(x.name for x in p.tags),
|
||||||
|
"comment": ""
|
||||||
}
|
}
|
||||||
if p.is_math_enabled:
|
if p.is_math_enabled:
|
||||||
form["enablemath"] = "1"
|
form["enablemath"] = "1"
|
||||||
|
|
@ -766,6 +770,15 @@ def history(id):
|
||||||
abort(404)
|
abort(404)
|
||||||
return render_template('history.html', p=p, history=p.revisions.order_by(PageRevision.pub_date.desc()))
|
return render_template('history.html', p=p, history=p.revisions.order_by(PageRevision.pub_date.desc()))
|
||||||
|
|
||||||
|
@app.route('/u/<username>/')
|
||||||
|
def contributions(username):
|
||||||
|
try:
|
||||||
|
user = User.get(User.username == username)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
abort(404)
|
||||||
|
return render_template('contributions.html', u=user, contributions=user.contributions.order_by(PageRevision.pub_date.desc()))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/history/revision/<int:revisionid>/')
|
@app.route('/history/revision/<int:revisionid>/')
|
||||||
def view_old(revisionid):
|
def view_old(revisionid):
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,8 @@
|
||||||
"already-have-account": "Already have an account?",
|
"already-have-account": "Already have an account?",
|
||||||
"logged-in-as": "Logged in as",
|
"logged-in-as": "Logged in as",
|
||||||
"not-logged-in": "Not logged in",
|
"not-logged-in": "Not logged in",
|
||||||
"owner": "Owner"
|
"owner": "Owner",
|
||||||
|
"page-created": "Page created",
|
||||||
|
"write-a-comment": "Write a comment…"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -46,6 +46,7 @@
|
||||||
"revision-count": "Numero di revisioni",
|
"revision-count": "Numero di revisioni",
|
||||||
"revision-count-per-page": "Media di revisioni per pagina",
|
"revision-count-per-page": "Media di revisioni per pagina",
|
||||||
"remember-me-for": "Ricordami per",
|
"remember-me-for": "Ricordami per",
|
||||||
"owner": "Proprietario"
|
"owner": "Proprietario",
|
||||||
|
"write-a-comment": "Scrivi un commento…"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
30
templates/contributions.html
Normal file
30
templates/contributions.html
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Contributions of {{ u.username }} - {{ app_name }}{% endblock %}
|
||||||
|
|
||||||
|
{% block meta %}
|
||||||
|
<meta name="robots" content="noindex,nofollow" />
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Contributions of {{ u.username }}</div>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{% for rev in contributions %}
|
||||||
|
<li>
|
||||||
|
<a href="/history/revision/{{ rev.id }}/">
|
||||||
|
#{{ rev.id }}
|
||||||
|
·
|
||||||
|
{{ rev.pub_date.strftime("%B %-d, %Y %H:%M:%S") }}
|
||||||
|
{% if rev.comment %}
|
||||||
|
“{{ rev.comment }}”
|
||||||
|
{% endif %}
|
||||||
|
</a>
|
||||||
|
on
|
||||||
|
<a href="{{ rev.page.get_url() }}">
|
||||||
|
{{ rev.page.title }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endblock %}
|
||||||
|
|
@ -64,6 +64,7 @@
|
||||||
<div>
|
<div>
|
||||||
<input type="submit" value="Save" id="save-button" class="submit-primary">
|
<input type="submit" value="Save" id="save-button" class="submit-primary">
|
||||||
<input type="submit" name="preview" value="Preview" id="preview-button" class="submit-secondary">
|
<input type="submit" name="preview" value="Preview" id="preview-button" class="submit-secondary">
|
||||||
|
<input type="text" name="comment" value="{{ pl_comment }}" placeholder="{{ T('write-a-comment') }}" />
|
||||||
</div>
|
</div>
|
||||||
<h3>Advanced options</h3>
|
<h3>Advanced options</h3>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -78,6 +79,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,22 @@
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{% for rev in history %}
|
{% for rev in history %}
|
||||||
<li><a href="/history/revision/{{ rev.id }}/">
|
<li>
|
||||||
#{{ rev.id }}
|
<a href="/history/revision/{{ rev.id }}/">
|
||||||
·
|
#{{ rev.id }}
|
||||||
{{ rev.pub_date.strftime("%B %-d, %Y %H:%M:%S") }}
|
·
|
||||||
|
{{ rev.pub_date.strftime("%B %-d, %Y %H:%M:%S") }}
|
||||||
|
{% if rev.comment %}
|
||||||
|
“{{ rev.comment }}”
|
||||||
|
{% endif %}
|
||||||
|
</a>
|
||||||
by
|
by
|
||||||
{{ rev.user.username }}
|
<a href="/u/{{ rev.user.username }}">
|
||||||
</a></li>
|
{{ rev.user.username }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<p>{{ T("back-to") }} <a href="{{ p.get_url() }}">{{ p.title }}</a>.</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue