diff options
-rw-r--r-- | app/links/admin.py | 6 | ||||
-rw-r--r-- | app/links/migrations/0005_alter_link_options_remove_link_status.py | 21 | ||||
-rw-r--r-- | app/links/migrations/0006_remove_link_image.py | 17 | ||||
-rw-r--r-- | app/links/models.py | 46 |
4 files changed, 42 insertions, 48 deletions
diff --git a/app/links/admin.py b/app/links/admin.py index 6e0504e..6b93dc9 100644 --- a/app/links/admin.py +++ b/app/links/admin.py @@ -12,21 +12,19 @@ from .models import Link class LinkAdmin(admin.ModelAdmin): list_display = ('title', 'admin_link', 'pub_date', 'admin_tags') search_fields = ['title', 'description', 'url'] - list_filter = ['status', TagListFilter] + list_filter = [TagListFilter] fieldsets = ( (None, { 'fields': ( 'title', 'url', 'description', - 'body_markdown', ) }), ('Details', { 'fields': ( 'pub_date', - ('tags', 'image'), - 'status' + ('tags'), ), 'classes': 'collapse' }), diff --git a/app/links/migrations/0005_alter_link_options_remove_link_status.py b/app/links/migrations/0005_alter_link_options_remove_link_status.py new file mode 100644 index 0000000..0df7996 --- /dev/null +++ b/app/links/migrations/0005_alter_link_options_remove_link_status.py @@ -0,0 +1,21 @@ +# Generated by Django 4.1.3 on 2022-12-04 16:40 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('links', '0004_link_image'), + ] + + operations = [ + migrations.AlterModelOptions( + name='link', + options={'get_latest_by': 'pub_date', 'ordering': ['-pub_date']}, + ), + migrations.RemoveField( + model_name='link', + name='status', + ), + ] diff --git a/app/links/migrations/0006_remove_link_image.py b/app/links/migrations/0006_remove_link_image.py new file mode 100644 index 0000000..a1b53e9 --- /dev/null +++ b/app/links/migrations/0006_remove_link_image.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.3 on 2022-12-04 16:46 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('links', '0005_alter_link_options_remove_link_status'), + ] + + operations = [ + migrations.RemoveField( + model_name='link', + name='image', + ), + ] 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): |