コード例 #1
0
def homepage():
    category_slug = flask.request.args.get("category")

    category = None
    sticky_posts, _, _ = helpers.get_formatted_expanded_posts(sticky=True)
    featured_posts = sticky_posts[:3] if sticky_posts else None
    page = helpers.to_int(flask.request.args.get("page"), default=1)
    posts_per_page = 12

    upcoming_categories = api.get_categories(slugs=["events", "webinars"])
    upcoming_category_ids = []

    for upcoming_category_id in upcoming_categories:
        upcoming_category_ids.append(upcoming_category_id["id"])

    upcoming_events, _, _ = helpers.get_formatted_expanded_posts(
        per_page=3, category_ids=upcoming_category_ids
    )

    if category_slug:
        categories = api.get_categories(slugs=[category_slug])

        if categories:
            category = categories[0]

    posts, total_posts, total_pages = helpers.get_formatted_expanded_posts(
        per_page=posts_per_page,
        category_ids=[category["id"]] if category else [],
        page=page,
        sticky=False,
    )

    # Manipulate the posts to add a newsletter placeholder
    if page == 1:
        print("page: " + str(page))
        posts.insert(2, "newsletter")
        posts.pop(11)

    return flask.render_template(
        "index.html",
        posts=posts,
        category=category,
        current_page=page,
        total_posts=total_posts,
        total_pages=total_pages,
        featured_posts=featured_posts,
        upcoming_events=upcoming_events,
    )
コード例 #2
0
def upcoming():
    page = helpers.to_int(flask.request.args.get('page'), default=1)
    posts_per_page = 12

    upcoming_categories = api.get_categories(slugs=['events', 'webinars'])
    upcoming_category_ids = []

    for upcoming_category_id in upcoming_categories:
        upcoming_category_ids.append(upcoming_category_id['id'])

    upcoming_events, _, _ = helpers.get_formatted_expanded_posts(
        per_page=3,
        category_ids=upcoming_category_ids
    )

    posts, total_posts, total_pages = helpers.get_formatted_expanded_posts(
        per_page=posts_per_page,
        category_ids=upcoming_category_ids,
        page=page
    )

    return flask.render_template(
        'upcoming.html',
        posts=posts,
        current_page=page,
        total_posts=total_posts,
        total_pages=total_pages
    )
コード例 #3
0
def alternate_homepage():
    category_slug = flask.request.args.get('category')

    category = None
    sticky_posts, _, _ = helpers.get_formatted_expanded_posts(sticky=True)
    featured_posts = sticky_posts[:3] if sticky_posts else None
    page = helpers.to_int(flask.request.args.get('page'), default=1)
    posts_per_page = 12

    if category_slug:
        categories = api.get_categories(slugs=[category_slug])

        if categories:
            category = categories[0]

    posts, total_posts, total_pages = helpers.get_formatted_expanded_posts(
        per_page=posts_per_page,
        category_ids=[category['id']] if category else [],
        page=page,
        sticky=False
    )

    return flask.render_template(
        'alternate_index.html',
        posts=posts,
        category=category,
        current_page=page,
        total_posts=total_posts,
        total_pages=total_pages,
        featured_posts=featured_posts
    )
コード例 #4
0
def archives():
    page = helpers.to_int(flask.request.args.get('page'), default=1)
    year = helpers.to_int(flask.request.args.get('year'))
    month = helpers.to_int(flask.request.args.get('month'))
    group_slug = flask.request.args.get('group')
    category_slug = flask.request.args.get('category')

    if month and month > 12:
        month = None

    friendly_date = None
    group = None
    after = None
    before = None

    if year:
        if month:
            after = datetime(year=year, month=month, day=1)
            before = after + relativedelta(months=1)
            friendly_date = after.strftime('%B %Y')
        if not month:
            after = datetime(year=year, month=1, day=1)
            before = after + relativedelta(years=1)
            friendly_date = after.strftime('%Y')

    if group_slug:
        groups = api.get_groups(slugs=[group_slug])

        if groups:
            group = groups[0]

    if category_slug:
        categories = api.get_categories(slugs=[category_slug])
        category_ids = [category['id'] for category in categories]
    else:
        categories = []
        category_ids = []

    posts, total_posts, total_pages = helpers.get_formatted_posts(
        page=page,
        after=after,
        before=before,
        group_ids=[group['id']] if group else [],
        category_ids=category_ids if category_ids else [],
    )

    return flask.render_template(
        'archives.html',
        categories=categories,
        category_ids=category_ids,
        category_slug=category_slug if category_slug else None,
        current_page=page,
        friendly_date=friendly_date,
        group=group,
        now=datetime.now(),
        posts=posts,
        total_pages=total_pages,
        total_posts=total_posts,
    )
