notify talk edition
This commit is contained in:
parent
92cacd30a7
commit
eb0cf5010a
|
@ -4,7 +4,7 @@ from django.dispatch import receiver
|
||||||
|
|
||||||
from accounts.models import Participation
|
from accounts.models import Participation
|
||||||
from proposals.models import Talk
|
from proposals.models import Talk
|
||||||
from proposals.signals import new_talk
|
from proposals.signals import *
|
||||||
|
|
||||||
from .models import ConversationAboutTalk, ConversationWithParticipant, Message
|
from .models import ConversationAboutTalk, ConversationWithParticipant, Message
|
||||||
|
|
||||||
|
@ -25,20 +25,31 @@ def create_conversation_about_talk(sender, instance, created, **kwargs):
|
||||||
conversation.save()
|
conversation.save()
|
||||||
|
|
||||||
|
|
||||||
@receiver(new_talk, dispatch_uid="Notify new talk")
|
def check_talk(talk):
|
||||||
def notify_new_talk(sender, instance, **kwargs):
|
|
||||||
# Subscribe reviewer for these topics to conversations
|
# Subscribe reviewer for these topics to conversations
|
||||||
reviewers = User.objects.filter(participation__topic__talk=instance)
|
reviewers = User.objects.filter(participation__topic__talk=talk)
|
||||||
instance.conversation.subscribers.add(*reviewers)
|
talk.conversation.subscribers.add(*reviewers)
|
||||||
for user in instance.speakers.all():
|
for user in talk.speakers.all():
|
||||||
participation = Participation.on_site.get(user=user)
|
participation, created = Participation.on_site.get_or_create(user=user, site=talk.site)
|
||||||
participation.conversation.subscribers.add(*reviewers)
|
participation.conversation.subscribers.add(*reviewers)
|
||||||
# Notification of this new talk
|
|
||||||
message = Message(conversation=instance.conversation, author=instance.proposer,
|
|
||||||
|
@receiver(talk_added, dispatch_uid="Notify talk added")
|
||||||
|
def notify_talk_added(sender, instance, author, **kwargs):
|
||||||
|
check_talk(instance)
|
||||||
|
message = Message(conversation=instance.conversation, author=author,
|
||||||
content='The talk has been proposed.')
|
content='The talk has been proposed.')
|
||||||
message.save()
|
message.save()
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(talk_edited, dispatch_uid="Notify talk edited")
|
||||||
|
def notify_talk_edited(sender, instance, author, **kwargs):
|
||||||
|
check_talk(instance)
|
||||||
|
message = Message(conversation=instance.conversation, author=author,
|
||||||
|
content='The talk has been modified.')
|
||||||
|
message.save()
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Message, dispatch_uid="Notify new message")
|
@receiver(post_save, sender=Message, dispatch_uid="Notify new message")
|
||||||
def notify_new_message(sender, instance, created, **kwargs):
|
def notify_new_message(sender, instance, created, **kwargs):
|
||||||
if not created:
|
if not created:
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
from django.dispatch import Signal
|
from django.dispatch import Signal
|
||||||
|
|
||||||
new_talk = Signal(providing_args=["sender", "instance"])
|
|
||||||
|
__all__ = [ 'talk_added', 'talk_edited' ]
|
||||||
|
|
||||||
|
|
||||||
|
talk_added = Signal(providing_args=["sender", "instance", "author"])
|
||||||
|
talk_edited = Signal(providing_args=["sender", "instance", "author"])
|
||||||
|
|
|
@ -15,8 +15,8 @@ from accounts.utils import is_orga
|
||||||
|
|
||||||
from .forms import TalkForm, TopicForm, TopicOrgaForm
|
from .forms import TalkForm, TopicForm, TopicOrgaForm
|
||||||
from .models import Talk, Topic, Vote
|
from .models import Talk, Topic, Vote
|
||||||
from .signals import new_talk
|
|
||||||
from .utils import allowed_talks
|
from .utils import allowed_talks
|
||||||
|
from .signals import *
|
||||||
|
|
||||||
|
|
||||||
def home(request):
|
def home(request):
|
||||||
|
@ -53,12 +53,13 @@ def talk_edit(request, talk=None):
|
||||||
if request.method == 'POST' and form.is_valid():
|
if request.method == 'POST' and form.is_valid():
|
||||||
if hasattr(talk, 'id'):
|
if hasattr(talk, 'id'):
|
||||||
talk = form.save()
|
talk = form.save()
|
||||||
|
talk_edited.send(talk.__class__, instance=talk, author=request.user)
|
||||||
messages.success(request, 'Talk modified successfully!')
|
messages.success(request, 'Talk modified successfully!')
|
||||||
else:
|
else:
|
||||||
form.instance.site = get_current_site(request)
|
form.instance.site = get_current_site(request)
|
||||||
form.instance.proposer = request.user
|
form.instance.proposer = request.user
|
||||||
talk = form.save()
|
talk = form.save()
|
||||||
new_talk.send(talk.__class__, instance=talk)
|
talk_added.send(talk.__class__, instance=talk, author=request.user)
|
||||||
messages.success(request, 'Talk proposed successfully!')
|
messages.success(request, 'Talk proposed successfully!')
|
||||||
return redirect(talk.get_absolute_url())
|
return redirect(talk.get_absolute_url())
|
||||||
return render(request, 'proposals/talk_edit.html', {
|
return render(request, 'proposals/talk_edit.html', {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user