Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Az/fix codacy issues part2 #408

Merged
merged 7 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions cvat/apps/authentication/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from django.db.models import Q
import rules
from . import AUTH_ROLE
from rest_framework.permissions import (BasePermission, IsAuthenticated)

from rest_framework.permissions import BasePermission

def register_signals():
from django.db.models.signals import post_migrate, post_save
Expand Down Expand Up @@ -88,32 +87,32 @@ def is_job_annotator(db_user, db_job):
is_job_annotator)

class AdminRolePermission(BasePermission):
# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def has_permission(self, request, view):
return request.user.has_perm("engine.role.admin")

class UserRolePermission(BasePermission):
# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def has_permission(self, request, view):
return request.user.has_perm("engine.role.user")

class AnnotatorRolePermission(BasePermission):
# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def has_permission(self, request, view):
return request.user.has_perm("engine.role.annotator")

class ObserverRolePermission(BasePermission):
# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def has_permission(self, request, view):
return request.user.has_perm("engine.role.observer")

class TaskCreatePermission(BasePermission):
# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def has_permission(self, request, view):
return request.user.has_perm("engine.task.create")

class TaskAccessPermission(BasePermission):
# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def has_object_permission(self, request, view, obj):
return request.user.has_perm("engine.task.access", obj)

Expand All @@ -129,21 +128,21 @@ def get_queryset(self):
Q(segment__job__assignee=user) | Q(assignee=None)).distinct()

class TaskChangePermission(BasePermission):
# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def has_object_permission(self, request, view, obj):
return request.user.has_perm("engine.task.change", obj)

class TaskDeletePermission(BasePermission):
# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def has_object_permission(self, request, view, obj):
return request.user.has_perm("engine.task.delete", obj)

class JobAccessPermission(BasePermission):
# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def has_object_permission(self, request, view, obj):
return request.user.has_perm("engine.job.access", obj)

class JobChangePermission(BasePermission):
# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def has_object_permission(self, request, view, obj):
return request.user.has_perm("engine.job.change", obj)
2 changes: 0 additions & 2 deletions cvat/apps/engine/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
import numpy as np
from scipy.optimize import linear_sum_assignment
from collections import OrderedDict
from distutils.util import strtobool
from xml.sax.saxutils import XMLGenerator
from abc import ABCMeta, abstractmethod
from PIL import Image
from shapely import geometry

import django_rq
from django.conf import settings
from django.db import transaction

Expand Down
14 changes: 7 additions & 7 deletions cvat/apps/engine/migrations/0017_db_redesign_20190221.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cvat.apps.engine.annotation import _merge_table_rows

# some modified functions to transer annotation
def _bulk_create(db_model, db_alias, objects, flt_param = {}):
def _bulk_create(db_model, db_alias, objects, flt_param):
if objects:
if flt_param:
if 'postgresql' in settings.DATABASES["default"]["ENGINE"]:
Expand Down Expand Up @@ -252,7 +252,7 @@ def process_shapes(db_job, apps, db_labels, db_attributes, db_alias):
for db_attrval in new_db_attrvals:
db_attrval.shape_id = new_db_shapes[db_attrval.shape_id].id

_bulk_create(LabeledShapeAttributeVal, db_alias, new_db_attrvals)
_bulk_create(LabeledShapeAttributeVal, db_alias, new_db_attrvals, {})

def process_paths(db_job, apps, db_labels, db_attributes, db_alias):
TrackedShape = apps.get_model('engine', 'TrackedShape')
Expand Down Expand Up @@ -315,7 +315,7 @@ def process_paths(db_job, apps, db_labels, db_attributes, db_alias):

for db_attrval in new_db_track_attrvals:
db_attrval.track_id = new_db_tracks[db_attrval.track_id].id
_bulk_create(LabeledTrackAttributeVal, db_alias, new_db_track_attrvals)
_bulk_create(LabeledTrackAttributeVal, db_alias, new_db_track_attrvals, {})

for db_shape in new_db_shapes:
db_shape.track_id = new_db_tracks[db_shape.track_id].id
Expand All @@ -325,7 +325,7 @@ def process_paths(db_job, apps, db_labels, db_attributes, db_alias):
for db_attrval in new_db_shape_attrvals:
db_attrval.shape_id = new_db_shapes[db_attrval.shape_id].id

_bulk_create(TrackedShapeAttributeVal, db_alias, new_db_shape_attrvals)
_bulk_create(TrackedShapeAttributeVal, db_alias, new_db_shape_attrvals, {})

def copy_annotations_forward(apps, schema_editor):
db_alias = schema_editor.connection.alias
Expand Down Expand Up @@ -419,7 +419,7 @@ def _get_shape_attr_class(shape_type):
else:
db_attrval.points_id = new_db_shapes[db_attrval.points_id].id

_bulk_create(_get_shape_attr_class(shape_type), db_alias, new_db_attrvals)
_bulk_create(_get_shape_attr_class(shape_type), db_alias, new_db_attrvals, {})

def _save_old_tracks_to_db(apps, db_shapes, db_attributes, db_alias, db_job):
def _get_shape_class(shape_type):
Expand Down Expand Up @@ -521,7 +521,7 @@ def _get_shape_attr_class(shape_type):

for db_attrval in new_db_path_attrvals:
db_attrval.track_id = new_db_paths[db_attrval.track_id].id
_bulk_create(ObjectPathAttributeVal, db_alias, new_db_path_attrvals)
_bulk_create(ObjectPathAttributeVal, db_alias, new_db_path_attrvals, {})

