Beispiel #1
0
 def save(self, *args, **kwargs):
     success, response = add_order_shipment(
         order_id=self.order.scheduler_id,
         shipment_details=self.cleaned_data.get("details"),
     )
     if not success:
         raise SchedulerAPIError(response)
Beispiel #2
0
    def _submit_provisionned_order(cls, order, skip_units=False):
        if not skip_units:
            if (order.created_by.is_limited
                    and order.units > order.created_by.organization.units):
                raise ValueError(
                    _("Order requires %(req_u)dU but %(org)s has only %(avail_u)d"
                      ) % {
                          "req_u": order.units,
                          "org": order.created_by.organization,
                          "avail_u": order.created_by.organization.units,
                      })
            if order.created_by.is_limited:
                # remove units from org
                order.created_by.organization.units -= order.units
                order.created_by.organization.save()

        payload = order.to_payload()
        created, scheduler_id = create_order(payload)
        if not created:
            logger.error(scheduler_id)
            # restore units on org
            if not skip_units and order.created_by.is_limited:
                order.created_by.organization.units += order.units
                order.created_by.organization.save()
            raise SchedulerAPIError(scheduler_id)
        order.scheduler_id = scheduler_id
        order.save()
        return order
Beispiel #3
0
 def get_warehouse_details(self, use_public=False):
     success, warehouse = get_warehouse_from(
         self.public_warehouse if use_public else self.warehouse
     )
     if not success:
         raise SchedulerAPIError(warehouse)
     return warehouse
Beispiel #4
0
    def save(self):
        if not self.is_valid():
            raise ValueError("{cls} is not valid".format(type(self)))

        success, warehouse_id = add_warehouse(
            slug=self.cleaned_data.get("slug"),
            upload_uri=self.cleaned_data.get("upload_uri"),
            download_uri=self.cleaned_data.get("download_uri"),
            active=self.cleaned_data.get("active"),
        )
        if not success:
            raise SchedulerAPIError(warehouse_id)
        return warehouse_id
Beispiel #5
0
    def save(self):
        if not self.is_valid():
            raise ValueError(_("%(class)s is not valid") % {"class": type(self)})

        success, warehouse_id = add_warehouse(
            slug=self.cleaned_data.get("slug"),
            upload_uri=self.cleaned_data.get("upload_uri"),
            download_uri=self.cleaned_data.get("download_uri"),
            active=self.cleaned_data.get("active"),
        )
        if not success:
            raise SchedulerAPIError(warehouse_id)
        return warehouse_id
Beispiel #6
0
    def create_from(cls, client, config, media, quantity, address=None):
        if not address and media.kind != Media.VIRTUAL:
            raise ValueError("Non-virtual order requires an address")
        warehouse = client.organization.get_warehouse_details(
            use_public=media.kind == Media.VIRTUAL)
        order = cls(
            organization=client.organization,
            created_by=client,
            channel=client.organization.channel,
            client_name=client.name,
            client_email=client.email,
            client_limited=client.is_limited,
            config=config.json,
            media_name=media.name,
            media_type=media.kind,
            media_size=media.size,
            media_duration=media.get_duration_for(quantity),
            quantity=quantity,
            units=media.units * quantity,
            recipient_name=address.recipient if address else client.name,
            recipient_email=address.email if address else client.email,
            recipient_phone=address.phone if address else "",
            recipient_address=address.address if address else "",
            recipient_country_code=address.country if address else "",
            warehouse_upload_uri=warehouse["upload_uri"],
            warehouse_download_uri=warehouse["download_uri"],
        )
        if client.is_limited and order.units > client.organization.units:
            raise ValueError(
                "Order requires {r}U but {org} has only {a}".format(
                    r=order.units,
                    org=client.organization,
                    a=client.organization.units))
        elif client.is_limited:
            # remove units from org
            client.organization.units -= order.units
            client.organization.save()

        payload = order.to_payload()
        created, scheduler_id = create_order(payload)
        if not created:
            logger.error(scheduler_id)
            # restore units on org
            if client.is_limited:
                client.organization.units += order.units
                client.organization.save()
            raise SchedulerAPIError(scheduler_id)
        order.scheduler_id = scheduler_id
        order.save()
        return order
Beispiel #7
0
    def save(self):
        if not self.is_valid():
            raise ValueError("{cls} is not valid".format(cls=type(self)))

        success, autoimage_slug = add_autoimage(
            slug=self.cleaned_data.get("slug"),
            config=self.cleaned_data.get("config").to_dict(),
            contact_email=self.cleaned_data.get("contact_email"),
            periodicity="monthly",
            warehouse=self.cleaned_data.get("warehouse"),
            channel=self.cleaned_data.get("channel"),
            private=self.cleaned_data.get("private"))
        if not success:
            raise SchedulerAPIError(autoimage_slug)
        return autoimage_slug
Beispiel #8
0
    def save(self):
        if not self.is_valid():
            raise ValueError("{cls} is not valid".format(type(self)))

        success, channel_id = add_channel(
            slug=self.cleaned_data.get("slug"),
            name=self.cleaned_data.get("name"),
            active=self.cleaned_data.get("active"),
            private=self.cleaned_data.get("private"),
            sender_name=self.cleaned_data.get("sender_name"),
            sender_email=self.cleaned_data.get("sender_email"),
            sender_address=self.cleaned_data.get("sender_address"),
        )
        if not success:
            raise SchedulerAPIError(channel_id)
        return channel_id
Beispiel #9
0
    def save(self):
        if not self.is_valid():
            raise ValueError("{cls} is not valid".format(type(self)))

        success, user_id = add_user(
            username=self.cleaned_data.get("username"),
            email=self.cleaned_data.get("email"),
            password=self.cleaned_data.get("password"),
            role=self.cleaned_data.get("role"),
            channel=self.cleaned_data.get("channel"),
            is_admin=self.cleaned_data.get("is_admin"),
        )

        if not success:
            raise SchedulerAPIError(user_id)

        return user_id
Beispiel #10
0
def do_delete_account(profile):
    """Remove all information for a particular user"""

    # clean-up details on all orders created by user
    order_ids = [p.scheduler_id for p in profile.order_set.all()]
    for order in profile.order_set.all():
        if order.status == order.IN_PROGRESS:
            order.cancel()
        order.anonymize()

    # delete django user, will cascade to Profile, Address and Configuration
    profile.user.delete()

    # request anonymization of orders on API
    success, response = anonymize_orders(order_ids)
    if not success:
        raise SchedulerAPIError(response)