mostly implement topics app
This commit is contained in:
parent
19bf98f5b5
commit
453aeff95a
@ -69,3 +69,44 @@ def topic(slug):
|
|||||||
current_page = page,
|
current_page = page,
|
||||||
page_count = page_count
|
page_count = page_count
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.get("/<slug>/edit")
|
||||||
|
@login_required
|
||||||
|
@mod_only(".topic", slug = lambda slug: slug)
|
||||||
|
def edit(slug):
|
||||||
|
topic = Topics.find({"slug": slug})
|
||||||
|
if not topic:
|
||||||
|
return "no"
|
||||||
|
return render_template("topics/edit.html", topic=topic)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.post("/<slug>/edit")
|
||||||
|
@login_required
|
||||||
|
@mod_only(".topic", slug = lambda slug: slug)
|
||||||
|
def edit_post(slug):
|
||||||
|
topic = Topics.find({"slug": slug})
|
||||||
|
if not topic:
|
||||||
|
return "no"
|
||||||
|
|
||||||
|
topic.update({
|
||||||
|
"name": request.form.get('name', default = topic.name).strip(),
|
||||||
|
"description": request.form.get('description', default = topic.description),
|
||||||
|
"is_locked": int(request.form.get("is_locked", default = topic.is_locked)),
|
||||||
|
})
|
||||||
|
|
||||||
|
return redirect(url_for("topics.topic", slug=slug))
|
||||||
|
|
||||||
|
|
||||||
|
@bp.post("/<slug>/delete")
|
||||||
|
@login_required
|
||||||
|
@mod_only(".topic", slug = lambda slug: slug)
|
||||||
|
def delete(slug):
|
||||||
|
topic = Topics.find({"slug": slug})
|
||||||
|
if not topic:
|
||||||
|
return "no"
|
||||||
|
|
||||||
|
topic.delete()
|
||||||
|
|
||||||
|
flash("Topic deleted.", InfoboxKind.INFO)
|
||||||
|
return redirect(url_for("topics.all_topics"))
|
||||||
|
@ -50,7 +50,7 @@ def redirect_if_logged_in(*args, **kwargs):
|
|||||||
if is_logged_in():
|
if is_logged_in():
|
||||||
# resolve callables
|
# resolve callables
|
||||||
processed_kwargs = {
|
processed_kwargs = {
|
||||||
k: v() if callable(v) else v
|
k: v(**view_kwargs) if callable(v) else v
|
||||||
for k, v in kwargs.items()
|
for k, v in kwargs.items()
|
||||||
}
|
}
|
||||||
endpoint = args[0] if args else processed_kwargs.get("endpoint")
|
endpoint = args[0] if args else processed_kwargs.get("endpoint")
|
||||||
@ -81,7 +81,7 @@ def mod_only(*args, **kwargs):
|
|||||||
if not get_active_user().is_mod():
|
if not get_active_user().is_mod():
|
||||||
# resolve callables
|
# resolve callables
|
||||||
processed_kwargs = {
|
processed_kwargs = {
|
||||||
k: v() if callable(v) else v
|
k: v(**view_kwargs) if callable(v) else v
|
||||||
for k, v in kwargs.items()
|
for k, v in kwargs.items()
|
||||||
}
|
}
|
||||||
endpoint = args[0] if args else processed_kwargs.get("endpoint")
|
endpoint = args[0] if args else processed_kwargs.get("endpoint")
|
||||||
|
16
app/templates/topics/edit.html
Normal file
16
app/templates/topics/edit.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}creating a topic{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="darkbg settings-container">
|
||||||
|
<h1>Editing topic {{ topic['name'] }}</h1>
|
||||||
|
<form method="post">
|
||||||
|
<label for=name>Name</label>
|
||||||
|
<input type="text" name="name" id="name" required value="{{ topic['name'] }}"><br>
|
||||||
|
<label for="description">Description</label>
|
||||||
|
<textarea id="description" name="description" required rows=5>{{ topic['description'] }}</textarea><br>
|
||||||
|
<input type="submit" value="Save changes">
|
||||||
|
<a class="linkbutton warn" href={{ url_for("topics.topic", slug=topic['slug'] )}}>Cancel</a><br>
|
||||||
|
<i> Note: to preserve history, you cannot change the topic URL.</i>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -7,6 +7,12 @@
|
|||||||
<span>{{topic['description']}}</span>
|
<span>{{topic['description']}}</span>
|
||||||
<div>
|
<div>
|
||||||
{% if active_user and active_user.is_mod() %}
|
{% if active_user and active_user.is_mod() %}
|
||||||
|
<a class="linkbutton" href="{{url_for("topics.edit", slug=topic['slug'])}}">Edit topic</a>
|
||||||
|
<form class="modform" method="post" action="{{url_for("topics.edit", slug=topic['slug']) }}">
|
||||||
|
<input type="hidden" name="is_locked" value="{{ (not topic.is_locked) | int }}">
|
||||||
|
<input class="warn" type="submit" id="lock" value="{{"Unlock topic" if topic['is_locked'] else "Lock topic"}}">
|
||||||
|
</form>
|
||||||
|
<button type="button" class="critical" id="topic-delete-dialog-open">Delete</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
@ -52,4 +58,17 @@
|
|||||||
<nav id="bottomnav">
|
<nav id="bottomnav">
|
||||||
{{ pager(current_page = current_page, page_count = page_count) }}
|
{{ pager(current_page = current_page, page_count = page_count) }}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
<dialog id="delete-dialog">
|
||||||
|
<div class="delete-dialog-inner">
|
||||||
|
Are you sure you want to delete this topic?
|
||||||
|
<span>
|
||||||
|
<button id=topic-delete-dialog-close>Cancel</button>
|
||||||
|
<button class="critical" form=topic-delete-form>Delete</button>
|
||||||
|
<form id="topic-delete-form" method="post" action="{{ url_for("topics.delete", slug = topic.slug) }}"></form>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
|
|
||||||
|
<script src="/static/js/topic.js"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
{% from 'common/macros.html' import timestamp %}
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<nav class="darkbg">
|
<nav class="darkbg">
|
||||||
@ -16,12 +17,12 @@
|
|||||||
{{ topic['description'] }}
|
{{ topic['description'] }}
|
||||||
{% if topic['latest_thread_username'] %}
|
{% if topic['latest_thread_username'] %}
|
||||||
<span>
|
<span>
|
||||||
Latest thread: <a href="{{ url_for("threads.thread", slug=topic['latest_thread_slug'])}}">{{topic['latest_thread_title']}}</a> by <a href="{{url_for("users.page", username=topic['latest_thread_username'])}}">{{topic['latest_thread_username']}}</a> on ...
|
Latest thread: <a href="{{ url_for("threads.thread", slug=topic['latest_thread_slug'])}}">{{topic['latest_thread_title']}}</a> by <a href="{{url_for("users.page", username=topic['latest_thread_username'])}}">{{topic['latest_thread_username']}}</a> on {{ timestamp(topic['latest_thread_created_at']) }}
|
||||||
</span>
|
</span>
|
||||||
{% if topic['id'] in active_threads %}
|
{% if topic['id'] in active_threads %}
|
||||||
{% with thread=active_threads[topic['id']] %}
|
{% with thread=active_threads[topic['id']] %}
|
||||||
<span>
|
<span>
|
||||||
Latest post in: <a href="{{ url_for("threads.thread", slug=thread['thread_slug'])}}">{{ thread['thread_title'] }}</a> by <a href="{{ url_for("users.page", username=thread['username'])}}">{{ thread['username'] }}</a> on ...
|
Latest post in: <a href="{{ url_for("threads.thread", slug=thread['thread_slug'])}}">{{ thread['thread_title'] }}</a> by <a href="{{ url_for("users.page", username=thread['username'])}}">{{ thread['username'] }}</a> at <a href="">{{ timestamp(thread['post_created_at']) }}</a>
|
||||||
</span>
|
</span>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
Reference in New Issue
Block a user