Esempio n. 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)
        })
Esempio n. 2
0
 def test_posting_activity_requires_login(self):
     res = self.client.post('/activity', data=dict(
         message=u"hello there"
     ), follow_redirects=True)
     self.assert200(res)
     self.assertEqual(SharedMessageEvent.query_in_deployment().count(), 0)
     assert 'You must log in to post a message' in res.data
Esempio n. 3
0
File: views.py Progetto: 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)
    })
Esempio n. 4
0
 def test_posting_activity_requires_login(self):
     res = self.client.post('/activity',
                            data=dict(message=u"hello there"),
                            follow_redirects=True)
     self.assert200(res)
     self.assertEqual(SharedMessageEvent.query_in_deployment().count(), 0)
     assert 'You must log in to post a message' in res.data
Esempio n. 5
0
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),
        }
    )
Esempio n. 6
0
File: views.py Progetto: 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)
    })
Esempio n. 7
0
 def test_posting_activity_requires_full_name(self):
     self.login(first_name=u'', last_name=u'')
     res = self.client.post('/activity', data=dict(
         message=u"hello there"
     ), follow_redirects=True)
     self.assert200(res)
     self.assertEqual(SharedMessageEvent.query_in_deployment().count(), 0)
     assert 'We need your name before you can post' in res.data
Esempio n. 8
0
 def test_posting_activity_requires_full_name(self):
     self.login(first_name=u'', last_name=u'')
     res = self.client.post('/activity',
                            data=dict(message=u"hello there"),
                            follow_redirects=True)
     self.assert200(res)
     self.assertEqual(SharedMessageEvent.query_in_deployment().count(), 0)
     assert 'We need your name before you can post' in res.data
Esempio n. 9
0
 def test_posting_activity_works(self):
     self.login()
     user = User.query_in_deployment().filter(User.email == "*****@*****.**").one()
     user.first_name = "John"
     user.last_name = "Doe"
     res = self.client.post("/activity", data=dict(message=u"hello there"), follow_redirects=True)
     self.assert200(res)
     self.assertEqual(SharedMessageEvent.query_in_deployment().count(), 1)
     assert "Message posted" in res.data
     assert "hello there" in res.data
Esempio n. 10
0
 def test_posting_activity_works(self):
     self.login()
     user = User.query_in_deployment()\
              .filter(User.email == '*****@*****.**').one()
     user.first_name = 'John'
     user.last_name = 'Doe'
     res = self.client.post('/activity', data=dict(
         message=u"hello there"
     ), follow_redirects=True)
     self.assert200(res)
     self.assertEqual(SharedMessageEvent.query_in_deployment().count(), 1)
     assert 'Message posted' in res.data
     assert 'hello there' in res.data
Esempio n. 11
0
 def test_posting_activity_works(self):
     self.login()
     user = User.query_in_deployment()\
              .filter(User.email == '*****@*****.**').one()
     user.first_name = 'John'
     user.last_name = 'Doe'
     res = self.client.post('/activity',
                            data=dict(message=u"hello there"),
                            follow_redirects=True)
     self.assert200(res)
     self.assertEqual(SharedMessageEvent.query_in_deployment().count(), 1)
     assert 'Message posted' in res.data
     assert 'hello there' in res.data