コード例 #5
0
def homepage():
    category_slug = flask.request.args.get('category')

    category = None
    sticky_posts, _, _ = helpers.get_formatted_expanded_posts(sticky=True)
    featured_posts = sticky_posts[:3] if sticky_posts else None
    page = helpers.to_int(flask.request.args.get('page'), default=1)
    posts_per_page = 12

    upcoming_categories = api.get_categories(slugs=['events', 'webinars'])
    upcoming_category_ids = []

    for upcoming_category_id in upcoming_categories:
        upcoming_category_ids.append(upcoming_category_id['id'])

    upcoming_events, _, _ = helpers.get_formatted_expanded_posts(
        per_page=3,
        category_ids=upcoming_category_ids
    )

    if category_slug:
        categories = api.get_categories(slugs=[category_slug])

        if categories:
            category = categories[0]

    posts, total_posts, total_pages = helpers.get_formatted_expanded_posts(
        per_page=posts_per_page,
        category_ids=[category['id']] if category else [],
        page=page,
        sticky=False
    )

    return flask.render_template(
        'index.html',
        posts=posts,
        category=category,
        current_page=page,
        total_posts=total_posts,
        total_pages=total_pages,
        featured_posts=featured_posts,
        upcoming_events=upcoming_events
    )
コード例 #6
0
    def test_get_categories_values(self):
        _calling_method()
        response = api.get_categories()
        categories = response.json()
        expected_values = [{"id": 1, "name": "Sci-Fi"},
                           {"id": 2, "name": "Politics"},
                           {"id": 3, "name": "Tech"}]

        for category in categories:
            e_value = expected_values[category.get("id") - 1]
            self.assertEqual(e_value.get("name"), category.get("name"), f"Error with {e_value}")
コード例 #7
0
def _group_view(group_slug, page_slug, template):
    """
    View function which gets all posts for a given group slug,
    and returns a response loading those posts with the template provided
    """

    page = int(flask.request.args.get('page') or '1')
    category_slug = flask.request.args.get('category')

    groups = api.get_groups(slugs=[group_slug])
    category = None

    if not groups:
        flask.abort(404)

    group = groups[0]

    if category_slug:
        categories = api.get_categories(slugs=[category_slug])

        if categories:
            category = categories[0]

    posts, total_posts, total_pages = helpers.get_formatted_expanded_posts(
        group_ids=[group['id']],
        category_ids=[category['id']] if category else [],
        page=page,
        per_page=12
    )

    return flask.render_template(
        template,
        posts=posts,
        group=group,
        category=category if category_slug else None,
        current_page=page,
        page_slug=page_slug,
        total_posts=total_posts,
        total_pages=total_pages,
    )
コード例 #8
0
def alternate_homepage():
    category_slug = flask.request.args.get('category')

    category = None
    sticky_posts, _, _ = helpers.get_formatted_expanded_posts(sticky=True)
    featured_posts = sticky_posts[:3] if sticky_posts else None
    page = helpers.to_int(flask.request.args.get('page'), default=1)
    posts_per_page = 13 if page == 1 else 12

    if category_slug:
        categories = api.get_categories(slugs=[category_slug])

        if categories:
            category = categories[0]

    posts, total_posts, total_pages = helpers.get_formatted_expanded_posts(
        per_page=posts_per_page,
        category_ids=[category['id']] if category else [],
        page=page
    )

    if featured_posts:
        for post in featured_posts:
            if post in posts:
                posts.remove(post)

    return flask.render_template(
        'alternate_index.html',
        posts=posts,
        category=category,
        current_page=page,
        total_posts=total_posts,
        total_pages=total_pages,
        featured_posts=featured_posts,
        webinars=feeds.get_rss_feed_content(
            'https://www.brighttalk.com/channel/6793/feed'
        )
    )
コード例 #9
0
ファイル: main.py プロジェクト: boudabass/RTBF
def list_categories(params):
    
    listing = []
    
    categories = api.get_categories()

    if categories:
        for item in categories:
            li = category_to_kodi_item(item)
            listing.append(li)  # Item label
        
    sortable_by = (
        xbmcplugin.SORT_METHOD_LABEL
    )

    return common.plugin.create_listing(
        listing,
        #succeeded = True, #if False Kodi won’t open a new listing and stays on the current level.
        #update_listing = False, #if True, Kodi won’t open a sub-listing but refresh the current one. 
        #cache_to_disk = True, #cache this view to disk.
        #sort_methods = sortable_by, #he list of integer constants representing virtual folder sort methods.
        #view_mode = None, #a numeric code for a skin view mode. View mode codes are different in different skins except for 50 (basic listing).
        #content = None #string - current plugin content, e.g. ‘movies’ or ‘episodes’.
    )
