예제 #1
0
    def update():
        """
        Updates product!
        """

        FlaskWebServicesProductsManager.check_service_requirements(
            ['ticket', 'user_name', 'id'])
        options = FlaskWebServicesProductsManager.get_service_options()

        if 'price' in request.json:
            options['price'] = request.json['price']
        if 'image_data' in request.json:
            options['image_data'] = request.json['image_data']
        if 'status' in request.json:
            options['status'] = request.json['status']
        if 'colors' in request.json:
            options['colors'] = request.json['colors']
        if 'sizes' in request.json:
            options['sizes'] = request.json['sizes']
        if 'brands' in request.json:
            options['brands'] = request.json['brands']
        if 'counter' in request.json:
            options['counter'] = request.json['counter']
        if 'age_category' in request.json:
            options['age_category'] = request.json['age_category']
        if 'gender' in request.json:
            options['gender'] = request.json['gender']
        if 'comment' in request.json:
            options['comment'] = request.json['comment']

        product = \
            pyro_server.execute_ex(request.json['ticket'], request.json['user_name'], 'server.products.update', {},
                                   request.json['id'], **options)

        return jsonify(product)
예제 #2
0
    def activate(input_data):
        '''
        Activates!
        '''

        if input_data is None or input_data.strip() == "":
            abort(400)

        decrypted = decrypt_aes(input_data)
        user_id, activation_data = decrypted.split('$')

        ticket = pyro_server.login('admin', 'sportmagazineserver')
        data = pyro_server.execute_ex(ticket,
                                      'admin',
                                      'security.user.activate', {},
                                      user_id,
                                      True,
                                      activation_data=input_data)
        pyro_server.logoff(ticket, 'admin')

        if data is not None and data.get('result') is not None:
            return jsonify('activate/{0}'.format(
                encrypt_aes('{0}${1}'.format(user_id, data.get('result')))))

        return jsonify(SUCCESS_RESPONSE)
예제 #3
0
    def find_history():
        """
        Finds products histories!
        """

        FlaskWebServicesProductsManager.check_service_requirements(
            ['ticket', 'user_name'])
        options = FlaskWebServicesProductsManager.get_service_options()

        if 'from_edit_date' in request.json:
            options['from_edit_date'] = request.json['from_edit_date']
        if 'to_creation_date' in request.json:
            options['to_edit_date'] = request.json['to_edit_date']
        if 'from_price' in request.json:
            options['from_price'] = request.json['from_price']
        if 'to_price' in request.json:
            options['to_price'] = request.json['to_price']
        if 'name' in request.json:
            options['name'] = request.json['name']
        if 'categories' in request.json:
            options['categories'] = request.json['categories']
        if 'include_out_of_stock' in request.json:
            options['include_out_of_stock'] = request.json[
                'include_out_of_stock']

        products = \
            pyro_server.execute_ex(request.json['ticket'], request.json['user_name'], 'server.products.history.find', {})

        return jsonify(products)
    def get_invoice(id):
        """
        Gets product!
        """

        FlaskWebServicesInvoiceManager.check_service_requirements(
            ['ticket', 'user_name'])

        invoice = \
            pyro_server.execute_ex(request.json['ticket'], request.json['user_name'], 'server.invoices.get', {}, id)

        return jsonify(invoice)
예제 #5
0
    def get_product_by_name(name):
        """
        Gets product!
        """

        FlaskWebServicesProductsManager.check_service_requirements(
            ['ticket', 'user_name'])

        product = \
            pyro_server.execute_ex(request.json['ticket'], request.json['user_name'], 'server.products.get.by_name', {}, name)

        return jsonify(product)
    def register():
        """
        Registers invoice!
        """

        FlaskWebServicesInvoiceManager.check_service_requirements(
            ['ticket', 'user_name', 'invoice_items'])

        invoice = \
            pyro_server.execute_ex(request.json['ticket'], request.json['user_name'], 'server.invoices.register', {},
                                   request.json['invoice_items'])

        invoice = invoice.get('result')
        return jsonify(invoice.get('invoice_id'))
