Example #1
0
def index():
    # app.logger.error( " ######################################################################## BASE " )
    """Renders the index template"""
    menus = fromcache('menuprincipal') or tocache(
        'menuprincipal',
        wordpress.exapi.getMenuItens(menu_slug='menu-principal'))
    try:
        vote_url = app.config['VOTACAO_URL']
    except KeyError:
        vote_url = ""
    try:
        vote_root = app.config['VOTACAO_ROOT']
    except KeyError:
        vote_root = ""
    try:
        vote_altura = app.config['VOTACAO_ALTURA']
    except KeyError:
        vote_altura = ""

    try:
        twitter_hash_cabecalho = twitts()
    except KeyError:
        twitter_hash_cabecalho = ""

    # pagepri = fromcache('pagepri')      or tocache('pagepri', wordpress.getPageByPath('prioridades'))
    pagepq = fromcache('pagepq') or tocache('pagepq',
                                            wordpress.getPageByPath('por-que'))
    # pageproc = fromcache('pageproc')    or tocache('pageproc', wordpress.getPageByPath('processo'))
    pagevot = fromcache('pagevot') or tocache(
        'pagevot', wordpress.getPageByPath('votacao'))
    pagehow = fromcache('pagehow') or tocache(
        'pagehow', wordpress.getPageByPath('como-funciona'))
    pageseg = fromcache('pageseg') or tocache(
        'pageseg', wordpress.getPageByPath('seguranca-2'))
    # pagesobre = fromcache('pagesobre')  or tocache('pagesobre', wordpress.getPageByPath('sobre'))

    return render_template(
        'index.html',
        wp=wordpress,
        sidebar=wordpress.getSidebar,
        # page_about=pagesobre,
        # page_pri=pagepri,
        page_pq=pagepq,
        pagevot=pagevot,
        # page_pro=pageproc,
        page_como=pagehow,
        page_seg=pageseg,
        menu=menus,
        reforma_voted=request.cookies.get('reforma_voted') or False,
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        VOTACAO_URL=vote_url,
        VOTACAO_ROOT=vote_root,
        VOTACAO_ALTURA=vote_altura,
    )
Example #2
0
def conselho():
    """Renders a wordpress page special"""
    path = 'conselho-comunicacao'
    # picday = wordpress.wpgd.getLastFromGallery(conf.GALLERIA_FOTO_DO_DIA_ID)
    page = fromcache("page-%s" % path) or tocache(
        "page-%s" % path, wordpress.getPageByPath(path))
    cmts = fromcache("cmts-page-%s" % path) or tocache(
        "cmts-page-%s" % path,
        wordpress.getComments(
            status='approve', post_id=page.data['id'], number=1000))
    try:
        twitter_hash_cabecalho = twitts()
    except KeyError:
        twitter_hash_cabecalho = ""
    menus = fromcache('menuprincipal') or tocache(
        'menuprincipal',
        wordpress.exapi.getMenuItens(menu_slug='menu-principal'))
    return render_template(
        'post.html',
        post=page,
        sidebar=wordpress.getSidebar,
        # picday=picday,
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        comments=cmts,
        show_comment_form=is_authenticated(),
        categoria_contribuicao_text=categoria_contribuicao_text,
        menu=menus)
Example #3
0
def index(page=0):
    sortby = request.values.get('sortby') or 'date'
    pagination, posts = fromcache('govescuta-posts-%s' % sortby) or \
                        tocache('govescuta-posts-%s' %sortby,
                                    wordpress.wpgove.getAudiencias(
                                            page=page,
                                            sortby=sortby,
                                            totalporpage='10'))
    how_to = fromcache('howtouse') or tocache(
        'howtouse', wordpress.getPageByPath('how-to-use-governo-escuta'))

    menus = fromcache('menuprincipal') or tocache(
        'menuprincipal',
        wordpress.exapi.getMenuItens(menu_slug='menu-principal'))
    try:
        twitter_hash_cabecalho = twitts()
    except:
        twitter_hash_cabecalho = ""

    return render_template(
        'govescuta.html',
        menu=menus,
        # sidebar=wordpress.getSidebar,
        pagination=pagination,
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        audiences=posts,
        sortby=sortby,
        how_to=getattr(how_to, 'content', ''),
    )
