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

Fixed codacy issues part 1 #403

Merged
merged 7 commits into from
Apr 17, 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
13 changes: 11 additions & 2 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,
IsAdminUser)
from rest_framework.permissions import (BasePermission, IsAuthenticated)


def register_signals():
Expand Down Expand Up @@ -89,26 +88,32 @@ def is_job_annotator(db_user, db_job):
is_job_annotator)

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

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

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

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

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

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

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

class TaskChangePermission(BasePermission):
# pylint: disable=method-could-be-a-function
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
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
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
def has_object_permission(self, request, view, obj):
return request.user.has_perm("engine.job.change", obj)
1 change: 0 additions & 1 deletion cvat/apps/auto_annotation/model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from cvat.apps.engine.log import slogger
from cvat.apps.engine.models import Task as TaskModel
from cvat.apps.engine import annotation
from cvat.apps.engine.serializers import LabeledDataSerializer
from cvat.apps.engine.annotation import put_task_data, patch_task_data

Expand Down
1 change: 0 additions & 1 deletion cvat/apps/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from django.conf import settings
from cvat.apps.authentication.decorators import login_required

from cvat.apps.engine.models import Task as TaskModel, Job as JobModel
from cvat.settings.base import JS_3RDPARTY, CSS_3RDPARTY

import os
Expand Down
2 changes: 1 addition & 1 deletion cvat/apps/dextr_segmentation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from cvat.apps.authentication.decorators import login_required
from rules.contrib.views import permission_required, objectgetter

from cvat.apps.engine.models import Job, Task
from cvat.apps.engine.models import Job
from cvat.apps.engine.log import slogger
from cvat.apps.dextr_segmentation.dextr import DEXTR_HANDLER

Expand Down
57 changes: 42 additions & 15 deletions cvat/apps/engine/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import copy
from enum import Enum
from django.utils import timezone
from collections import OrderedDict
import numpy as np
from scipy.optimize import linear_sum_assignment
from collections import OrderedDict
Expand Down Expand Up @@ -127,7 +126,7 @@ def dump_task_data(pk, file_path, scheme, host, query_params):

######

def bulk_create(db_model, objects, flt_param = {}):
def bulk_create(db_model, objects, flt_param):
if objects:
if flt_param:
if 'postgresql' in settings.DATABASES["default"]["ENGINE"]:
Expand Down Expand Up @@ -246,23 +245,37 @@ def _save_tracks_to_db(self, tracks):
track["attributes"] = track_attributes
track["shapes"] = shapes

db_tracks = bulk_create(models.LabeledTrack, db_tracks,
{"job_id": self.db_job.id})
db_tracks = bulk_create(
db_model=models.LabeledTrack,
objects=db_tracks,
flt_param={"job_id": self.db_job.id}
)

for db_attrval in db_track_attrvals:
db_attrval.track_id = db_tracks[db_attrval.track_id].id
bulk_create(models.LabeledTrackAttributeVal, db_track_attrvals)
bulk_create(
db_model=models.LabeledTrackAttributeVal,
objects=db_track_attrvals,
flt_param={}
)

for db_shape in db_shapes:
db_shape.track_id = db_tracks[db_shape.track_id].id

db_shapes = bulk_create(models.TrackedShape, db_shapes,
{"track__job_id": self.db_job.id})
db_shapes = bulk_create(
db_model=models.TrackedShape,
objects=db_shapes,
flt_param={"track__job_id": self.db_job.id}
)

for db_attrval in db_shape_attrvals:
db_attrval.shape_id = db_shapes[db_attrval.shape_id].id

bulk_create(models.TrackedShapeAttributeVal, db_shape_attrvals)
bulk_create(
db_model=models.TrackedShapeAttributeVal,
objects=db_shape_attrvals,
flt_param={}
)

shape_idx = 0
for track, db_track in zip(tracks, db_tracks):
Expand Down Expand Up @@ -295,13 +308,20 @@ def _save_shapes_to_db(self, shapes):
db_shapes.append(db_shape)
shape["attributes"] = attributes

db_shapes = bulk_create(models.LabeledShape, db_shapes,
{"job_id": self.db_job.id})
db_shapes = bulk_create(
db_model=models.LabeledShape,
objects=db_shapes,
flt_param={"job_id": self.db_job.id}
)

for db_attrval in db_attrvals:
db_attrval.shape_id = db_shapes[db_attrval.shape_id].id

bulk_create(models.LabeledShapeAttributeVal, db_attrvals)
bulk_create(
db_model=models.LabeledShapeAttributeVal,
objects=db_attrvals,
flt_param={}
)

for shape, db_shape in zip(shapes, db_shapes):
shape["id"] = db_shape.id
Expand All @@ -328,13 +348,20 @@ def _save_tags_to_db(self, tags):
db_tags.append(db_tag)
tag["attributes"] = attributes

db_tags = bulk_create(models.LabeledImage, db_tags,
{"job_id": self.db_job.id})
db_tags = bulk_create(
db_model=models.LabeledImage,
objects=db_tags,
flt_param={"job_id": self.db_job.id}
)

for db_attrval in db_attrvals:
db_attrval.tag_id = db_tags[db_attrval.tag_id].id

