diff options
Diffstat (limited to 'app/notes')
-rw-r--r-- | app/notes/admin.py | 54 | ||||
-rw-r--r-- | app/notes/mdx_urlize.py | 81 | ||||
-rw-r--r-- | app/notes/migrations/0001_initial.py | 45 | ||||
-rw-r--r-- | app/notes/migrations/0002_auto_20160208_1107.py | 20 | ||||
-rw-r--r-- | app/notes/migrations/0003_auto_20160208_1120.py | 33 | ||||
-rw-r--r-- | app/notes/migrations/0004_auto_20160616_1444.py | 27 | ||||
-rw-r--r-- | app/notes/migrations/0005_auto_20160616_1445.py | 20 | ||||
-rw-r--r-- | app/notes/migrations/0006_auto_20160617_2058.py | 24 | ||||
-rw-r--r-- | app/notes/migrations/0007_auto_20160617_2143.py | 20 | ||||
-rw-r--r-- | app/notes/migrations/0008_remove_luxnote_date_last_updated.py | 19 | ||||
-rw-r--r-- | app/notes/models.py | 161 | ||||
-rw-r--r-- | app/notes/static/count.js | 17 | ||||
-rw-r--r-- | app/notes/static/jquery.simplyCountable.js | 137 | ||||
-rw-r--r-- | app/notes/urls.py | 7 | ||||
-rw-r--r-- | app/notes/views.py | 56 |
15 files changed, 19 insertions, 702 deletions
diff --git a/app/notes/admin.py b/app/notes/admin.py index 3d1d593..eafd0dc 100644 --- a/app/notes/admin.py +++ b/app/notes/admin.py @@ -1,21 +1,19 @@ from django.contrib import admin -from django.contrib.gis.admin import OSMGeoAdmin -from django.contrib.contenttypes.admin import GenericTabularInline -from notes.models import Note, LuxNote +from notes.models import Note from utils.widgets import LGEntryForm, OLAdminBase -@admin.register(LuxNote) -class LuxNoteAdmin(OLAdminBase): +@admin.register(Note) +class NoteAdmin(OLAdminBase): + form = LGEntryForm prepopulated_fields = {"slug": ('title',)} - list_display = ('slug', 'pub_date', 'location') + list_display = ('slug', 'pub_date') fieldsets = ( ('Note', { 'fields': ( ('title', 'slug'), 'body_markdown', - ('pub_date', 'status'), - 'point' + 'pub_date', ), 'classes': ( 'show', @@ -26,43 +24,5 @@ class LuxNoteAdmin(OLAdminBase): ), ) - - - -class NoteAdmin(OSMGeoAdmin): - form = LGEntryForm - list_display = ('slug', 'date_created', 'location', 'twitter_id') - list_filter = ('location',) - prepopulated_fields = {"slug": ('title',)} - fieldsets = ( - ('Note', { - 'fields': ( - 'title', - 'body_markdown', - ('twitter_send', 'slug'), - 'point' - ), - 'classes': ( - 'show', - 'extrapretty', - 'wide' - ) - }), - ) - # options for OSM map Using custom ESRI topo map - default_lon = -9285175 - default_lat = 4025046 - default_zoom = 11 - units = True - scrollable = False - map_width = 700 - map_height = 425 - map_template = 'gis/admin/osm.html' - openlayers_url = '/static/admin/js/OpenLayers.js' - class Media: - js = ( - '/static/jquery.simplyCountable.js', - '/static/count.js', - ) -admin.site.register(Note, NoteAdmin) + js = ('image-loader.js', 'next-prev-links.js') diff --git a/app/notes/mdx_urlize.py b/app/notes/mdx_urlize.py deleted file mode 100644 index dc8d1d7..0000000 --- a/app/notes/mdx_urlize.py +++ /dev/null @@ -1,81 +0,0 @@ -"""A more liberal autolinker - -Inspired by Django's urlize function. - -Positive examples: - ->>> import markdown ->>> md = markdown.Markdown(extensions=['urlize']) - ->>> md.convert('http://example.com/') -u'<p><a href="http://example.com/">http://example.com/</a></p>' - ->>> md.convert('go to http://example.com') -u'<p>go to <a href="http://example.com">http://example.com</a></p>' - ->>> md.convert('example.com') -u'<p><a href="http://example.com">example.com</a></p>' - ->>> md.convert('example.net') -u'<p><a href="http://example.net">example.net</a></p>' - ->>> md.convert('www.example.us') -u'<p><a href="http://www.example.us">www.example.us</a></p>' - ->>> md.convert('(www.example.us/path/?name=val)') -u'<p>(<a href="http://www.example.us/path/?name=val">www.example.us/path/?name=val</a>)</p>' - ->>> md.convert('go to <http://example.com> now!') -u'<p>go to <a href="http://example.com">http://example.com</a> now!</p>' - -Negative examples: - ->>> md.convert('del.icio.us') -u'<p>del.icio.us</p>' - -""" - -import markdown - -# Global Vars -URLIZE_RE = '(%s)' % '|'.join([ - r'<(?:f|ht)tps?://[^>]*>', - r'\b(?:f|ht)tps?://[^)<>\s]+[^.,)<>\s]', - r'\bwww\.[^)<>\s]+[^.,)<>\s]', - r'[^(<\s]+\.(?:com|net|org)\b', -]) - -class UrlizePattern(markdown.inlinepatterns.Pattern): - """ Return a link Element given an autolink (`http://example/com`). """ - def handleMatch(self, m): - url = m.group(2) - - if url.startswith('<'): - url = url[1:-1] - - text = url - - if not url.split('://')[0] in ('http','https','ftp'): - if '@' in url and not '/' in url: - url = 'mailto:' + url - else: - url = 'http://' + url - - el = markdown.util.etree.Element("a") - el.set('href', url) - el.text = markdown.util.AtomicString(text) - return el - -class UrlizeExtension(markdown.Extension): - """ Urlize Extension for Python-Markdown. """ - - def extendMarkdown(self, md, md_globals): - """ Replace autolink with UrlizePattern """ - md.inlinePatterns['autolink'] = UrlizePattern(URLIZE_RE, md) - -def makeExtension(configs=None): - return UrlizeExtension(configs=configs) - -if __name__ == "__main__": - import doctest - doctest.testmod() diff --git a/app/notes/migrations/0001_initial.py b/app/notes/migrations/0001_initial.py index 598b81b..ea67ad1 100644 --- a/app/notes/migrations/0001_initial.py +++ b/app/notes/migrations/0001_initial.py @@ -1,10 +1,7 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-02-08 10:57 -from __future__ import unicode_literals +# Generated by Django 2.0.1 on 2018-05-09 09:35 -import django.contrib.gis.db.models.fields from django.db import migrations, models -import django.db.models.deletion +import django.utils.timezone class Migration(migrations.Migration): @@ -12,52 +9,18 @@ class Migration(migrations.Migration): initial = True dependencies = [ - #('locations', '__first__'), ] operations = [ migrations.CreateModel( - name='LuxNote', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(blank=True, max_length=250, null=True)), - ('slug', models.SlugField(blank=True, unique_for_date='date_created')), - ('date_created', models.DateTimeField(editable=False)), - ('date_last_updated', models.DateTimeField(blank=True, verbose_name='Date')), - ('body_html', models.TextField(blank=True)), - ('body_markdown', models.TextField(verbose_name='Note')), - ], - ), - migrations.CreateModel( name='Note', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('title', models.CharField(blank=True, max_length=250, null=True)), - ('slug', models.SlugField(blank=True, unique_for_date='date_created')), - ('date_created', models.DateTimeField(blank=True, verbose_name='Date')), - ('date_last_updated', models.DateTimeField(blank=True, verbose_name='Date')), - ('point', django.contrib.gis.db.models.fields.PointField(srid=4326)), - ('city_name', models.CharField(blank=True, max_length=250, null=True)), - ('state_name', models.CharField(blank=True, max_length=250, null=True)), - ('country_name', models.CharField(blank=True, max_length=150, null=True)), + ('slug', models.SlugField(blank=True, unique_for_date='pub_date')), + ('pub_date', models.DateTimeField(default=django.utils.timezone.now)), ('body_html', models.TextField(blank=True)), ('body_markdown', models.TextField(verbose_name='Note')), - ('twitter_text', models.CharField(blank=True, max_length=450, null=True, verbose_name='Twitter text')), - ('twitter_id', models.CharField(max_length=450, verbose_name='twitter_id')), - ('twitter_send', models.BooleanField(default=False, verbose_name='send to twitter?')), - ('twitter_sent', models.BooleanField(default=False)), - ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')), - ], - ), - migrations.CreateModel( - name='OriginNoteForReplies', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('date_created', models.DateTimeField()), - ('profile_image', models.CharField(blank=True, max_length=450, null=True)), - ('screen_name', models.CharField(blank=True, max_length=75, null=True)), - ('body_html', models.TextField(blank=True)), - ('remote_url', models.CharField(blank=True, max_length=450, null=True)), ], ), ] diff --git a/app/notes/migrations/0002_auto_20160208_1107.py b/app/notes/migrations/0002_auto_20160208_1107.py deleted file mode 100644 index 3333a34..0000000 --- a/app/notes/migrations/0002_auto_20160208_1107.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-02-08 11:07 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('notes', '0001_initial'), - ] - - operations = [ - migrations.RenameField( - model_name='luxnote', - old_name='date_created', - new_name='pub_date', - ), - ] diff --git a/app/notes/migrations/0003_auto_20160208_1120.py b/app/notes/migrations/0003_auto_20160208_1120.py deleted file mode 100644 index 43f49a6..0000000 --- a/app/notes/migrations/0003_auto_20160208_1120.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-02-08 11:20 -from __future__ import unicode_literals - -import django.contrib.gis.db.models.fields -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - #('locations', '__first__'), - ('notes', '0002_auto_20160208_1107'), - ] - - operations = [ - migrations.AddField( - model_name='luxnote', - name='location', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location'), - ), - migrations.AddField( - model_name='luxnote', - name='point', - field=django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326), - ), - migrations.AlterField( - model_name='luxnote', - name='slug', - field=models.SlugField(blank=True, unique_for_date='pub_date'), - ), - ] diff --git a/app/notes/migrations/0004_auto_20160616_1444.py b/app/notes/migrations/0004_auto_20160616_1444.py deleted file mode 100644 index 76b1f3a..0000000 --- a/app/notes/migrations/0004_auto_20160616_1444.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-06-16 14:44 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.utils.timezone - - -class Migration(migrations.Migration): - - dependencies = [ - ('photos', '0010_auto_20160517_0906'), - ('notes', '0003_auto_20160208_1120'), - ] - - operations = [ - migrations.AddField( - model_name='luxnote', - name='images', - field=models.ManyToManyField(to='photos.LuxImage'), - ), - migrations.AlterField( - model_name='luxnote', - name='pub_date', - field=models.DateTimeField(default=django.utils.timezone.now), - ), - ] diff --git a/app/notes/migrations/0005_auto_20160616_1445.py b/app/notes/migrations/0005_auto_20160616_1445.py deleted file mode 100644 index 129bbc2..0000000 --- a/app/notes/migrations/0005_auto_20160616_1445.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-06-16 14:45 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('notes', '0004_auto_20160616_1444'), - ] - - operations = [ - migrations.AlterField( - model_name='luxnote', - name='images', - field=models.ManyToManyField(blank=True, null=True, to='photos.LuxImage'), - ), - ] diff --git a/app/notes/migrations/0006_auto_20160617_2058.py b/app/notes/migrations/0006_auto_20160617_2058.py deleted file mode 100644 index 8d32528..0000000 --- a/app/notes/migrations/0006_auto_20160617_2058.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-06-17 20:58 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('notes', '0005_auto_20160616_1445'), - ] - - operations = [ - migrations.RemoveField( - model_name='luxnote', - name='images', - ), - migrations.AddField( - model_name='luxnote', - name='status', - field=models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=0), - ), - ] diff --git a/app/notes/migrations/0007_auto_20160617_2143.py b/app/notes/migrations/0007_auto_20160617_2143.py deleted file mode 100644 index 478e324..0000000 --- a/app/notes/migrations/0007_auto_20160617_2143.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-06-17 21:43 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('notes', '0006_auto_20160617_2058'), - ] - - operations = [ - migrations.AlterField( - model_name='luxnote', - name='status', - field=models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=1), - ), - ] diff --git a/app/notes/migrations/0008_remove_luxnote_date_last_updated.py b/app/notes/migrations/0008_remove_luxnote_date_last_updated.py deleted file mode 100644 index b16b2ea..0000000 --- a/app/notes/migrations/0008_remove_luxnote_date_last_updated.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.5 on 2017-12-14 22:39 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('notes', '0007_auto_20160617_2143'), - ] - - operations = [ - migrations.RemoveField( - model_name='luxnote', - name='date_last_updated', - ), - ] diff --git a/app/notes/models.py b/app/notes/models.py index 698ca14..86b2918 100644 --- a/app/notes/models.py +++ b/app/notes/models.py @@ -1,42 +1,21 @@ -import json -import datetime +from django import forms from django.contrib.gis.db import models -from django.template.defaultfilters import slugify -from django.utils.html import urlize from django.utils import timezone -from django.db.models.signals import post_save -from django.dispatch import receiver from django.conf import settings -import requests +from django.urls import reverse from locations.models import Location -from .build import * -from twython import Twython -# http://freewisdom.org/projects/python-markdown/ -import markdown -#from twitter_text.autolink import Autolink from utils.widgets import markdown_to_html from locations.models import CheckIn from jrnl.models import render_images -def twitter_truncate(txt): - return txt.split("|")[0] - - -class LuxNote(models.Model): +class Note(models.Model): title = models.CharField(max_length=250, null=True, blank=True) slug = models.SlugField(unique_for_date='pub_date', blank=True) pub_date = models.DateTimeField(default=timezone.now) body_html = models.TextField(blank=True) body_markdown = models.TextField('Note') - point = models.PointField(blank=True, null=True) - location = models.ForeignKey(Location, on_delete=models.CASCADE, blank=True, null=True) - PUB_STATUS = ( - (0, 'Draft'), - (1, 'Published'), - ) - status = models.IntegerField(choices=PUB_STATUS, default=1) def __str__(self): return self.title @@ -66,141 +45,7 @@ class LuxNote(models.Model): def get_next_published(self): return self.get_next_by_pub_date() - def save(self, *args, **kwargs): md = render_images(self.body_markdown) self.body_html = markdown_to_html(md) - if not self.point: - self.point = CheckIn.objects.latest().point - try: - self.location = Location.objects.filter(geometry__contains=self.point).get() - except Location.DoesNotExist: - raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL)) - if not self.id: - self.pub_date= timezone.now() - self.date_last_updated = timezone.now() - super(LuxNote, self).save() - - -class Note(models.Model): - title = models.CharField(max_length=250, null=True, blank=True) - slug = models.SlugField(unique_for_date='date_created', blank=True) - date_created = models.DateTimeField('Date', blank=True) - date_last_updated = models.DateTimeField('Date', blank=True) - point = models.PointField() - location = models.ForeignKey(Location, on_delete=models.CASCADE, null=True, blank=True) - city_name = models.CharField(max_length=250, null=True, blank=True) - state_name = models.CharField(max_length=250, null=True, blank=True) - country_name = models.CharField(max_length=150, null=True, blank=True) - body_html = models.TextField(blank=True) - body_markdown = models.TextField('Note') - twitter_text = models.CharField('Twitter text', max_length=450, null=True, blank=True) - twitter_id = models.CharField('twitter_id', max_length=450) - twitter_send = models.BooleanField("send to twitter?", default=False) - twitter_sent = models.BooleanField(default=False, blank=True) - #in_reply_to = models.CharField('in reply to url', max_length=450) - - def __str__(self): - return self.slug - - def get_absolute_url(self): - return '/field-notes/%s/%s' % (self.date_created.strftime("%Y/%m").lower(), self.slug) - - @property - def state(self): - return self.location.state - - @property - def country(self): - return self.location.state.country - - @property - def region(self): - return self.location.state.country.lux_region - - @property - def longitude(self): - '''Get the site's longitude.''' - return round(self.point.x, 2) - - @property - def latitude(self): - '''Get the site's latitude.''' - return round(self.point.y, 2) - - @property - def get_previous_published(self): - return self.get_previous_by_date_created() - - @property - def get_next_published(self): - return self.get_next_by_date_created() - - def render(self): - opts = {'username_include_symbol': True} - temp = " ".join(self.body_markdown.split("|")) - html = markdown.markdown(urlize(temp, 45), extensions=['extra'], safe_mode=False) - return html - - def save(self): - self.body_html = markdown.markdown(urlize(self.body_markdown, 45), extensions=['extra'], safe_mode=False) - self.date_last_updated = datetime.datetime.now() - if not self.date_created: - self.date_created = datetime.datetime.now() - if not self.slug: - self.slug = slugify(self.title)[:30] - if not self.twitter_text: - self.twitter_text = twitter_truncate(self.body_markdown) super(Note, self).save() - - -@receiver(post_save, sender=Note) -def post_save_events(sender, instance, **kwargs): - if kwargs["created"]: - try: - l = Location.objects.filter(geometry__contains=instance.point).get() - instance.location = l - instance.city_name = l.name - instance.state_name = l.state.name - instance.country_name = l.state.country.name - except Location.DoesNotExist: - r_str = 'http://nominatim.openstreetmap.org/reverse?format=json&lat=%s&lon=%s&zoom=18' % (instance.latitude, instance.longitude) - response = requests.get(r_str) - data = json.loads(response.text) - adr = data.get('address', {}) - instance.city_name = adr.get('hamlet') or adr.get('village') or adr.get('town') or adr.get('city') - instance.state_name = adr.get('state') - instance.country_name = adr.get('country') - #if instance.in_reply_to: - #crawl url, extract text, store it locally with a reference to instance - pass - if instance.twitter_send and not instance.twitter_sent: - t = Twython(settings.TWITTER_API_KEY, settings.TWITTER_API_SECRET, settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_SECRET) - geo = t.reverse_geocode(lat=instance.latitude, lon=instance.longitude, accuracy=1500, granularity="city") - geo_id = geo['result']['places'][0]['id'] - status = t.update_status(status=instance.twitter_text, place_id=geo_id) - instance.twitter_id = status['id'] - instance.twitter_sent = True - post_save.disconnect(post_save_events, sender=Note) - instance.save() - post_save.connect(post_save_events, sender=Note) - b = BuildNotes() - b.build() - - -def write_note(sender, instance, **kwargs): - if kwargs["created"]: - pass - - -class OriginNoteForReplies(models.Model): - #created_at - date_created = models.DateTimeField() - #profile_image_url_https - profile_image = models.CharField(max_length=450, null=True, blank=True) - #screen_name - screen_name = models.CharField(max_length=75, null=True, blank=True) - #text - body_html = models.TextField(blank=True) - #url - remote_url = models.CharField(max_length=450, null=True, blank=True) diff --git a/app/notes/static/count.js b/app/notes/static/count.js deleted file mode 100644 index 6d1b5a0..0000000 --- a/app/notes/static/count.js +++ /dev/null @@ -1,17 +0,0 @@ -var jQuery = django.jQuery; -var $ = jQuery; -$(document).ready(function () { - $('#id_body_markdown').after('<span style="display: inline-block; margin-left: 2em;"><span id="counter">40000</span> chars used </span>'); - -$('#id_body_markdown').simplyCountable({ - counter: '#counter', - countType: 'characters', - maxCount: 40000, - strictMax: false, - countDirection: 'up', - safeClass: 'safe', -}); - - -}); - diff --git a/app/notes/static/jquery.simplyCountable.js b/app/notes/static/jquery.simplyCountable.js deleted file mode 100644 index a911466..0000000 --- a/app/notes/static/jquery.simplyCountable.js +++ /dev/null @@ -1,137 +0,0 @@ -/* -* jQuery Simply Countable plugin -* Provides a character counter for any text input or textarea -* -* @version 0.4.2 -* @homepage http://github.com/aaronrussell/jquery-simply-countable/ -* @author Aaron Russell (http://www.aaronrussell.co.uk) -* -* Copyright (c) 2009-2010 Aaron Russell (aaron@gc4.co.uk) -* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) -* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. -*/ -var jQuery = django.jQuery, $ = jQuery; -(function($){ - - $.fn.simplyCountable = function(options){ - - options = $.extend({ - counter: '#counter', - countType: 'characters', - maxCount: 140, - strictMax: false, - countDirection: 'down', - safeClass: 'safe', - overClass: 'over', - thousandSeparator: ',', - onOverCount: function(){}, - onSafeCount: function(){}, - onMaxCount: function(){} - }, options); - - var navKeys = [33,34,35,36,37,38,39,40]; - - return $(this).each(function(){ - - var countable = $(this); - var counter = $(options.counter); - if (!counter.length) { return false; } - - var countCheck = function(){ - - var count; - var revCount; - - var reverseCount = function(ct){ - return ct - (ct*2) + options.maxCount; - } - - var countInt = function(){ - return (options.countDirection === 'up') ? revCount : count; - } - - var numberFormat = function(ct){ - var prefix = ''; - if (options.thousandSeparator){ - ct = ct.toString(); - // Handle large negative numbers - if (ct.match(/^-/)) { - ct = ct.substr(1); - prefix = '-'; - } - for (var i = ct.length-3; i > 0; i -= 3){ - ct = ct.substr(0,i) + options.thousandSeparator + ct.substr(i); - } - } - return prefix + ct; - } - - var changeCountableValue = function(val){ - countable.val(val).trigger('change'); - } - - /* Calculates count for either words or characters */ - if (options.countType === 'words'){ - count = options.maxCount - $.trim(countable.val()).split(/\s+/).length; - if (countable.val() === ''){ count += 1; } - } - else { count = options.maxCount - countable.val().length; } - revCount = reverseCount(count); - - /* If strictMax set restrict further characters */ - if (options.strictMax && count <= 0){ - var content = countable.val(); - if (count < 0) { - options.onMaxCount(countInt(), countable, counter); - } - if (options.countType === 'words'){ - var allowedText = content.match( new RegExp('\\s?(\\S+\\s+){'+ options.maxCount +'}') ); - if (allowedText) { - changeCountableValue(allowedText[0]); - } - } - else { changeCountableValue(content.substring(0, options.maxCount)); } - count = 0, revCount = options.maxCount; - } - - counter.text(numberFormat(countInt())); - - /* Set CSS class rules and API callbacks */ - if (!counter.hasClass(options.safeClass) && !counter.hasClass(options.overClass)){ - if (count < 0){ counter.addClass(options.overClass); } - else { counter.addClass(options.safeClass); } - } - else if (count < 0 && counter.hasClass(options.safeClass)){ - counter.removeClass(options.safeClass).addClass(options.overClass); - options.onOverCount(countInt(), countable, counter); - } - else if (count >= 0 && counter.hasClass(options.overClass)){ - counter.removeClass(options.overClass).addClass(options.safeClass); - options.onSafeCount(countInt(), countable, counter); - } - - }; - - countCheck(); - - countable.on('keyup blur paste', function(e) { - switch(e.type) { - case 'keyup': - // Skip navigational key presses - if ($.inArray(e.which, navKeys) < 0) { countCheck(); } - break; - case 'paste': - // Wait a few miliseconds if a paste event - setTimeout(countCheck, (e.type === 'paste' ? 5 : 0)); - break; - default: - countCheck(); - break; - } - }); - - }); - - }; - -})(jQuery); diff --git a/app/notes/urls.py b/app/notes/urls.py index 0f9fad7..3c47c3d 100644 --- a/app/notes/urls.py +++ b/app/notes/urls.py @@ -12,11 +12,6 @@ urlpatterns = [ name="detail-txt" ), url( - r'(?P<year>\d{4})/(?P<month>\d{2})/(?P<slug>[-\w]+).amp$', - views.NoteDetailViewAMP.as_view(), - name="detail-amp" - ), - url( r'(?P<year>\d{4})/(?P<month>\d{2})/(?P<slug>[-\w]+)$', views.NoteDetailView.as_view(), name="detail" @@ -31,8 +26,6 @@ urlpatterns = [ views.NoteYearArchiveView.as_view(), name="list_year" ), - - url( r'(?P<year>\d{4})/(?P<month>\d{2})/$', views.date_list, diff --git a/app/notes/views.py b/app/notes/views.py index 1fbe6f4..05fe18e 100644 --- a/app/notes/views.py +++ b/app/notes/views.py @@ -1,23 +1,21 @@ -from django.shortcuts import render_to_response, get_object_or_404 -from django.template import RequestContext from django.views.generic.dates import YearArchiveView, MonthArchiveView from django.views.generic.detail import DetailView from utils.views import PaginatedListView -from notes.models import LuxNote, Note +from notes.models import Note class NoteList(PaginatedListView): """ Return a list of Notes in reverse chronological order """ - queryset = LuxNote.objects.all().order_by('-pub_date') + queryset = Note.objects.all().order_by('-pub_date') template_name = "archives/notes.html" class NoteDetailView(DetailView): - model = LuxNote + model = Note template_name = "details/note.html" slug_field = "slug" @@ -26,12 +24,8 @@ class NoteDetailViewTXT(NoteDetailView): template_name = "details/entry.txt" -class NoteDetailViewAMP(NoteDetailView): - template_name = "details/entry.amp" - - class NoteYearArchiveView(YearArchiveView): - queryset = LuxNote.objects.all() + queryset = Note.objects.all() date_field = "pub_date" make_object_list = True allow_future = True @@ -39,47 +33,7 @@ class NoteYearArchiveView(YearArchiveView): class NoteMonthArchiveView(MonthArchiveView): - queryset = LuxNote.objects.all() + queryset = Note.objects.all() date_field = "pub_date" allow_future = True template_name = "archives/notes_date.html" - - -""" -Legacy Notes views -""" - - -def entry_detail(request, year, month, slug): - context = { - 'object': get_object_or_404(Note, slug__exact=slug), - } - return render_to_response( - 'details/note.html', - context, - context_instance=RequestContext(request) - ) - - -def date_list(request, year, month=None): - if month: - qs = Note.objects.filter(date_created__year=year, date_created__month=month).order_by('-date_created') - else: - qs = Note.objects.filter(date_created__year=year).order_by('-date_created') - context = { - 'year': year, - 'month': month, - 'object_list': qs, - } - return render_to_response( - "archives/notes_date.html", - context, - context_instance=RequestContext(request) - ) - - -def entry_list(request): - context = { - 'object_list': Note.objects.all().order_by('-date_created').select_related(), - } - return render_to_response("archives/notes.html", context, context_instance=RequestContext(request)) |