Interface improvements: homepage, workshop, submitpage + it is now possible to edit changes + added CategoryChangesAPI
--- a/src/catedit/api.py Wed Dec 31 15:28:40 2014 +0100
+++ b/src/catedit/api.py Fri Jan 02 10:56:43 2015 +0100
@@ -74,8 +74,6 @@
modified_cat_list = session.get("modified_categories", []),
message=args["commit_message"]
)
- session["deleted_categories"] = []
- session["modified_categories"] = []
else:
new_property_list = []
logger.debug(args["property_predicate"])
@@ -98,7 +96,21 @@
new_property_list.append((property_predicate,
property_object_to_append))
logger.debug(new_property_list)
- cat = cat_manager_instance.load_category(cat_id)
+
+ # is the edition occuring on an already modified category?
+ if cat_id in [category["name"] for category
+ in session.get("modified_categories", [])]:
+ for element in session.get("modified_categories", []):
+ if element["name"] == cat_id:
+ cat_graph = Graph()
+ cat_graph.parse(
+ source=StringIO(element["content"]),
+ format="turtle"
+ )
+ cat = Category(graph=cat_graph)
+ else:
+ cat = cat_manager_instance.load_category(cat_id)
+
cat.edit_category(new_description=args["description"],
new_label=args["label"],
new_other_properties=new_property_list)
@@ -169,7 +181,8 @@
@classmethod
def delete(cls, deleted_cat_id):
"""
- API to delete the category of id cat_id from the deletion list
+ API to delete the category of id cat_id or restore it from the
+ deletion list
"""
args = cat_parser.parse_args()
if (deleted_cat_id in [
@@ -198,12 +211,15 @@
logger.debug(session["modified_categories"])
element_list = list(session.get("modified_categories", []))
if deleted_cat_id in [element["name"] for
- element in session.get("deleted_categories", [])]:
+ element in session.get("deleted_categories",
+ [])]:
for element in element_list:
logger.debug(str(element))
modified_cat_graph = Graph()
- modified_cat_graph.parse(source=StringIO(element["content"]),
- format="turtle")
+ modified_cat_graph.parse(
+ source=StringIO(element["content"]),
+ format="turtle"
+ )
modified_cat = Category(graph=modified_cat_graph)
if (modified_cat.cat_id !=
app.config["CATEGORY_NAMESPACE"] + deleted_cat_id):
@@ -283,7 +299,52 @@
cache.clear()
return 204
+class CategoryChangesAPI(Resource):
+ """
+ API for getting and deleting category changes, returns a dict when
+ succesful if category is a modified one, returns only the cat_id if it
+ is a deleted one
+
+ All changes and deletions are saved in session["modified_categories"]
+ and session["deleted_categories"]
+ """
+ @classmethod
+ def get(cls, modified_cat_id=None):
+ """
+ API to get the pending changes for category cat_id
+ """
+ logger.debug(modified_cat_id)
+ logger.debug(session.get("modified_categories", []))
+ if modified_cat_id is None:
+ return {
+ "modified_categories": session.get("modified_categories", []),
+ "deleted_categories": session.get("deleted_categories", [])
+ }, 201
+ else:
+ for category in session.get("modified_categories", []):
+ logger.debug(category)
+ if category["name"] == modified_cat_id:
+ return { "type": "modified", "category": category }, 201
+ for category in session.get("deleted_categories", []):
+ logger.debug(category)
+ if category["name"] == modified_cat_id:
+ return { "type": "deleted", "category": category }, 201
+ return 404
+
+ def delete(cls, cat_id=None):
+ """
+ API to delete the category cat_id from the changelist or if cat_id
+ is None, delete the whole changelist
+ """
+ session["modified_categories"] = []
+ session["deleted_categories"] = []
+ return 204
+
api.add_resource(CategoryAPI,
'/category/<string:cat_id>',
'/category',
endpoint='category')
+api.add_resource(CategoryChangesAPI,
+ '/category-changes/<string:cat_id>',
+ '/category-changes',
+ endpoint='category_changes')
--- a/src/catedit/static/css/style.css Wed Dec 31 15:28:40 2014 +0100
+++ b/src/catedit/static/css/style.css Fri Jan 02 10:56:43 2015 +0100
@@ -19,3 +19,8 @@
{
padding:8px;
}
+
+.form-button
+{
+ display: inline;
+}
--- a/src/catedit/templates/cateditor.html Wed Dec 31 15:28:40 2014 +0100
+++ b/src/catedit/templates/cateditor.html Fri Jan 02 10:56:43 2015 +0100
@@ -9,7 +9,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Editeur de catégorie: {% if cat_id: %} Edition {% else %} Création {% endif %} </title>
+ <title>Editeur de catégorie</title>
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
</head>
@@ -17,7 +17,7 @@
<div class="navbar navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
- <a class="navbar-brand" href="{{ url_for('cat_recap') }}">
+ <a class="navbar-brand" href="{{ url_for('cat_index') }}">
<img alt="Brand" src="{{ url_for('static', filename='img/catedit_brand.png') }}" class="navbar-img" width="32" height="32">
</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
@@ -29,11 +29,9 @@
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
- <li><a href="#">Page d'accueil</a></li>
+ <li><a href="{{ url_for('cat_index') }}">Page d'accueil</a></li>
{% if session.get("user_logged", None) %}
- <li><a href="{{ url_for('cat_recap') }}">Vue d'ensemble</a></li>
- <li class="active"><a>{% if cat_id: %}Editer{% else %}Créer{% endif %} une catégorie</a></li>
- <li><a href="{{ url_for('cat_modifs') }}">Mes modifications</a></li>
+ <li><a href="{{ url_for('cat_recap') }}">Atelier</a></li>
{% endif %}
</ul>
<div class="navbar-text navbar-right">
@@ -80,7 +78,6 @@
{{ form.description.label }} <br> {{ form.description(size=150, class="form-control", readonly=readonly, placeholder=description_placeholder) }} <br>
<label>Propriétés </label>
<div class="form-inline">
- <input type="button" value="Ajouter propriété" onClick="CatEditScripts.addProperty('properties','property_table_body');" class="btn btn-default" {{ readonly }}>
<select id="property_selector" class="form-control" onChange="CatEditScripts.displayCorrespondingField();" {{readonly}}>
<option label="property_type_default" selected>
Liste des propriétés ...
@@ -97,10 +94,9 @@
<option value="{{ cat.cat_id }}"> {{ cat.cat_label }} </option>
{% endfor %}
</select>
- <div class="alert alert-warning hidden" role="alert" id="uriref-category-field-text">
- <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
- Les catégories actuellement en suppression (voir onglet "Mes modifications") ne sont pas référençables
- </div>
+ <input type="button" value="Ajouter propriété" onClick="CatEditScripts.addProperty('properties','property_table_body');" class="btn btn-default" {{ readonly }}>
+ </div>
+ <div class="alert alert-warning hidden" role="alert" id="uriref-category-field-text">
</div>
<div id="properties" class="row hidden">
<div class="row">
@@ -155,6 +151,7 @@
</div>
</div><br>
<br><input type="submit" value="Sauvegarder" class="btn btn-default">
+ <a href="{{ url_for('cat_recap')}}"class="btn btn-default">Annuler</a>
</form>
{% if readonly %} </fieldset> {% endif %}
<script src="{{ url_for('static', filename='js/property_functions.js') }}" language="Javascript" type="text/javascript"></script>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/catedit/templates/catindex.html Fri Jan 02 10:56:43 2015 +0100
@@ -0,0 +1,110 @@
+{% if not session["user_logged"] or not session["user_can_edit"] %}
+ {% set readonly="readonly" %}
+{% else %}
+ {% set readonly=False %}
+{% endif %}
+<!DOCTYPE html>
+<html lang="fr">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>Page d'accueil</title>
+ <link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
+ <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
+ <script src="{{ url_for('static', filename='js/jquery-1.11.1.min.js') }}" language="Javascript" type="text/javascript"></script>
+ <script>
+ $(document).ready(function(){
+ {% for cat in cat_list %}
+ $("#properties_{{cat.cat_id}}").hide();
+ $("#info_button_{{cat.cat_id}}").click(function(){
+ $("#properties_{{cat.cat_id}}").slideToggle();
+ });
+ {% endfor %}
+ });
+ </script>
+ </head>
+ <body>
+ <div class="navbar navbar-inverse" role="navigation">
+ <div class="container">
+ <div class="navbar-header">
+ <a class="navbar-brand" href="{{ url_for('cat_index') }}">
+ <img alt="Brand" src="{{ url_for('static', filename='img/catedit_brand.png') }}" class="navbar-img" width="32" height="32">
+ </a>
+ <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
+ <span class="sr-only">Toggle navigation</span>
+ <span class="icon-bar"></span>
+ </button>
+ </div>
+ <div class="collapse navbar-collapse">
+ <ul class="nav navbar-nav">
+ <li class="active"><a>Page d'accueil</a></li>
+ {% if session.get("user_logged", None) %}
+ <li><a href="{{url_for('cat_recap')}}">Atelier</a></li>
+ {% endif %}
+ </ul>
+ <div class="navbar-text navbar-right">
+ {% if not session.get("user_logged", None)%}Non authentifié - <a href="{{ url_for('github_login') }}" class="navbar-link">S'authentifier</a>
+ {% else %} Authentifié: {{ session["user_login"] }} - <a href="{{ url_for('logout') }}" class="navbar-link">Quitter</a>{% endif %}
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="container">
+ <h2> <b>CatEdit</b>: Editeur de Catégories</h2>
+ <h3> Mode d'emploi </h3>
+ <div class="col-md-8">
+ <p>
+ CatEdit est un outil permettant de créer et d'éditer des catégories.
+ Vous aurez besoin d'un compte Github pour utiliser CatEdit:
+ <a href="https://github.com/">s'inscrire sur Github</a>
+ </p>
+ <p>
+ Une fois authentifié, l'édition se fait en utilisant l'onglet Atelier.
+ Vous pourrez y trouver la liste des catégories existantes (pour l'instant,
+ l'outil ne porte que sur un unique ensemble de catégories) présentée dans
+ un tableau qui initialement ne comprend que les catégories de l'état courant.
+ </p>
+ <p>
+ L'état courant de l'ensemble de catégorie est la base à partir de laquelle
+ vous pourrez créer et éditer des catégories. Une catégorie consiste en un label, unique
+ et non-vide, une description, unique et non-vide et un nombre variable de propriétés.
+ </p>
+ <h4><b>La liste de catégories</b></h4>
+ <p>
+ A chaque fois que vous faites des modifications, elles sont stockées
+ de manière temporaire tant que vous restez authentifié. La liste de catégories
+ dans l'Atelier est mise à jour au fil de vos modifications selon un code couleur
+ vous permettant de visualiser vos changements.
+ </p>
+ <ul>
+ <li>
+ Une ligne de tableau <b>blanche</b> représente une catégorie de l'état courant
+ que vous n'avez ni modifié ni supprimé.
+ </li>
+ <li>
+ Une ligne de tableau <b class="text-success">verte</b> représente une catégorie que vous avez créée de zéro
+ et qui n'existait pas précédemment dans l'état courant.
+ </li>
+ <li>
+ Une ligne de tableau <b class="text-warning">orange</b> représente une catégorie qui existait
+ initialement et que vous avez modifié.
+ </li>
+ <li>
+ Une ligne de tableau <b class="text-danger">rouge</b> représente une catégorie de l'état courant que
+ vous avez supprimé.
+ </li>
+ </ul>
+ </p>
+ <p>
+ Pour que vos modifications soient permanentes et qu'elles deviennent le nouvel état courant
+ de l'ensemble de catégories, vous devez soumettre vos modifications en suivant le lien dans l'Atelier.
+ Vous trouverez une page vous présentant l'état initial d'une part et vos changements d'autre part.
+ </p>
+ <p>
+ Vous devez obligatoirement renseigner une explication de vos changements avant soumission.
+ </p>
+ </div>
+ </div>
+ </body>
+</html>
--- a/src/catedit/templates/catmodifs.html Wed Dec 31 15:28:40 2014 +0100
+++ b/src/catedit/templates/catmodifs.html Fri Jan 02 10:56:43 2015 +0100
@@ -9,7 +9,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Mes modifications</title>
+ <title>Soumettre mes changements</title>
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
<script src="{{ url_for('static', filename='js/jquery-1.11.1.min.js') }}" language="Javascript" type="text/javascript"></script>
@@ -20,10 +20,6 @@
$("#info_button_{{cat.cat_id}}").click(function(){
$("#properties_{{cat.cat_id}}").slideToggle();
});
- $("#delete_cat_{{cat.cat_id}}").hide();
- $("#delete_button_{{cat.cat_id}}").click(function(){
- $("#delete_cat_{{cat.cat_id}}").slideToggle();
- });
{% endfor %}
{% for cat in modified_cat_list %}
$("#properties_modified_{{cat.cat_id}}").hide();
@@ -52,7 +48,7 @@
<div class="navbar navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
- <a class="navbar-brand" href="{{ url_for('cat_recap') }}">
+ <a class="navbar-brand" href="{{ url_for('cat_index') }}">
<img alt="Brand" src="{{ url_for('static', filename='img/catedit_brand.png') }}" class="navbar-img" width="32" height="32">
</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
@@ -64,11 +60,9 @@
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
- <li><a href="#">Page d'accueil</a></li>
+ <li><a href="{{ url_for('cat_index') }}">Page d'accueil</a></li>
{% if session.get("user_logged", None) %}
- <li><a href="{{ url_for('cat_recap') }}">Vue d'ensemble</a></li>
- <li><a href="{{ url_for('cat_editor') }}">Créer une catégorie</a></li>
- <li class="active"><a>Mes modifications</a></li>
+ <li><a href="{{ url_for('cat_recap') }}">Atelier</a></li>
{% endif %}
</ul>
<div class="navbar-text navbar-right">
@@ -79,19 +73,19 @@
</div>
</div>
<div class="container">
- <h2> Créer une catégorie <a href="{{url_for('cat_editor')}}" class="btn btn-default {% if readonly %}disabled{% endif %}"><span class="glyphicon glyphicon-plus"/></a></h2>
- <h2> Editer ou supprimer une catégorie </h2>
+ <h2> <b>CatEdit</b> - <small>{{config.get("REPOSITORY_NAME", "Titre-Ensemble-Catégories")}} </small></h2>
+ <h3> Catégories existantes </h3>
<table class="table table-bordered table-condensed">
<thead>
<tr class="active">
<th class="col-md-2"><b>Nom de la catégorie</b></th>
- <th class="col-md-10" colspan="2"><b>Description de la catégorie</b></th>
+ <th class="col-md-10"><b>Description de la catégorie</b></th>
</tr>
</thead>
<tbody>
{% if not session["user_logged"] %}
<tr>
- <td class="col-md-12" colspan="3">
+ <td class="col-md-12" colspan="2">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Attention:</span>
Veuillez vous identifier pour visualiser les catégories
@@ -100,23 +94,38 @@
{% else %}
{% if cat_list|length == 0 %}
<tr>
- <td class="col-md-12" colspan="3">Aucune catégorie n'a été créée pour l'instant. {% if not readonly %}<a href="{{ url_for('cat_editor') }}">Créer une catégorie</a>{% endif %}</td>
+ <td class="col-md-12" colspan="2">Aucune catégorie n'a été créée pour l'instant. {% if not readonly %}<a href="{{ url_for('cat_editor') }}">Créer une catégorie</a>{% endif %}</td>
</tr>
{% else %}
{% for cat in cat_list %}
<tr>
<td class="col-md-2">{{ cat.cat_label }}</td>
<td class="col-md-8">{{ cat.cat_description}}</td>
- <td class="col-md-2 text-center">
- <button class="btn btn-default" id="info_button_{{ cat.cat_id }}"><span class="glyphicon glyphicon glyphicon-plus-sign"/></button>
- {% if cat.cat_id not in deleted_cat_list %}
- <a href="{{ url_for('cat_editor', cat_id=cat.cat_id)}}" class="btn btn-default"><span class="glyphicon glyphicon glyphicon-pencil"/></a>
- <button class="btn btn-default" id="delete_button_{{cat.cat_id}}"><span class="glyphicon glyphicon-trash"/></a>
+ <td class="text-center">
+ <a title="Détails catégorie"><button class="btn btn-default" id="info_button_{{ cat.cat_id }}"><span class="glyphicon glyphicon glyphicon-plus-sign"/></button></a>
+ </td>
+ {% if cat.cat_id not in deleted_cat_namelist and cat.cat_id not in modified_cat_namelist %}
+ <td class="text-center">
+ <a href="{{ url_for('cat_editor', cat_id=cat.cat_id)}}" title="Editer catégorie" class="btn btn-default"><span class="glyphicon glyphicon glyphicon-pencil"/></a>
+ </td>
+ <td class="text-center">
+ <a title="Supprimer catégorie">
+ <form method="POST" action="{{ url_for('cat_modifs', deleted_cat_id=cat.cat_id) }}" class="form-inline form-button">
+ <fieldset {% if readonly %}disabled{% endif %}>
+ <button type="submit" class="btn btn-default">
+ <span class="glyphicon glyphicon-trash" title="Supprimer catégorie"/>
+ </button>
+ </fieldset>
+ </form>
+ </a>
+ </td>
+ {% else %}
+ <td colspan="2">
+ </td>
{% endif %}
- </td>
</tr>
<tr>
- <td colspan="3">
+ <td colspan="2">
<div id="properties_{{cat.cat_id}}">
<dl class="dl-horizontal">
{% if cat.cat_properties|length == 0 %} <dt></dt><dd>Aucune autre propriété</dd>
@@ -140,18 +149,6 @@
{% endif %}
</dl>
</div>
- <div id="delete_cat_{{cat.cat_id}}">
- <form method="POST" action="{{ url_for('cat_modifs', delete_cat_id=cat.cat_id) }}" class="form-inline align-center">
- <fieldset {% if readonly %}disabled{% endif %}>
- <div class="input-group">
- <div class="input-group-addon">
- Vous devrez soumettre les changements pour appliquer la suppression. Supprimer une catégorie édite automatiquement les autres catégories qui y font référence.
- </div>
- <input type="submit" class="btn btn-default" value="Supprimer">
- </div>
- </fieldset>
- </form>
- </div>
</td>
</tr>
{% endfor %}
@@ -160,7 +157,7 @@
</tbody>
</table>
- <h2> Mes modifications </h2>
+ <h3> Mes modifications </h3>
<table class="table table-bordered table-condensed">
<thead>
<tr class="active">
@@ -191,10 +188,11 @@
{% for cat in created_cat_list %}
<tr class="success">
<td class="col-md-2">{{ cat.cat_label }}</td>
- <td class="col-md-9">{{ cat.cat_description}}</td>
- <td class="col-md-1 text-center">
- <button class="btn btn-default" id="info_button_created_{{ cat.cat_id }}"><span class="glyphicon glyphicon-plus-sign"/></button>
- <button class="btn btn-default" id="remove_modifs_created_{{ cat.cat_id }}"><span class="glyphicon glyphicon-remove-sign"/></button>
+ <td class="col-md-8">{{ cat.cat_description}}</td>
+ <td class="col-md-2 text-center">
+ <a title="Détails catégorie"><button class="btn btn-default" id="info_button_created_{{ cat.cat_id }}"><span class="glyphicon glyphicon-plus-sign"/></button></a>
+ <a href="{{ url_for('cat_editor', cat_id=cat.cat_id)}}" title="Editer catégorie" class="btn btn-default"><span class="glyphicon glyphicon glyphicon-pencil"/></a>
+ <a title="Supprimer modifications"><button class="btn btn-default" id="remove_modifs_created_{{ cat.cat_id }}"><span class="glyphicon glyphicon-remove-sign"/></button></a>
</td>
</tr>
<tr class="success">
@@ -223,7 +221,7 @@
</dl>
</div>
<div id="delete_created_{{cat.cat_id}}">
- <form method="POST" action="{{ url_for('cat_modifs', delete_modifs_id=cat.cat_id) }}" class="form-inline align-center">
+ <form method="POST" action="{{ url_for('cat_modifs', deleted_modifs_id=cat.cat_id) }}" class="form-inline align-center">
<fieldset {% if readonly %}disabled{% endif %}>
<div class="input-group">
<div class="input-group-addon">
@@ -251,10 +249,11 @@
{% for cat in modified_cat_list %}
<tr class="warning">
<td class="col-md-2">{{ cat.cat_label }}</td>
- <td class="col-md-9">{{ cat.cat_description}}</td>
- <td class="col-md-1 text-center">
- <button class="btn btn-default" id="info_button_modified_{{ cat.cat_id }}"><span class="glyphicon glyphicon-plus-sign"/></button>
- <button class="btn btn-default" id="remove_modifs_modified_{{ cat.cat_id }}"><span class="glyphicon glyphicon-remove-sign"/></button>
+ <td class="col-md-8">{{ cat.cat_description}}</td>
+ <td class="col-md-2 text-center">
+ <a title="Détails catégorie"><button class="btn btn-default" id="info_button_modified_{{ cat.cat_id }}"><span class="glyphicon glyphicon-plus-sign"/></button></a>
+ <a href="{{ url_for('cat_editor', cat_id=cat.cat_id)}}" title="Editer catégorie" class="btn btn-default"><span class="glyphicon glyphicon glyphicon-pencil"/></a>
+ <a title="Supprimer modifications"><button class="btn btn-default" id="remove_modifs_modified_{{ cat.cat_id }}"><span class="glyphicon glyphicon-remove-sign"/></button></a>
</td>
</tr>
<tr class="warning">
@@ -283,7 +282,7 @@
</dl>
</div>
<div id="delete_modified_{{cat.cat_id}}">
- <form method="POST" action="{{ url_for('cat_modifs', delete_modifs_id=cat.cat_id) }}" class="form-inline align-center">
+ <form method="POST" action="{{ url_for('cat_modifs', deleted_modifs_id=cat.cat_id) }}" class="form-inline align-center">
<fieldset {% if readonly %}disabled{% endif %}>
<div class="input-group">
<div class="input-group-addon">
@@ -304,19 +303,19 @@
<b> Catégories supprimées</b>
</td>
</tr>
- {% if deleted_cat_list|length == 0 %}
+ {% if deleted_cat_namelist|length == 0 %}
<tr>
<td class="col-md-12" colspan="3">Aucune catégorie n'a été supprimée pour l'instant.</td>
</tr>
{% else %}
- {% for deleted_cat in deleted_cat_list %}
+ {% for deleted_cat in deleted_cat_namelist %}
{% for existing_cat in cat_list %}
{% if existing_cat.cat_id == deleted_cat %}
<tr class="danger">
<td class="col-md-2">{{ existing_cat.cat_label }}</td>
- <td class="col-md-9"><i>Cette catégorie va être supprimée quand vous soumettrez vos modifications.</i></td>
- <td class="col-md-1 text-center">
- <form method="POST" action="{{ url_for('cat_modifs', delete_cat_id=deleted_cat) }}">
+ <td class="col-md-8"><i>Cette catégorie va être supprimée quand vous soumettrez vos modifications.</i></td>
+ <td class="col-md-2 text-center">
+ <form method="POST" action="{{ url_for('cat_modifs', deleted_cat_id=deleted_cat) }}">
<fieldset {% if readonly %}disabled{% endif %}>
<input type="submit" class="btn btn-default" value="Restaurer">
</fieldset>
@@ -330,7 +329,7 @@
{% endif %}
</tbody>
</table>
- <h2> Soumettre mes changements </h2>
+ <h3> Soumettre mes changements </h3>
<div class="col-md-12">
<form method="POST" action="{{ url_for('cat_modifs')}}">
<fieldset {% if readonly %}disabled{% endif %}>
@@ -340,6 +339,7 @@
{{ commit_form.commit_message(size=40, class="form-control", readonly=readonly) }}
</div>
<button type="submit" class="btn btn-default">Soumettre modifications</button>
+ <a href="{{ url_for('cat_recap')}}"class="btn btn-default">Retour</a>
</fieldset>
</form><br>
</div>
--- a/src/catedit/templates/catrecap.html Wed Dec 31 15:28:40 2014 +0100
+++ b/src/catedit/templates/catrecap.html Fri Jan 02 10:56:43 2015 +0100
@@ -9,7 +9,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Vue d'ensemble</title>
+ <title>Atelier</title>
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
<script src="{{ url_for('static', filename='js/jquery-1.11.1.min.js') }}" language="Javascript" type="text/javascript"></script>
@@ -28,23 +28,19 @@
<div class="navbar navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
- <a class="navbar-brand" href="{{ url_for('cat_recap') }}">
+ <a class="navbar-brand" href="{{ url_for('cat_index') }}">
<img alt="Brand" src="{{ url_for('static', filename='img/catedit_brand.png') }}" class="navbar-img" width="32" height="32">
</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
- <li><a href="#">Page d'accueil</a></li>
+ <li><a href="{{ url_for('cat_index') }}">Page d'accueil</a></li>
{% if session.get("user_logged", None) %}
- <li class="active"><a>Vue d'ensemble</a></li>
- <li><a href="{{ url_for('cat_editor') }}">Créer une catégorie</a></li>
- <li><a href="{{ url_for('cat_modifs') }}">Mes modifications</a></li>
+ <li class="active"><a>Atelier</a></li>
{% endif %}
</ul>
<div class="navbar-text navbar-right">
@@ -55,6 +51,8 @@
</div>
</div>
<div class="container">
+ <h2> <b>CatEdit</b> - <small>{{config.get("REPOSITORY_NAME", "Titre-Ensemble-Catégories")}} </small></h2>
+ <h3> Créer une catégorie : <a href="{{url_for('cat_editor')}}" title="Créer catégorie" class="btn btn-default {% if readonly %}disabled{% endif %}"><span class="glyphicon glyphicon-plus"/></a></h3>
{% if session["user_logged"] and not session["user_can_edit"] %}
<div class="alert alert-warning" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
@@ -62,18 +60,18 @@
Vous n'avez pas accès en écriture au repository contenant les catégories - Vous ne pourrez pas les modifier.
</div>
{% endif %}
- <h2>Liste des catégories existantes</h2>
- <table class="table table-striped table-bordered table-condensed">
+ <h3>Mes catégories</h3>
+ <table class="table table-bordered table-condensed">
<thead>
- <tr>
+ <tr class="active">
<th class="col-md-2"><b>Nom de la catégorie</b></th>
- <th class="col-md-10" colspan="2"><b>Description de la catégorie</b></th>
+ <th class="col-md-10"><b>Description de la catégorie</b></th>
</tr>
</thead>
<tbody>
{% if not session["user_logged"] %}
<tr>
- <td class="col-md-12" colspan="3">
+ <td class="col-md-12" colspan="2">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Attention:</span>
Veuillez vous identifier pour visualiser les catégories
@@ -82,52 +80,111 @@
{% else %}
{% if cat_list|length == 0 %}
<tr>
- <td class="col-md-12" colspan="3">Aucune catégorie n'a été créée pour l'instant. {% if not readonly %}<a href="{{ url_for('cat_editor') }}">Créer une catégorie</a>{% endif %}</td>
+ <td class="col-md-12" colspan="2">Aucune catégorie n'a été créée pour l'instant. {% if not readonly %}<a href="{{ url_for('cat_editor') }}">Créer une catégorie</a>{% endif %}</td>
</tr>
{% else %}
{% for cat in cat_list %}
- <tr>
+ <tr
+ {% if cat.state == "created" %}
+ class="success"
+ {% elif cat.state == "modified" %}
+ class="warning"
+ {% elif cat.state == "deleted" %}
+ class="danger"
+ {% endif %}>
<td class="col-md-2">{{ cat.cat_label }}</td>
- <td class="col-md-9">{{ cat.cat_description}}</td>
+ <td class="col-md-8">{{ cat.cat_description}}</td>
+ <td class="col-md-1 text-center">
+ <a title="Détails catégorie">
+ <button class="btn btn-default" id="info_button_{{ cat.cat_id }}"><span class="glyphicon glyphicon-plus-sign"/></button>
+ </a>
+ </td>
+ {% if (cat.state != "deleted") %}
+ <td class="col-md-1 text-center">
+ <a href="{{ url_for('cat_editor', cat_id=cat.cat_id)}}" title="Editer catégorie" class="btn btn-default">
+ <span class="glyphicon glyphicon glyphicon-pencil"/>
+ </a>
+ </td>
+ {% endif %}
+ {% if (cat.state == "untouched") %}
+ <td class="col-md-1 text-center">
+ <form method="POST" action="{{url_for('cat_recap', deleted_cat_id=cat.cat_id)}}" class="form-inline">
+ <a title="Supprimer catégorie">
+ <button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-trash"/></button>
+ </a>
+ </form>
+ </td>
+ {% elif (cat.state == "created" or cat.state == "modified") %}
<td class="col-md-1 text-center">
- <button class="btn btn-default" id="info_button_{{ cat.cat_id }}"><span class="glyphicon glyphicon-plus-sign"/></button>
+ <form method="POST" action="{{url_for('cat_recap', deleted_modifs_id=cat.cat_id)}}" class="form-inline">
+ <a title="Supprimer changements">
+ <button class="btn btn-default"><span class="glyphicon glyphicon-remove-sign"/></button>
+ </a>
+ </form>
+ </td>
+ {% else %}
+ <td colspan="2">
+ <form method="POST" action="{{url_for('cat_recap', deleted_cat_id=cat.cat_id)}}" class="form-inline">
+ <a title="Restaurer catégorie">
+ <button class="btn btn-default" type="submit">Restaurer</button>
+ </a>
+ </form>
+ </td>
+ {% endif %}
+ </tr>
+ <tr
+ {% if cat.state == "created" %}
+ class="success"
+ {% elif cat.state == "modified" %}
+ class="warning"
+ {% elif cat.state == "deleted" %}
+ class="danger"
+ {% endif %}>
+ <td colspan="5">
+ <div id="properties_{{cat.cat_id}}">
+ <dl class="dl-horizontal">
+ {% if cat.cat_properties|length == 0 %} <dt></dt><dd>Aucune autre propriété</dd>
+ {% else %}
+ {% for (predicate, object) in cat.cat_properties %}
+ <dt>{{ config["PROPERTY_LIST"][predicate]["descriptive_label_fr"] }}</dt>
+ <dd>
+ {% if config["PROPERTY_LIST"][predicate]["object_type"]=="uriref-category" %}
+ {% for cat in cat_list %}
+ {% if object == config["CATEGORY_NAMESPACE"]+cat.cat_id %}
+ {{ cat.cat_label }}
+ {% endif %}
+ {% endfor %}
+ {% elif config["PROPERTY_LIST"][predicate]["object_type"]=="uriref-link" %}
+ <a href="{{ object }}">{{ object }}</a>
+ {% else %}
+ {{ object }}
+ {% endif %}
+ </dd>
+ {% endfor %}
+ {% endif %}
+ </dl>
+ </div>
</td>
</tr>
- <tr>
- <td colspan="3">
- <div id="properties_{{cat.cat_id}}">
- <dl class="dl-horizontal">
- {% if cat.cat_properties|length == 0 %} <dt></dt><dd>Aucune autre propriété</dd>
- {% else %}
- {% for (predicate, object) in cat.cat_properties %}
- <dt>{{ config["PROPERTY_LIST"][predicate]["descriptive_label_fr"] }}</dt>
- <dd>
- {% if config["PROPERTY_LIST"][predicate]["object_type"]=="uriref-category" %}
- {% for cat in cat_list %}
- {% if object == config["CATEGORY_NAMESPACE"]+cat.cat_id %}
- {{ cat.cat_label }}
- {% endif %}
- {% endfor %}
- {% elif config["PROPERTY_LIST"][predicate]["object_type"]=="uriref-link" %}
- <a href="{{ object }}">{{ object }}</a>
- {% else %}
- {{ object }}
- {% endif %}
- </dd>
- {% endfor %}
- {% endif %}
- </dl>
- </div>
- </td>
- </tr>
{% endfor %}
{% endif %}
{% endif %}
</tbody>
</table>
{% if session.get("user_logged") %}
- <h3> Consulter l'historique des modifications : <a href="https://github.com/{{config['REPOSITORY_OWNER']}}/{{config['REPOSITORY_NAME']}}/commits/master" class="btn btn-default"><span class="glyphicon glyphicon-list"/></a></h3>
+ <form method="POST" action="{{url_for('cat_recap')}}" class="form-inline">
+ <h4> Annuler tous mes changements actuels :
+ <a title="Supprimer changements">
+ <button type="submit" class="btn btn-default" {% if readonly %}disabled{% endif %}>
+ <span class="glyphicon glyphicon-remove"/>
+ </button>
+ </a>
+ </h4>
+ </form>
+ <h4> Soumettre mes changements actuels : <a href="{{ url_for('cat_modifs')}}" title="Soumettre changements" class="btn btn-default" {% if readonly %}disabled{% endif %}><span class="glyphicon glyphicon-share"/></a>
+ </h4>
{% endif %}
+ <h3> Consulter l'historique des modifications : <a href="https://github.com/{{config['REPOSITORY_OWNER']}}/{{config['REPOSITORY_NAME']}}/commits/master" title="Aller à l'historique des modifications sur Github" class="btn btn-default"><span class="glyphicon glyphicon-list"/></a></h3>
</div>
</body>
</html>
--- a/src/catedit/views.py Wed Dec 31 15:28:40 2014 +0100
+++ b/src/catedit/views.py Fri Jan 02 10:56:43 2015 +0100
@@ -9,7 +9,7 @@
from flask import render_template, request, redirect, url_for, session
from flask.ext.github import GitHubError
from flask_wtf import Form
-from catedit.api import CategoryAPI
+from catedit.api import CategoryAPI, CategoryChangesAPI
from wtforms import StringField, TextAreaField
from wtforms.validators import DataRequired
from rdflib import Graph
@@ -44,8 +44,21 @@
@app.route('/', methods=['GET'])
-@app.route('/catrecap', methods=['GET'])
-def cat_recap():
+@app.route('/index', methods=['GER'])
+def cat_index():
+ return render_template("catindex.html")
+
+
+@app.route('/catrecap/delete-modifs-<deleted_modifs_id>',
+ defaults={'deleted_cat_id': None},
+ methods=['POST'])
+@app.route('/catrecap/delete-<deleted_cat_id>',
+ defaults={'deleted_modifs_id': None},
+ methods=['POST'])
+@app.route('/catrecap',
+ defaults={'deleted_cat_id': None, 'deleted_modifs_id': None},
+ methods=['GET', 'POST'])
+def cat_recap(deleted_cat_id, deleted_modifs_id):
"""
View that has a list of all categories available. Template is
catrecap.html, located in src/templates/
@@ -53,24 +66,191 @@
Note: it also handles category deletion from the same page.
"""
cat_api_instance = CategoryAPI()
- serialized_cat_list = []
- if session.get("user_logged", None) is not None:
- serialized_cat_list = cat_api_instance.get()
- # logger.debug(serialized_cat_list)
+ cat_changes_api_instance = CategoryChangesAPI()
+
+ if request.method == "POST":
+ if (session.get("user_logged", None) is not None and
+ session.get("user_can_edit", False) is not False):
+ if (deleted_modifs_id is None and deleted_cat_id is None):
+ cat_changes_api_instance.delete()
+ elif deleted_modifs_id is not None:
+ logger.debug("Changes for category "
+ + deleted_modifs_id
+ + " will be deleted.")
+ cat_changes_api_instance.delete(deleted_modifs_id)
+ # We identify if we want to delete a category
+ elif deleted_cat_id is not None:
+ logger.debug("Category "
+ + deleted_cat_id
+ + " will be deleted.")
+ cat_api_instance.delete(deleted_cat_id)
+ return redirect(url_for('cat_recap'))
+ elif request.method == "GET":
+
+ deleted_cat_list = []
+ modified_cat_list = []
+ serialized_cat_list = []
+ if session.get("user_logged", None) is not None:
+ serialized_cat_list = cat_api_instance.get()
+ cat_changes = cat_changes_api_instance.get()[0]
+ modified_cat_list = cat_changes["modified_categories"]
+ logger.debug(modified_cat_list)
+ deleted_cat_list = cat_changes["deleted_categories"]
+ logger.debug(deleted_cat_list)
+ # logger.debug(serialized_cat_list)
+ cat_list = []
+
+ # first we find the untouched, edited and deleted categories
+ for serialized_cat in serialized_cat_list:
+ cat_rdf_graph = Graph()
+ cat_rdf_graph.parse(source=StringIO(serialized_cat),
+ format='turtle')
+ cat = Category(graph=cat_rdf_graph)
+
+ logger.debug(str([cat["name"] for cat in modified_cat_list]))
+ logger.debug(str([cat["name"] for cat in deleted_cat_list]))
+
+ if cat.cat_id in [cat["name"] for cat in modified_cat_list]:
+ cat_state = "modified"
+ elif cat.cat_id in [cat["name"] for cat in deleted_cat_list]:
+ cat_state = "deleted"
+ else:
+ cat_state = "untouched"
+
+ cat_list.append({"cat_label": cat.label,
+ "cat_description": cat.description,
+ "cat_id": cat.cat_id,
+ "cat_properties": cat.properties,
+ "state": cat_state})
+
+ # now we must find the not yet submitted categories that were created
+ for modified_cat in modified_cat_list:
+ if modified_cat["name"] not in [cat["cat_id"] for cat in cat_list]:
+ new_cat_rdf_graph = Graph()
+ new_cat_rdf_graph.parse(source=StringIO(
+ modified_cat["content"]
+ ),
+ format='turtle')
+ new_cat = Category(graph=new_cat_rdf_graph)
+ cat_list.append({"cat_label": new_cat.label,
+ "cat_description": new_cat.description,
+ "cat_id": new_cat.cat_id,
+ "cat_properties": new_cat.properties,
+ "state": "created"})
+
+ # logger.debug(c.properties)
+ return render_template('catrecap.html',
+ cat_list=cat_list)
+
+@app.route('/catmodifs/delete-modifs-<deleted_modifs_id>',
+ defaults={'deleted_cat_id': None},
+ methods=['POST'])
+@app.route('/catmodifs/delete-<deleted_cat_id>',
+ defaults={'deleted_modifs_id': None},
+ methods=['POST'])
+@app.route('/catmodifs',
+ defaults={'deleted_cat_id': None, 'deleted_modifs_id': None},
+ methods=['GET', 'POST'])
+def cat_modifs(deleted_cat_id, deleted_modifs_id):
+ """
+ View that handles all the visualisation of changes for a user's
+ session, links to the editor forms, allows the users to cancel their
+ own changes and submits all their changes.
+ """
cat_list = []
- for serialized_cat in serialized_cat_list:
- cat_rdf_graph = Graph()
- cat_rdf_graph.parse(source=StringIO(serialized_cat),
- format='turtle')
- cat = Category(graph=cat_rdf_graph)
+ modified_cat_list = []
+ created_cat_list = []
+ deleted_cat_namelist = []
+ modified_cat_namelist = []
+
+ cat_api_instance = CategoryAPI()
+ cat_changes_api_instance = CategoryChangesAPI()
+
+ if deleted_cat_id is None and deleted_modifs_id is None:
+ commit_form = CommitForm(request.form)
+
+ # if it's a GET with no delete_cat_id or deleted_modifs_id, then we'll
+ # display the changes
+ if request.method == "GET":
+ if session.get("user_logged", None) is not None:
+ serialized_cat_list = cat_api_instance.get()
+ changes_list = cat_changes_api_instance.get()[0]
+
+ # Creating existing cat list
+ for serialized_cat in serialized_cat_list:
+ cat_rdf_graph = Graph()
+ cat_rdf_graph.parse(source=StringIO(serialized_cat),
+ format='turtle')
+ cat = Category(graph=cat_rdf_graph)
+
+ cat_list.append({"cat_label": cat.label,
+ "cat_description": cat.description,
+ "cat_id": cat.cat_id,
+ "cat_properties": cat.properties})
- cat_list.append({"cat_label": cat.label,
- "cat_description": cat.description,
- "cat_id": cat.cat_id,
- "cat_properties": cat.properties})
- # logger.debug(c.properties)
- return render_template('catrecap.html',
- cat_list=cat_list)
+ # Creating modified and created cat lists
+ for modified_category in \
+ changes_list.get("modified_categories", []):
+ modified_cat_rdf_graph = Graph()
+ modified_cat_rdf_graph.parse(
+ source=StringIO(
+ modified_category["content"]
+ ),
+ format='turtle'
+ )
+ modified_cat = Category(graph=modified_cat_rdf_graph)
+ if modified_cat.cat_id in \
+ [existing_cat["cat_id"]
+ for existing_cat in cat_list]:
+ modified_cat_list.append(
+ {"cat_label": modified_cat.label,
+ "cat_description": modified_cat.description,
+ "cat_id": modified_cat.cat_id,
+ "cat_properties": modified_cat.properties})
+ else:
+ created_cat_list.append(
+ {"cat_label": modified_cat.label,
+ "cat_description": modified_cat.description,
+ "cat_id": modified_cat.cat_id,
+ "cat_properties": modified_cat.properties})
+
+ # Creating deleted cat list
+ deleted_cat_namelist = [
+ element["name"] for element in
+ changes_list.get("deleted_categories", [])
+ ]
+ modified_cat_namelist = [
+ element["name"] for element in
+ changes_list.get("modified_categories", [])
+ ]
+ return render_template('catmodifs.html',
+ cat_list=cat_list,
+ created_cat_list=created_cat_list,
+ modified_cat_list=modified_cat_list,
+ modified_cat_namelist=modified_cat_namelist,
+ deleted_cat_namelist=deleted_cat_namelist,
+ commit_form=commit_form)
+ # If it's a POST with no delete_cat_id and delete_modifs_id, then we
+ # will submit all the stored changes
+ elif request.method == "POST":
+ if commit_form.validate_on_submit():
+ cat_api_instance.put()
+ cat_changes_api_instance.delete()
+ return redirect(url_for('cat_recap'))
+
+ # One of the ids is not None (either deleting a category or a modification)
+ else:
+ # We only do that if we have a POST
+ if request.method == "POST":
+ # We identify if we want to delete a change
+ if (session.get("user_logged", None) is not None and
+ session.get("user_can_edit", False) is not False):
+ if deleted_modifs_id is not None:
+ cat_changes_api_instance.delete(deleted_modifs_id)
+ # We identify if we want to delete a category
+ elif deleted_cat_id is not None:
+ cat_api_instance.delete(delete_cat_id)
+ return redirect(url_for('cat_modifs'))
@app.route('/cateditor', methods=['GET', 'POST'])
@@ -81,28 +261,57 @@
cateditor.html, located in src/templates
"""
cat_api_instance = CategoryAPI()
+ cat_changes_api_instance = CategoryChangesAPI()
+
cat_list = []
deleted_cat_list = []
serialized_cat_list = []
if session.get("user_logged", None) is not None:
serialized_cat_list = cat_api_instance.get()
- deleted_cat_list = [element["name"] for
- element in session.get("deleted_categories", [])]
+ cat_changes=cat_changes_api_instance.get()
+ deleted_cat_list = [
+ category["name"] for category in
+ cat_changes_api_instance.get()[0]["deleted_categories"]
+ ]
+ modified_cat_list = [
+ category["name"] for category in
+ cat_changes_api_instance.get()[0]["modified_categories"]
+ ]
for serialized_cat in serialized_cat_list:
cat_rdf_graph = Graph()
cat_rdf_graph.parse(source=StringIO(serialized_cat),
format='turtle')
cat = Category(graph=cat_rdf_graph)
- if cat.cat_id not in [element["name"] for element
- in session.get("deleted_categories", [])]:
+ if cat.cat_id not in deleted_cat_list:
cat_list.append({"cat_label": cat.label,
"cat_description": cat.description,
"cat_id": cat.cat_id,
"cat_properties": cat.properties})
+ for modified_cat in modified_cat_list:
+ if modified_cat["name"] not in [cat["cat_id"] for cat in cat_list]:
+ modified_cat_rdf_graph = Graph()
+ modified_cat_rdf_graph.parse(
+ source=StringIO(modified_cat["content"]),
+ format='turtle'
+ )
+ modified_cat = Category(graph=modified_cat_rdf_graph)
+ cat_list.append({"cat_label": modified_cat.label,
+ "cat_description": modified_cat.description,
+ "cat_id": modified_cat.cat_id,
+ "cat_properties": modified_cat.properties})
+
if cat_id is not None:
- specific_serialized_cat = cat_api_instance.get(cat_id)
-
+ specific_serialized_cat = ""
+ changes_response = cat_changes_api_instance.get(cat_id)
+ # that means the category was modified or deleted
+ if changes_response != 404:
+ if changes_response[0]["type"] is not "deleted":
+ specific_serialized_cat = changes_response[0]["category"] \
+ ["content"]
+ else:
+ specific_serialized_cat = cat_api_instance.get(cat_id)
+ logger.debug(specific_serialized_cat)
cat_rdf_graph = Graph()
cat_rdf_graph.parse(source=StringIO(specific_serialized_cat),
format='turtle')
@@ -141,7 +350,7 @@
if (session.get("user_logged", None) is not None and
session.get("user_can_edit", False) is not False):
cat_api_instance.put(cat_id)
- return redirect(url_for('cat_modifs'))
+ return redirect(url_for('cat_recap'))
else:
return render_template('cateditor.html',
cat_id=cat_id,
@@ -174,7 +383,7 @@
if (session.get("user_logged", None) is not None and
session.get("user_can_edit", False) is not False):
cat_api_instance.post()
- return redirect(url_for('cat_modifs'))
+ return redirect(url_for('cat_recap'))
else:
return render_template('cateditor.html',
form=cat_form,
@@ -182,112 +391,6 @@
deleted_cat_list=deleted_cat_list)
-@app.route('/catrecap/delete-modifs-<delete_modifs_id>',
- defaults={'delete_cat_id': None},
- methods=['POST'])
-@app.route('/catrecap/delete-<delete_cat_id>',
- defaults={'delete_modifs_id': None},
- methods=['POST'])
-@app.route('/catmodifs',
- defaults={'delete_cat_id': None, 'delete_modifs_id': None},
- methods=['GET', 'POST'])
-def cat_modifs(delete_cat_id, delete_modifs_id):
- """
- View that handles all the visualisation of changes for a user's
- session, links to the editor forms, allows the users to cancel their
- own changes and submits all their changes.
- """
- cat_list = []
- modified_cat_list = []
- deleted_cat_list = []
- created_cat_list = []
- cat_api_instance = CategoryAPI()
- if delete_cat_id is None and delete_modifs_id is None:
- commit_form = CommitForm(request.form)
-
- # if it's a GET with no delete_cat_id or deleted_modifs_id, then we'll
- # display the changes
- if request.method == "GET":
- if session.get("user_logged", None) is not None:
- serialized_cat_list = cat_api_instance.get()
-
- # Creating existing cat list
- for serialized_cat in serialized_cat_list:
- cat_rdf_graph = Graph()
- cat_rdf_graph.parse(source=StringIO(serialized_cat),
- format='turtle')
- cat = Category(graph=cat_rdf_graph)
-
- cat_list.append({"cat_label": cat.label,
- "cat_description": cat.description,
- "cat_id": cat.cat_id,
- "cat_properties": cat.properties})
-
- # Creating modified and created cat lists
- for modified_category in \
- session.get("modified_categories", []):
- modified_cat_rdf_graph = Graph()
- modified_cat_rdf_graph.parse(
- source=StringIO(
- modified_category["content"]
- ),
- format='turtle'
- )
- modified_cat = Category(graph=modified_cat_rdf_graph)
- if modified_cat.cat_id in \
- [existing_cat["cat_id"]
- for existing_cat in cat_list]:
- modified_cat_list.append(
- {"cat_label": modified_cat.label,
- "cat_description": modified_cat.description,
- "cat_id": modified_cat.cat_id,
- "cat_properties": modified_cat.properties})
- else:
- created_cat_list.append(
- {"cat_label": modified_cat.label,
- "cat_description": modified_cat.description,
- "cat_id": modified_cat.cat_id,
- "cat_properties": modified_cat.properties})
-
- # Creating deleted cat list
- deleted_cat_list = [element["name"] for element in
- session.get("deleted_categories", [])]
- return render_template('catmodifs.html',
- cat_list=cat_list,
- created_cat_list=created_cat_list,
- modified_cat_list=modified_cat_list,
- deleted_cat_list=deleted_cat_list,
- commit_form=commit_form)
- # If it's a POST with no delete_cat_id and delete_modifs_id, then we
- # will submit all the stored changes
- elif request.method == "POST":
- logger.debug("Submitting changes")
- if commit_form.validate_on_submit():
- logger.debug("Form validates")
- cat_api_instance.put()
- return redirect(url_for('cat_modifs'))
-
- # One of the ids is not None (either deleting a category or a modification)
- else:
- # We only do that if we have a POST
- if request.method == "POST":
- # We identify if we want to delete a change
- if delete_modifs_id is not None:
- for element in session.get("modified_categories", []):
- if element["name"] == delete_modifs_id:
- logger.debug("Modification for "
- + delete_modifs_id
- + " will be deleted.")
- session["modified_categories"].remove(element)
- # We identify if we want to delete a category
- if delete_cat_id is not None:
- logger.debug("Category "+delete_cat_id+" will be deleted.")
- if (session.get("user_logged", None) is not None and
- session.get("user_can_edit", False) is not False):
- cat_api_instance.delete(delete_cat_id)
- return redirect(url_for('cat_modifs'))
-
-
@app.route('/catedit-github-login')
def github_login():
"""
@@ -308,7 +411,7 @@
session["user_logged"] = True
session["user_can_edit"] = True
session["user_login"] = "FileEditUser"
- return redirect(url_for('cat_recap'))
+ return redirect(url_for('cat_index'))
@app.route('/catedit-github-callback')
@@ -335,7 +438,7 @@
logger.debug("error getting repos!")
logger.debug(session["user_login"])
- return redirect(url_for('cat_recap'))
+ return redirect(url_for('cat_index'))
@github.access_token_getter