Example #4
0
def index(page=0):
    sortby = request.values.get('sortby') or 'date'
    pagination, posts = fromcache('govescuta-posts-%s' % sortby) or \
                        tocache('govescuta-posts-%s' %sortby,
                                    wordpress.wpgove.getAudiencias(
                                            page=page,
                                            sortby=sortby,
                                            totalporpage='10'))
    how_to = fromcache('howtouse') or tocache('howtouse', wordpress.getPageByPath('how-to-use-governo-escuta'))

    menus = fromcache('menuprincipal') or tocache('menuprincipal', wordpress.exapi.getMenuItens(menu_slug='menu-principal') )
    try:
        twitter_hash_cabecalho = twitts()
    except:
        twitter_hash_cabecalho = ""

    return render_template(
        'govescuta.html',
        menu=menus,
        # sidebar=wordpress.getSidebar,
        pagination=pagination,
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        audiences=posts,
        sortby=sortby,
        how_to=getattr(how_to, 'content', ''),)
Example #5
0
def index():
    # app.logger.error( " ######################################################################## BASE " )
    """Renders the index template"""
    menus = fromcache('menuprincipal') or tocache('menuprincipal', wordpress.exapi.getMenuItens(menu_slug='menu-principal') )
    try:
        vote_url = app.config['VOTACAO_URL']
    except KeyError:
        vote_url = ""
    try:
        vote_root = app.config['VOTACAO_ROOT']
    except KeyError:
        vote_root = ""
    try:
        vote_altura = app.config['VOTACAO_ALTURA']
    except KeyError:
        vote_altura = ""

    try:
        twitter_hash_cabecalho = twitts()
    except KeyError:
        twitter_hash_cabecalho = ""

    # pagepri = fromcache('pagepri')      or tocache('pagepri', wordpress.getPageByPath('prioridades'))
    pagepq = fromcache('pagepq')        or tocache('pagepq', wordpress.getPageByPath('por-que'))
    # pageproc = fromcache('pageproc')    or tocache('pageproc', wordpress.getPageByPath('processo'))
    pagevot = fromcache('pagevot')    or tocache('pagevot', wordpress.getPageByPath('votacao'))
    pagehow = fromcache('pagehow')      or tocache('pagehow', wordpress.getPageByPath('como-funciona'))
    pageseg = fromcache('pageseg')      or tocache('pageseg', wordpress.getPageByPath('seguranca-2'))
    # pagesobre = fromcache('pagesobre')  or tocache('pagesobre', wordpress.getPageByPath('sobre'))

    return render_template(
        'index.html', wp=wordpress,
        sidebar=wordpress.getSidebar,
        # page_about=pagesobre,
        # page_pri=pagepri,
        page_pq=pagepq,
        pagevot=pagevot,
        # page_pro=pageproc,
        page_como=pagehow,
        page_seg=pageseg,
        menu=menus,
        reforma_voted=request.cookies.get('reforma_voted') or False,
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        VOTACAO_URL=vote_url,
        VOTACAO_ROOT=vote_root,
        VOTACAO_ALTURA=vote_altura,
    )
Example #6
0
def sobre_gd():
    pagesobre = fromcache('pagesobre')  or tocache('pagesobre', wordpress.getPageByPath('sobre'))
    menus = fromcache('menuprincipal') or tocache('menuprincipal', wordpress.exapi.getMenuItens(menu_slug='menu-principal') )
    try:
        twitter_hash_cabecalho = twitts()
    except KeyError:
        twitter_hash_cabecalho = ""
    return render_template(
        'sobre.html', wp=wordpress,
        menu=menus,
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        sidebar=wordpress.getSidebar,
        page_about=pagesobre
    )
