Auto posting to twitter from the blog when a blog is made active.
This commit is contained in:
parent
b2c0c6ce42
commit
47aa81fb1d
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.1.1 on 2018-09-26 18:37
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('blog', '0005_added_excerpt'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='post',
|
||||||
|
name='sent_on_social',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,11 +1,18 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from django.db.models.signals import post_save
|
||||||
|
from django.contrib.sites.models import Site
|
||||||
|
|
||||||
|
|
||||||
from martor.models import MartorField
|
from martor.models import MartorField
|
||||||
from stdimage.validators import MinSizeValidator
|
from stdimage.validators import MinSizeValidator
|
||||||
from stdimage.models import StdImageField
|
from stdimage.models import StdImageField
|
||||||
from dynamic_filenames import FilePattern
|
from dynamic_filenames import FilePattern
|
||||||
|
from django.core.mail import EmailMessage
|
||||||
|
from mhackspace.base.tasks import matrix_message, twitter_message
|
||||||
|
|
||||||
|
|
||||||
from mhackspace.users.models import User
|
from mhackspace.users.models import User
|
||||||
|
@ -51,6 +58,7 @@ class Post(models.Model):
|
||||||
updated_date = models.DateTimeField(default=timezone.now)
|
updated_date = models.DateTimeField(default=timezone.now)
|
||||||
active = models.BooleanField(default=True)
|
active = models.BooleanField(default=True)
|
||||||
members_only = models.BooleanField(default=False)
|
members_only = models.BooleanField(default=False)
|
||||||
|
sent_on_social = models.BooleanField(default=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
@ -60,3 +68,19 @@ class Post(models.Model):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ("-published_date",)
|
ordering = ("-published_date",)
|
||||||
|
|
||||||
|
|
||||||
|
def blog_article_updated(sender, instance, **kwargs):
|
||||||
|
if instance.active is False:
|
||||||
|
return
|
||||||
|
if instance.sent_on_social is True:
|
||||||
|
return
|
||||||
|
|
||||||
|
instance.sent_on_social = True
|
||||||
|
instance.save()
|
||||||
|
url = "https://%s%s" % (Site.objects.get_current().domain, instance.get_absolute_url())
|
||||||
|
message = f"{instance.title} {url}"
|
||||||
|
twitter_message.delay(message)
|
||||||
|
matrix_message.delay(message)
|
||||||
|
|
||||||
|
post_save.connect(blog_article_updated, sender=Post)
|
||||||
|
|
Loading…
Reference in New Issue