From 3ca2b93cac5687a2b1e571ec2f30d5ceb4f3854b Mon Sep 17 00:00:00 2001 From: luxagraf Date: Sun, 4 Dec 2022 15:51:10 -0600 Subject: links: cleaned up code, got rid of markdown parser since it stopped working long ago --- app/links/models.py | 46 ++-------------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) (limited to 'app/links/models.py') diff --git a/app/links/models.py b/app/links/models.py index 25bc28a..89e2dfc 100644 --- a/app/links/models.py +++ b/app/links/models.py @@ -17,35 +17,6 @@ from taggit.managers import TaggableManager from utils.util import markdown_to_html -def random_link(): - """ - Emails me a random link everyday (via cron) - """ - total = Link.objects.all().count() - pk = randint(1, total) - try: - link = Link.objects.get(pk=pk) - except Link.DoesNotExist: - try: - link = Link.objects.get(pk=pk+1) - except Link.DoesNotExist: - link = Link.objects.get(pk=pk+91) - subject = "today's link: %s" % link.title - body = "%s\n\n%s\n\n\nvisit site:%s\n\n\ndelete link: https://live.luxagraf.net/admin/links/link/%s/" % (link.title, link.description, link.url, link.pk) - msg = EmailMessage(subject, striptags(body), 'sng@luxagraf.net', ['sng@luxagraf.net']) - msg.send() - - -def get_source(source): - try: - url = "http://heckyesmarkdown.com/go/?read=1&preview=0&showframe=0&output=json&u=%s" % (source) - r = requests.get(url, timeout=15.001) - data = r.json() - except: - data = {'markdown':'error getting markdown'} - return data - - def email_link(link): """ Emails me a copy of link @@ -70,16 +41,11 @@ class Link(models.Model): description = models.TextField(blank=True, null=True) body_markdown = models.TextField(blank=True, null=True) pub_date = models.DateTimeField(default=timezone.now) - PUB_STATUS = ( - (0, 'Private'), - (1, 'Public'), - ) - status = models.IntegerField(choices=PUB_STATUS, default=0) tags = TaggableManager(blank=True) - image = models.FileField(blank=True, null=True, upload_to=get_upload_path) class Meta: ordering = ['-pub_date'] + get_latest_by = "pub_date" def __str__(self): return self.title @@ -125,15 +91,7 @@ class Link(models.Model): @receiver(post_save, sender=Link) def post_save_events(sender, update_fields, created, instance, **kwargs): - if instance.body_markdown: - pass - else: - md = get_source(instance.url) - instance.body_markdown = md['markdown'] - post_save.disconnect(post_save_events, sender=Link) - instance.save() - post_save.connect(post_save_events, sender=Link) - email_link(instance) + email_link(instance) class LinkSitemap(Sitemap): -- cgit v1.2.3-70-g09d2