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
27
app.py
27
app.py
|
|
@ -21,8 +21,8 @@ from werkzeug.security import generate_password_hash, check_password_hash
|
|||
from werkzeug.routing import BaseConverter
|
||||
from peewee import *
|
||||
from playhouse.db_url import connect as dbconnect
|
||||
import csv, datetime, hashlib, html, importlib, json, markdown, os, random, \
|
||||
re, sys, uuid, warnings
|
||||
import datetime, hashlib, html, importlib, json, markdown, os, random, \
|
||||
re, sys, warnings
|
||||
from functools import lru_cache, partial
|
||||
from urllib.parse import quote
|
||||
from configparser import ConfigParser
|
||||
|
|
@ -250,7 +250,7 @@ class PageText(BaseModel):
|
|||
|
||||
class PageRevision(BaseModel):
|
||||
page = FK(Page, backref='revisions', index=True)
|
||||
user = ForeignKeyField(User, null=True)
|
||||
user = ForeignKeyField(User, backref='contributions', null=True)
|
||||
comment = CharField(1024, default='')
|
||||
textref = FK(PageText)
|
||||
pub_date = DateTimeField(index=True)
|
||||
|
|
@ -439,7 +439,7 @@ forbidden_urls = [
|
|||
'create', 'edit', 'p', 'ajax', 'history', 'manage', 'static', 'media',
|
||||
'accounts', 'tags', 'init-config', 'upload', 'upload-info', 'about',
|
||||
'stats', 'terms', 'privacy', 'easter', 'search', 'help', 'circles',
|
||||
'protect', 'kt', 'embed', 'backlinks'
|
||||
'protect', 'kt', 'embed', 'backlinks', 'u'
|
||||
]
|
||||
|
||||
app = Flask(__name__)
|
||||
|
|
@ -541,6 +541,7 @@ def savepoint(form, is_preview=False, pageobj=None):
|
|||
pl_title=form['title'],
|
||||
pl_text=form['text'],
|
||||
pl_tags=form['tags'],
|
||||
pl_comment=form['comment'],
|
||||
pl_enablemath='enablemath' in form,
|
||||
pl_is_locked='lockpage' in form,
|
||||
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"),
|
||||
"title": "",
|
||||
"text": "",
|
||||
"tags": ""
|
||||
"tags": "",
|
||||
"comment": get_string(g.lang, "page-created")
|
||||
})
|
||||
|
||||
@app.route('/edit/<int:id>/', methods=['GET', 'POST'])
|
||||
|
|
@ -632,10 +634,11 @@ def edit(id):
|
|||
p.is_locked = 'lockpage' in request.form
|
||||
p.save()
|
||||
p.change_tags(p_tags)
|
||||
if request.form['text'] != p.latest.text:
|
||||
pr = PageRevision.create(
|
||||
page=p,
|
||||
user_id=current_user.id,
|
||||
comment='',
|
||||
comment=request.form["comment"],
|
||||
textref=PageText.create_content(request.form['text']),
|
||||
pub_date=datetime.datetime.now(),
|
||||
length=len(request.form['text'])
|
||||
|
|
@ -647,7 +650,8 @@ def edit(id):
|
|||
"url": p.url,
|
||||
"title": p.title,
|
||||
"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:
|
||||
form["enablemath"] = "1"
|
||||
|
|
@ -766,6 +770,15 @@ def history(id):
|
|||
abort(404)
|
||||
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>/')
|
||||
def view_old(revisionid):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@
|
|||
"already-have-account": "Already have an account?",
|
||||
"logged-in-as": "Logged in as",
|
||||
"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-per-page": "Media di revisioni per pagina",
|
||||
"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>
|
||||
<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="text" name="comment" value="{{ pl_comment }}" placeholder="{{ T('write-a-comment') }}" />
|
||||
</div>
|
||||
<h3>Advanced options</h3>
|
||||
<div>
|
||||
|
|
@ -78,6 +79,7 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
|
|
|
|||
|
|
@ -12,13 +12,22 @@
|
|||
|
||||
<ul>
|
||||
{% for rev in history %}
|
||||
<li><a href="/history/revision/{{ rev.id }}/">
|
||||
<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>
|
||||
by
|
||||
<a href="/u/{{ rev.user.username }}">
|
||||
{{ rev.user.username }}
|
||||
</a></li>
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<p>{{ T("back-to") }} <a href="{{ p.get_url() }}">{{ p.title }}</a>.</p>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue