Пример #1
0
    def simple_csv(self):
        object = appier.get_object(
            alias = True,
            find = True,
            limit = 0
        )
        countries = budy.Country.find(**object)

        countries_s = [(
            "name",
            "country_code",
            "currency_code",
            "locale"
        )]
        for country in countries:
            country_s = (
                country.name,
                country.country_code,
                country.currency_code,
                country.locale
            )
            countries_s.append(country_s)

        result = appier.serialize_csv(countries_s, delimiter = ",")
        self.content_type("text/csv")
        return result
Пример #2
0
    def simple_csv(self):
        object = appier.get_object(
            alias = True,
            find = True,
            limit = 0
        )
        accounts = budy.BudyAccount.find(
            **object
        )

        accounts_s = [(
            "username",
            "email",
            "first_name",
            "last_name",
            "birth_date"
        )]
        for account in accounts:
            account_s = (
                account.username,
                account.email,
                account.first_name,
                account.last_name,
                account.birth_date
            )
            accounts_s.append(account_s)

        result = appier.serialize_csv(accounts_s, delimiter = ",")
        self.content_type("text/csv")
        return result
Пример #3
0
    def simple_csv(self):
        object = appier.get_object(
            alias = True,
            find = True,
            limit = 0
        )
        currencies = budy.Currency.find(**object)

        currencies_s = [("iso", "decimal_places")]
        for currency in currencies:
            currency_s = (currency.iso, currency.decimal_places)
            currencies_s.append(currency_s)

        result = appier.serialize_csv(currencies_s, delimiter = ",")
        self.content_type("text/csv")
        return result
Пример #4
0
    def lines_csv(self, key):
        order = budy.Order.get(key = key)
        lines_s = [(
            "id",
            "product",
            "product_id",
            "quantity",
            "size",
            "scale",
            "gender",
            "line_total",
            "currency",
            "order_id",
            "order_reference",
            "order_total",
            "order_status",
            "account",
            "date",
        )]
        for line in order.lines:
            if not line.product: continue
            line_s = (
                line.id,
                line.product.id,
                line.product.product_id,
                line.quantity,
                line.size,
                line.scale,
                line.product.gender,
                line.total,
                line.currency,
                order.id,
                order.reference,
                order.total,
                order.status,
                order.account.username,
                order.created_d.strftime("%d/%m/%Y"),
            )
            lines_s.append(line_s)

        result = appier.serialize_csv(lines_s, delimiter = ",")
        self.content_type("text/csv")
        return result
Пример #5
0
    def list_events_csv(self):
        object = appier.get_object(
            alias = True,
            find = True,
            limit = 0
        )
        events = models.Event.find(**object)

        events_s = [(
            "name",
            "handler",
            "arguments"
        )]
        for event in events:
            event_s = (
                event.name,
                event.handler,
                event.arguments and json.dumps(event.arguments)
            )
            events_s.append(event_s)

        result = appier.serialize_csv(events_s, delimiter = ",")
        self.content_type("text/csv")
        return result
Пример #6
0
    def test_csv(self):
        result = appier.serialize_csv([["item"], ["hello world"]])
        self.assertEqual(result, "item\r\nhello world\r\n")

        result = appier.serialize_csv([[appier.legacy.u("item")],
                                       [appier.legacy.u("hello world")]])
        self.assertEqual(result, "item\r\nhello world\r\n")

        result = appier.serialize_csv([[appier.legacy.u("item")],
                                       [appier.legacy.u("你好世界")]])
        self.assertEqual(result, "item\r\n你好世界\r\n")

        result = appier.serialize_csv([dict(item="hello world")])
        self.assertEqual(result, "item\r\nhello world\r\n")

        result = appier.serialize_csv(
            [dict(item=appier.legacy.u("hello world"))])
        self.assertEqual(result, "item\r\nhello world\r\n")

        result = appier.serialize_csv([dict(item=appier.legacy.u("你好世界"))])
        self.assertEqual(result, "item\r\n你好世界\r\n")
Пример #7
0
    def test_csv(self):
        result = appier.serialize_csv([["item"], ["hello world"]])
        self.assertEqual(result, "item\r\nhello world\r\n")

        result = appier.serialize_csv([
            [appier.legacy.u("item")],
            [appier.legacy.u("hello world")]
        ])
        self.assertEqual(result, "item\r\nhello world\r\n")

        result = appier.serialize_csv([
            [appier.legacy.u("item")],
            [appier.legacy.u("你好世界")]
        ])
        self.assertEqual(result, "item\r\n你好世界\r\n")

        result = appier.serialize_csv([dict(item = "hello world")])
        self.assertEqual(result, "item\r\nhello world\r\n")

        result = appier.serialize_csv([dict(item = appier.legacy.u("hello world"))])
        self.assertEqual(result, "item\r\nhello world\r\n")

        result = appier.serialize_csv([dict(item = appier.legacy.u("你好世界"))])
        self.assertEqual(result, "item\r\n你好世界\r\n")