for db_shape in new_db_shapes:
db_shape.track_id = new_db_paths[db_shape.track_id].id
Expand All @@ -538,7 +538,7 @@ def _get_shape_attr_class(shape_type):
elif shape_type == 'points_paths':
db_attrval.points_id = db_shapes[db_attrval.points_id].id

_bulk_create(_get_shape_attr_class(shape_type), db_alias, new_db_shape_attrvals)
_bulk_create(_get_shape_attr_class(shape_type), db_alias, new_db_shape_attrvals, {})

def copy_annotations_backward(apps, schema_editor):
Task = apps.get_model('engine', 'Task')
Expand Down
8 changes: 4 additions & 4 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ class Meta:
model = models.ServerFile
fields = ('file', )

# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def to_internal_value(self, data):
return {'file': data}

# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def to_representation(self, instance):
return instance.file

Expand Down Expand Up @@ -189,7 +189,7 @@ class Meta:
write_once_fields = ('overlap', 'segment_size', 'image_quality')
ordering = ['-id']

# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def create(self, validated_data):
labels = validated_data.pop('label_set')
db_task = models.Task.objects.create(size=0, **validated_data)
Expand All @@ -210,7 +210,7 @@ def create(self, validated_data):

return db_task

# pylint: disable=method-could-be-a-function
# pylint: disable=no-self-use
def update(self, instance, validated_data):
instance.name = validated_data.get('name', instance.name)
instance.owner = validated_data.get('owner', instance.owner)
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/engine/static/engine/js/annotationSaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class AnnotationSaverView {
});

window.onbeforeunload = (e) => {
if (this._controller.hasUnsavedChanges()) {
if (this._controller.hasUnsavedChanges()) { // eslint-disable-line react/no-this-in-sfc
const message = 'You have unsaved changes. Leave this page?';
e.returnValue = message;
return message;
Expand Down
70 changes: 34 additions & 36 deletions cvat/apps/engine/static/engine/js/coordinateTranslator.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,78 +81,76 @@ class CoordinateTranslator {

this._pointsTranslator = {
_playerOffset: 0,
_convert: function(points, sign) {
if (typeof(points) === 'string') {
return points.split(' ').map((coord) => coord.split(',')
.map((x) => +x + this._playerOffset * sign).join(',')).join(' ');
_convert(points, sign) {
if (typeof (points) === 'string') {
return points.split(' ').map(coord => coord.split(',')
.map(x => +x + this._playerOffset * sign).join(',')).join(' ');
}
else if (typeof(points) === 'object') {
let result = [];
for (let point of points) {
result.push({
x: point.x + this._playerOffset * sign,
y: point.y + this._playerOffset * sign,
});
}
return result;
}
else {
throw Error('Unknown points type was found');
if (typeof (points) === 'object') {
return points.map(point => ({
x: point.x + this._playerOffset * sign,
y: point.y + this._playerOffset * sign,
}));
}
throw Error('Unknown points type was found');
},
actualToCanvas: function(actualPoints) {
actualToCanvas(actualPoints) {
return this._convert(actualPoints, 1);
},

canvasToActual: function(canvasPoints) {
canvasToActual(canvasPoints) {
return this._convert(canvasPoints, -1);
},

serverToClient: function(shape) {
serverToClient(shape) {
return {
points: shape.points.reduce((acc, el, idx) => {
idx % 2 ? acc.slice(-1)[0].push(el) : acc.push([el]);
return acc
}, []).map((point) => point.join(',')).join(' '),
}
if (idx % 2) {
acc.slice(-1)[0].push(el);
} else {
acc.push([el]);
}
return acc;
}, []).map(point => point.join(',')).join(' '),
};
},

clientToServer: function(clientPoints) {
clientToServer(clientPoints) {
return {
points: clientPoints.points.split(' ').join(',').split(',').map((x) => +x),
points: clientPoints.points.split(' ').join(',').split(',').map(x => +x),
};
},
},
};

this._pointTranslator = {
_rotation: 0,
clientToCanvas: function(targetCanvas, clientX, clientY) {
clientToCanvas(targetCanvas, clientX, clientY) {
let pt = targetCanvas.createSVGPoint();
pt.x = clientX;
pt.y = clientY;
pt = pt.matrixTransform(targetCanvas.getScreenCTM().inverse());
return pt;
},
canvasToClient: function(sourceCanvas, canvasX, canvasY) {
canvasToClient(sourceCanvas, canvasX, canvasY) {
let pt = sourceCanvas.createSVGPoint();
pt.x = canvasX;
pt.y = canvasY;
pt = pt.matrixTransform(sourceCanvas.getScreenCTM());
return pt;
},
rotate(x, y, cx, cy) {
cx = (typeof cx === "undefined" ? 0 : cx);
cy = (typeof cy === "undefined" ? 0 : cy);
cx = (typeof cx === 'undefined' ? 0 : cx);
cy = (typeof cy === 'undefined' ? 0 : cy);

let radians = (Math.PI / 180) * window.cvat.player.rotation;
let cos = Math.cos(radians);
let sin = Math.sin(radians);
const radians = (Math.PI / 180) * window.cvat.player.rotation;
const cos = Math.cos(radians);
const sin = Math.sin(radians);

return {
x: (cos * (x - cx)) + (sin * (y - cy)) + cx,
y: (cos * (y - cy)) - (sin * (x - cx)) + cy
}
}
y: (cos * (y - cy)) - (sin * (x - cx)) + cy,
};
},
};
}

Expand Down
Loading