diff options
Diffstat (limited to 'app/links')
-rw-r--r-- | app/links/admin.py | 5 | ||||
-rw-r--r-- | app/links/models.py | 39 |
2 files changed, 43 insertions, 1 deletions
diff --git a/app/links/admin.py b/app/links/admin.py index b772d24..1f45f1e 100644 --- a/app/links/admin.py +++ b/app/links/admin.py @@ -1,4 +1,9 @@ from django.contrib import admin +from django.conf.urls import url +from django.utils.translation import ungettext, ugettext_lazy as _ +from django.shortcuts import render +from django.contrib.admin import helpers +from django.http import HttpResponseRedirect from utils.widgets import TagListFilter import autocomplete_light diff --git a/app/links/models.py b/app/links/models.py index 0a82366..6cbe497 100644 --- a/app/links/models.py +++ b/app/links/models.py @@ -1,12 +1,35 @@ +import requests +import json from django.core.urlresolvers import reverse from django.utils.encoding import force_text from django.db import models from django.contrib.sitemaps import Sitemap -from taggit.managers import TaggableManager +from django.db.models.signals import post_save +from django.dispatch import receiver +from taggit.managers import TaggableManager from utils.widgets import markdown_to_html +def get_source(source): + 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() + return data + + +def email_link(link): + """ + Sends an imported link to Gmail (never hurts to have backups) + """ + subject = link.title + body = "%s\n\n%s\n\n\nvisit site:%s\n" % (link.title, link.description, link.url) + msg = EmailMessage(subject, striptags(body), 'sng@luxagraf.net', ['luxagraf+links@gmail.com']) + msg.send() + msg = EmailMessage(subject, striptags(body), 'sng@luxagraf.net', ['sng+links@luxagraf.net']) + msg.send() + + class Link(models.Model): title = models.CharField(max_length=400) url = models.CharField(max_length=400) @@ -43,6 +66,20 @@ class Link(models.Model): admin_link.allow_tags = True admin_link.short_description = 'Link' +@receiver(post_save, sender=Link) +def post_save_events(sender, update_fields, created, instance, **kwargs): + if instance.body_markdown: + pass + else: + try: + md = get_source(instance.url) + instance.body_markdown = md['markdown'] + except: + pass + post_save.disconnect(post_save_events, sender=Link) + instance.save() + post_save.connect(post_save_events, sender=Link) + email_link(instance) class LinkSitemap(Sitemap): changefreq = "never" |