Skip to content

Commit

Permalink
Extract zerver/lib/events.py from actions.py with event registration.
Browse files Browse the repository at this point in the history
This moves do_events_register, fetch_initial_state_data and friends to
a new file.

Modified significantly by tabbott for correctness and to remove unused
imports.

Fixes zulip#3635.
  • Loading branch information
saisrivathsa authored and timabbott committed Feb 11, 2017
1 parent 0564beb commit b867ac3
Show file tree
Hide file tree
Showing 9 changed files with 387 additions and 357 deletions.
3 changes: 2 additions & 1 deletion docs/events-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ dozens of queries to the database, caches, etc. over the course of
things together atomically. So instead, we use a more complicated
algorithm that can produce the atomic result from non-atomic
subroutines. Here's how it works when you make a `register` API
request. The request is directly handled by Django:
request; the logic is in `zerver/views/events_register.py` and
`zerver/lib/events.py`. The request is directly handled by Django:

* Django makes an HTTP request to Tornado, requesting that a new event
queue be created, and records its queue ID.
Expand Down
2 changes: 1 addition & 1 deletion docs/new-feature-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ realm. :
### Update application state

You then need to add code that will handle the event and update the
application state. In `zerver/lib/actions.py` update the
application state. In `zerver/lib/events.py` update the
`fetch_initial_state` and `apply_events` functions. :

def fetch_initial_state_data(user_profile, event_types, queue_id):
Expand Down
348 changes: 0 additions & 348 deletions zerver/lib/actions.py

Large diffs are not rendered by default.

374 changes: 374 additions & 0 deletions zerver/lib/events.py

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions zerver/tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
)

from zerver.lib.actions import (
apply_events,
bulk_remove_subscriptions,
do_add_alert_words,
check_add_realm_emoji,
Expand Down Expand Up @@ -59,9 +58,11 @@
do_change_enable_digest_emails,
do_add_realm_alias,
do_remove_realm_alias,
)
from zerver.lib.events import (
apply_events,
fetch_initial_state_data,
)

from zerver.lib.message import render_markdown
from zerver.lib.test_helpers import POSTRequestMock, get_subscription
from zerver.lib.test_classes import (
Expand Down
4 changes: 2 additions & 2 deletions zerver/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1969,8 +1969,8 @@ def test_home(self):
def _get_home_page(self, **kwargs):
# type: (**Any) -> HttpResponse
with \
patch('zerver.lib.actions.request_event_queue', return_value=42), \
patch('zerver.lib.actions.get_user_events', return_value=[]):
patch('zerver.lib.events.request_event_queue', return_value=42), \
patch('zerver.lib.events.get_user_events', return_value=[]):
result = self.client_get('/', dict(**kwargs))
return result

Expand Down
2 changes: 1 addition & 1 deletion zerver/views/events_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Text
from typing import Iterable, Optional, Sequence

from zerver.lib.actions import do_events_register
from zerver.lib.events import do_events_register
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
from zerver.lib.validator import check_string, check_list, check_bool
Expand Down
3 changes: 2 additions & 1 deletion zerver/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
PreregistrationUser, get_client, UserActivity, \
UserPresence, get_recipient, name_changes_disabled, email_to_username, \
list_of_domains_for_realm
from zerver.lib.events import do_events_register
from zerver.lib.actions import update_user_presence, do_change_tos_version, \
do_events_register, do_update_pointer, get_cross_realm_dicts, realm_user_count
do_update_pointer, get_cross_realm_dicts, realm_user_count
from zerver.lib.avatar import avatar_url
from zerver.lib.i18n import get_language_list, get_language_name, \
get_language_list_for_templates
Expand Down
3 changes: 2 additions & 1 deletion zerver/views/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
name_changes_disabled, email_to_username, \
completely_open, get_unique_open_realm, email_allowed_for_realm, \
get_realm, get_realm_by_email_domain
from zerver.lib.events import do_events_register
from zerver.lib.actions import do_change_password, do_change_full_name, do_change_is_admin, \
do_activate_user, do_create_user, do_create_realm, set_default_streams, \
do_events_register, user_email_is_unique, \
user_email_is_unique, \
compute_mit_user_fullname
from zerver.forms import RegistrationForm, HomepageForm, RealmCreationForm, \
CreateUserForm, FindMyTeamForm
Expand Down

0 comments on commit b867ac3

Please sign in to comment.