Пример #8
0
 def subscriptions_csv(self, name):
     object = appier.get_object(alias = True, find = True)
     subscriptions = campaigner.Subscription.find(campaign = name, map = True, **object)
     result = appier.serialize_csv(subscriptions)
     self.content_type("text/csv")
     return result
Пример #9
0
 def complex_csv(self):
     start = self.field("start", cast = int)
     end = self.field("end", cast = int)
     paid = self.field("paid", True, cast = bool)
     object = appier.get_object(
         alias = True,
         find = True,
         limit = 0,
         sort = [("id", -1)]
     )
     id = object.get("id", {})
     if start: id["$gte"] = start
     if end: id["$lte"] = end
     if start or end: object["id"] = id
     if paid: object["paid"] = True
     orders = budy.Order.find(**object)
     orders_s = [(
         "id",
         "reference",
         "date",
         "status",
         "email",
         "account",
         "store",
         "product",
         "gender",
         "size",
         "quantity",
         "total",
         "currency",
         "first_name",
         "last_name",
         "billing_address",
         "billing_city",
         "billing_state",
         "billing_postal_code",
         "billing_country",
         "billing_phone",
         "shipping_address",
         "shipping_city",
         "shipping_state",
         "shipping_postal_code",
         "shipping_country",
         "shipping_phone"
     )]
     for order in orders:
         for line in order.lines:
             if not line.product: continue
             account = order.account
             shipping_address = order.shipping_address
             billing_address = order.billing_address
             order_s = (
                 order.id,
                 order.reference,
                 order.created_d.strftime("%d/%m/%Y"),
                 order.status,
                 order.email,
                 account.username,
                 order.store and order.store.name,
                 line.product.short_description,
                 line.product.gender,
                 line.size,
                 line.quantity,
                 line.total,
                 line.currency,
                 billing_address.first_name,
                 billing_address.last_name,
                 billing_address.address,
                 billing_address.city,
                 billing_address.state,
                 billing_address.postal_code,
                 billing_address.country,
                 billing_address.phone_number,
                 shipping_address and shipping_address.address,
                 shipping_address and shipping_address.city,
                 shipping_address and shipping_address.state,
                 shipping_address and shipping_address.postal_code,
                 shipping_address and shipping_address.country,
                 shipping_address and shipping_address.phone_number
             )
             orders_s.append(order_s)
     result = appier.serialize_csv(orders_s, delimiter = ",")
     self.content_type("text/csv")
     return result
Пример #10
0
 def ctt_csv(self):
     start = self.field("start", cast = int)
     end = self.field("end", cast = int)
     paid = self.field("paid", True, cast = bool)
     sms = self.field("sms", False, cast = bool)
     object = appier.get_object(
         alias = True,
         find = True,
         limit = 0,
         sort = [("id", -1)]
     )
     id = object.get("id", {})
     if start: id["$gte"] = start
     if end: id["$lte"] = end
     if start or end: object["id"] = id
     if paid: object["paid"] = True
     orders = budy.Order.find(**object)
     orders_s = []
     for order in orders:
         shipping_address = order.shipping_address
         postal_code = shipping_address.postal_code or ""
         if not "-" in postal_code: postal_code += "-"
         weight = "%.2f" % (order.quantity * 100)
         weight = weight.replace(".", ",")
         line = dict(
             reference = order.reference,
             quantity = int(order.quantity),
             weight = weight,
             price = "0ue",
             destiny = shipping_address.full_name[:60],
             title = order.account.title[:20],
             name = shipping_address.full_name[:60],
             address = shipping_address.address[:60],
             town = shipping_address.city[:50],
             zip_code_4 = postal_code.split("-", 1)[0][:4],
             zip_code_3 = postal_code.split("-", 1)[1][:3],
             not_applicable_1 = "",
             observations = "",
             back = 0,
             document_code = "",
             phone_number = (shipping_address.phone_number or "").replace("+", "00")[:15],
             saturday = 0,
             email = (order.email or "")[:200],
             country = order.country,
             fragile = 0,
             not_applicable_2 = "",
             document_collection = "",
             code_email = "",
             mobile_phone = (shipping_address.phone_number or "").replace("+", "00")[:15],
             second_delivery = 0,
             delivery_date = "",
             return_signed_document = 0,
             expeditor_instructions = 0,
             sms = 1 if sms else 0,
             not_applicable_3 = "",
             printer = "",
             ticket_machine = "",
             at_code = ""
         )
         order_s = (
             line["reference"],
             str(line["quantity"]),
             line["weight"],
             line["price"],
             line["destiny"],
             line["title"],
             line["name"],
             line["address"],
             line["town"],
             line["zip_code_4"],
             line["zip_code_3"],
             line["not_applicable_1"],
             line["observations"],
             str(line["back"]),
             line["document_code"],
             line["phone_number"],
             str(line["saturday"]),
             line["email"],
             line["country"],
             str(line["fragile"]),
             line["not_applicable_2"],
             line["document_collection"],
             line["code_email"],
             line["mobile_phone"],
             str(line["second_delivery"]),
             line["delivery_date"],
             str(line["return_signed_document"]),
             str(line["expeditor_instructions"]),
             str(line["sms"]),
             line["not_applicable_3"],
             line["printer"],
             line["ticket_machine"],
             line["at_code"]
         )
         orders_s.append(order_s)
     result = appier.serialize_csv(orders_s, delimiter = "+")
     self.content_type("text/csv")
     return result
