예제 #1
0
    def resolve(self, _, info, input):
        # TODO - move to model
        (shift, _) = models.Shift.objects.get_or_create(
            date=input['date'],
            shift=input['shift'],
        )
        shift.is_night = input.get('is_night', False)
        if 'watchman_id' in input:
            try:
                shift.watchman = models.Watchman.objects.get(
                    pk=input['watchman_id'])
            except models.Watchman.DoesNotExist:
                return GenericError("Watchman does not exist")
        else:
            shift.watchman = None

        try:
            shift.full_clean()
        except ValidationError as e:
            return BoxedError(e)

        shift.save()

        def on_commit():
            # can't broadcast empty dict, channels-redis complains
            channels.watchmen_updates_group.broadcast({'updated': True})

        transaction.on_commit(on_commit)
        return shift
예제 #2
0
 def resolve(self, _, info, input):
     try:
         return models.Chat.objects.create_by_invite_link(input['invite_link'])
     except models.Chat.objects.BadInviteLinkFormatError:
         return GenericError(
             "invite_link должен быть в форме https://t.me/joinchat/xxxxx"
         )
     except ValidationError as e:
         return BoxedError(e)
예제 #3
0
    def resolve(self, obj, info, input):
        try:
            return self.smart_resolve(obj, info, input)
        except Exception as e:
            if isinstance(e, PublicError):
                return GenericError(e.message)
            if isinstance(e, ValidationError):
                return BoxedError(e)

            raise Exception("Internal error")
예제 #4
0
    def resolve(self, _, info, input):
        # TODO - return generic error if object is not found
        obj = self.model.objects.get(id=input['id'])

        for field in self.fields:
            if field in input:
                setattr(obj, field, input[field])

        try:
            obj.full_clean()
        except ValidationError as e:
            return BoxedError(e)
        obj.save()
        return obj
예제 #5
0
    def resolve(self, _, info, input):
        params = {}
        for field in self.fields:
            if field in input:
                params[field] = input[field]

        params = self.prepare_params(params, info)
        obj = self.model(**params)

        try:
            obj.full_clean()
        except ValidationError as e:
            return BoxedError(e)
        obj.save()
        return obj
예제 #6
0
    def resolve(self, _, info, input):
        maybe_entity = find_discountable_entity(input)
        if isinstance(maybe_entity, GenericError):
            return maybe_entity
        entity = maybe_entity

        try:
            with transaction.atomic():
                promocode = models.Promocode.objects.create(
                    code=input['code'],
                    discount=input['discount'],
                    uses_max=input.get('uses_max'),
                )
                entity.promocodes.add(promocode)
                entity.save()
        except ValidationError as e:
            return BoxedError(e)
        except django.db.utils.IntegrityError as e:
            if e.args[0] == 1062:
                return GenericError("Промокод уже существует")
            raise e

        return promocode
예제 #7
0
    def resolve(self, _, info, input):
        obj = models.Chat.objects.get(pk=input['id'])

        if 'force_public' in input:
            obj.force_public = input['force_public']
        if 'delisted' in input:
            obj.delisted = input['delisted']
        if 'project_slug' in input:
            if not input['project_slug']:
                obj.project = None
            else:
                obj.project = (
                    kocherga.projects.models.ProjectPage.objects.live()
                    .public()
                    .get(slug=input['project_slug'])
                )

        try:
            obj.full_clean()
        except ValidationError as e:
            return BoxedError(e)
        obj.save()
        return obj
예제 #8
0
파일: orders.py 프로젝트: KochergaClub/core
    def resolve(self, _, info, input):
        ticket_type_id = input['ticket_type_id']
        try:
            ticket_type = models.TicketType.objects.get(uuid=ticket_type_id)
        except models.TicketType.DoesNotExist:
            return GenericError('Тип билета не найден')

        try:
            order = models.Order.objects.create_order(
                ticket_type=ticket_type,
                email=input['email'],
                first_name=input.get('first_name', ''),
                last_name=input.get('last_name', ''),
                city=input.get('city', ''),
                promocode=input.get('promocode', ''),
                payer_email=input.get('payer', {}).get('email', ''),
                payer_first_name=input.get('payer', {}).get('first_name', ''),
                payer_last_name=input.get('payer', {}).get('last_name', ''),
            )
            order.full_clean()  # extra precaution, make sure that order is ok
        except ValidationError as e:
            return BoxedError(e)

        return order