--- a/src/catedit/models.py Fri Feb 13 17:22:21 2015 +0100
+++ b/src/catedit/models.py Mon Feb 16 15:13:39 2015 +0100
@@ -246,7 +246,7 @@
modification_dict=modified_cat_dict,
message=message)
- def delete_category(self, deleted_cat_id, message=None):
+ def delete_category(self, deleted_cat_id):
"""
Deletes a category from its id
@@ -257,8 +257,6 @@
references to deleted category. This is handled in the api as such
operations apply to the intermediary persistence (changeset)
"""
- if message is None:
- message = ""
self.persistence.delete(name=deleted_cat_id, message=message)
# Now we must clean up the categories that reference the deleted cat
--- a/src/catedit/resources.py Fri Feb 13 17:22:21 2015 +0100
+++ b/src/catedit/resources.py Mon Feb 16 15:13:39 2015 +0100
@@ -44,7 +44,7 @@
)
if cat_id is not None:
cat = cat_manager_instance.load_category(cat_id)
- if cat != None:
+ if cat is not None:
return cat.cat_graph.serialize(
format='turtle'
).decode("utf-8"), 200
--- a/src/catedit/templates/categories/submit.html Fri Feb 13 17:22:21 2015 +0100
+++ b/src/catedit/templates/categories/submit.html Mon Feb 16 15:13:39 2015 +0100
@@ -71,7 +71,7 @@
</tr>
{% else %}
{% import "macros.html" as macros %}
- {{ macros.category_table(original_cat_list, current_repository, state_list=["original"], target="categories.submit") }}
+ {{ macros.category_table(original_cat_list, current_repository, state_list=["original"], interactive=False) }}
{% endif %}
{% endif %}
</tbody>
--- a/src/catedit/templates/categories/workshop.html Fri Feb 13 17:22:21 2015 +0100
+++ b/src/catedit/templates/categories/workshop.html Mon Feb 16 15:13:39 2015 +0100
@@ -58,13 +58,13 @@
<thead>
<tr class="active">
<th class="col-md-2"><b>Nom de la catégorie</b></th>
- <th class="col-md-10"><b>Description de la catégorie</b></th>
+ <th class="col-md-10" colspan="5"><b>Description de la catégorie</b></th>
</tr>
</thead>
<tbody>
{% if not session["user_logged"] %}
<tr>
- <td class="col-md-12" colspan="2">
+ <td class="col-md-12" colspan="5">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Attention:</span>
Veuillez vous identifier pour visualiser les catégories
--- a/src/catedit/views/categories.py Fri Feb 13 17:22:21 2015 +0100
+++ b/src/catedit/views/categories.py Mon Feb 16 15:13:39 2015 +0100
@@ -115,15 +115,21 @@
"state": cat_state})
return cat_list
-@module.route('/<string:repository>/workshop',
- defaults={'deleted_cat_id': None, 'deleted_changes_id': None},
- methods=['GET', 'POST'])
-@module.route('/<string:repository>/workshop/delete-modifs-<deleted_changes_id>',
- defaults={'deleted_cat_id': None},
- methods=['POST'])
-@module.route('/<string:repository>/workshop/delete-<deleted_cat_id>',
- defaults={'deleted_changes_id': None},
- methods=['POST'])
+@module.route(
+ '/<string:repository>/workshop',
+ defaults={'deleted_cat_id': None, 'deleted_changes_id': None},
+ methods=['GET', 'POST']
+)
+@module.route(
+ '/<string:repository>/workshop/delete-modifs-<deleted_changes_id>',
+ defaults={'deleted_cat_id': None},
+ methods=['POST']
+)
+@module.route(
+ '/<string:repository>/workshop/delete-<deleted_cat_id>',
+ defaults={'deleted_changes_id': None},
+ methods=['POST']
+)
def workshop(repository, deleted_cat_id, deleted_changes_id):
"""
View that has a list of all categories available. Template is
@@ -180,17 +186,21 @@
)
-@module.route('/<string:repository>/'
- + 'submit/'
- + 'delete-changes-<deleted_changes_id>',
- defaults={'deleted_cat_id': None},
- methods=['POST'])
-@module.route('/<string:repository>/submit/delete-<deleted_cat_id>',
- defaults={'deleted_changes_id': None},
- methods=['POST'])
-@module.route('/<string:repository>/submit',
- defaults={'deleted_cat_id': None, 'deleted_changes_id': None},
- methods=['GET', 'POST'])
+@module.route(
+ '/<string:repository>/submit/delete-changes-<deleted_changes_id>',
+ defaults={'deleted_cat_id': None},
+ methods=['POST']
+)
+@module.route(
+ '/<string:repository>/submit/delete-<deleted_cat_id>',
+ defaults={'deleted_changes_id': None},
+ methods=['POST']
+)
+@module.route(
+ '/<string:repository>/submit',
+ defaults={'deleted_cat_id': None, 'deleted_changes_id': None},
+ methods=['GET', 'POST']
+)
def submit(repository, deleted_cat_id, deleted_changes_id):
"""
View that handles all the visualisation of changes for a user's
@@ -258,7 +268,7 @@
# 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"):
+ 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(
@@ -371,7 +381,7 @@
if category_api_response == 404:
abort(404)
else:
- specific_serialized_cat = cat_api_response[0]
+ specific_serialized_cat = category_api_response[0]
logger.debug(specific_serialized_cat)
cat_rdf_graph = Graph()
@@ -426,7 +436,7 @@
if app.config["PROPERTY_LIST"] \
[cat_predicate] \
["object_type"] == "uriref-category":
- namespace, object_id = cat_object.split("#",1)
+ namespace, object_id = cat_object.split("#", 1)
else:
object_id = cat_object
cat_form.properties.append_entry({
--- a/src/catedit/views/home.py Fri Feb 13 17:22:21 2015 +0100
+++ b/src/catedit/views/home.py Mon Feb 16 15:13:39 2015 +0100
@@ -53,12 +53,12 @@
"""
if not session.get("user_logged", False):
session["modified_categories"] = {
- repo: {} for repo in app.config["PERSISTENCE_CONFIG"]
- ["REPOSITORY_LIST"]
+ repo: {} for repo
+ in app.config["PERSISTENCE_CONFIG"]["REPOSITORY_LIST"]
}
session["deleted_categories"] = {
- repo: {} for repo in app.config["PERSISTENCE_CONFIG"]
- ["REPOSITORY_LIST"]
+ repo: {} for repo
+ in app.config["PERSISTENCE_CONFIG"]["REPOSITORY_LIST"]
}
if app.config["PERSISTENCE_CONFIG"]["METHOD"] == "PersistenceToGithub":
login_form = LoginForm(request.form)
@@ -82,7 +82,7 @@
)
for auth in auth_response.json():
if auth["app"]["client_id"] \
- == app.config["GITHUB_CLIENT_ID"]:
+ == app.config["GITHUB_CLIENT_ID"]:
session["user_code"] = auth["token"]
session["user_logged"] = True
except:
@@ -96,7 +96,7 @@
"user token found by request: "
+ str(session.get("user_code", None))
)
- if session.get("user_code", None) == None:
+ if session.get("user_code", None) is None:
# We didn't get it, so we direct the user to the login page
# with a link to github oauth system
return render_template(
@@ -111,7 +111,7 @@
# form didn't validate, so we send it back to user
return render_template(
"home/login.html",
- form = login_form
+ form=login_form
)
elif app.config["PERSISTENCE_CONFIG"]["METHOD"] == "PersistenceToFile":
session["user_logged"] = True
@@ -122,6 +122,7 @@
else:
return redirect(url_for('home.index'))
+
@module.route('/catedit-login-confirm', methods=["GET", "POST"])
def login_confirm():
"""
@@ -136,6 +137,7 @@
else:
return redirect(url_for('home.index'))
+
@module.route('/catedit-callback')
@github.authorized_handler
def login_callback(oauth_code):
@@ -143,8 +145,9 @@
Function that handles callback from Github after succesful login
"""
session.permanent = False
- if session.get("user_code", None) == None:
- # That means we got here using github callback and not the login form
+ if session.get("user_code", None) is None:
+ # That means we got here using github callback
+ # and not the login form
session["user_code"] = oauth_code
logger.debug(session["user_code"])
session["user_logged"] = True
@@ -169,8 +172,7 @@
user_repos_name = [repo["name"] for repo in repo_list]
logger.debug(
str(user_repos_name) + " "
- + str(app.config["PERSISTENCE_CONFIG"]
- ["REPOSITORY_LIST"])
+ + str(app.config["PERSISTENCE_CONFIG"]["REPOSITORY_LIST"])
)
session["user_repositories"] = list(
set(user_repos_name).intersection(
@@ -190,6 +192,7 @@
logger.error(ghe.response.text)
return redirect(url_for('home.index'))
+
@module.route('/catedit-logout')
def logout():
"""
@@ -204,11 +207,11 @@
session["user_login"] = None
session["user_can_edit"] = None
session["modified_categories"] = {
- repo: {} for repo in app.config["PERSISTENCE_CONFIG"]
- ["REPOSITORY_LIST"]
+ repo: {} for
+ repo in app.config["PERSISTENCE_CONFIG"]["REPOSITORY_LIST"]
}
session["deleted_categories"] = {
- repo: {} for repo in app.config["PERSISTENCE_CONFIG"]
- ["REPOSITORY_LIST"]
+ repo: {} for repo
+ in app.config["PERSISTENCE_CONFIG"]["REPOSITORY_LIST"]
}
return redirect(url_for('home.index'))
--- a/src/catedit/views/social.py Fri Feb 13 17:22:21 2015 +0100
+++ b/src/catedit/views/social.py Mon Feb 16 15:13:39 2015 +0100
@@ -3,13 +3,12 @@
The views functions that handle comment display and posting
"""
-from catedit import app, github, cache
+from catedit import app
from views.utils import check_user_status, get_comments, \
- post_comment, get_commits, get_issues, \
- convert_github_date, get_category_list
+ post_comment, get_commits, get_issues, \
+ get_category_list
from flask import render_template, request, redirect, url_for, \
- session, Blueprint
-from flask.ext.github import GitHubError
+ abort, Blueprint
from flask_wtf import Form
from wtforms import TextAreaField, StringField
from wtforms.validators import DataRequired
@@ -17,6 +16,7 @@
module = Blueprint('social', __name__)
logger = app.logger
+
@module.route("/<string:repository>/social",
methods=["GET"])
def index(repository):
@@ -29,9 +29,6 @@
check_user_status(repository)
- issues_data = []
- commits_data = []
-
changeset_list = get_commits(repository)
discussion_list = get_issues(repository)
@@ -42,6 +39,7 @@
changeset_list=changeset_list
)
+
class CommentForm(Form):
"""
Custom form class for commiting changes
@@ -86,8 +84,8 @@
"social/changeset.html",
cat_list=cat_list,
comments=comments_list,
- changeset_id = changeset_id,
- comment_form = comment_form,
+ changeset_id=changeset_id,
+ comment_form=comment_form,
current_repository=repository
)
elif request.method == "POST":
@@ -102,18 +100,19 @@
return redirect(url_for(
"social.changeset",
repository=repository,
- changeset_id = return_id
+ changeset_id=return_id
))
- else :
+ else:
return render_template(
"social/changeset.html",
cat_list=cat_list,
comments=comments_list,
- changeset_id = changeset_id,
- comment_form = comment_form,
+ changeset_id=changeset_id,
+ comment_form=comment_form,
current_repository=repository
)
+
class NewDiscussionForm(Form):
"""
Custom form class for commiting changes
@@ -126,6 +125,7 @@
"Commentaire d'ouverture (facultatif): "
)
+
@module.route("/<string:repository>/discussions/<string:discussion_id>",
methods=["GET", "POST"])
def discussion(repository, discussion_id):
--- a/src/catedit/views/utils.py Fri Feb 13 17:22:21 2015 +0100
+++ b/src/catedit/views/utils.py Mon Feb 16 15:13:39 2015 +0100
@@ -15,6 +15,7 @@
logger = app.logger
+
def check_user_status(repository):
"""
Function to call at the beginning of every view that would require
@@ -26,6 +27,7 @@
if not session.get("user_can_edit", {}).get(repository, False):
return redirect(url_for("home.index"))
+
@cache.memoize(timeout=3600)
def get_comments(request_data):
"""
@@ -106,7 +108,7 @@
thread_opening_post = ""
if request_data["type"] == "commits":
- thread_author = discussion_data.get("author",{}).get("login", "")
+ thread_author = discussion_data.get("author", {}).get("login", "")
thread_opening_date = convert_github_date(
discussion_data.get(
"commit",
@@ -114,11 +116,11 @@
).get(
"author",
{}
- ).get("date","")
+ ).get("date", "")
)
- thread_title = discussion_data.get("commit",{}).get("message","")
+ thread_title = discussion_data.get("commit", {}).get("message", "")
elif request_data["type"] == "issues":
- thread_author = discussion_data.get("user",{}).get("login", "")
+ thread_author = discussion_data.get("user", {}).get("login", "")
thread_opening_date = convert_github_date(
discussion_data.get("created_at", "0001-01-01T00:00:00Z")
)
@@ -190,6 +192,7 @@
cache.clear()
return return_id
+
@cache.memoize(timeout=3600)
def get_commits(repository):
"""
@@ -229,6 +232,7 @@
logger.debug(str(github.get("rate_limit")["resources"]))
return changeset_list
+
@cache.memoize(timeout=3600)
def get_issues(repository):
"""
@@ -246,10 +250,11 @@
issues_data = []
try:
issues_data = github.get(
- "repos/"
- + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
- + repository
- + "/issues?per_page=100")
+ "repos/"
+ + app.config["PERSISTENCE_CONFIG"]["REPOSITORY_OWNER"] + "/"
+ + repository
+ + "/issues?per_page=100"
+ )
except GitHubError as ghe:
logger.error("Error getting issues for repo " + repository)
logger.error(ghe.response.text)
@@ -269,6 +274,7 @@
logger.debug(str(github.get("rate_limit")["resources"]))
return discussion_list
+
@cache.memoize(timeout=3600)
def get_category_list(repository, changeset_id):
"""
@@ -352,6 +358,7 @@
logger.debug(str(github.get("rate_limit")["resources"]))
return cat_list
+
def convert_github_date(date):
"""
Function that converts github date format to a