# HG changeset patch # User durandn # Date 1429260330 -7200 # Node ID 7684ea24c3305b15dece16c93628660e409a4e5f # Parent ef95cc947b59ff32f6bd62977c5da1692657376e started refactoring viewe + fix bug with corrupted properties diff -r ef95cc947b59 -r 7684ea24c330 src/catedit/config.py.tmpl --- a/src/catedit/config.py.tmpl Thu Apr 16 21:23:49 2015 +0200 +++ b/src/catedit/config.py.tmpl Fri Apr 17 10:45:30 2015 +0200 @@ -39,6 +39,7 @@ """ CACHE_CONFIG = { "CACHE_TYPE": "simple" + "CACHE_DEFAULT_TIMEOUT": 3600 } """ diff -r ef95cc947b59 -r 7684ea24c330 src/catedit/resources.py --- a/src/catedit/resources.py Thu Apr 16 21:23:49 2015 +0200 +++ b/src/catedit/resources.py Fri Apr 17 10:45:30 2015 +0200 @@ -149,9 +149,6 @@ new_property_list.append( (URIRef(get_property_list()[repository][predicate]["rdflib_class"]), app.config["CATEGORY_NAMESPACE"][obj]) ) - new_property_list.append( - (URIRef(get_property_list()[repository][predicate]["rdflib_class"]), URIRef(obj)) - ) else: new_property_list.append( (URIRef(get_property_list()[repository][predicate]["rdflib_class"]), Literal(obj)) diff -r ef95cc947b59 -r 7684ea24c330 src/catedit/templates/categories/submit.html --- a/src/catedit/templates/categories/submit.html Thu Apr 16 21:23:49 2015 +0200 +++ b/src/catedit/templates/categories/submit.html Fri Apr 17 10:45:30 2015 +0200 @@ -19,12 +19,12 @@ }); }); $(".cat-delete-toggle").click(function(evt){ - $("#delete_confirm_"+evt.target.id.split('_').slice(2,5).join('_')).slideToggle("fast"); + $("#delete_confirm_"+evt.redirect_target.id.split('_').slice(2,5).join('_')).slideToggle("fast"); }); $(".cat-info-toggle").click(function(evt){ - $("#properties_"+evt.target.id.split('_').slice(2,5).join('_')).slideToggle(function(){ - $("#info_button_"+evt.target.id.split('_').slice(2,5).join('_')).children().toggleClass("glyphicon-plus-sign"); - $("#info_button_"+evt.target.id.split('_').slice(2,5).join('_')).children().toggleClass("glyphicon-minus-sign"); + $("#properties_"+evt.redirect_target.id.split('_').slice(2,5).join('_')).slideToggle(function(){ + $("#info_button_"+evt.redirect_target.id.split('_').slice(2,5).join('_')).children().toggleClass("glyphicon-plus-sign"); + $("#info_button_"+evt.redirect_target.id.split('_').slice(2,5).join('_')).children().toggleClass("glyphicon-minus-sign"); }); }); }); @@ -46,7 +46,7 @@

CatEdit - {{current_repository}}

Soumettre mes changements