Example #7
0
def sobre_gd():
    pagesobre = fromcache('pagesobre') or tocache(
        'pagesobre', wordpress.getPageByPath('sobre'))
    menus = fromcache('menuprincipal') or tocache(
        'menuprincipal',
        wordpress.exapi.getMenuItens(menu_slug='menu-principal'))
    try:
        twitter_hash_cabecalho = twitts()
    except KeyError:
        twitter_hash_cabecalho = ""
    return render_template('sobre.html',
                           wp=wordpress,
                           menu=menus,
                           twitter_hash_cabecalho=twitter_hash_cabecalho,
                           sidebar=wordpress.getSidebar,
                           page_about=pagesobre)
Example #8
0
def pages(path):
    """Renders a wordpress page"""
    #Retorna a ultima foto inserida neste album.
    # picday = wordpress.wpgd.getLastFromGallery(conf.GALLERIA_FOTO_DO_DIA_ID)
    menus = fromcache('menuprincipal') or tocache('menuprincipal', wordpress.exapi.getMenuItens(menu_slug='menu-principal') )
    try:
        twitter_hash_cabecalho = twitts()
    except KeyError:
        twitter_hash_cabecalho = ""
    return render_template(
        'page.html',
        page=wordpress.getPageByPath(path),
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        sidebar=wordpress.getSidebar,
        # picday=picday
        menu=menus
    )
Example #9
0
def pages(path):
    """Renders a wordpress page"""
    #Retorna a ultima foto inserida neste album.
    # picday = wordpress.wpgd.getLastFromGallery(conf.GALLERIA_FOTO_DO_DIA_ID)
    menus = fromcache('menuprincipal') or tocache(
        'menuprincipal',
        wordpress.exapi.getMenuItens(menu_slug='menu-principal'))
    try:
        twitter_hash_cabecalho = twitts()
    except KeyError:
        twitter_hash_cabecalho = ""
    return render_template(
        'page.html',
        page=wordpress.getPageByPath(path),
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        sidebar=wordpress.getSidebar,
        # picday=picday
        menu=menus)
Example #10
0
def conselho():
    """Renders a wordpress page special"""
    path = 'conselho-comunicacao'
    # picday = wordpress.wpgd.getLastFromGallery(conf.GALLERIA_FOTO_DO_DIA_ID)
    page = fromcache("page-%s" %path) or tocache("page-%s" %path,  wordpress.getPageByPath(path) )
    cmts = fromcache("cmts-page-%s" %path) or tocache("cmts-page-%s" %path, wordpress.getComments(status='approve',post_id=page.data['id'], number=1000))
    try:
        twitter_hash_cabecalho = twitts()
    except KeyError:
        twitter_hash_cabecalho = ""
    menus = fromcache('menuprincipal') or tocache('menuprincipal', wordpress.exapi.getMenuItens(menu_slug='menu-principal') )
    return render_template(
        'post.html',
        post=page,
        sidebar=wordpress.getSidebar,
        # picday=picday,
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        comments=cmts,
        show_comment_form=is_authenticated(),
        categoria_contribuicao_text=categoria_contribuicao_text
        ,menu=menus
    )
Example #11
0
def results_page(path):
    page = fromcache("page-{0}".format(path)) or tocache(
        "page-{0}".format(path), wordpress.getPageByPath(path))
    return render_template('results_page.html', page=page)