bulk_create(models.LabeledImageAttributeVal, db_attrvals)
bulk_create(
db_model=models.LabeledImageAttributeVal,
objects=db_attrvals,
flt_param={}
)

for tag, db_tag in zip(tags, db_tags):
tag["id"] = db_tag.id
Expand Down Expand Up @@ -614,7 +641,7 @@ def _add_meta(self, meta):
self._add_meta(v)
self._indent()
self.xmlgen.endElement(k)
elif type(v) == list:
elif isinstance(v, list):
self._indent()
self.xmlgen.startElement(k, {})
for tup in v:
Expand Down
3 changes: 0 additions & 3 deletions cvat/apps/engine/migrations/0015_db_redesign_20190217.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Generated by Django 2.1.5 on 2019-02-17 19:32

import re
import csv
from io import StringIO
from django.conf import settings
from django.db import migrations, models
import django.db.migrations.operations.special
Expand Down
6 changes: 1 addition & 5 deletions cvat/apps/engine/migrations/0016_attribute_spec_20190217.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
import csv
from io import StringIO
from PIL import Image
from django.db import migrations
from django.conf import settings
from django.db import migrations, models
import django.db.migrations.operations.special
import django.db.models.deletion
import cvat.apps.engine.models
from cvat.apps.engine.task import _get_mime


def parse_attribute(value):
match = re.match(r'^([~@])(\w+)=(\w+):(.+)?$', value)
if match:
Expand Down
3 changes: 0 additions & 3 deletions cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
from enum import Enum

import shlex
import csv
import os
import sys
import re

from django.db import models
from django.conf import settings
Expand Down
5 changes: 4 additions & 1 deletion cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import os
import shutil
import json

from rest_framework import serializers
from django.contrib.auth.models import User, Group
Expand Down Expand Up @@ -75,9 +74,11 @@ class Meta:
model = models.ServerFile
fields = ('file', )

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

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

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

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

return db_task

# pylint: disable=method-could-be-a-function
def update(self, instance, validated_data):
instance.name = validated_data.get('name', instance.name)
instance.owner = validated_data.get('owner', instance.owner)
Expand Down
48 changes: 24 additions & 24 deletions cvat/apps/engine/static/engine/js/coordinateTranslator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,58 @@ class CoordinateTranslator {
constructor() {
this._boxTranslator = {
_playerOffset: 0,
_convert: function(box, sign) {
for (let prop of ["xtl", "ytl", "xbr", "ybr", "x", "y"]) {
_convert(box, sign) {
for (const prop of ['xtl', 'ytl', 'xbr', 'ybr', 'x', 'y']) {
if (prop in box) {
box[prop] += this._playerOffset * sign;
}
}

return box;
},
actualToCanvas: function(actualBox) {
let canvasBox = {};
for (let key in actualBox) {
actualToCanvas(actualBox) {
const canvasBox = {};
for (const key in actualBox) {
canvasBox[key] = actualBox[key];
}

return this._convert(canvasBox, 1);
},

canvasToActual: function(canvasBox) {
let actualBox = {};
for (let key in canvasBox) {
canvasToActual(canvasBox) {
const actualBox = {};
for (const key in canvasBox) {
actualBox[key] = canvasBox[key];
}

return this._convert(actualBox, -1);
},

canvasToClient: function(sourceCanvas, canvasBox) {
let points = [
window.cvat.translate.point.canvasToClient(sourceCanvas, canvasBox.x, canvasBox.y),
window.cvat.translate.point.canvasToClient(sourceCanvas, canvasBox.x + canvasBox.width, canvasBox.y),
window.cvat.translate.point.canvasToClient(sourceCanvas, canvasBox.x, canvasBox.y + canvasBox.height),
window.cvat.translate.point.canvasToClient(sourceCanvas, canvasBox.x + canvasBox.width, canvasBox.y + canvasBox.height),
];
canvasToClient(sourceCanvas, canvasBox) {
const points = [
[canvasBox.x, canvasBox.y],
[canvasBox.x + canvasBox.width, canvasBox.y],
[canvasBox.x, canvasBox.y + canvasBox.height],
[canvasBox.x + canvasBox.width, canvasBox.y + canvasBox.height],
].map(el => window.cvat.translate.point.canvasToClient(sourceCanvas, ...el));

let xes = points.map((el) => el.x);
let yes = points.map((el) => el.y);
const xes = points.map(el => el.x);
const yes = points.map(el => el.y);

let xmin = Math.min(...xes);
let xmax = Math.max(...xes);
let ymin = Math.min(...yes);
let ymax = Math.max(...yes);
const xmin = Math.min(...xes);
const xmax = Math.max(...xes);
const ymin = Math.min(...yes);
const ymax = Math.max(...yes);

return {
x: xmin,
y: ymin,
width: xmax - xmin,
height: ymax - ymin
height: ymax - ymin,
};
},

serverToClient: function(shape) {
serverToClient(shape) {
return {
xtl: shape.points[0],
ytl: shape.points[1],
Expand All @@ -71,7 +71,7 @@ class CoordinateTranslator {
};
},

clientToServer: function(clientObject) {
clientToServer(clientObject) {
return {
points: [clientObject.xtl, clientObject.ytl,
clientObject.xbr, clientObject.ybr],
Expand Down
Loading