Gitlab CSE Unil

Commit b59c0d4b authored by M. Chardon's avatar M. Chardon
Browse files

analyse sonarqube

parent 178fd0d2
......@@ -51,17 +51,17 @@ class Command(BaseCommand):
if len(files_to_remove) == 0:
if self.verbosity >= 1:
print "No files to remove."
print("No files to remove.")
sys.exit(0)
if self.verbosity >= 1:
print "List of files to be deleted: "
print "---------------------------"
print "\n".join(f.replace(settings.MEDIA_ROOT, ' .') for f in files_to_remove)
print "\n"
print("List of files to be deleted: ")
print("---------------------------")
print("\n".join(f.replace(settings.MEDIA_ROOT, ' .') for f in files_to_remove))
print("\n")
message = "Continue and delete {} files ? [yes/NO] ".format(len(files_to_remove))
if self.interactive and raw_input(message) != 'yes':
if self.interactive and input(message) != 'yes':
raise CommandError("Removing unused files cancelled.")
if not self.dry_run:
......@@ -70,8 +70,7 @@ class Command(BaseCommand):
os.unlink(f)
except OSError:
if self.verbosity >= 1:
print "# Unable to delete file {}\n -> {}".format(f, sys.exc_info()[1][1])
print("# Unable to delete file {}\n -> {}".format(f, sys.exc_info()[1][1]))
if self.verbosity >= 1:
print "Done."
print("Done.")
......@@ -221,9 +221,8 @@ class ATTP(PermissionClass):
raise PermissionDenied()
else:
if request.user not in anobj.members.all():
if not self._register_user(request.user, anobj):
raise PermissionDenied()
if request.user not in anobj.members.all() and not self._register_user(request.user, anobj):
raise PermissionDenied()
# Check ownership
owners = anobj.owners.all()
......@@ -300,6 +299,4 @@ def has_anobj_access(request, anobj):
:param anobj:
:return: boolean
"""
# return request.user == anobj.owner or request.user in anobj.members.all()
# return request.user in anobj.owners.all() or request.user in anobj.members.all()
return anobj.is_owned(request.user.id) or request.user in anobj.members.all()
......@@ -44,7 +44,7 @@ define([
var _color = null;
var _opacity = 1;
var _isFill = false;
var _fontSize = 48;
//var _fontSize = 48;
var _strokeWidth = 7;
var _imgopacity = 100;
......@@ -81,10 +81,10 @@ define([
// ----- Private Functions ------------------------------------
function _updateCurrentStyle() {
/*function _updateCurrentStyle() {
paper.project.currentStyle.fillColor = _isFill ? _color : null;
//paper.project.currentStyle.strokeColor = _isFill ? null : _color;
}
}*/
/**
* This set the value of an attribute to the currently selected items.
......@@ -221,7 +221,6 @@ define([
setAttrCallback: function (isFill) {
var itemColor = this.fillColor || this.strokeColor;
this.fillColor = isFill ? itemColor : null;
//this.strokeColor = isFill ? null : itemColor;
}
},
fireAnnotationChange);
......@@ -231,7 +230,7 @@ define([
// Fonts
// -----
function setFontSize(size, fireAnnotationChange, silent) {
_fontSize = size;
//_fontSize = size;
paper.project.currentStyle.fontSize = size;
if (silent !== true)
_events.fontSizeChanged.dispatch(size, fireAnnotationChange);
......@@ -257,7 +256,15 @@ define([
var _minStrokeWidth = 1;
function setStrokeWidth(width, fireAnnotationChange, silent) {
_strokeWidth = (width > _maxStrokeWidth) ? _maxStrokeWidth : (width < _minStrokeWidth) ? _minStrokeWidth : width;
_strokeWidth = _maxStrokeWidth;
if (width <= _maxStrokeWidth) {
if (width < _minStrokeWidth) {
_strokeWidth = _minStrokeWidth;
} else {
_strokeWidth = width;
}
}
//_strokeWidth = (width > _maxStrokeWidth) ? _maxStrokeWidth : (width < _minStrokeWidth) ? _minStrokeWidth : width;
paper.project.currentStyle.strokeWidth = _strokeWidth;
if (silent !== true)
_events.strokeWidthChanged.dispatch(width, fireAnnotationChange);
......@@ -349,7 +356,7 @@ define([
* @param {Object} fixedPt [offsetX, offsetY] from mouse event. If defined, the view is scrolled in order to have this point fixed
*/
function setZoom(zoom, fixedPt) {
var beta, pc, offset, imgLayer;
var beta, pc, offset;
// validate params
zoom = Math.max(_minZoom, Math.min(_maxZoom, zoom));
......@@ -389,7 +396,8 @@ define([
var dDir = dVal / delta; // Delta direction [-1,1]
// validate limits and re-sign delta
delta = dDir * ((dVal > dMax) ? dMax : (dVal < dMin) ? dMin : dVal);
var deltaTmp = (dVal < dMin) ? dMin : dVal;
delta = dDir * ((dVal > dMax) ? dMax : deltaTmp);
var zoom = paper.project.view.zoom;
zoom += paper.project.view.zoom * delta / 100;
......
......@@ -32,15 +32,15 @@ define(["underscore", "paper", "signals"], function (_, paper, Signal) {
* @param parameters
* @private
*/
function _init(parameters){
function _init(parameters) {
var env = null;
if (parameters && parameters.env){
if (parameters && parameters.env) {
env = parameters.env;
}
// Init category container element
if (_.isString(_catContainer)) _catContainer = $(_catContainer);
_(_catContainer.find("[data-category]")).each(function(el, i){
_(_catContainer.find("[data-category]")).each(function (el, i) {
var $el = $(el),
colorStr = $el.data('color') || $el.css("backgroundColor"),
colorBgStr = $el.data('colorBg') || $el.css("backgroundColor"),
......@@ -54,7 +54,7 @@ define(["underscore", "paper", "signals"], function (_, paper, Signal) {
_categories['default'] = _categories[id];
}
});
if (env && env=='geomo'){
if (env && env == 'geomo') {
_categories['default'] = _categories['cat_geo_1'];
} else {
_categories['default'] = _categories['cat_2'];
......@@ -72,9 +72,14 @@ define(["underscore", "paper", "signals"], function (_, paper, Signal) {
function _getColorFromStr(colorStr, asPaperColor) {
var color;
if (colorStr.indexOf('rgb') === 0) {
var colA = colorStr.split(/[(),]/)
.map(function(part){return parseFloat(part.trim())})
.filter(function(n){ return !isNaN(n)});
var regex = /[(),]/; // RegExp object from regex literal
var colA = colorStr.split(new RegExp(regex))
.map(function (part) {
return parseFloat(part.trim())
})
.filter(function (n) {
return !isNaN(n)
});
color = new paper.Color(colA[0] / 255, colA[1] / 255, colA[2] / 255);
} else {
color = new paper.Color(colorStr);
......@@ -85,7 +90,7 @@ define(["underscore", "paper", "signals"], function (_, paper, Signal) {
return {
init: _init,
getCategory: function(cat) {
getCategory: function (cat) {
return _categories[cat];
}
}
......
......@@ -35,33 +35,33 @@ define([
"env/shortcuts",
"tools/marker-ui"
],
function($, _, paper, Signal, config, view, attributes, io, tools, ui, category, shortcuts, markerUI){
function ($, _, paper, Signal, config, view, attributes, io, tools, ui, category, shortcuts, markerUI) {
/**
* Signal binding specific to anodate environment
* @private
*/
function _initSignalRouting(){
function _initSignalRouting() {
console.info("_initSignalRouting from env/anodate");
io.events.annotableLoaded.add(function(annotableData){
io.events.annotableLoaded.add(function (annotableData) {
// p.raster is a paper.Raster
view.events.annotationRemoved.add(function(annotation){
view.events.annotationRemoved.add(function (annotation) {
if (annotation.data.type === 'marker') {
tools.tools['marker'].listeners.updateNumbering();
}
});
view.events.imageLoaded.add(function(p){
view.events.imageLoaded.add(function (p) {
// Here we initilize tools that needs some image properties
});
}, 100);
// called after all other handlers
view.events.annotationsLoaded.add(function() {
view.events.annotationsLoaded.add(function () {
tools.tools['marker'].listeners.updateNumbering();
}, -100);
ui.events.modeChanged.add(function(opts) {
ui.events.modeChanged.add(function (opts) {
var mode = opts.mode;
if (mode === 'edit') {
$("#annotation-display-panel").hide();
......@@ -86,20 +86,15 @@ define([
$("#tool-colorselect").find(".color-menu").addClass("no-picker");
// Init Type Display Selector
$(".adim-display-type-selector").find("button").on('click', function(event) {
$(".adim-display-type-selector").find("button").on('click', function (event) {
var $but = $(this);
var activate = !$but.hasClass("active");
var category = $but.data('category');
if (event.metaKey) {
//if (category !== 'image') {
// view.selectItemsByType(category);
//}
} else {
if (!event.metaKey) {
$but.toggleClass("active", activate);
if (category === 'image') {
attributes.setImageOpacity(activate ? 100 : 0, true);
//_opacitySlider.slider('setValue', activate ? 100 : 0);
} else {
view.toggleItemsByProp({prop: 'category', val: category, undef: true}, activate);
}
......@@ -116,8 +111,6 @@ define([
sharedAnnotationMarkersPanel = $("#shared-annotation-markers-panel");
function displayAltCol(show) {
//sideCol.toggleClass("col-sm-1", !show)
// .toggleClass("col-sm-2", show);
sideCol.toggleClass("w-25", show);
sideCol.toggleClass("default", !show);
canvasCol.toggleClass("w-100", !show);
......@@ -126,10 +119,10 @@ define([
} else {
altSideColPanelGroup.show();
}
//altSideColPanelGroup.toggleClass("hidden", !show);
sideColPanelGroup.toggleClass("w-50", show);
sideColPanelGroup.toggleClass("w-100", !show);
}
function displayAltColAndLabels(show) {
displayAltCol(show && sharedAnnotationMarkersPanel.find(".collapse").hasClass("show"));
if (!show) {
......@@ -138,9 +131,10 @@ define([
sharedAnnotationMarkersPanel.show();
}
}
displayAltColAndLabels(params.mode === 'review');
ui.events.modeChanged.add(function(opts) {
ui.events.modeChanged.add(function (opts) {
var mode = opts.mode;
displayAltColAndLabels(mode === 'review');
ui.updateReservedSpace();
......@@ -172,7 +166,6 @@ define([
}
/**
* Define initial strokeColor from the forth color of the current color palette.
* This has to be define as a getter function as we cannot compute the color before
......@@ -185,9 +178,14 @@ define([
var colStr = $("#tool-colorselect").find(".color-menu .c4").css("backgroundColor");
var color;
if (colStr.indexOf('rgb') === 0) {
var colA = colStr.split(/[(),]/)
.map(function(part){return parseFloat(part.trim())})
.filter(function(n){ return !isNaN(n)});
var regex = /[(),]/; // RegExp object from regex literal
var colA = colStr.split(new RegExp(regex))
.map(function (part) {
return parseFloat(part.trim())
})
.filter(function (n) {
return !isNaN(n)
});
color = new paper.Color(colA[0] / 255, colA[1] / 255, colA[2] / 255);
} else {
color = new paper.Color(colStr);
......@@ -206,4 +204,4 @@ define([
Object.defineProperty(env, 'style', {get: _getStyle});
return env;
});
\ No newline at end of file
});
\ No newline at end of file
......@@ -34,13 +34,13 @@ define([
"adim/ui",
"env/shortcuts"
],
function($, _, paper, Signal, config, view, attributes, io, tools, ui, shortcuts){
function ($, _, paper, Signal, config, view, attributes, io, tools, ui, shortcuts) {
/**
* Signal binding specific to CIMAF environment
* @private
*/
function _initSignalRouting(){
function _initSignalRouting() {
console.info("_initSignalRouting from env/cimaf");
var userLayer;
......@@ -61,8 +61,12 @@ define([
}
if (!userLayer) return;
var zones = userLayer.children.filter(function(a) { return a.data.type && a.data.type === 'cmsarea'; });
var striae = userLayer.children.filter(function(a) { return a.data.type && a.data.type === 'concordantstr'; });
var zones = userLayer.children.filter(function (a) {
return a.data.type && a.data.type === 'cmsarea';
});
var striae = userLayer.children.filter(function (a) {
return a.data.type && a.data.type === 'concordantstr';
});
// If the current selection is an area, keep it's current nbConcordances
var items = paper.project.getSelectedItems();
......@@ -72,7 +76,7 @@ define([
var zone, nbInter, i, ii, nbStria = striae.length;
for (i = 0; zone = zones[i]; i++) {
nbInter = 0;
for (ii=0; ii<nbStria; ii++) {
for (ii = 0; ii < nbStria; ii++) {
nbInter += Math.round(zone.getIntersections(striae[ii]).length / 2);
}
zone.data.prop.nbConcordances = nbInter;
......@@ -83,19 +87,19 @@ define([
}
}
tools.events.annotationAdded.add(function(annotation) {
tools.events.annotationAdded.add(function (annotation) {
updateAreaIntersectionCount(annotation);
}, this, 100);
tools.events.annotationChanged.add(function(annotations) {
updateAreaIntersectionCount(annotations.length===1 ? annotations[0] : void(0));
tools.events.annotationChanged.add(function (annotations) {
updateAreaIntersectionCount(annotations.length === 1 ? annotations[0] : void (0));
}, this, 100);
// This should be called before the annotations are rendered, so we bind it to the imageLoaded event
// before the image loading is started. To do so we set a higher priority (100)
// than the handler defined in main. @TODO: get the cut position and cut margin from config
io.events.annotableLoaded.add(function(annotableData){
io.events.annotableLoaded.add(function (annotableData) {
var concordantstrTool = tools.tools['concordantstr'];
var discordantstrTool = tools.tools['discordantstr'];
var cmsareaTool = tools.tools['cmsarea'];
......@@ -103,15 +107,15 @@ define([
var cutPos = annotableData.envparam && annotableData.envparam.cimaf_cut_pos;
var cutMargin = annotableData.envparam && annotableData.envparam.cimaf_cut_margin;
view.events.imageLoaded.add(function(p){
cutPos = cutPos || p.raster.scaling.x * p.raster.width / 2 ;
view.events.imageLoaded.add(function (p) {
cutPos = cutPos || p.raster.scaling.x * p.raster.width / 2;
cutMargin = cutMargin || 25;
concordantstrTool.listeners.onCutPositionChanged(cutPos);
concordantstrTool.listeners.onCutMarginChanged(cutMargin);
discordantstrTool.listeners.onCutPositionChanged(cutPos);
cmsareaTool.listeners.onCutPositionChanged(cutPos);
cmsareaTool.listeners.onSetAreaWidth(cutMargin*2);
cmsareaTool.listeners.onSetAreaWidth(cutMargin * 2);
});
}, 100);
......@@ -125,7 +129,7 @@ define([
*/
// Init Type Display Selector
$(".adim-display-type-selector").find("button").on('click', function(event) {
$(".adim-display-type-selector").find("button").on('click', function (event) {
var $but = $(this);
var activate = !$but.hasClass("active");
var typeName = $but.data('typeName');
......@@ -138,7 +142,6 @@ define([
$but.toggleClass("active", activate);
if (typeName === 'image') {
attributes.setImageOpacity(activate ? 100 : 0, true);
//_opacitySlider.slider('setValue', activate ? 100 : 0);
} else {
view.toggleItemsByType($but.data('typeName'), activate);
ui.enableTool(typeName, activate);
......@@ -155,4 +158,4 @@ define([
initUI: _initUI
}
});
\ No newline at end of file
});
\ No newline at end of file
......@@ -37,15 +37,22 @@ define([
],
function ($, paper, Signal, config, view, tools, ui) {
// Two contexts corresponding to the view modes: 'edit' 'review' 'analysis'
var _keyblock = function(){ return function(){return false} };
var activeTool;
var _keyblock = function () {
return function () {
return false
}
};
//var activeTool;
var EDIT_REVIEW = "edit review";
var ANNOTATION_DISPLAY_CONTAINER_DIV_ID = "#annotation-display-container";
var SHORTCUTS = {
// DELETE -> [edit]:delete selected annot. [review]:prevent default
'backspace del': [{
event: "keydown",
ctxt: "edit",
fn: function(){
fn: function () {
view.removeSelectedItems();
return false;
}
......@@ -58,15 +65,15 @@ define([
// SPACEBAR -> [*]:activate pan tool while pressed, in all context
'space': [{
event: "keydown",
ctxt: "edit review",
fn: function(){
ctxt: EDIT_REVIEW,
fn: function () {
$("#tool-pan").click();
return false;
}
}, {
event: "keyup",
ctxt: "edit review",
fn: function(){
ctxt: EDIT_REVIEW,
fn: function () {
$("#tool-pan").click();
return false;
}
......@@ -74,7 +81,7 @@ define([
'1 2 3': {
ctxt: 'edit',
fn : function(event) {
fn: function (event) {
if (paper.project.selectedItems.length > 0)
$("#confidence-input").val([event.key]).change()
.siblings("[data-value]").trigger('mouseleave');
......@@ -86,7 +93,7 @@ define([
'a': [{
event: "keydown",
ctxt: "edit",
fn: function(){
fn: function () {
$("#tool-select").click();
return false;
}
......@@ -96,8 +103,10 @@ define([
'ctrl+a meta+a': [{
event: "keydown",
ctxt: "edit",
fn: function(){
paper.project.activeLayer.children.map(function(c){c.selected = true;});
fn: function () {
paper.project.activeLayer.children.map(function (c) {
c.selected = true;
});
return false;
}
}, {
......@@ -117,12 +126,12 @@ define([
$("#tool-concordantstr").click();
return false;
}
},{
}, {
event: "keydown",
ctxt: "analysis",
fn: function(){
fn: function () {
var c = $("#checkShowConcordance");
c.val([c.is(":checked")?'off':'on']).change();
c.val([c.is(":checked") ? 'off' : 'on']).change();
return false;
}
}],
......@@ -132,27 +141,27 @@ define([
'd': [{
event: "keydown",
ctxt: "edit",
fn: function(){
fn: function () {
if ($("#tool-discordantstr").is(":disabled"))
return false;
$("#tool-discordantstr").click();
return false;
}
},{
}, {
event: "keydown",
ctxt: "analysis",
fn: function(){
fn: function () {
var c = $("#checkShowDiscordance");
c.val([c.is(":checked")?'off':'on']).change();
c.val([c.is(":checked") ? 'off' : 'on']).change();
return false;
}
}],
// SHIFT-D, SHIFT-C -> [edit,review]:show hide striae
'shift+d shift+c': {
ctxt: "edit review",
fn: function(){
$("#annotation-display-container").find("[data-type-name='concordantstr,discordantstr']").click();
ctxt: EDIT_REVIEW,
fn: function () {
$(ANNOTATION_DISPLAY_CONTAINER_DIV_ID).find("[data-type-name='concordantstr,discordantstr']").click();
}
},
......@@ -161,7 +170,7 @@ define([
'e b': [{
event: "keydown",
ctxt: "edit",
fn: function(){
fn: function () {
if ($("#tool-fieldedges").is(":disabled"))
return false;
$("#tool-fieldedges").click();
......@@ -171,9 +180,9 @@ define([
// SHIFT-E -> [edit,review]:show hide field edges
'shift+e': {
ctxt: "edit review",
fn: function(){
$("#annotation-display-container").find("[data-type-name='fieldedges']").click();
ctxt: EDIT_REVIEW,
fn: function () {
$(ANNOTATION_DISPLAY_CONTAINER_DIV_ID).find("[data-type-name='fieldedges']").click();
}
},
......@@ -182,7 +191,7 @@ define([
'f': [{
event: "keydown",
ctxt: "edit",