Skip to content

Commit

Permalink
spark.api should always be importable
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Oct 30, 2018
1 parent 77e9d20 commit b690dca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Send mails related to challenges (uses django-authlib's
from authlib.email import render_to_mail
def send_challenge_mails(event):
def send_challenge_mail(event):
challenge = event["context"]["challenge"]
render_to_mail(
# Different mail text per event group:
Expand All @@ -75,21 +75,20 @@ Register the handlers:

.. code-block:: python
from spark import api
class ChallengesConfig(AppConfig):
def ready(self):
# Prevent circular imports:
from spark import api
api.register_group_handler(
handler=send_challenge_mails,
handler=send_challenge_mail,
group=r'^challenge',
)
Challenge = self.get_model('Challenge')
# All this does right now is register a post_save signal
# handler which runs the challenge instance through
# events_from_challenge:
# events_from_challenge and processes the events:
api.register_model_event_source(
sender=Challenge,
source=events_from_challenge,
Expand Down
4 changes: 2 additions & 2 deletions spark/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import re

from django.db.models import signals


MODEL_SOURCES = {}
HANDLERS = []
Expand Down Expand Up @@ -31,6 +29,8 @@ def process_events(iterable):


def register_model_event_source(*, sender, source):
from django.db.models import signals

MODEL_SOURCES.setdefault(sender, []).append(source)

def on_post_save(sender, instance, **kwargs):
Expand Down

0 comments on commit b690dca

Please sign in to comment.