예제 #7
0
    def change_password():
        '''
        Changes password!
        '''

        FlaskWebServicesSecurityManager.check_service_requirements(
            ['user_name', 'current_password', 'new_password'])
        options = FlaskWebServicesSecurityManager.get_service_options()

        if 'activation_data' in request.json:
            options['activation_data'] = request.json['activation_data']

        ticket = pyro_server.login('admin', 'sportmagazineserver')
        data = pyro_server.execute_ex(ticket, 'admin',
                                      'security.password.change', {},
                                      request.json['user_name'],
                                      request.json['current_password'],
                                      request.json['new_password'], **options)
        pyro_server.logoff(ticket, 'admin')

        return jsonify(SUCCESS_RESPONSE)
예제 #8
0
    def get_user():
        '''
        Gets user!
        '''

        FlaskWebServicesSecurityManager.check_service_requirements(
            ['ticket', 'user_name'])

        user = \
            pyro_server.execute_ex(request.json['ticket'], request.json['user_name'], 'security.user.get.by_id',
                                   {}, request.json['user_name'])

        user = user.get('result')
        return jsonify({
            "user_name":
            user.get('user_id'),
            "password":
            user.get('user_password'),
            "full_name":
            user.get('user_full_name'),
            "mobile":
            user.get('user_mobile'),
            "email":
            user.get('user_email'),
            "address":
            user.get('user_address'),
            "phone":
            user.get('user_phone'),
            "work_address":
            user.get('user_work_address'),
            "national_code":
            user.get('user_national_code'),
            "production_type":
            user.get('user_production_type'),
            "production_package":
            user.get('user_production_package'),
            "image":
            user.get('user_image')
        })
예제 #9
0
    def create_product():
        """
        Creates product!
        """

        FlaskWebServicesProductsManager.check_service_requirements([
            'ticket', 'user_name', 'name', 'price', 'category', 'colors',
            'sizes', 'brands'
        ])
        options = FlaskWebServicesProductsManager.get_service_options()

        if 'status' in request.json:
            options['status'] = request.json['status']
        if 'counter' in request.json:
            options['counter'] = request.json['counter']
        if 'age_category' in request.json:
            options['age_category'] = request.json['age_category']
        if 'gender' in request.json:
            options['gender'] = request.json['gender']
        if 'comment' in request.json:
            options['comment'] = request.json['comment']
        if 'image' in request.json:
            options['image'] = request.json['image']
        if 'wholesale_type' in request.json:
            options['wholesale_type'] = request.json['wholesale_type']

        product = \
            pyro_server.execute_ex(request.json['ticket'], request.json['user_name'], 'server.products.create', {},
                                   request.json['name'], request.json['price'], request.json['category'],
                                   request.json['colors'].split(','), request.json['sizes'].split(','),
                                   request.json['brands'].split(','), **options)

        product = product.get('result')
        product['product_price'] = None
        return jsonify({
            "name": product.get("product_name"),
            "comment": product.get("product_comment")
        })
    def find_invoices():
        """
        Finds products!
        """

        FlaskWebServicesInvoiceManager.check_service_requirements(
            ['ticket', 'user_name'])
        options = FlaskWebServicesInvoiceManager.get_service_options()

        if 'from_invoice_date' in request.json:
            options['from_invoice_date'] = request.json['from_invoice_date']
        if 'to_invoice_date' in request.json:
            options['to_invoice_date'] = request.json['to_invoice_date']
        if '__offset__' in request.json:
            options['__offset__'] = request.json['__offset__']
        if '__limit__' in request.json:
            options['__limit__'] = request.json['__limit__']

        invoices = \
            pyro_server.execute_ex(request.json['ticket'], request.json['user_name'], 'server.invoices.find', {},
                                   **options)

        invoices = invoices.get('result')

        flat_invoices = []
        for invoice in invoices:
            flat_invoice = {
                "id": invoice.get("invoice_id"),
                "date": invoice.get("invoice_date"),
                "status": invoice.get("invoice_status"),
                "consumer_user_id": invoice.get("invoice_consumer_user_id"),
                "comment": invoice.get("invoice_comment"),
                "total_price": invoice.get("total_invoce_price"),
                "invoice_items": []
            }

            invoice_items = []
            for item in invoice.get("invoice_items"):
                invoice_item = {
                    "id": item.get("item_id"),
                    "product_id": item.get("item_product_id"),
                    "price": item.get("item_price"),
                    "quantity": item.get("item_quantity"),
                    "row": item.get("item_row"),
                    "color": item.get("item_color"),
                    "size": item.get("item_size"),
                    "brand": item.get("item_brand")
                }

                p = item.get("product")
                product = {
                    "id": p.get("product_id"),
                    "name": p.get("product_name"),
                    "category": p.get("product_category"),
                    "image": p.get("product_image"),
                    "age_category": p.get("product_age_category"),
                    "comment": p.get("product_comment"),
                    "creation_date": p.get("product_creation_date"),
                    "gender": p.get("product_gender")
                }

                invoice_item.update(product=product)
                invoice_items.append(invoice_item)

            flat_invoice.update(invoice_items=invoice_items)
            flat_invoices.append(flat_invoice)

        return jsonify(flat_invoices)
    def find_producer_invoices():
        """
        Finds producer invoices!
        """

        FlaskWebServicesInvoiceManager.check_service_requirements(
            ['ticket', 'user_name'])
        options = FlaskWebServicesInvoiceManager.get_service_options()

        if 'from_invoice_date' in request.json:
            options['from_invoice_date'] = request.json['from_invoice_date']
        if 'to_invoice_date' in request.json:
            options['to_invoice_date'] = request.json['to_invoice_date']
        if 'wholesale_type' in request.json:
            options['wholesale_type'] = request.json['wholesale_type']
        if '__offset__' in request.json:
            options['__offset__'] = request.json['__offset__']
        if '__limit__' in request.json:
            options['__limit__'] = request.json['__limit__']

        producer_invoices = \
            pyro_server.execute_ex(request.json['ticket'], request.json['user_name'], 'server.invoices.producer_registered_invoices',
                                   {}, **options)

        producer_invoices = producer_invoices.get('result')

        flat_invoices = []
        for invoice in producer_invoices:
            flat_invoice = {
                "invoice_id": invoice.get("invoice_id"),
                "invoice_date": invoice.get("invoice_date"),
                "invoice_status": invoice.get("invoice_status"),
                "invoice_consumer_user_id":
                invoice.get("invoice_consumer_user_id"),
                "invoice_comment": invoice.get("invoice_comment"),
                "item_id": invoice.get("item_id"),
                "item_product_id": invoice.get("item_product_id"),
                "item_price": invoice.get("item_price"),
                "item_quantity": invoice.get("item_quantity"),
                "item_row": invoice.get("item_row"),
                "item_color": invoice.get("item_color"),
                "item_size": invoice.get("item_size"),
                "item_brand": invoice.get("item_brand")
            }

            p = invoice.get("product")
            product = {
                "id": p.get("product_id"),
                "name": p.get("product_name"),
                "category": p.get("product_category"),
                "image": p.get("product_image"),
                "age_category": p.get("product_age_category"),
                "comment": p.get("product_comment"),
                "creation_date": p.get("product_creation_date"),
                "gender": p.get("product_gender")
            }

            flat_invoice.update(product=product)
            flat_invoices.append(flat_invoice)

        return jsonify(flat_invoices)
