Ejemplo n.º 1
0
 def post(self):
     user = get_user_from_id(session['user_id'])
     if int(request.json['folder_id']) not in get_user_folders(user):
         return abort(403, message='Access is denied', status=403)
     new_sticker = Sticker(**request.json)
     db.session.add(new_sticker)
     db.session.commit()
     return {'sticker': new_sticker.as_json(), 'user_id': user.id}, 201
Ejemplo n.º 2
0
	def setUp(self):
		self.user = User(username='******',email='*****@*****.**')
		self.user.set_password('testpass')
		self.user.save()
		self.sticker = Sticker(name='t1')
		self.sticker.save()
		date_time = datetime.datetime.utcnow().replace(tzinfo=utc)
		self.order = Order(date_time=date_time, user=self.user)
		self.order.save()
Ejemplo n.º 3
0
async def delete_sticker(message: types.Message, state: FSMContext):
    if not message.text.isdigit():
        await message.answer('id состоит из цифр если что))')
        return
    try:
        Sticker.get(id=message.text).delete_instance()
    except Sticker.DoesNotExist:
        await message.answer(f'стикера с id: {message.text} - не существует')
        return
    await state.finish()
    await message.answer('Стикер успешно удален',
                         reply_markup=Markup.after_cancel())
Ejemplo n.º 4
0
async def create_sticker(message: types.Message, state: FSMContext):
    if Sticker.select().where(
            Sticker.stick_uniq == message.sticker.file_unique_id):
        await message.answer('Такой стикер уже существует')
        stick = Sticker.get(stick_uniq=message.sticker.file_unique_id)
        await send_stick(message, stick)
        state.finish()
        return
    await state.update_data(sticker_id=message.sticker.file_id,
                            sticker_uniq_id=message.sticker.file_unique_id)
    await message.answer('Придумайте название для стикера',
                         reply_markup=Markup.every_state())
    await SSticker.name.set()
Ejemplo n.º 5
0
async def get_sticker(message: types.Message):
    try:
        stick = Sticker.get(stick_uniq=message.sticker.file_unique_id)
    except Sticker.DoesNotExist:
        await message.answer('К сожелению такова стикера нету')
        return
    await send_stick(message, stick)
Ejemplo n.º 6
0
async def all_stickers(message: types.Message):
    stickers = Sticker.select()
    if not stickers:
        await message.answer('Ещё не существует ни одного стикера')
        return
    for stick in stickers:
        await send_stick(message, stick)
Ejemplo n.º 7
0
def all_sticker(bot, update):
    user_id = update.message.from_user.id

    userSessionObject = check_session(user_id, STICKER_ADD_WAITING_STATE)
    if userSessionObject:
        tag_id = userSessionObject.tag_id

        stickerObject = Sticker(sticker_uuid=update.message.sticker.file_id,
                                user_id=userSessionObject.user_id,
                                tag_id=userSessionObject.tag_id)
        database.add_sticker(stickerObject)

        update.message.reply_text("Sticker added!\nContinue sending to add more!\n\n/end : exit bot", parse_mode=ParseMode.MARKDOWN)

        database.update_session(user_id, STICKER_ADD_WAITING_STATE, tag_id)

    
    userSessionObject = check_session(user_id, STICKER_DELETE_WAITING_STATE)
    if userSessionObject:
        sticker_to_delete_uuid = update.message.sticker.file_id
        tag_id = userSessionObject.tag_id

        database.delete_sticker_by_userid_and_tagid_stickeruuid(user_id, tag_id, sticker_to_delete_uuid)

        update.message.reply_text("Sticker deleted!\nContinue sending to delete more!\n\n/end : exit bot", parse_mode=ParseMode.MARKDOWN)

        database.update_session(user_id, STICKER_DELETE_WAITING_STATE, tag_id)

    return
Ejemplo n.º 8
0
async def name_sticker(message: types.Message, state: FSMContext):
    slen = Sticker.name.max_length
    if len(message.text) > slen:
        await message.answer(
            f'Минимальная длинна названия стикера - {slen} символов')
        return
    data = await state.get_data()
    name = message.text[0].upper() + message.text[1:]
    user = User.get(chat_id=message.chat.id)
    Sticker.create(sticker=data['sticker_id'],
                   stick_uniq=data['sticker_uniq_id'],
                   name=name,
                   author=user)
    await state.finish()
    await message.answer(f'Стикер {name} создан успешно\nid:')
    await message.answer(Sticker.get(stick_uniq=data['sticker_uniq_id']).id)
    await message.answer_sticker(data['sticker_id'],
                                 reply_markup=Markup.after_cancel())
Ejemplo n.º 9
0
async def del_sticker(message: types.Message):
    try:
        user = User.get(chat_id=message.chat.id)
    except User.DoesNotExist:
        await message.answer('Вам нужен профиль для создания стикера')
        return
    for stick in Sticker.select().where(Sticker.author == user):
        await message.answer(f'id: {stick.id}')
        await send_stick(message, stick)
    await message.answer('Напишите id стикера для удаления',
                         reply_markup=Markup.every_state())
    await SSticker.delete.set()
Ejemplo n.º 10
0
class OrderItemTest(TestCase):
	def setUp(self):
		self.user = User(username='******',email='*****@*****.**')
		self.user.set_password('testpass')
		self.user.save()
		self.sticker = Sticker(name='t1')
		self.sticker.save()
		date_time = datetime.datetime.utcnow().replace(tzinfo=utc)
		self.order = Order(date_time=date_time, user=self.user)
		self.order.save()

	def test_order_item(self):
		orderItem = OrderItem(sticker=self.sticker, order=self.order)
		orderItem.save()

		self.assertEqual(orderItem, OrderItem.objects.get(order=self.order.id))

	def test_relation(self):
		uid = self.user.id
		User.objects.get(pk=self.user.id).delete()

		self.assertEqual(len(Order.objects.filter(user=uid)), 0)