diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/fatcat_web/routes.py | 44 | ||||
-rw-r--r-- | python/fatcat_web/templates/editgroup_view.html | 58 |
2 files changed, 90 insertions, 12 deletions
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py index 7a148e94..e20cd3c5 100644 --- a/python/fatcat_web/routes.py +++ b/python/fatcat_web/routes.py @@ -6,7 +6,7 @@ from flask import Flask, render_template, send_from_directory, request, \ from flask_login import login_required from flask_wtf.csrf import CSRFError -from fatcat_client import Editgroup +from fatcat_client import Editgroup, EditgroupAnnotation from fatcat_client.rest import ApiException from fatcat_tools.transforms import * from fatcat_web import app, api, auth_api, priv_api @@ -313,19 +313,51 @@ def editgroup_view(ident): try: eg = api.get_editgroup(str(ident)) eg.editor = api.get_editor(eg.editor_id) + eg.annotations = api.get_editgroup_annotations(eg.editgroup_id, expand="editors") except ApiException as ae: abort(ae.status) # TODO: idomatic check for login? - auth_to_submit = False - auth_to_accept = False + auth_to = dict( + submit=False, + accept=False, + annotate=False, + ) if session.get('editor'): user = load_user(session['editor']['editor_id']) + auth_to['annotate'] = True if user.is_admin or user.editor_id == eg.editor_id: - auth_to_submit = True + auth_to['submit'] = True if user.is_admin: - auth_to_accept = True + auth_to['accept'] = True return render_template('editgroup_view.html', editgroup=eg, - auth_to_submit=auth_to_submit, auth_to_accept=auth_to_accept) + auth_to=auth_to) + +@app.route('/editgroup/<ident>/annotation', methods=['POST']) +@login_required +def editgroup_create_annotation(ident): + app.csrf.protect() + comment_markdown = request.form.get('comment_markdown') + if not comment_markdown: + app.logger.info("empty comment field") + abort(400) + # on behalf of user... + user_api = auth_api(session['api_token']) + try: + eg = user_api.get_editgroup(str(ident)) + if eg.changelog_index: + flash("Editgroup already accepted") + abort(400) + ega = EditgroupAnnotation( + comment_markdown=comment_markdown, + extra=None, + ) + user_api.create_editgroup_annotation(eg.editgroup_id, ega) + except ApiException as ae: + app.logger.info(ae) + abort(ae.status) + return redirect('/editgroup/{}'.format(ident)) + +# XXX: editor's annotations @app.route('/editgroup/<ident>/accept', methods=['POST']) @login_required diff --git a/python/fatcat_web/templates/editgroup_view.html b/python/fatcat_web/templates/editgroup_view.html index 37771273..2f61671d 100644 --- a/python/fatcat_web/templates/editgroup_view.html +++ b/python/fatcat_web/templates/editgroup_view.html @@ -1,4 +1,6 @@ {% extends "base.html" %} +{% import "entity_macros.html" as entity_macros %} + {% block body %} {% macro edit_list(edits, entity_type, entity_name) -%} @@ -37,13 +39,13 @@ {% block editgroupheader %} {% if not editgroup.changelog_index %} <div class="ui right floated center aligned segment"> - {% if auth_to_accept %} + {% if auth_to.accept %} <form id="submit_editgroup_form" method="POST" action="/editgroup/{{ editgroup.editgroup_id }}/accept"> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/> <button class="ui orange button">Accept Edits</button> </form><br> {% endif %} - {% if auth_to_submit %} + {% if auth_to.submit %} {% if editgroup.submitted %} <form id="submit_editgroup_form" method="POST" action="/editgroup/{{ editgroup.editgroup_id }}/unsubmit"> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/> @@ -67,6 +69,11 @@ <div class="sub header"><code>editgroup {{ editgroup.editgroup_id }}</code></div></h1> {% endblock %} +<p><b>What is an editgroup?</b> +An editgroup is a set of entity edits, bundled together into a coherent, +reviewable bundle. +<br> + <br><b>Status:</b> {% if editgroup.changelog_index %} Merged (<a href="/changelog/{{ editgroup.changelog_index }}">Changelog #{{ editgroup.changelog_index }}</a>) @@ -95,11 +102,50 @@ {{ edit_list(editgroup.edits.webcaptures, "webcapture", "Web Capture") }} </div> - <br> -<p><b>What is an editgroup?</b> -An editgroup is a set of entity edits, bundled together into a coherent, -reviewable bundle. +<h2 class="ui header">Comments and Annotations</h2> +{% for annotation in editgroup.annotations|reverse %} + <div class="ui segments"> + <div class="ui top attached secondary segment"> + {% if annotation.editor.is_bot %} + <i class="icon bug"></i> + {% else %} + <i class="icon user"></i> + {% endif %} + <b><a href="/editor/{{ annotation.editor_id }}">{{ annotation.editor.username}}</a></b> + {% if annotation.editor.is_admin %} + <span class="ui tiny olive label">Admin</span> + {% endif %} + at {{ annotation.created.strftime("%Y-%m-%d %H:%M:%S") }} + </div> + {% if annotation.extra %} + <div class="ui attached segment"> + {{ entity_macros.extra_metadata(annotation.extra) }} + </div> + {% endif %} + <div class="ui bottom attached segment"> + {{ annotation.comment_markdown }} + </div> + </div> +{% else %} + <i>None!</i> +{% endfor %} + +{% if auth_to.annotate and not editgroup.changelog_index %} + <div class="ui segment"> + <h3 class="ui header">Add Comment</h3> + <form class="ui form" id="submit_editgroup_annotation_form" method="POST" action="/editgroup/{{ editgroup.editgroup_id }}/annotation"> + <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/> + <div class="field"> + <textarea rows="2" name="comment_markdown" required type="text" value=""></textarea> + </div> + <button class="ui right floated primary button"> + <i class="icon edit"></i> Submit + </button> + <br> + </form><br> + </div> +{% endif %} {% endblock %} |