Example #12
0
def govescuta_details(aid):
    """Renders an audience with its public template"""
    pagination, inst = fromcache('audiencia-escuta-%s' %str(aid)) or \
                       tocache('audiencia-escuta-%s' %str(aid),wordpress.wpgove.getAudiencias(postID=aid))
    how_to = fromcache('how-to-use-governo-escuta') or tocache(
        'how-to-use-governo-escuta',
        wordpress.getPageByPath('how-to-use-governo-escuta'))
    menus = fromcache('menuprincipal') or tocache(
        'menuprincipal',
        wordpress.exapi.getMenuItens(menu_slug='menu-principal'))
    try:
        twitter_hash_cabecalho = twitts()
    except:
        twitter_hash_cabecalho = ""

    category = None
    tag = None
    for cat in inst:
        category = cat['category']
        try:
            tag = cat['category_slug']
        except:
            tag = ""

    if category:
        pagination, posts = fromcache('audiencia-category-%s' % category) or \
                            tocache('audiencia-category-%s' % category,wordpress.getPostsByCategory(
                                       cat=category))
    else:
        pagination, posts = None, []

    try:
        if tag:
            photos = get_instagram_photos(tag)
        else:
            photos = None
    except:
        photos = None

    buzzes = AudiencePosts.query.get(aid).get_moderated_buzz()
    buzzesSelec = AudiencePosts.query.get(aid).get_last_published_notice()
    govescuta = True
    video_sources = {}
    audience = inst[0]
    if audience['video_sources']:
        for s in audience['video_sources']:
            if (s['format'].find(';') > 0):
                f = s['format'][0:s['format'].find(';')]
            else:
                f = s['format']
            video_sources[f] = s['url']
    return render_template(
        'audience.html',  #this template is from gd/audience
        # 'govescuta_edicaoanter.html',
        sources=video_sources,
        audiences=inst,
        referrals=posts,
        pagination=pagination,
        buzzes=buzzes,
        buzzesSelec=buzzesSelec,
        menu=menus,
        tag=tag,
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        govescuta=govescuta,
        photos=photos,
        how_to=getattr(how_to, 'content', ''),
    )
Example #13
0
File: webapp.py Project: calcwb/gd
def signup():
    """Renders the signup form"""

    if authapi.is_authenticated():
        return redirect(url_for('.profile'))

    # default_data=None
    ret_code = -1
    form = social(SignupForm)
    print "CADASTRANDO"
    #form = SignupForm()
    fromsocial = request.cookies.get('connect_type') in ('social_f','social_t')
    form.social = fromsocial

    print "VALIDANDO"
    if request.method == 'POST' and form.validate_on_submit():
        print "VALIDADO!"
        try:
            meta = form.meta
            dget = meta.pop
            if fromsocial:
                print "\nsenha fromsocial"
                password = ""
            else:
                password = dget('password')
                print "\nsenha", password

            # Finally, it's time to create the user
            email = dget('email')

            username = email
            if request.cookies.get('connect_type') == 'social_t':
                username = session['tmp_twitter_id']
            # if request.cookies.get('connect_type') == 'social_f':
            #     username = dget('fbid')
            #     print "FACEBOOK ID =", username

            user = authapi.create_user(
                dget('name'), username, password,
                email, form.meta,
                dget('receive_sms'), dget('receive_email') )

            if fromsocial:
                if request.cookies.get('connect_type') == 'social_t':
                    user.set_meta('twitter', session['tmp_twitter_id'])
                    user.set_meta('twitteruser', True)
                    dbsession.commit()
                if request.cookies.get('connect_type') == 'social_f':
                    user.set_meta('facebookuser', True)
                    dbsession.commit()

            utils.send_welcome_email(user)

            flash(_(u'Your user was registered with successful!'), 'alert-success')
            ret_code = 0
        except authapi.UserExists:
            flash( _(u'User already exists'), 'alert-error')
            ret_code = 1
        except authapi.UserExistsUnconfirmed:
            flash( _(u'User already exists, but need confirmation'), 'alert-error')
            ret_code = 4
        except authapi.EmailAddressExists:
            flash(_(u'The email address informed is being used by another person'), 'alert-error')
            ret_code = 2
    else:
        if request.method == 'POST' :
            print form.errors
            # for errorMessages, fieldName in enumerate(form.errors):
            #     print errorMessages, fieldName
            #     for err in errorMessages:
            #         # do something with your errorMessages for fieldName
            #         flash( "%s - %s" % (fieldName,err),'alert-error')
            flash(_(u'Correct the validation errors and resend'),'alert-error')
            ret_code = 3

    tos = fromcache('tossigin') or tocache('tossigin',wordpress.getPageByPath('tos'))
    rm = fromcache('moresigin') or tocache('moresigin',wordpress.getPageByPath('signup-read-more'))
    menus = fromcache('menuprincipal') or tocache('menuprincipal', wordpress.exapi.getMenuItens(menu_slug='menu-principal') )
    try:
        twitter_hash_cabecalho = utils.twitts()
    except KeyError:
        twitter_hash_cabecalho = ""

    return render_template(
        'signup.html', form=form,
        readmore=rm,tos=tos, menu=menus,
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        ret_code=ret_code
    )
