matrix tasks for spirit and wiki
This commit is contained in:
parent
5e5312fe74
commit
80601ce000
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals, absolute_import
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
from django.contrib.sites.models import Site
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
@ -8,6 +9,7 @@ from stdimage.utils import UploadToAutoSlugClassNameDir
|
||||||
from stdimage.validators import MinSizeValidator
|
from stdimage.validators import MinSizeValidator
|
||||||
|
|
||||||
from spirit.comment.models import Comment
|
from spirit.comment.models import Comment
|
||||||
|
from wiki.models.article import ArticleRevision
|
||||||
# from django.contrib.auth.models import User
|
# from django.contrib.auth.models import User
|
||||||
from django.core.mail import EmailMessage
|
from django.core.mail import EmailMessage
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
|
@ -67,7 +69,18 @@ def send_topic_update_email(sender, instance, **kwargs):
|
||||||
to=[user_email],
|
to=[user_email],
|
||||||
headers={'Reply-To': 'no-reply@maidstone-hackspace.org.uk'})
|
headers={'Reply-To': 'no-reply@maidstone-hackspace.org.uk'})
|
||||||
email.send()
|
email.send()
|
||||||
matrix_message.delay('[MH] %s' % instance.topic.title)
|
matrix_message.delay('%s https://%s%s' % (
|
||||||
|
instance.topic.title,
|
||||||
|
Site.objects.get_current().domain,
|
||||||
|
instance.topic.get_absolute_url()))
|
||||||
|
|
||||||
|
|
||||||
|
def wiki_article_updated(sender, instance, **kwargs):
|
||||||
|
matrix_message.delay('%s https://%s%s' % (
|
||||||
|
instance.title,
|
||||||
|
Site.objects.get_current().domain,
|
||||||
|
instance.article.get_absolute_url()))
|
||||||
|
|
||||||
|
|
||||||
|
post_save.connect(wiki_article_updated, sender=ArticleRevision)
|
||||||
post_save.connect(send_topic_update_email, sender=Comment)
|
post_save.connect(send_topic_update_email, sender=Comment)
|
||||||
|
|
|
@ -14,6 +14,7 @@ matrix_join_room_alias_url = matrix_url + "/join/{room}?access_token={access_tok
|
||||||
matrix_join_room_id_url = matrix_url + "rooms/%21{room}/join?access_token={access_token}"
|
matrix_join_room_id_url = matrix_url + "rooms/%21{room}/join?access_token={access_token}"
|
||||||
matrix_send_msg_url = matrix_url + "/rooms/%21{room}/send/m.room.message?access_token={access_token}"
|
matrix_send_msg_url = matrix_url + "/rooms/%21{room}/send/m.room.message?access_token={access_token}"
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def matrix_message(message):
|
def matrix_message(message):
|
||||||
# login
|
# login
|
||||||
|
@ -38,7 +39,7 @@ def matrix_message(message):
|
||||||
url = matrix_send_msg_url.format(**url_params)
|
url = matrix_send_msg_url.format(**url_params)
|
||||||
details = {
|
details = {
|
||||||
"msgtype": "m.text",
|
"msgtype": "m.text",
|
||||||
"body":message}
|
"body": "%s %s" % (settings.MSG_PREFIX, message)}
|
||||||
r2 = requests.post(url, json=details)
|
r2 = requests.post(url, json=details)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue