示例#1
0
def activity():
    '''
    View for the activity feed of recent events.
    '''

    events = get_latest_events()
    shared_message_form = SharedMessageForm()

    if request.method == 'POST':
        if not current_user.is_authenticated():
            flash(gettext(u'You must log in to post a message.'), 'error')
        elif not current_user.display_in_search:
            flash(gettext(u'We need your name before you can post a message.'),
                  'error')
        elif shared_message_form.validate():
            data = shared_message_form.message.data
            msg = SharedMessageEvent.from_user(current_user, message=data)
            db.session.add(msg)
            db.session.commit()
            flash(gettext(u'Message posted!'))
            return redirect(url_for('views.activity'))

    return render_template(
        'activity.html', **{
            'user': current_user,
            'events': events,
            'blog_posts': get_blog_posts(),
            'page_config_json': json_blob(LOADING_TEXT=gettext("Loading...")),
            'most_complete_profiles': User.get_most_complete_profiles(limit=5),
            'most_connected_profiles':
            User.get_most_connected_profiles(limit=5)
        })
示例#2
0
文件: views.py 项目: batusayici/noi2
def activity():
    """
    View for the activity feed of recent events.
    """

    events = Event.query_in_deployment().order_by(desc(Event.created_at)).limit(50).all()
    shared_message_form = SharedMessageForm()

    if request.method == "POST":
        if not current_user.is_authenticated():
            flash(gettext(u"You must log in to post a message."), "error")
        elif not current_user.display_in_search:
            flash(gettext(u"We need your name before you can post a message."), "error")
        elif shared_message_form.validate():
            data = shared_message_form.message.data
            msg = SharedMessageEvent.from_user(current_user, message=data)
            db.session.add(msg)
            db.session.commit()
            flash(gettext(u"Message posted!"))
            return redirect(url_for("views.activity"))

    return render_template(
        "activity.html",
        **{
            "user": current_user,
            "events": events,
            "most_complete_profiles": User.get_most_complete_profiles(limit=5),
            "most_connected_profiles": User.get_most_connected_profiles(limit=5),
        }
    )
示例#3
0
文件: views.py 项目: tekd/noi2
def activity():
    '''
    View for the activity feed of recent events.
    '''

    events = get_latest_events()
    shared_message_form = SharedMessageForm()

    if request.method == 'POST':
        if not current_user.is_authenticated():
            flash(gettext(u'You must log in to post a message.'), 'error')
        elif not current_user.display_in_search:
            flash(gettext(u'We need your name before you can post a message.'), 'error')
        elif shared_message_form.validate():
            data = shared_message_form.message.data
            msg = SharedMessageEvent.from_user(
                current_user,
                message=data
            )
            db.session.add(msg)
            db.session.commit()
            flash(gettext(u'Message posted!'))
            return redirect(url_for('views.activity'))

    return render_template('activity.html', **{
        'user': current_user,
        'events': events,
        'blog_posts': get_blog_posts(),
        'page_config_json': json_blob(
            LOADING_TEXT=gettext("Loading...")
        ),
        'most_complete_profiles': User.get_most_complete_profiles(limit=5),
        'most_connected_profiles': User.get_most_connected_profiles(limit=5)
    })
示例#4
0
文件: views.py 项目: GovLab/noi2
def activity():
    '''
    View for the activity feed of recent events.

    Note that we want anonymous users to be able to get a "sneak peek" at
    this page, so we allow them in; however, if the user has
    logged in but hasn't yet completed the registration process,
    we want them to finish it first.
    '''

    if (current_user.is_authenticated()
        and not current_user.has_fully_registered):
        return redirect(get_best_registration_step_url(current_user))

    if not session.get('activity_route_visited'):
        # reset tutorials if repeat_tutorials flag is set
        num_tutorials = 3
        if ('DISCOURSE_ENABLED' in current_app.jinja_env.globals):
            if (current_app.jinja_env.globals['DISCOURSE_ENABLED']):
                num_tutorials = 4
        if hasattr(current_user, 'repeat_tutorials'):
            if current_user.repeat_tutorials and current_user.tutorial_step > num_tutorials:
                current_user.tutorial_step = 1
                db.session.add(current_user)
                db.session.commit()


    events = get_latest_events()
    shared_message_form = SharedMessageForm()


    if request.method == 'POST':
        if not current_user.is_authenticated():
            flash(gettext(u'You must log in to post a message.'), 'error')
        elif not current_user.display_in_search:
            flash(gettext(u'We need your name before you can post a message.'), 'error')
        elif shared_message_form.validate():
            data = shared_message_form.message.data
            msg = SharedMessageEvent.from_user(
                current_user,
                message=data
            )
            db.session.add(msg)
            db.session.commit()
            flash(gettext(u'Message posted!'))
            return redirect(url_for('views.activity'))

    session['activity_route_visited'] = True;

    return render_template('activity.html', **{
        'user': current_user,
        'events': events,
        'blog_posts': get_blog_posts(),
        'page_config_json': json_blob(
            LOADING_TEXT=gettext("Loading...")
        ),
        'most_complete_profiles': User.get_most_complete_profiles(limit=5),
        'most_connected_profiles': User.get_most_connected_profiles(limit=5)
    })