Example #14
0
def page_json(path):
    """Returns a page data in the JSON format"""
    page = wordpress.getPageByPath(path)
    return dumps(page and page.data or None)
Example #15
0
def results_page(path):
    page = fromcache("page-{0}".format(path)) or tocache("page-{0}".format(path),wordpress.getPageByPath(path))
    return render_template('results_page.html', page=page)
Example #16
0
def govescuta_details(aid):
    """Renders an audience with its public template"""
    pagination, inst = fromcache('audiencia-escuta-%s' %str(aid)) or \
                       tocache('audiencia-escuta-%s' %str(aid),wordpress.wpgove.getAudiencias(postID=aid))
    how_to = fromcache('how-to-use-governo-escuta') or tocache('how-to-use-governo-escuta', wordpress.getPageByPath('how-to-use-governo-escuta'))
    menus = fromcache('menuprincipal') or tocache('menuprincipal', wordpress.exapi.getMenuItens(menu_slug='menu-principal') )
    try:
        twitter_hash_cabecalho = twitts()
    except:
        twitter_hash_cabecalho = ""

    category = None
    tag = None
    for cat in inst:
        category = cat['category']
        try:
            tag = cat['category_slug']
        except:
            tag = ""

    if category:
        pagination, posts = fromcache('audiencia-category-%s' % category) or \
                            tocache('audiencia-category-%s' % category,wordpress.getPostsByCategory(
                                       cat=category))
    else:
        pagination, posts = None, []

    try:
        if tag:
            photos = get_instagram_photos(tag)
        else:
            photos = None
    except:
        photos = None

    buzzes = AudiencePosts.query.get(aid).get_moderated_buzz()
    buzzesSelec = AudiencePosts.query.get(aid).get_last_published_notice()
    govescuta = True
    video_sources = {}
    audience = inst[0]
    if audience['video_sources']:
        for s in audience['video_sources']:
            if(s['format'].find(';') > 0):
                f = s['format'][0:s['format'].find(';')]
            else:
                f = s['format']
            video_sources[f] = s['url']
    return render_template(
        'audience.html', #this template is from gd/audience
        # 'govescuta_edicaoanter.html',
        sources=video_sources,
        audiences=inst,
        referrals=posts,
        pagination=pagination,
        buzzes = buzzes,
        buzzesSelec = buzzesSelec,
        menu=menus,
        tag=tag,
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        govescuta=govescuta,
        photos=photos,
        how_to=getattr(how_to, 'content', ''),
    )
Example #17
0
def page_json(path):
    """Returns a page data in the JSON format"""
    page = wordpress.getPageByPath(path)
    return dumps(page and page.data or None)
