Skip to content

Commit

Permalink
66 - Custom Signals
Browse files Browse the repository at this point in the history
  • Loading branch information
jmitchel3 committed Jul 27, 2015
1 parent a996925 commit 090a17c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
Binary file modified src/db.sqlite3
Binary file not shown.
17 changes: 17 additions & 0 deletions src/matches/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from jobs.models import Job, Employer, Location

from .signals import user_matches_update
from .utils import get_match


Expand Down Expand Up @@ -49,6 +50,14 @@ def get_or_create_match(self, user_a=None, user_b=None):
new_instance.do_match()
return new_instance, True


def update_for_user(self, user):
qs = self.get_queryset().matches(user)
for instance in qs:
instance.do_match()
return True


def update_all(self):
queryset = self.all()
now = timezone.now()
Expand Down Expand Up @@ -130,6 +139,14 @@ def check_update(self):
print("already updated")


def user_matches_update_receiver(sender, user, *args, **kwargs):
updated = Match.objects.update_for_user(user)
print updated


user_matches_update.connect(user_matches_update_receiver)



class PositionMatchManager(models.Manager):
def update_top_suggestions(self, user, match_int):
Expand Down
5 changes: 5 additions & 0 deletions src/matches/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.dispatch import Signal



user_matches_update = Signal(providing_args=['user'])
5 changes: 5 additions & 0 deletions src/questions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# Create your views here.

from matches.signals import user_matches_update

from .forms import UserResponseForm
from .models import Question, Answer, UserAnswer

Expand Down Expand Up @@ -59,6 +61,9 @@ def single(request, id):
user_answer.their_importance = "Not Important"
user_answer.save()

user_matches_update.send(user=request.user, sender=user_answer.__class__)


if updated_q:
messages.success(request, "Your response was updated successfully.<br/><a href='#'>Hello</a>", extra_tags='safe updated')

Expand Down

0 comments on commit 090a17c

Please sign in to comment.