Пример #11
0
 def show_model_csv(self, model):
     model = self.get_model(model)
     entities = model.find(map = True)
     result = appier.serialize_csv(entities)
     self.content_type("text/csv")
     return result
Пример #12
0
    def simple_csv(self):
        object = appier.get_object(
            alias = True,
            find = True,
            limit = 0
        )
        products = budy.Product.find(
            eager = (
                "colors",
                "categories",
                "collections",
                "variants",
                "brand",
                "season",
                "measurements",
                "compositions"
            ),
            **object
        )

        products_s = [(
            "description",
            "short_description",
            "product_id",
            "gender",
            "price",
            "order",
            "tag",
            "tag_description",
            "farfetch_url",
            "farfetch_male_url",
            "farfetch_female_url",
            "colors",
            "categories",
            "collections",
            "variants",
            "brand",
            "season",
            "measurements",
            "compositions",
            "price_provider",
            "price_url"
        )]
        for product in products:
            product_s = (
                product.description,
                product.short_description,
                product.product_id,
                product.gender,
                product.price,
                product.order,
                product.tag,
                product.tag_description,
                product.farfetch_url,
                product.farfetch_male_url,
                product.farfetch_female_url,
                ";".join([color.name for color in product.colors]),
                ";".join([category.name for category in product.categories]),
                ";".join([collection.name for collection in product.collections]),
                ";".join([variant.product_id for variant in product.variants]),
                product.brand.name if product.brand else None,
                product.season.name if product.season else None,
                ";".join([measurement.name for measurement in product.measurements]),
                ";".join([composition.name for composition in product.compositions]),
                product.price_provider,
                product.price_url
            )
            products_s.append(product_s)

        result = appier.serialize_csv(products_s, delimiter = ",")
        self.content_type("text/csv")
        return result
Пример #13
0
 def ctt_csv(self):
     paid = self.field("paid", True, cast = bool)
     sms = self.field("sms", False, cast = bool)
     quantity = self.field("quantity", 1, cast = int)
     weight = self.field("weight", 100, cast = int)
     object = appier.get_object(
         alias = True,
         find = True,
         limit = 0,
         sort = [("s_id", -1)]
     )
     if paid: object["payment"] = shopdesk.Order.PAID
     orders = self.admin_part._find_view(shopdesk.Order, **object)
     orders_s = []
     for order in orders:
         s_shipping_zip = order.s_shipping_zip or ""
         if not "-" in s_shipping_zip: s_shipping_zip += "-"
         weight_s = "%.2f" % (order.s_quantity * weight)
         weight_s = weight_s.replace(".", ",")
         line = dict(
             reference = order.s_name,
             quantity = int(order.s_quantity) if quantity == None else quantity,
             weight = weight_s,
             price = "0ue",
             destiny = order.s_shipping_name[:60],
             title = "",
             name = order.s_shipping_name[:60],
             address = order.s_shipping_street[:60],
             town = order.s_shipping_city[:50],
             zip_code_4 = s_shipping_zip.split("-", 1)[0][:4],
             zip_code_3 = s_shipping_zip.split("-", 1)[1][:3],
             not_applicable_1 = "",
             observations = "",
             back = 0,
             document_code = "",
             phone_number = "",
             saturday = 0,
             email = (order.s_email or "")[:200],
             country = order.s_shipping_country_code,
             fragile = 0,
             not_applicable_2 = "",
             document_collection = "",
             code_email = "",
             mobile_phone = "",
             second_delivery = 0,
             delivery_date = "",
             return_signed_document = 0,
             expeditor_instructions = 0,
             sms = 1 if sms else 0,
             not_applicable_3 = "",
             printer = "",
             ticket_machine = "",
             at_code = ""
         )
         order_s = (
             line["reference"],
             str(line["quantity"]),
             line["weight"],
             line["price"],
             line["destiny"],
             line["title"],
             line["name"],
             line["address"],
             line["town"],
             line["zip_code_4"],
             line["zip_code_3"],
             line["not_applicable_1"],
             line["observations"],
             str(line["back"]),
             line["document_code"],
             line["phone_number"],
             str(line["saturday"]),
             line["email"],
             line["country"],
             str(line["fragile"]),
             line["not_applicable_2"],
             line["document_collection"],
             line["code_email"],
             line["mobile_phone"],
             str(line["second_delivery"]),
             line["delivery_date"],
             str(line["return_signed_document"]),
             str(line["expeditor_instructions"]),
             str(line["sms"]),
             line["not_applicable_3"],
             line["printer"],
             line["ticket_machine"],
             line["at_code"]
         )
         orders_s.append(order_s)
     result = appier.serialize_csv(
         orders_s,
         encoding = "Cp1252",
         errors = "ignore",
         delimiter = "+"
     )
     result = appier.legacy.bytes(
         result,
         encoding = "Cp1252",
         errors = "ignore"
     )
     self.content_type("text/csv")
     return result