예제 #1
0
def read_emojis():
    """
    find list of emojis for the agent
    :return:
    """
    emojis = Emoji.objects()
    if request.args.get('name'):
        emojis = emojis.filter(name__iexact=request.args.get('name'))

    if request.args.get('category'):
        category = Category.objects(
            name__iexact=request.args.get('category')).get()
        emojis = emojis.filter(category=category)

    if request.args.get('q'):
        emojis = emojis.filter(tags__icontains=request.args.get('q'))

    if request.args.get('isPaid'):
        emojis = emojis.filter(isPaid=True) if request.args.get(
            'isPaid').lower() == 'true' else emojis.filter(isPaid=False)

    if not emojis:
        return build_response.build_json([])

    response_emojis = []

    for emoji in emojis:
        obj_emoji = transpose_emoji(emoji)
        response_emojis.append(obj_emoji)

    return build_response.build_json(response_emojis)
예제 #2
0
def get_categories():
    '''
    For inserting the categories
    '''
    '''categories = ['Bollywood', 'Hollywood', 'Modern']
    for cat in categories:
        category = Category()
        category.name = cat
        category.save()

    return build_response.sent_ok()'''

    categories = Category.objects().order_by('name')
    if not categories:
        return build_response.build_json([])
    #return build_response.sent_json(emojis.to_json())

    response_categories = []

    for category in categories:
        obj_category = {
            'id': str(category.id),
            'name': category.name,
            'date_created': category.date_created.isoformat(),
            'date_modified': category.date_modified.isoformat()
        }
        response_categories.append(obj_category)

    return build_response.build_json(response_categories)
예제 #3
0
def find_categories():
    """
    find list of categories for the agent
    :return:
    """
    categories = Category.objects(status=1).order_by('name')
    if not categories:
        return build_response.build_json([])

    response_categories = []

    for category in categories:
        obj_category = transpose_category(category)
        response_categories.append(obj_category)
    return build_response.build_json(response_categories)
예제 #4
0
def save_emoji(emoji):

    # check if the post request has the file part
    if 'Image' in request.files:
        imageDirectory = os.path.join(app.config.get('APP_ROOT'), 'static',
                                      'uploads', 'emojis')
        # remove image file if it is update
        if emoji.imagefile is not None:
            try:
                os.remove(os.path.join(imageDirectory, emoji.imagefile))
            except OSError:
                pass

        file = request.files['Image']

        filename = secure_filename(file.filename)
        file.save(os.path.join(imageDirectory, filename))
        emoji.imagefile = filename

    if request.form.get("category"):
        category = Category.objects(name=request.form.get("category")).get()
        if category:
            emoji.category = category

    if request.form.get("tags"):
        tags_string = request.form.get("tags")
        tags = [x.strip() for x in tags_string.split(',')]
        emoji.tags = tags

    if request.form['isPaid'] == 'Paid':
        emoji.isPaid = True
    else:
        emoji.isPaid = False

    emoji.name = request.form['name']

    if request.form.get("description"):
        emoji.description = request.form['description']

    try:
        emoji_id = emoji.save()
        return {'emoji_id': str(emoji_id.id)}
    except Exception as e:
        return {'error': str(e)}
예제 #5
0
def find_emojis():
    """
    find list of emojis for the agent
    :return:
    """
    page_nb = int(request.args.get('pageNumber'))

    items_per_page = int(request.args.get('pageSize'))

    offset = (page_nb - 1) * items_per_page if page_nb > 0 else 0

    emojis = Emoji.objects()
    if request.args.get('name'):
        emojis = emojis.filter(name__iexact=request.args.get('name'))

    if request.args.get('category'):
        category = Category.objects(
            name__iexact=request.args.get('category')).get()
        emojis = emojis.filter(category=category)

    if request.args.get('q'):
        emojis = emojis.filter(tags__icontains=request.args.get('q'))

    if request.args.get('isPaid'):
        emojis = emojis.filter(isPaid=True) if request.args.get(
            'isPaid').lower() == 'true' else emojis.filter(isPaid=False)

    if not emojis:
        return build_response.build_json([])

    emojis = emojis.order_by('-date_modified')
    #emojis = skip( offset ).limit( items_per_page )

    response_emojis = []

    for emoji in emojis:
        obj_emoji = transpose_emoji(emoji)
        response_emojis.append(obj_emoji)

    return build_response.build_json({"payload": response_emojis})
예제 #6
0
def stickers():
    """
    return list  of stikers grouped by category
    :return:
    """
    strikers = []
    categories = Category.objects(status=1).order_by('displayOrder')

    for category in categories:
        emojis = Emoji.objects()
        emojis = emojis.filter(category=category)

        if request.args.get('q'):
            emojis = emojis.filter(tags__icontains=request.args.get('q'))

        emojis_list = []
        for emoji in emojis:
            obj_emoji = transpose_emoji(emoji)
            emojis_list.append(obj_emoji)

        categoryD = {
            'name':
            category.name,
            'icon':
            url_for('categories_file', path=category.imagefile,
                    _external=True),
            'stickers':
            emojis_list
        }

        strikers.append({"category": categoryD})

    isNewUser = True if (datetime.datetime.now() -
                         g.user.date_created).days <= 7 else False
    return build_response.build_json({
        'status': True,
        'isNewUser': isNewUser,
        'result': strikers
    })