예제 #12
0
    def signin():
        '''
        Sign in!
        '''

        FlaskWebServicesSecurityManager.check_service_requirements(
            ['user_name', 'full_name', 'password'])
        FlaskWebServicesSecurityManager.check_user_name()

        ticket = pyro_server.login('admin', 'sportmagazineserver')
        options = FlaskWebServicesSecurityManager.get_service_options()

        if 'status' in request.json:
            options['status'] = request.json['status']
        if 'type' in request.json:
            options['type'] = request.json['type']
        if 'mobile' in request.json:
            options['mobile'] = request.json['mobile']
        if 'phone' in request.json:
            options['phone'] = request.json['phone']
        if 'email' in request.json:
            options['email'] = request.json['email']
        if 'address' in request.json:
            options['address'] = request.json['address']
        if 'work_address' in request.json:
            options['work_address'] = request.json['work_address']
        if 'national_code' in request.json:
            options['national_code'] = request.json['national_code']
        if 'production_type' in request.json:
            options['production_type'] = request.json['production_type']
        if 'production_package' in request.json:
            options['production_package'] = request.json['production_package']
        if 'image' in request.json:
            options['image'] = request.json['image']

        user = pyro_server.execute_ex(ticket, 'admin', 'security.user.create',
                                      {}, request.json['user_name'],
                                      request.json['password'],
                                      request.json['full_name'], **options)
        pyro_server.logoff(ticket, 'admin')

        user = user.get('result')
        return jsonify({
            "user_name":
            user.get('user_id'),
            "password":
            user.get('user_password'),
            "full_name":
            user.get('user_full_name'),
            "mobile":
            user.get('user_mobile'),
            "email":
            user.get('user_email'),
            "address":
            user.get('user_address'),
            "phone":
            user.get('user_phone'),
            "work_address":
            user.get('user_work_address'),
            "national_code":
            user.get('user_national_code'),
            "production_type":
            user.get('user_production_type'),
            "production_package":
            user.get('user_production_package'),
            "image":
            user.get('user_image')
        })
