Exemple #1
0
    def create(self):
        title, price = self.required_params(['title', 'price'])
        user = account.get(self.user_id)
        longitude, latitude, place_ref, place_name, address = self.optional_params(
            [
                'longitude', 'latitude', 'place_ref', 'place_name',
                'formatted_address'
            ])
        new_item = ItemModel.create(self.user_id,
                                    title,
                                    price=price,
                                    loc=[longitude, latitude],
                                    place_name=place_name,
                                    place_ref=place_ref,
                                    address=address)

        if 'picture' in self.request.POST:
            extension = self.request.POST['picture'].filename.split('.')[-1]
            sha = hashlib.sha224('%s_%s_%s' % (new_item['id'], 0, '*&(##BD!@'))
            image_key = sha.hexdigest() + '.' + extension
            input_file = self.request.POST['picture'].file
            content_type = self.request.POST['picture'].type
            aws.s3_upload_file(
                input_file,
                content_type,
                image_key,
                'gleebox_items',
            )
            new_item['pictures'].append(image_key)
            new_item.save()

        return {'item': new_item.data}
Exemple #2
0
    def create(self):
        title, price = self.required_params(['title', 'price'])
        user = account.get(self.user_id)
        longitude, latitude, place_ref, place_name, address = self.optional_params(['longitude', 'latitude', 'place_ref', 'place_name', 'formatted_address'])
        new_item = ItemModel.create(self.user_id, title, price=price, loc=[longitude, latitude], place_name=place_name, place_ref=place_ref, address=address)

        if 'picture' in self.request.POST:
            extension = self.request.POST['picture'].filename.split('.')[-1]
            sha = hashlib.sha224('%s_%s_%s' % (new_item['id'], 0, '*&(##BD!@'))
            image_key = sha.hexdigest() + '.' + extension
            input_file = self.request.POST['picture'].file
            content_type = self.request.POST['picture'].type
            aws.s3_upload_file(input_file, content_type, image_key, 'gleebox_items',)
            new_item['pictures'].append(image_key)
            new_item.save()

        return {'item': new_item.data}
Exemple #3
0
    def get(self):
        item_id, = self.required_params(['item_id'])
        item_obj = ItemModel.find(item_id)

        return {'item': item_obj.data}
Exemple #4
0
    def get(self):
        item_id, = self.required_params(['item_id'])
        item_obj = ItemModel.find(item_id)

        return {'item': item_obj.data}