コード例 #10
0
ファイル: menu.py プロジェクト: BASBK/ChefBot
def category_menu():
    user_markup = types.ReplyKeyboardMarkup(True, False)
    for row in api.get_categories():
        user_markup.add(row)
    return user_markup
コード例 #11
0
def handle_text(message):
    if not User.exists(chatID=message.chat.id):
        User(chatID=message.chat.id,
             username=message.from_user.username,
             state=config.STATE_START)
        bot.send_message(message.chat.id,
                         '👨‍🍳 Приветствую! Что желаете откушать?',
                         reply_markup=menu.category_menu())
    elif User[
            message.chat.
            id].state == config.STATE_START and message.text in api.get_categories(
            ):
        User[message.chat.id].state = message.text
        bot.send_message(message.chat.id,
                         '🚚 А вот и все доставочки, выбирай!',
                         reply_markup=menu.goto_home_menu())
        send_deliveries(message)
    elif message.text == '🛍 На главную':
        User[message.chat.id].state = config.STATE_START
        bot.send_message(message.chat.id,
                         '👨‍🍳 Приветствую! Что желаете откушать?',
                         reply_markup=menu.category_menu())
    elif message.text == '🛒 Корзина':
        User[message.chat.id].state = config.STATE_IN_CART
        send_cart(message)
    elif message.text == '🍽 Добавить ещё еды!' and User[
            message.chat.id].state == config.STATE_IN_CART:
        User[message.chat.id].state = config.STATE_START
        bot.send_message(message.chat.id,
                         'Выбирай вкусняхи!',
                         reply_markup=menu.goto_cart_menu())
        send_menu(User[message.chat.id].in_menu, message.chat.id)
    elif message.text == '🗑 Очистить корзину' and User[
            message.chat.id].state == config.STATE_IN_CART:
        User[message.chat.id].state = config.STATE_START
        api.clear_cart(message.from_user.username)
        bot.send_message(message.chat.id,
                         'Приветствую! Что желаете откушать?',
                         reply_markup=menu.category_menu())
    elif message.text == '✅ Оформить заказ' and User[
            message.chat.id].state == config.STATE_IN_CART:
        User[message.chat.id].state = config.STATE_CHECKOUT
        bot.send_message(
            message.chat.id,
            'Отлично, рассказывай где находишься!\nЖми кнопку внизу и подожди немного, мы ищем тебя!',
            reply_markup=menu.send_location_menu())
    elif message.text == '👍 Всё правильно, я тут' and User[
            message.chat.id].state == config.STATE_OBTAIN_GPS_ADDRESS:
        User[message.chat.id].state = config.STATE_VALID_ADDRESS
        bot.send_message(
            message.chat.id,
            '✏️ Отлично, тогда напиши дополнительную информацию (подъезд, этаж, квартира)',
            reply_markup=telebot.types.ReplyKeyboardRemove())
    elif message.text == '👎 Не, не нашли вы меня' and User[
            message.chat.id].state == config.STATE_OBTAIN_GPS_ADDRESS:
        User[message.chat.id].state = config.STATE_INVALID_ADDRESS
        bot.send_message(
            message.chat.id,
            '📡💥 Эхх, значит наши спутники барахлят, напиши тогда свой полный адрес сам, пожалуйста',
            reply_markup=telebot.types.ReplyKeyboardRemove())
    elif User[message.chat.id].state == config.STATE_VALID_ADDRESS:
        User[message.chat.id].address_info += ', ' + message.text
        User[message.chat.id].state = config.STATE_OBTAIN_FULL_ADDRESS
        api.post_address(message.chat.id, message.from_user.username)
        order_confirmation(message)
    elif User[message.chat.id].state == config.STATE_INVALID_ADDRESS:
        User[message.chat.id].address_info = message.text
        User[message.chat.id].state = config.STATE_OBTAIN_FULL_ADDRESS
        api.post_address(message.chat.id, message.from_user.username)
        order_confirmation(message)
    elif message.text == '✅ Да, оформляем!' and User[
            message.chat.id].state == config.STATE_OBTAIN_FULL_ADDRESS:
        order = api.proceed_checkout(message.from_user.username)
        bot.send_message(message.chat.id,
                         'Всё готово! Номер заказа: ' +
                         str(order['order_number']),
                         reply_markup=menu.goto_home_menu())
        send_to_cook(order)
    elif message.text == '❌ Отмена' and User[
            message.chat.id].state == config.STATE_OBTAIN_FULL_ADDRESS:
        User[message.chat.id].state = config.STATE_START
        bot.send_message(message.chat.id,
                         '👨‍🍳 Приветствую! Что желаете откушать?',
                         reply_markup=menu.category_menu())
コード例 #12
0
 def test_get_categories_successful_200(self):
     _calling_method()
     response = api.get_categories()
     self.assertEqual(200, response.status_code)