Move tutorial views into their own file.

This commit is contained in:
Tim Abbott
2015-11-23 20:02:46 -08:00
parent f77b0bdb43
commit 4d79083cf5
3 changed files with 44 additions and 31 deletions

View File

@@ -1004,35 +1004,6 @@ def get_profile_backend(request, user_profile):
return json_success(result) return json_success(result)
@authenticated_json_post_view
@has_request_variables
def json_tutorial_send_message(request, user_profile, type=REQ,
recipient=REQ, topic=REQ, content=REQ):
"""
This function, used by the onboarding tutorial, causes the Tutorial Bot to
send you the message you pass in here. (That way, the Tutorial Bot's
messages to you get rendered by the server and therefore look like any other
message.)
"""
sender_name = "welcome-bot@zulip.com"
if type == 'stream':
internal_send_message(sender_name, "stream", recipient, topic, content,
realm=user_profile.realm)
return json_success()
# For now, there are no PM cases.
return json_error('Bad data passed in to tutorial_send_message')
@authenticated_json_post_view
@has_request_variables
def json_tutorial_status(request, user_profile, status=REQ('status')):
if status == 'started':
user_profile.tutorial_status = UserProfile.TUTORIAL_STARTED
elif status == 'finished':
user_profile.tutorial_status = UserProfile.TUTORIAL_FINISHED
user_profile.save(update_fields=["tutorial_status"])
return json_success()
@require_realm_admin @require_realm_admin
@has_request_variables @has_request_variables
def update_realm(request, user_profile, name=REQ(validator=check_string, default=None), def update_realm(request, user_profile, name=REQ(validator=check_string, default=None),

42
zerver/views/tutorial.py Normal file
View File

@@ -0,0 +1,42 @@
from __future__ import absolute_import
from django.views.decorators.csrf import csrf_exempt
from zerver.decorator import authenticated_json_post_view, has_request_variables, REQ
from zerver.lib.actions import internal_send_message
from zerver.lib.response import json_error, json_success
from zerver.lib.validator import check_string
from zerver.models import UserProfile
from zerver.lib.rest import rest_dispatch as _rest_dispatch
rest_dispatch = csrf_exempt((lambda request, *args, **kwargs: _rest_dispatch(request, globals(), *args, **kwargs)))
@authenticated_json_post_view
@has_request_variables
def json_tutorial_send_message(request, user_profile, type=REQ,
recipient=REQ, topic=REQ, content=REQ):
"""
This function, used by the onboarding tutorial, causes the Tutorial Bot to
send you the message you pass in here. (That way, the Tutorial Bot's
messages to you get rendered by the server and therefore look like any other
message.)
"""
sender_name = "welcome-bot@zulip.com"
if type == 'stream':
internal_send_message(sender_name, "stream", recipient, topic, content,
realm=user_profile.realm)
return json_success()
# For now, there are no PM cases.
return json_error('Bad data passed in to tutorial_send_message')
@authenticated_json_post_view
@has_request_variables
def json_tutorial_status(request, user_profile, status=REQ('status')):
if status == 'started':
user_profile.tutorial_status = UserProfile.TUTORIAL_STARTED
elif status == 'finished':
user_profile.tutorial_status = UserProfile.TUTORIAL_FINISHED
user_profile.save(update_fields=["tutorial_status"])
return json_success()

View File

@@ -124,8 +124,8 @@ urlpatterns += patterns('zerver.views',
url(r'^json/fetch_api_key$', 'json_fetch_api_key'), url(r'^json/fetch_api_key$', 'json_fetch_api_key'),
url(r'^json/update_active_status$', 'json_update_active_status'), url(r'^json/update_active_status$', 'json_update_active_status'),
url(r'^json/get_active_statuses$', 'json_get_active_statuses'), url(r'^json/get_active_statuses$', 'json_get_active_statuses'),
url(r'^json/tutorial_send_message$', 'json_tutorial_send_message'), url(r'^json/tutorial_send_message$', 'tutorial.json_tutorial_send_message'),
url(r'^json/tutorial_status$', 'json_tutorial_status'), url(r'^json/tutorial_status$', 'tutorial.json_tutorial_status'),
url(r'^json/change_enter_sends$', 'user_settings.json_change_enter_sends'), url(r'^json/change_enter_sends$', 'user_settings.json_change_enter_sends'),
url(r'^json/get_profile$', 'json_get_profile'), url(r'^json/get_profile$', 'json_get_profile'),
url(r'^json/report_error$', 'report.json_report_error'), url(r'^json/report_error$', 'report.json_report_error'),