Esempio n. 1
0
def get_blog_counts(p_id, CONTEXT={}, ENVIRO={}):
    q_str = """ select bc_views 
                from blog_counter where bc_blog_id = %(id)s  """

    _rec = m.run_sql_command(ENVIRO.get('CONN'), q_str, {'id': p_id})
    CONTEXT.update({'web_urls': m.build_url_links(_rec, ENVIRO=ENVIRO)})
    return True, CONTEXT
Esempio n. 2
0
def get_cats(POST,
             GET,
             ENVIRO,
             COOKIES,
             CLIENT_STATE,
             CONTEXT,
             TEMPLATE,
             TEMPLATE_ENGINE,
             CSB='',
             TEMPLATE_STACK={}):
    q_str = """ select  '?cat_id=' || cat_id::text as url, cat_short as Name, 
                cat_long || ' ' ||  coalesce(bc_count, 0)::text as LinkText
            from category 
                left join ( select count(*) as bc_count, 
                                bc_cat_id from blog_cats 
                                group by bc_cat_id ) bl
                    on bc_cat_id = cat_id 
    """

    _rec = m.run_sql_command(ENVIRO.get('CONN'), q_str)
    _cat = m.build_url_links(_rec,
                             p_url_path='',
                             p_app_command='view_category',
                             ENVIRO=ENVIRO)
    CONTEXT.update({'category': _cat})
    return True, CONTEXT
Esempio n. 3
0
def get_blog_view_counts(p_id, CONTEXT={}, ENVIRO={}):
    q_str = """ select blog_title as Name, 
                        blog_title || coalesce(bc_views, 0)::text as LinkText,
                        '?id='||blog_id::text as url
                from blog 
                    left join blog_counter on blog_id = bc_blog_id
                order by blog_counter desc limit 5  """

    _rec = m.run_sql_command(ENVIRO.get('CONN'), q_str)
    CONTEXT.update({'web_urls': m.build_url_links(_rec, ENVIRO=ENVIRO)})
    return True, CONTEXT
Esempio n. 4
0
def list_category(POST,
                  GET,
                  ENVIRO,
                  COOKIES,
                  CLIENT_STATE,
                  CONTEXT,
                  TEMPLATE,
                  TEMPLATE_ENGINE,
                  CSB='',
                  TEMPLATE_STACK={}):
    _key = -1
    if 'cat_id' in GET:
        _key = int(''.join(GET.get('cat_id', '-1')))
        _prev_id = int(''.join(GET.get('prev_id', '9999999999')))
        _count = int(''.join(GET.get('count', '-1')))
    elif 'cat_id' in POST:
        _key = int(''.join(POST.get('cat_id', '-1')))
        _prev_id = int(''.join(POST.get('prev_id', '9999999999')))
        _count = int(''.join(POST.get('count', '-1')))

    q_str = """ select  '?blog_id=' || blog_id::text as url, blog_title as Name, 
                Blog_title  as LinkText
            from blog, blog_cats 
                where bc_blog_id = blog_id 
                    and bc_cat_id = %(cat_id)s
                    and blog_id <= %(prev_id)s
                    ordered by blog_id desc 
                    limit by %(count)s)
    """
    _rec = m.run_sql_command(ENVIRO.get('CONN'), q_str, {
        'cat_id': _key,
        'prev_id': _prev_id,
        'count': _count
    })
    _list_arts = m.build_url_links(_rec,
                                   p_url_path='',
                                   p_app_command='view_category',
                                   ENVIRO=ENVIRO)
    CONTEXT.update({'list_articles': _list_arts})
    _rec = m.run_sql_command(
        ENVIRO.get('CONN'),
        "select cat_long from catergory where cat_id = %(cat_id)", {
            'cat_id': _key,
        })
    CONTEXT.update({'PAGE_NAME': "List of Blogs in " + _rec[0]['cat_long']})

    _ouput = TEMPLATE_ENGINE(pfile=TEMPLATE,
                             ptype='string',
                             pcontext=CONTEXT,
                             preturn_type='string',
                             pcache_path=ENVIRO.get(
                                 'TEMPLATE_CACHE_PATH_PRE_RENDER', ''))

    return True, _ouput, ENVIRO, CLIENT_STATE, COOKIES, CSB
Esempio n. 5
0
def get_older_post(p_id, CONTEXT={}, ENVIRO={}):
    q_str = """select '?blog_id=' ||  blog_id::text as url, blog_title as Name, 
            blog_title as LinkText
            from blog where
            blog_id < %(p_id)s order by 1 desc limit 1 ;

    """
    _rec = m.run_sql_command(ENVIRO.get('CONN'), q_str, {'p_id': p_id})
    if len(_rec) == 1:
        _tops = m.build_url_links(_rec,
                                  p_url_path='',
                                  p_app_command='view',
                                  p_escape=False,
                                  ENVIRO=ENVIRO)
        CONTEXT.update({'older': _tops[0]})
    else:
        CONTEXT.update({'older': 'no older posts'})
    return True, CONTEXT
Esempio n. 6
0
def get_top_post(CONTEXT={}, ENVIRO={}):

    q_str = """select '?id=' ||  blog_id::text as url, blog_title as Name, 
            blog_title || ' ' ||  coalesce(bc_views, 0)::text as LinkText
            from blog, blog_counter where
            blog_id = bc_blog_id 
            order by bc_views desc
            limit 5 
    """

    _rec = m.run_sql_command(ENVIRO.get('CONN'), q_str)
    _tops = m.build_url_links(_rec,
                              p_url_path='',
                              p_app_command='view',
                              p_escape=False,
                              ENVIRO=ENVIRO)
    CONTEXT.update({'tops': _tops})
    return True, CONTEXT