summaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/fatcat_web/editing_routes.py39
-rw-r--r--python/fatcat_web/templates/container_edit.html5
-rw-r--r--python/fatcat_web/templates/edit_macros.html50
3 files changed, 59 insertions, 35 deletions
diff --git a/python/fatcat_web/editing_routes.py b/python/fatcat_web/editing_routes.py
index 88fb4557..fb45ca7b 100644
--- a/python/fatcat_web/editing_routes.py
+++ b/python/fatcat_web/editing_routes.py
@@ -50,7 +50,7 @@ def form_editgroup_get_or_create(api, edit_form):
### Views ###################################################################
-def generic_entity_edit(entity_type, edit_template, existing_ident, editgroup_id):
+def generic_entity_edit(editgroup_id, entity_type, existing_ident, edit_template):
"""
existing (entity)
@@ -83,6 +83,11 @@ def generic_entity_edit(entity_type, edit_template, existing_ident, editgroup_id
except ApiException as ae:
abort(ae.status)
+ # check that editgroup is edit-able
+ if editgroup.changelog_index != None:
+ flash("Editgroup already merged")
+ abort(400)
+
# fetch entity (if set) or 404
existing = None
existing_edit = None
@@ -106,10 +111,6 @@ def generic_entity_edit(entity_type, edit_template, existing_ident, editgroup_id
editgroup = form_editgroup_get_or_create(user_api, form)
if editgroup:
- # check that editgroup is edit-able
- if editgroup.changelog_index != None:
- flash("Editgroup already merged")
- abort(400)
if not existing_ident: # it's a create
entity = form.to_entity()
@@ -170,10 +171,14 @@ def generic_entity_edit(entity_type, edit_template, existing_ident, editgroup_id
if not editgroup_id:
form.editgroup_id.data = session.get('active_editgroup_id', None)
+ editor_editgroups = api.get_editor_editgroups(session['editor']['editor_id'], limit=20)
+ potential_editgroups = [e for e in editor_editgroups if e.changelog_index == None and e.submitted == None]
+
return render_template(edit_template, form=form,
- existing_ident=existing_ident, editgroup=editgroup), status
+ existing_ident=existing_ident, editgroup=editgroup,
+ potential_editgroups=potential_editgroups), status
-def generic_edit_delete(entity_type, editgroup_id, edit_id):
+def generic_edit_delete(editgroup_id, entity_type, edit_id):
# fetch editgroup (if set) or 404
editgroup = None
if editgroup_id:
@@ -182,6 +187,11 @@ def generic_edit_delete(entity_type, editgroup_id, edit_id):
except ApiException as ae:
abort(ae.status)
+ # check that editgroup is edit-able
+ if editgroup.changelog_index != None:
+ flash("Editgroup already merged")
+ abort(400)
+
# API on behalf of user
user_api = auth_api(session['api_token'])
@@ -192,32 +202,29 @@ def generic_edit_delete(entity_type, editgroup_id, edit_id):
else:
raise NotImplementedError
except ApiException as ae:
- if ae.status == 404:
- pass
- else:
- abort(ae.status)
+ abort(ae.status)
return redirect("/editgroup/{}".format(editgroup_id))
@app.route('/container/create', methods=['GET', 'POST'])
@login_required
def container_create():
- return generic_entity_edit('container', 'container_create.html', None, None)
+ return generic_entity_edit(None, 'container', None, 'container_create.html')
@app.route('/container/<ident>/edit', methods=['GET', 'POST'])
@login_required
def container_edit(ident):
- return generic_entity_edit('container', 'container_edit.html', ident, None)
+ return generic_entity_edit(None, 'container', ident, 'container_edit.html')
@app.route('/editgroup/<editgroup_id>/container/<ident>/edit', methods=['GET', 'POST'])
@login_required
def container_editgroup_edit(editgroup_id, ident):
- return generic_entity_edit('container', 'container_edit.html', ident, editgroup_id)
+ return generic_entity_edit(editgroup_id, 'container', ident, 'container_edit.html')
-@app.route('/editgroup/<editgroup_id>/container/edit/<edit_id>/delete', methods=['POST', 'DELETE'])
+@app.route('/editgroup/<editgroup_id>/container/edit/<edit_id>/delete', methods=['POST'])
@login_required
def container_edit_delete(editgroup_id, edit_id):
- return generic_edit_delete('container', editgroup_id, edit_id)
+ return generic_edit_delete(editgroup_id, 'container', edit_id)
@app.route('/creator/<ident>/edit', methods=['GET'])
def creator_edit(ident):
diff --git a/python/fatcat_web/templates/container_edit.html b/python/fatcat_web/templates/container_edit.html
index 6a08b1ae..91432d5e 100644
--- a/python/fatcat_web/templates/container_edit.html
+++ b/python/fatcat_web/templates/container_edit.html
@@ -10,8 +10,8 @@
{% endblock %}
{{ form.hidden_tag() }}
- <br>
- {{ edit_macros.editgroup_dropdown(form, editgroup) }}
+ <h3 class="ui dividing header">Editgroup</h3>
+ {{ edit_macros.editgroup_dropdown(form, editgroup, potential_editgroups) }}
<h3 class="ui dividing header">The Basics</h3>
<br>
@@ -71,6 +71,7 @@
$(document).ready(function() {
$('.ui.accordion').accordion();
+ $('.ui.dropdown') .dropdown();
var fixup_url_numbering = function(group_item) {
items = Array.from(group_item.querySelectorAll(".list-group-item"))
diff --git a/python/fatcat_web/templates/edit_macros.html b/python/fatcat_web/templates/edit_macros.html
index 66da04e7..a207e51e 100644
--- a/python/fatcat_web/templates/edit_macros.html
+++ b/python/fatcat_web/templates/edit_macros.html
@@ -35,22 +35,38 @@
</div>
{%- endmacro %}
-{% macro editgroup_dropdown(form, editgroup=None) -%}
- <div class="ui accordion">
- <div class="{% if not editgroup %}active{% endif %} title">
- <h3><i class="dropdown icon"></i>Editgroup Meta</h3>
- </div>
- <div class="{% if not editgroup %}active{% endif %} content">
- {% if editgroup %}
- <p>You have an editgroup in progress, and this edit will be included by
- default. You can override this below.
- {% else %}
- <p>No existing editgroup is in progress (or at least, not is selected).
- An existing ID can be pasted in, or if you leave that blank but give a
- description, a new editgroup will be created for this edit.
- {% endif %}
- {{ form_field_inline(form.editgroup_id) }}
+{% macro editgroup_dropdown(form, editgroup=None, potential_editgroups=None) -%}
+ {% if editgroup %}
+ <p>You are updating an existing un-merged editgroup: <a href="/editgroup/{{ editgroup.editgroup_id}}">{{ editgroup.editgroup_id }}</a>.
+ <p><b>Description:</b> {{ editgroup.description }}
+ {% else %}
+ {% if not potential_editgroups %}
+ <p>You have no un-submitted editgroups in progress; a new one will be
+ created. You can add a description for the whole group of edits:
{{ form_field_inline(form.editgroup_description) }}
- </div>
- </div>
+ {% else %}
+ <p>Select an in-progress editgroup for this change to be part of (or start a new one):
+
+ <div class="ui fluid selection dropdown">
+ <input type="hidden" id="editgroup_id" name="editgroup_id" value="{{ form.editgroup_id.data }}">
+ <i class="dropdown icon"></i>
+ <div class="default text">Select Editgroup</div>
+ <div class="menu">
+ {% for peg in potential_editgroups %}
+ <div class="item" data-value="{{ peg.editgroup_id }}">
+ <div class="right floated">{{ peg.created }}</div>
+ <code><b>editgroup_{{ peg.editgroup_id }}</b></code>
+ {% if peg.description %}
+ <br>{{ peg.description[:200] }}
+ {% endif %}
+ </div>
+ {% endfor %}
+ <div class="item" data-value=""><b>Start New Editgroup</b></div>
+ </div>
+ </div>
+
+ <p>If starting a new editgroup, you can add a description for the whole group:
+ {{ form_field_inline(form.editgroup_description) }}
+ {% endif %}
+ {% endif %}
{%- endmacro %}