Esempio n. 1
0
    def create_review(project, template_data, parent_review_project=None):
        project_name = 'Peer Review for ' + project.name

        review_project = models.Project.objects.create(
            name=project_name,
            owner=project.owner,
            parent=project,
            is_prototype=False,
            min_rating=1.99,
            post_mturk=False,
            timeout=project.timeout,
            is_review=True,
            deleted_at=timezone.now())
        if parent_review_project is not None:
            review_project.price = parent_review_project.price
        template_serializer = TemplateSerializer(data=template_data)
        if template_serializer.is_valid():
            review_template = template_serializer.create(with_defaults=False,
                                                         is_review=True,
                                                         owner=project.owner)
            review_project.template = review_template
        else:
            raise ValidationError(template_serializer.errors)
        review_project.group_id = review_project.id
        review_project.save()
        return review_project
Esempio n. 2
0
    def create(self, with_defaults=True, **kwargs):
        template_initial = self.validated_data.pop('template') if 'template' in self.validated_data else None
        template_items = template_initial['items'] if template_initial else []

        template = {
            "name": 't_' + generate_random_id(),
            "items": template_items
        }

        template_serializer = TemplateSerializer(data=template)
        self.validated_data.pop('post_mturk')
        project = models.Project.objects.create(owner=kwargs['owner'], post_mturk=True, amount_due=0,
                                                **self.validated_data)
        if template_serializer.is_valid():
            project_template = template_serializer.create(with_defaults=with_defaults, is_review=False,
                                                          owner=kwargs['owner'])
            project.template = project_template
        else:
            raise ValidationError(template_serializer.errors)

        project.group_id = project.id

        if not with_defaults:
            project.status = models.Project.STATUS_IN_PROGRESS
            project.published_at = timezone.now()
            # self.instance = project
            # if not project.is_paid:
            #     self.pay(self.instance.price * self.instance.repetition)
        # self.create_task(project.id)
        project.save()
        self.create_review(project=project, template_data=template)
        models.BoomerangLog.objects.create(object_id=project.group_id, min_rating=project.min_rating,
                                           rating_updated_at=project.rating_updated_at, reason='DEFAULT')

        return project
Esempio n. 3
0
 def create(self, **kwargs):
     project = models.Project.objects.create(deleted=False, owner=kwargs["owner"].requester)
     template = {"name": "t_" + generate_random_id()}
     template_serializer = TemplateSerializer(data=template)
     template = None
     if template_serializer.is_valid():
         template = template_serializer.create(with_default=True, owner=kwargs["owner"])
     else:
         raise ValidationError(template_serializer.errors)
     models.ProjectTemplate.objects.get_or_create(project=project, template=template)
     return project
 def create(self, **kwargs):
     project = models.Project.objects.create(
         deleted=False, owner=kwargs['owner'].requester)
     template = {"name": 't_' + generate_random_id()}
     template_serializer = TemplateSerializer(data=template)
     template = None
     if template_serializer.is_valid():
         template = template_serializer.create(with_default=True,
                                               owner=kwargs['owner'])
     else:
         raise ValidationError(template_serializer.errors)
     models.ProjectTemplate.objects.get_or_create(project=project,
                                                  template=template)
     return project
Esempio n. 5
0
    def create_review(project, template_data, parent_review_project=None):
        project_name = 'Peer Review for ' + project.name

        review_project = models.Project.objects.create(name=project_name, owner=project.owner,
                                                       parent=project, is_prototype=False, min_rating=1.99,
                                                       post_mturk=True, timeout=project.timeout,
                                                       is_review=True, deleted_at=timezone.now())
        if parent_review_project is not None:
            review_project.price = parent_review_project.price
        template_serializer = TemplateSerializer(data=template_data)
        if template_serializer.is_valid():
            review_template = template_serializer.create(with_defaults=False, is_review=True,
                                                         owner=project.owner)
            review_project.template = review_template
        else:
            raise ValidationError(template_serializer.errors)
        review_project.group_id = review_project.id
        review_project.save()
        return review_project