예제 #13
0
    def update_user():
        '''
        Updates!
        '''

        FlaskWebServicesSecurityManager.check_service_requirements(
            ['ticket', 'user_name'])
        FlaskWebServicesSecurityManager.check_user_name()

        options = FlaskWebServicesSecurityManager.get_service_options()

        if 'mobile' in request.json:
            options['mobile'] = request.json['mobile']
        if 'phone' in request.json:
            options['phone'] = request.json['phone']
        if 'email' in request.json:
            options['email'] = request.json['email']
        if 'address' in request.json:
            options['address'] = request.json['address']
        if 'work_address' in request.json:
            options['work_address'] = request.json['work_address']
        if 'national_code' in request.json:
            options['national_code'] = request.json['national_code']
        if 'production_type' in request.json:
            options['production_type'] = request.json['production_type']
        if 'production_package' in request.json:
            options['production_package'] = request.json['production_package']
        if 'image' in request.json:
            options['image'] = request.json['image']

        user = pyro_server.execute_ex(request.json['ticket'],
                                      request.json['user_name'],
                                      'security.user.update', {},
                                      request.json['user_name'], **options)

        user = user.get('result')
        return jsonify({
            "user_name":
            user.get('user_id'),
            "password":
            user.get('user_password'),
            "full_name":
            user.get('user_full_name'),
            "mobile":
            user.get('user_mobile'),
            "email":
            user.get('user_email'),
            "address":
            user.get('user_address'),
            "phone":
            user.get('user_phone'),
            "work_address":
            user.get('user_work_address'),
            "national_code":
            user.get('user_national_code'),
            "production_type":
            user.get('user_production_type'),
            "production_package":
            user.get('user_production_package'),
            "image":
            user.get('user_image')
        })
예제 #14
0
    def find_products():
        """
        Finds products!
        """

        FlaskWebServicesProductsManager.check_service_requirements(
            ['ticket', 'user_name'])
        options = FlaskWebServicesProductsManager.get_service_options()

        if 'from_creation_date' in request.json:
            options['from_creation_date'] = request.json['from_creation_date']
        if 'to_creation_date' in request.json:
            options['to_creation_date'] = request.json['to_creation_date']
        if 'from_price' in request.json:
            options['from_price'] = request.json['from_price']
        if 'to_price' in request.json:
            options['to_price'] = request.json['to_price']
        if 'name' in request.json:
            options['name'] = request.json['name']
        if 'size' in request.json:
            options['size'] = request.json['size']
        if 'brand' in request.json:
            options['brand'] = request.json['brand']
        if 'categories' in request.json:
            options['categories'] = request.json['categories']
        if 'age_categories' in request.json:
            options['age_categories'] = request.json['age_categories']
        if 'gender' in request.json:
            options['gender'] = request.json['gender']
        if 'include_out_of_stock' in request.json:
            options['include_out_of_stock'] = request.json[
                'include_out_of_stock']
        if 'wholesale_type' in request.json:
            options['wholesale_type'] = request.json['wholesale_type']
        if 'just_current_user' in request.json:
            options['just_current_user'] = request.json['just_current_user']
        if '__offset__' in request.json:
            options['__offset__'] = request.json['__offset__']
        if '__limit__' in request.json:
            options['__limit__'] = request.json['__limit__']

        products = \
            pyro_server.execute_ex(request.json['ticket'], request.json['user_name'], 'server.products.find', {},
                                   **options)

        products = products.get('result')
        return jsonify([{
            "id": p.get("product_id"),
            "name": p.get("product_name"),
            "category": p.get("product_category"),
            "image": p.get("product_image"),
            "age_category": p.get("product_age_category"),
            "comment": p.get("product_comment"),
            "creation_date": p.get("product_creation_date"),
            "price": float(p.get("product_price")),
            "gender": p.get("product_gender"),
            "wholesale_type": p.get("product_whole_sale_type"),
            "colors": p.get("product_colors"),
            "sizes": p.get("product_sizes"),
            "brands": p.get("product_brands")
        } for p in products])