예제 #1
0
 def get_one(self, id):
     category = self._get_record_by_id(model=Category, id=id)
     result = category.output()
     for index, image_id in enumerate(category.images):
         image = Image.objects(id=image_id).first()
         result['images'][index] = image.url
     return result
예제 #2
0
    def get_one(self, id=None, slug=None):
        if not id and not slug:
            raise InvalidRequestParams('Must pass atleast code or slug!')

        params = dict(deleted=False)

        if id:
            params['id'] = id

        else:
            params['slug'] = slug

        product = Sim.objects(**params).first()
        if not product:
            raise InvalidRequestParams('Product not found!')
        product_output = product.output()
        print('product_output', product_output)

        image_id = product.image_id
        if image_id:
            image = Image.objects(id=image_id).first()
            print('image', image)
            product_output['image'] = image.url

        return product.output()
예제 #3
0
    def list(self, page, per_page, order, categories=None, search_text=None, statuses=None, is_sale_off=None):
        params = dict()
        if categories:
            params['category_id__in'] = categories

        if statuses:
            params['status__in'] = statuses

        matches = Product.objects(**params)

        if is_sale_off:
            matches = matches.filter(__raw__={'promotion_package_id': {'$ne': None}})

        if search_text:
            search_text_query = Q(slug__contains=slugify(search_text)) | \
                                Q(code__contains=search_text)
            matches = matches.filter(search_text_query)
        matches = matches.order_by(order)
        total = matches.count(True)

        result = []

        for product in matches.paginate(page=page, per_page=per_page).items:
            product_output = product.output()
            for index, image_id in enumerate(product.images):
                image = Image.objects(id=image_id).first()
                product_output['images'][index] = image.url

            if product.promotion_package_id:
                promotion_package = PromotionPackage.objects(id=product.promotion_package_id).first()
                product_output['sale_off_value'] = promotion_package.sale_off_value
            result.append(product_output)

        return dict(total=total, result=result)
예제 #4
0
    def get(self, id=None, slug=None):
        if not id and not slug:
            raise InvalidRequestParams('Must pass atleast code or slug!')

        params = dict(
            deleted=False
        )

        if id:
            params['id'] = id

        else:
            params['slug'] = slug

        product = Product.objects(**params).first()

        if not product:
            raise InvalidRequestParams('Product not found!')

        result = product.output()
        for index, image_id in enumerate(product.images):
            image = Image.objects(id=image_id).first()
            result['images'][index] = image.url

        if product.promotion_package_id:
            promotion_package = PromotionPackage.objects(id=product.promotion_package_id).first()
            result['sale_off_value'] = promotion_package.sale_off_value

        return result
예제 #5
0
 def delete(self, id):
     banner = self._get_record_by_id(id=id, model=Banner)
     for image_id in banner.images:
         image = Image.objects(id=image_id).first()
         image.delete()
     banner.delete()
     return dict(success=True)
예제 #6
0
 def delete(self, id):
     post = self._get_record_by_id(id=id, model=Post)
     images = Image.objects(object_id=post.id, object_type='post')
     for image in images:
         uploader.remove(image.path)
     images.delete()
     post.delete()
     return dict(success=True)
예제 #7
0
    def create(self, name, category_id, banner):
        post = Post()
        post.name = name
        post.category_id = category_id
        post.banner = banner
        post.create()

        post_output = post.output()
        if banner:
            image = Image.objects(id=banner).first()
            post_output['image'] = image.url
        return post_output
예제 #8
0
    def get_one(self, product_id):
        product = WifiProduct.objects(id=product_id).first()
        if not product:
            return dict(message=False)

        product_output = product.output()
        image_id = product.image
        # for index, image_id in enumerate(product.image):
        if image_id:
            image = Image.objects(id=image_id).first()
            product_output['image'] = image.url

        return product_output
예제 #9
0
 def list(self, page, per_page, order, name=None):
     params = dict()
     if name:
         params['slug__contains'] = slugify(name)
     matches = Banner.objects(**params).order_by(order)
     total = matches.count(True)
     result = []
     for banner in matches.paginate(page=page, per_page=per_page).items:
         banner_output = banner.output()
         for index, image_id in enumerate(banner.images):
             image = Image.objects(id=image_id).first()
             banner_output['images'][index] = image.url
         result.append(banner_output)
     return dict(result=result, total=total)
예제 #10
0
    def create(self, owned, day_used, price, image_id, country):
        product = SimProduct(owned=owned,
                             day_used=day_used,
                             price=price,
                             image=image_id,
                             country=country)
        product.create()
        product.save()

        product_output = product.output()
        image_id = product.image
        if image_id:
            image = Image.objects(id=image_id).first()
            product_output['image'] = image.url
        return product_output
예제 #11
0
    def create(self, name, price, category, image_id, country, owned,
               day_used):
        product = Sim(name=name,
                      price=price,
                      category=category,
                      image_id=image_id,
                      country=country,
                      owned=owned,
                      day_used=day_used)
        product.create()
        product.save()
        product_output = product.output()

        image_id = product.image_id
        if image_id:
            image = Image.objects(id=image_id).first()
            product_output['image'] = image.url

        return product.output()
예제 #12
0
        def get_one(self, id=None, slug=None):
            if not id and not slug:
                raise InvalidRequestParams('Must pass atleast id or slug!')

            if id:
                post = self._get_record_by_id(model=Post, id=id)

            else:
                post = Post.objects(slug=slug).first()

            if not post:
                return dict()

            result = post.output()
            for index, image_id in enumerate(post.images):
                image = Image.objects(id=image_id).first()
                result['images'][index] = image.url

            return result
예제 #13
0
        def list(self, page, per_page, order, search_text=None, categories=None):
            params = dict()
            if categories:
                params['category_id__in'] = categories

            if search_text:
                params['slug__contains'] = slugify(search_text)

            matches = Post.objects(**params).order_by(order)

            total = matches.count(True)
            result = []
            for post in matches.paginate(page=page, per_page=per_page).items:
                post_output = post.output()
                for index, image_id in enumerate(post.images):
                    image = Image.objects(id=image_id).first()
                    post_output['images'][index] = image.url
                result.append(post_output)
            return dict(total=total, result=result)
예제 #14
0
 def create(self, country, internet_name, connection, speed_download,
            speed_upload, information, prepayment, price_day, image_id, continent):
     product = WifiProduct(country=country,
                           internet_name=internet_name,
                           connection=connection,
                           speed_download=speed_download,
                           speed_upload=speed_upload,
                           information=information,
                           prepayment=prepayment,
                           price_day=price_day,
                           image=image_id,
                           continent=continent)
     product.create()
     product.save()
     product_output = product.output()
     image_id = product.image
     if image_id:
         image = Image.objects(id=image_id).first()
         product_output['image'] = image.url
     return product_output
예제 #15
0
    def list(self, page, per_page, order, search_text=None):
        matches = WifiProduct.objects()

        if search_text:
            search_text_query = Q(slug__contains=slugify(search_text)) | \
                                Q(code__contains=search_text)
            matches = matches.filter(search_text_query)
        matches = matches.order_by(order)
        total = matches.count(True)

        result = []

        for product in matches.paginate(page=page, per_page=per_page).items:
            product_output = product.output()
            image_id = product.image
            # for index, image_id in enumerate(product.image):
            if image_id:
                image = Image.objects(id=image_id).first()
            product_output['image'] = image.url
            result.append(product_output)

        return dict(total=total, result=result)