def get_queryset(self): org_pk = get_organization_from_request(self.request) org = get_object_with_check_and_log(self.request, Organization, pk=org_pk) self.check_object_permissions(self.request, org) return Project.objects.all()
def from_request(cls, request): if 'organization_pk' not in request.session: logger.debug( '"organization_pk" is missed in request.session: can\'t get Organization' ) return pk = get_organization_from_request(request) return get_object_with_check_and_log(request, Organization, pk=pk)
def task_page(request, pk): org_pk = get_organization_from_request(request) org = get_object_with_permissions(request, Organization, org_pk, 'organizations.view_organization') project = get_object_with_check_and_log(request, Project, pk=pk) response = {'project': project, 'version': get_short_version()} response.update(find_editor_files()) return render(request, 'data_manager/data.html', response)
def perform_create(self, ser): # get organization org_pk = get_organization_from_request(self.request) org = get_object_with_check_and_log(self.request, Organization, pk=org_pk) self.check_object_permissions(self.request, org) try: project = ser.save(organization=org) except IntegrityError as e: if str(e) == 'UNIQUE constraint failed: project.title, project.created_by_id': raise ProjectExistException('Project with the same name already exists: {}'. format(ser.validated_data.get('title', ''))) raise LabelStudioDatabaseException('Database error during project creation. Try again.')
def upload_example_using_config(request): """ Generate upload data example by config only """ config = request.GET.get('label_config', '') if not config: config = request.POST.get('label_config', '') org_pk = get_organization_from_request(request) secure_mode = False if org_pk is not None: org = get_object_with_check_and_log(request, Organization, pk=org_pk) secure_mode = org.secure_mode try: Project.validate_label_config(config) task_data, _, _ = get_sample_task(config, secure_mode) task_data = playground_replacements(request, task_data) except (ValueError, ValidationError, lxml.etree.Error): response = HttpResponse('error while example generating', status=status.HTTP_400_BAD_REQUEST) else: response = HttpResponse(json.dumps(task_data)) return response