Example #18
0
def index():
    """Returns the last published audience page"""
    try:
        # current_app.logger.debug( "================================================ AUDIENCE" )
        # current_app.logger.debug( request.args )
        # current_app.logger.debug( 'facebook' in request.args )

        pagination, inst = fromcache("audiencia_ativa") or tocache(
            "audiencia_ativa",
            wordpress.wpgove.getAudiencias(ativa='s', perpage=1))
        how_to = fromcache("how_to_audience") or tocache(
            "how_to_audience",
            wordpress.getPageByPath('how-to-use-governo-escuta'))
        menus = fromcache('menuprincipal') or tocache(
            'menuprincipal',
            wordpress.exapi.getMenuItens(menu_slug='menu-principal'))

        if pagination == '0':
            pagination, inst = fromcache("audiencias") or tocache(
                "audiencias", wordpress.wpgove.getAudiencias(perpage=1))
            for postid in inst:
                aid = postid['ID']

            return redirect(url_for('govescuta.govescuta_details', aid=aid))

        for postid in inst:
            aid = postid['ID']

        buzzes = AudiencePosts.query.get(aid).get_moderated_buzz()
        buzzesSelec = AudiencePosts.query.get(aid).get_last_published_notice()
        govescuta = False
        category = None
        for cat in inst:
            category = cat['category']

        if category:
            pagination, posts = wordpress.getPostsByCategory(cat=category)
        else:
            pagination, posts = None, []

        try:
            facebook_comment_url = current_app.config['FACEBOOK_COMMENT_URL']
        except:
            facebook_comment_url = ""

        try:
            facebook_app_id = current_app.config['FACEBOOK_APP_ID']
        except:
            facebook_app_id = ""

        try:
            facebook_comment_moderators = current_app.config[
                'FACEBOOK_COMMENT_MODERATORS']
        except:
            facebook_comment_moderators = ""

        return render_template(
            'audience.html',
            audiences=inst,
            pagination=pagination,
            referrals=posts,
            buzzes=buzzes,
            govescuta=govescuta,
            menu=menus,
            facebook='facebook' in request.args,
            FACEBOOK_COMMENT_URL=facebook_comment_url,
            FACEBOOK_APP_ID=facebook_app_id,
            FACEBOOK_COMMENT_MODERATORS=facebook_comment_moderators,
            buzzesSelec=buzzesSelec,
            how_to=getattr(how_to, 'content', ''),
            #notice=inst.get_last_published_notice(),
        )
    except (AttributeError, NoResultFound):
        abort(404)
Example #19
0
def signup():
    """Renders the signup form"""

    if authapi.is_authenticated():
        return redirect(url_for('.profile'))

    # default_data=None
    ret_code = -1
    form = social(SignupForm)
    print "CADASTRANDO"
    #form = SignupForm()
    fromsocial = request.cookies.get('connect_type') in ('social_f','social_t')
    form.social = fromsocial

    print "VALIDANDO"
    if request.method == 'POST' and form.validate_on_submit():
        print "VALIDADO!"
        try:
            meta = form.meta
            dget = meta.pop
            if fromsocial:
                print "\nsenha fromsocial"
                password = ""
            else:
                password = dget('password')
                print "\nsenha", password

            # Finally, it's time to create the user
            email = dget('email')

            username = email
            if request.cookies.get('connect_type') == 'social_t':
                username = session['tmp_twitter_id']
            # if request.cookies.get('connect_type') == 'social_f':
            #     username = dget('fbid')
            #     print "FACEBOOK ID =", username

            user = authapi.create_user(
                dget('name'), username, password,
                email, form.meta,
                dget('receive_sms'), dget('receive_email') )

            if fromsocial:
                if request.cookies.get('connect_type') == 'social_t':
                    user.set_meta('twitter', session['tmp_twitter_id'])
                    user.set_meta('twitteruser', True)
                    dbsession.commit()
                if request.cookies.get('connect_type') == 'social_f':
                    user.set_meta('facebookuser', True)
                    dbsession.commit()

            utils.send_welcome_email(user)

            flash(_(u'Your user was registered with successful!'), 'alert-success')
            ret_code = 0
        except authapi.UserExists:
            flash( _(u'User already exists'), 'alert-error')
            ret_code = 1
        except authapi.UserExistsUnconfirmed:
            flash( _(u'User already exists, but need confirmation'), 'alert-error')
            ret_code = 4
        except authapi.EmailAddressExists:
            flash(_(u'The email address informed is being used by another person'), 'alert-error')
            ret_code = 2
    else:
        if request.method == 'POST' :
            print form.errors
            # for errorMessages, fieldName in enumerate(form.errors):
            #     print errorMessages, fieldName
            #     for err in errorMessages:
            #         # do something with your errorMessages for fieldName
            #         flash( "%s - %s" % (fieldName,err),'alert-error')
            flash(_(u'Correct the validation errors and resend'),'alert-error')
            ret_code = 3

    tos = fromcache('tossigin') or tocache('tossigin',wordpress.getPageByPath('tos'))
    rm = fromcache('moresigin') or tocache('moresigin',wordpress.getPageByPath('signup-read-more'))
    menus = fromcache('menuprincipal') or tocache('menuprincipal', wordpress.exapi.getMenuItens(menu_slug='menu-principal') )
    try:
        twitter_hash_cabecalho = utils.twitts()
    except KeyError:
        twitter_hash_cabecalho = ""

    return render_template(
        'signup.html', form=form,
        readmore=rm,tos=tos, menu=menus,
        twitter_hash_cabecalho=twitter_hash_cabecalho,
        sidebar=wordpress.getSidebar,
        ret_code=ret_code
    )