-
+
{{ commit_form.hidden_tag() }}
@@ -87,7 +87,7 @@ {% else %} {% import "macros.html" as macros %} - {{ macros.category_table(cat_list, current_repository, state_list=["created"], target="categories.submit", buttons_id="created") }} + {{ macros.category_table(cat_list, current_repository, state_list=["created"], redirect_target="submit", buttons_id="created") }} {% endif %} @@ -100,7 +100,7 @@ {% else %} {% import "macros.html" as macros %} - {{ macros.category_table(cat_list, current_repository, state_list=["modified"], target="categories.submit", buttons_id="modified") }} + {{ macros.category_table(cat_list, current_repository, state_list=["modified"], redirect_target="submit", buttons_id="modified") }} {% endif %} @@ -114,7 +114,7 @@ {% else %} {% import "macros.html" as macros %} - {{ macros.category_table(cat_list, current_repository, state_list=["deleted"], target="categories.submit", buttons_id="deleted") }} + {{ macros.category_table(cat_list, current_repository, state_list=["deleted"], redirect_target="submit", buttons_id="deleted") }} {% endif %} {% endif %} diff -r ef95cc947b59 -r 7684ea24c330 src/catedit/templates/categories/workshop.html --- a/src/catedit/templates/categories/workshop.html Thu Apr 16 21:23:49 2015 +0200 +++ b/src/catedit/templates/categories/workshop.html Fri Apr 17 10:45:30 2015 +0200 @@ -113,7 +113,7 @@ {% else %} {% import "macros.html" as macros %} - {{ macros.category_table(cat_list, current_repository, target="categories.workshop") }} + {{ macros.category_table(cat_list, current_repository, redirect_target="workshop") }} {% endif %} {% endif %} diff -r ef95cc947b59 -r 7684ea24c330 src/catedit/templates/macros.html --- a/src/catedit/templates/macros.html Thu Apr 16 21:23:49 2015 +0200 +++ b/src/catedit/templates/macros.html Fri Apr 17 10:45:30 2015 +0200 @@ -1,4 +1,4 @@ -{% macro category_table(cat_list, current_repository, state_list=["mixed"], target="", interactive=True, with_colors=True, buttons_id="") -%} +{% macro category_table(cat_list, current_repository, state_list=["mixed"], redirect_target="categories.workshop", interactive=True, with_colors=True, buttons_id="") -%} {% for cat in cat_list %} {% if state_list == ["mixed"] or (cat.state in state_list) %} {% else %} - + @@ -95,9 +95,9 @@
diff -r ef95cc947b59 -r 7684ea24c330 src/catedit/views/categories.py --- a/src/catedit/views/categories.py Thu Apr 16 21:23:49 2015 +0200 +++ b/src/catedit/views/categories.py Fri Apr 17 10:45:30 2015 +0200 @@ -12,7 +12,7 @@ from catedit.utils import get_property_list from io import StringIO -from flask import render_template, request, redirect, url_for, abort, Blueprint, session +from flask import render_template, request, redirect, url_for, abort, Blueprint from rdflib import Graph from catedit.views.forms import CommitForm, CategoryForm @@ -23,91 +23,82 @@ @module.route( - '//workshop', - defaults={'deleted_cat_id': None, 'deleted_changes_id': None}, - methods=['GET', 'POST'] + '//workshop', methods=['GET'] ) -@module.route( - '//workshop/delete-modifs-', - defaults={'deleted_cat_id': None}, - methods=['POST'] -) -@module.route( - '//workshop/delete-', - defaults={'deleted_changes_id': None}, - methods=['POST'] -) -def workshop(repository, deleted_cat_id, deleted_changes_id): +def workshop(repository): """ View that has a list of all categories available. Template is categories/workshop.html, located in src/templates/ + """ + if repository not in app.config["PERSISTENCE_CONFIG"]["REPOSITORY_LIST"]: + abort(404) - Note: it also handles category deletion from the same page. + check_user_status_and_repo_access(repository) + + cat_list = get_current_category_list(repository=repository) + cat_list = sorted(cat_list, key=lambda cat: cat['cat_id']) + changeset_list = get_commits(repository, 5, 1)[0] + discussion_list = get_issues(repository, 5, 1)[0] + return render_template( + 'categories/workshop.html', + cat_list=cat_list, + changeset_list=changeset_list, + discussion_list=discussion_list, + current_repository=repository + ) + + +@module.route( + '//delete-modifs-&redirect_to=', + methods=['POST'] +) +def delete_changes(repository, deleted_changes_id, redirect_to): + """ + View that handles deleting changes for a given repo. If no deleted_changes_id is + given, it will delete every change """ if repository not in app.config["PERSISTENCE_CONFIG"]["REPOSITORY_LIST"]: abort(404) check_user_status_and_repo_access(repository) - - cat_api_instance = CategoryAPI() + cat_changes_api_instance = CategoryChangesAPI() - - if request.method == "POST": - if deleted_changes_id is None and deleted_cat_id is None: - cat_changes_api_instance.delete(repository=repository) - elif deleted_changes_id is not None: - cat_changes_api_instance.delete( - repository=repository, - modified_cat_id=deleted_changes_id - ) - # We identify if we want to delete a category - elif deleted_cat_id is not None: - cat_api_instance.delete( - repository=repository, - deleted_cat_id=deleted_cat_id - ) - return redirect(url_for('categories.workshop', repository=repository)) - elif request.method == "GET": + if deleted_changes_id is None: + cat_changes_api_instance.delete(repository=repository) + else: + cat_changes_api_instance.delete( + repository=repository, + modified_cat_id=deleted_changes_id + ) + return redirect(url_for('categories.'+redirect_to, repository=repository)) - cat_list = get_current_category_list(repository=repository) - # logger.debug(c.properties) - cat_list = sorted(cat_list, key=lambda cat: cat['cat_id']) - changeset_list = get_commits( - repository, - 5, - 1 - )[0] - discussion_list = get_issues( - repository, - 5, - 1 - )[0] - #logger.debug(repr(cat_list)) - return render_template( - 'categories/workshop.html', - cat_list=cat_list, - changeset_list=changeset_list, - discussion_list=discussion_list, - current_repository=repository - ) - @module.route( - '//submit/delete-changes-', - defaults={'deleted_cat_id': None}, + '//delete-&redirect_to=', methods=['POST'] ) -@module.route( - '//submit/delete-', - defaults={'deleted_changes_id': None}, - methods=['POST'] -) +def delete_category(repository, deleted_cat_id, redirect_to): + """ + View that handles deleting a given category for a given repo + """ + if repository not in app.config["PERSISTENCE_CONFIG"]["REPOSITORY_LIST"]: + abort(404) + + check_user_status_and_repo_access(repository) + + cat_api_instance = CategoryAPI() + if deleted_cat_id is not None: + cat_api_instance.delete( + repository=repository, + deleted_cat_id=deleted_cat_id + ) + return redirect(url_for('categories.'+redirect_to, repository=repository)) + + @module.route( - '//submit', - defaults={'deleted_cat_id': None, 'deleted_changes_id': None}, - methods=['GET', 'POST'] + '//submit', methods=['GET'] ) -def submit(repository, deleted_cat_id, deleted_changes_id): +def submit(repository): """ View that handles all the visualisation of changes for a user's session, links to the editor forms, allows the users to cancel their @@ -120,76 +111,61 @@ check_user_status_and_repo_access(repository) + commit_form = CommitForm(request.form) + + cat_list = get_current_category_list(repository=repository) + original_cat_list = get_current_category_list( + repository=repository, + with_local_changes=False + ) + + created_cat_count = len([ + created_cat for created_cat in cat_list + if created_cat["state"] == "created" + ]) + edited_cat_count = len([ + edited_cat for edited_cat in cat_list + if edited_cat["state"] == "modified" + ]) + deleted_cat_count = len([ + deleted_cat for deleted_cat in cat_list + if deleted_cat["state"] == "deleted" + ]) + + return render_template('categories/submit.html', + cat_list=cat_list, + original_cat_list=original_cat_list, + original_cat_count=len(original_cat_list), + created_cat_count=created_cat_count, + edited_cat_count=edited_cat_count, + deleted_cat_count=deleted_cat_count, + commit_form=commit_form, + current_repository=repository) + + +@module.route( + '//push_changes', methods=['POST'] +) +def push_changes(repository): + """ + View that handles POST from the submit page + """ + if repository not in app.config["PERSISTENCE_CONFIG"]["REPOSITORY_LIST"]: + abort(404) + + check_user_status_and_repo_access(repository) + cat_api_instance = CategoryAPI() cat_changes_api_instance = CategoryChangesAPI() - - if deleted_cat_id is None and deleted_changes_id is None: - - commit_form = CommitForm(request.form) - - # If it's a POST with no delete_cat_id and delete_modifs_id, then we - # will submit all the stored changes - if request.method == "POST": - if commit_form.validate_on_submit(): - cat_api_instance.put(repository=repository, message=commit_form.commit_message.data) - cat_changes_api_instance.delete(repository=repository) - return redirect(url_for('categories.workshop', repository=repository)) - - # if it's a GET with no delete_cat_id or deleted_changes_id, then we'll - # display the changes - elif request.method == "GET": - cat_list = get_current_category_list(repository=repository) - original_cat_list = get_current_category_list( - repository=repository, - with_local_changes=False - ) - - created_cat_count = len([ - created_cat for created_cat in cat_list - if created_cat["state"] == "created" - ]) - edited_cat_count = len([ - edited_cat for edited_cat in cat_list - if edited_cat["state"] == "modified" - ]) - deleted_cat_count = len([ - deleted_cat for deleted_cat in cat_list - if deleted_cat["state"] == "deleted" - ]) - - return render_template('categories/submit.html', - cat_list=cat_list, - original_cat_list=original_cat_list, - original_cat_count=len(original_cat_list), - created_cat_count=created_cat_count, - edited_cat_count=edited_cat_count, - deleted_cat_count=deleted_cat_count, - commit_form=commit_form, - current_repository=repository) - - # One of the ids is not None (either deleting a category or a modification) + + commit_form = CommitForm(request.form) + + if commit_form.validate_on_submit(): + cat_api_instance.put(repository=repository, message=commit_form.commit_message.data) + cat_changes_api_instance.delete(repository=repository) + return redirect(url_for('categories.workshop', repository=repository)) else: - # We only do that if we have a POST - if request.method == "POST": - # We identify if we want to delete a change - if deleted_changes_id is not None: - cat_changes_api_instance.delete( - repository=repository, - modified_cat_id=deleted_changes_id - ) - # We identify if we want to delete a category - elif deleted_cat_id is not None: - cat_api_instance.delete( - repository=repository, - deleted_cat_id=deleted_cat_id - ) - return redirect( - url_for('categories.submit', repository=repository) - ) - else: - return redirect( - url_for('home.index') - ) + return redirect(url_for('categories.submit', repository=repository)) @module.route('//editor', @@ -304,14 +280,19 @@ cat_form.label.data = current_cat.label cat_form.description.data = current_cat.description for (cat_predicate, cat_object) in current_cat_properties: - if get_property_list()[repository][cat_predicate.toPython()]["object_type"] == "uriref-category": - namespace, object_id = cat_object.split("#", 1) + can_append = True + if get_property_list()[repository][cat_predicate.toPython()]["object_type"] == "uriref-category": + if "#" in cat_object: + namespace, object_id = cat_object.split("#", 1) + else: + can_append = False else: object_id = cat_object - cat_form.properties.append_entry({ - "property_predicate": cat_predicate.toPython(), - "property_object": object_id - }) + if can_append: + cat_form.properties.append_entry({ + "property_predicate": cat_predicate.toPython(), + "property_object": object_id + }) # list of category that will be used in property editor, list of dict # {"cat_id": cat.cat_id, # "cat_label": cat.label, @@ -339,7 +320,6 @@ cat_property["property_object"]) for cat_property in cat_form.properties.data ] - if cat_id is not None: #TODO: vérifier encoding - logger.debug(str(cat_data)) cat_api_instance.put( diff -r ef95cc947b59 -r 7684ea24c330 src/catedit/views/forms.py --- a/src/catedit/views/forms.py Thu Apr 16 21:23:49 2015 +0200 +++ b/src/catedit/views/forms.py Fri Apr 17 10:45:30 2015 +0200 @@ -5,7 +5,7 @@ from flask_wtf import Form from wtforms import StringField, TextAreaField, FormField, \ FieldList, HiddenField -from wtforms.validators import DataRequired, Optional, AnyOf +from wtforms.validators import DataRequired, Optional class CommitForm(Form):