diff --git a/crowdsourcing/models.py b/crowdsourcing/models.py index 116b42f1..a05d8e16 100644 --- a/crowdsourcing/models.py +++ b/crowdsourcing/models.py @@ -417,7 +417,7 @@ def filter_by_boomerang(self, worker, sort_by='-boomerang'): up.handle requester_handle, p.published_at FROM crowdsourcing_project p INNER JOIN crowdsourcing_userprofile up on up.user_id = p.owner_id - INNER JOIN projects ON projects.project_id = p.id ORDER BY case when %(sort_by)s='-boomerang' + INNER JOIN projects ON projects.project_id = p.id ORDER BY case when %(sort_by)s='-boomerang' then requester_rating when %(sort_by)s='-available_tasks' then available_tasks when %(sort_by)s='-published_at' then 12 when %(sort_by)s='-price' then p.price end desc nulls last, p.id desc; diff --git a/crowdsourcing/permissions/user.py b/crowdsourcing/permissions/user.py index d1e8ae06..205949db 100644 --- a/crowdsourcing/permissions/user.py +++ b/crowdsourcing/permissions/user.py @@ -1,7 +1,6 @@ from rest_framework import permissions from csp import settings from rest_framework.exceptions import PermissionDenied -from crowdsourcing.models import RegistrationWhitelist class IsWorker(permissions.BasePermission): @@ -16,8 +15,6 @@ def has_object_permission(self, request, view, object): class CanCreateAccount(permissions.BasePermission): def has_permission(self, request, view): - # user_email = request.data.get('email') - # users = RegistrationWhitelist.objects.filter(email=user_email).count() if view.action == 'create' and not (request.user.is_staff or settings.REGISTRATION_ALLOWED): raise PermissionDenied(detail='We are currently in closed beta. ' 'If you\'d like an account, email support@daemo.org ' diff --git a/crowdsourcing/serializers/message.py b/crowdsourcing/serializers/message.py index 53d4a2e0..d53a045a 100644 --- a/crowdsourcing/serializers/message.py +++ b/crowdsourcing/serializers/message.py @@ -106,7 +106,6 @@ class Meta: def get_sender_alias(self, obj): return obj.sender.profile.handle - def get_posted_time(self, obj): from crowdsourcing.utils import get_time_delta delta = get_time_delta(obj.created_at) diff --git a/crowdsourcing/serializers/project.py b/crowdsourcing/serializers/project.py index c27ff64d..685c1d63 100644 --- a/crowdsourcing/serializers/project.py +++ b/crowdsourcing/serializers/project.py @@ -1,8 +1,8 @@ import copy -import numpy as np from decimal import Decimal + +import numpy as np from django.db import transaction -from crowdsourcing.utils import hash_task from django.db.models import Q, F from django.utils import timezone from rest_framework import serializers @@ -11,14 +11,14 @@ from crowdsourcing import models from crowdsourcing.crypto import to_hash from crowdsourcing.serializers.dynamic import DynamicFieldsModelSerializer +from crowdsourcing.serializers.file import BatchFileSerializer from crowdsourcing.serializers.message import CommentSerializer from crowdsourcing.serializers.task import TaskSerializer, TaskCommentSerializer from crowdsourcing.serializers.template import TemplateSerializer, TemplateItemSerializer -from crowdsourcing.serializers.file import BatchFileSerializer from crowdsourcing.tasks import update_project_boomerang from crowdsourcing.utils import generate_random_id +from crowdsourcing.utils import hash_task from crowdsourcing.validators.project import ProjectValidator -from mturk.tasks import mturk_update_status class ProjectSerializer(DynamicFieldsModelSerializer): @@ -106,9 +106,8 @@ def create(self, with_defaults=True, **kwargs): template_items = template_initial['items'] if template_initial else [] template = { - "name": template_initial.get('name', - generate_random_id()) if template_initial - is not None else 't_' + generate_random_id(), + "name": template_initial.get('name', generate_random_id() + ) if template_initial is not None else 't_' + generate_random_id(), "items": template_items } if 'post_mturk' in self.validated_data: diff --git a/crowdsourcing/serializers/user.py b/crowdsourcing/serializers/user.py index 991acc75..135fe1a1 100644 --- a/crowdsourcing/serializers/user.py +++ b/crowdsourcing/serializers/user.py @@ -148,7 +148,7 @@ def create(self, **kwargs): password=self.initial_data.get('password1'), active=True, approved=True) - except: + except Exception: print("Failed to create Discourse user!") return user diff --git a/crowdsourcing/tasks.py b/crowdsourcing/tasks.py index 6c799b9a..de95376e 100644 --- a/crowdsourcing/tasks.py +++ b/crowdsourcing/tasks.py @@ -85,7 +85,7 @@ def expire_tasks(): INNER JOIN crowdsourcing_task t ON tw.task_id = t.id INNER JOIN crowdsourcing_project p ON t.project_id = p.id INNER JOIN crowdsourcing_taskworkersession sessions ON sessions.task_worker_id = tw.id - WHERE tw.status=%(in_progress)s + WHERE tw.status=%(in_progress)s GROUP BY tw.id, p.id HAVING sum(coalesce(sessions.ended_at, now()) - sessions.started_at) > coalesce(p.timeout, INTERVAL '24 hour')) @@ -137,7 +137,7 @@ def auto_approve_tasks(): INNER JOIN auth_user u_worker ON tw.worker_id = u_worker.id WHERE tw.submitted_at + INTERVAL %(auto_approve_freq)s < NOW() AND tw.status=%(submitted)s) - UPDATE crowdsourcing_taskworker tw_up SET status=%(accepted)s, approved_at = %(approved_at)s, + UPDATE crowdsourcing_taskworker tw_up SET status=%(accepted)s, approved_at = %(approved_at)s, auto_approved=TRUE FROM taskworkers WHERE taskworkers.id=tw_up.id @@ -448,7 +448,7 @@ def update_feed_boomerang(): WHERE p.status = 3 AND p.deleted_at IS NULL GROUP BY p.id, p.name, owner_id, p.min_rating, p.group_id, p.price, aux_attributes) available INNER JOIN auth_user u_workers ON TRUE - INNER JOIN crowdsourcing_userprofile p_workers ON p_workers.user_id = u_workers.id + INNER JOIN crowdsourcing_userprofile p_workers ON p_workers.user_id = u_workers.id AND p_workers.is_worker IS TRUE INNER JOIN get_worker_ratings(u_workers.id) worker_ratings ON worker_ratings.requester_id = available.owner_id diff --git a/crowdsourcing/utils.py b/crowdsourcing/utils.py index 85b4e0b5..e942df52 100644 --- a/crowdsourcing/utils.py +++ b/crowdsourcing/utils.py @@ -33,7 +33,7 @@ def get_pk(id_or_hash): try: project_id = int(id_or_hash) return project_id, False - except: + except Exception: return to_pk(id_or_hash), True diff --git a/crowdsourcing/viewsets/project.py b/crowdsourcing/viewsets/project.py index eaa6ea31..c8d302e3 100644 --- a/crowdsourcing/viewsets/project.py +++ b/crowdsourcing/viewsets/project.py @@ -17,7 +17,7 @@ from rest_framework.response import Response from yapf.yapflib.yapf_api import FormatCode -from crowdsourcing.models import Category, Project, Task, TaskWorker, TaskWorkerResult +from crowdsourcing.models import Project, Task, TaskWorker, TaskWorkerResult from crowdsourcing.permissions.project import IsProjectOwnerOrCollaborator, ProjectChangesAllowed from crowdsourcing.serializers.project import * from crowdsourcing.serializers.task import * @@ -229,7 +229,6 @@ def calculate_total(instance): @detail_route(methods=['POST']) def publish(self, request, pk=None, *args, **kwargs): - num_rows = request.data.get('num_rows', 0) project_id, is_hash = get_pk(pk) filter_by = {} if is_hash: @@ -435,7 +434,7 @@ def requester_projects(self, request, *args, **kwargs): INNER JOIN crowdsourcing_project p0 ON p0.id=p_max.id GROUP BY p_max.id, p0.repetition) t ON t.project_id = p.id - where p.deleted_at is NULL + where p.deleted_at is NULL ORDER BY id DESC; ''' projects = Project.objects.raw(query, params={'owner_id': request.user.id}) diff --git a/crowdsourcing/viewsets/task.py b/crowdsourcing/viewsets/task.py index d06238a6..d6a8ff4a 100644 --- a/crowdsourcing/viewsets/task.py +++ b/crowdsourcing/viewsets/task.py @@ -1,7 +1,6 @@ import datetime import json from decimal import Decimal, ROUND_UP -from urlparse import urlsplit import trueskill from django.conf import settings @@ -283,7 +282,7 @@ def list(self, request, *args, **kwargs): "next": None, "previous": None }) - except: + except Exception: return Response([]) @detail_route(methods=['get'], url_path='assignment-results', permission_classes=[IsTaskOwner]) @@ -789,7 +788,7 @@ def list_other_submissions(self, request, pk, *args, **kwargs): return Response(serializer.data) @detail_route(methods=['post']) - def reject(self, request, *args, **kwargs): + def collective_reject(self, request, *args, **kwargs): task_worker = self.get_object() serializer = CollectiveRejectionSerializer(data=request.data) if serializer.is_valid(): @@ -1025,13 +1024,13 @@ def post(self, request, *args, **kwargs): if len(identifier_hash.decode(identifier)) == 0: raise serializers.ValidationError(detail=daemo_error("Invalid identifier")) task_worker_id, task_id, template_item_id = identifier_hash.decode(identifier) - template_item = models.TemplateItem.objects.get(id=template_item_id) - task = models.Task.objects.get(id=task_id) - source_url = None - if template_item.aux_attributes['src']: - source_url = urlsplit(template_item.aux_attributes['src']) - else: - source_url = urlsplit(task.data[template_item.aux_attributes['data_source']]) + # template_item = models.TemplateItem.objects.get(id=template_item_id) + # task = models.Task.objects.get(id=task_id) + # source_url = None + # if template_item.aux_attributes['src']: + # source_url = urlsplit(template_item.aux_attributes['src']) + # else: + # source_url = urlsplit(task.data[template_item.aux_attributes['data_source']]) # if 'HTTP_REFERER' not in request.META.keys(): # return Response(data={"message": "Missing referer"}, status=status.HTTP_403_FORBIDDEN) # referer_url = urlsplit(request.META['HTTP_REFERER']) diff --git a/mturk/interface.py b/mturk/interface.py index 2d576e88..811d6f25 100644 --- a/mturk/interface.py +++ b/mturk/interface.py @@ -72,8 +72,8 @@ def _mturk_system_qualifications(qualification): requirement = None if item.expression['attribute'] == 'location': op = OP_IN if item.expression['operator'] == 'in' else OP_NOT_IN - requirement = MultiLocaleRequirement(op, [l.strip() for l in item.expression['value'] if - l is not None and l != '']) + requirement = MultiLocaleRequirement(op, [val.strip() for val in item.expression['value'] if + val is not None and val != '']) elif item.expression['attribute'] == 'approval_rate': op = OP_GT if item.expression['operator'] == 'gt' else OP_LT requirement = PercentAssignmentsApprovedRequirement(op, item.expression['value']) diff --git a/mturk/tasks.py b/mturk/tasks.py index e3956a63..4e922cae 100644 --- a/mturk/tasks.py +++ b/mturk/tasks.py @@ -214,7 +214,7 @@ def calculate_cumulative_ratings(owner_id, project_id): try: mat = IterativeSVD(verbose=False, init_fill_method="mean").complete(matrix) - except: + except Exception: mat = SoftImpute(verbose=False, init_fill_method="mean").complete(matrix) data['score'] = mat.mean(axis=ROW_WISE)