Example #20
0
def index():
    """Returns the last published audience page"""
    try:
        # current_app.logger.debug( "================================================ AUDIENCE" )
        # current_app.logger.debug( request.args )
        # current_app.logger.debug( 'facebook' in request.args )

        pagination, inst = fromcache("audiencia_ativa") or tocache("audiencia_ativa", wordpress.wpgove.getAudiencias(ativa='s',perpage=1))
        how_to = fromcache("how_to_audience") or tocache("how_to_audience", wordpress.getPageByPath('how-to-use-governo-escuta'))
        menus = fromcache('menuprincipal') or tocache('menuprincipal', wordpress.exapi.getMenuItens(menu_slug='menu-principal') )

        if pagination == '0':
            pagination, inst = fromcache("audiencias") or tocache("audiencias", wordpress.wpgove.getAudiencias(perpage=1))
            for postid in inst:
                aid = postid['ID']

            return redirect(url_for('govescuta.govescuta_details', aid=aid))

        for postid in inst:
            aid = postid['ID']

        buzzes = AudiencePosts.query.get(aid).get_moderated_buzz()
        buzzesSelec = AudiencePosts.query.get(aid).get_last_published_notice()
        govescuta = False
        category = None
        for cat in inst:
            category = cat['category']

        if category:
            pagination, posts = wordpress.getPostsByCategory(
                cat=category)
        else:
            pagination, posts = None, []

        try:
            facebook_comment_url = current_app.config['FACEBOOK_COMMENT_URL']
        except:
            facebook_comment_url = ""

        try:
            facebook_app_id = current_app.config['FACEBOOK_APP_ID']
        except:
            facebook_app_id = ""

        try:
            facebook_comment_moderators = current_app.config['FACEBOOK_COMMENT_MODERATORS']
        except:
            facebook_comment_moderators = ""

        return render_template(
            'audience.html',
            audiences=inst,
            pagination=pagination,
            referrals=posts,
            buzzes = buzzes,
            govescuta = govescuta,
            menu=menus,
            facebook = 'facebook' in request.args,
            FACEBOOK_COMMENT_URL = facebook_comment_url,
            FACEBOOK_APP_ID = facebook_app_id,
            FACEBOOK_COMMENT_MODERATORS = facebook_comment_moderators,
            buzzesSelec = buzzesSelec,
            how_to=getattr(how_to, 'content', ''),
           #notice=inst.get_last_published_notice(),
        )
    except (AttributeError, NoResultFound):
        abort(404)