From c24e6043db413f5722e7d378805da069698d64e7 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Sun, 3 Mar 2019 15:42:30 -0600 Subject: got rid of old sketches model --- app/jrnl/models.py | 1 - app/sketches/__init__.py | 0 app/sketches/admin.py | 40 ---------- app/sketches/build.py | 36 --------- app/sketches/migrations/0001_initial.py | 32 -------- app/sketches/migrations/0002_auto_20180208_0743.py | 17 ----- app/sketches/migrations/__init__.py | 0 app/sketches/models.py | 88 --------------------- app/sketches/urls.py | 39 ---------- app/sketches/views.py | 40 ---------- app/unused_apps/sketches/__init__.py | 0 app/unused_apps/sketches/admin.py | 42 ++++++++++ app/unused_apps/sketches/build.py | 36 +++++++++ .../sketches/migrations/0001_initial.py | 32 ++++++++ .../sketches/migrations/0002_auto_20180208_0743.py | 17 +++++ app/unused_apps/sketches/migrations/__init__.py | 0 app/unused_apps/sketches/models.py | 89 ++++++++++++++++++++++ app/unused_apps/sketches/urls.py | 39 ++++++++++ app/unused_apps/sketches/views.py | 40 ++++++++++ design/templates/archives/notes.html | 2 +- design/templates/archives/sketches.html | 72 ++++++----------- 21 files changed, 319 insertions(+), 343 deletions(-) delete mode 100644 app/sketches/__init__.py delete mode 100644 app/sketches/admin.py delete mode 100644 app/sketches/build.py delete mode 100644 app/sketches/migrations/0001_initial.py delete mode 100644 app/sketches/migrations/0002_auto_20180208_0743.py delete mode 100644 app/sketches/migrations/__init__.py delete mode 100644 app/sketches/models.py delete mode 100644 app/sketches/urls.py delete mode 100644 app/sketches/views.py create mode 100644 app/unused_apps/sketches/__init__.py create mode 100644 app/unused_apps/sketches/admin.py create mode 100644 app/unused_apps/sketches/build.py create mode 100644 app/unused_apps/sketches/migrations/0001_initial.py create mode 100644 app/unused_apps/sketches/migrations/0002_auto_20180208_0743.py create mode 100644 app/unused_apps/sketches/migrations/__init__.py create mode 100644 app/unused_apps/sketches/models.py create mode 100644 app/unused_apps/sketches/urls.py create mode 100644 app/unused_apps/sketches/views.py diff --git a/app/jrnl/models.py b/app/jrnl/models.py index c3aace3..88fd84b 100644 --- a/app/jrnl/models.py +++ b/app/jrnl/models.py @@ -20,7 +20,6 @@ from django_comments.moderation import CommentModerator, moderator from photos.models import PhotoGallery, LuxImage, LuxImageSize from locations.models import Location -from sketches.models import Sketch from books.models import Book from fieldnotes.models import FieldNote diff --git a/app/sketches/__init__.py b/app/sketches/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/sketches/admin.py b/app/sketches/admin.py deleted file mode 100644 index 07a2e6a..0000000 --- a/app/sketches/admin.py +++ /dev/null @@ -1,40 +0,0 @@ -from django.contrib import admin -from django.contrib.gis.admin import OSMGeoAdmin -from django.contrib.contenttypes.admin import GenericTabularInline - -from .models import Sketch -from utils.widgets import LGEntryForm, OLAdminBase -from utils.util import get_latlon - -@admin.register(Sketch) -class SketchAdmin(OLAdminBase): - form = LGEntryForm - - prepopulated_fields = {"slug": ('title',)} - list_display = ('title', 'slug', 'pub_date', 'location') - fieldsets = ( - ('Note', { - 'fields': ( - ('title', 'slug'), - 'body_markdown', - ('pub_date', 'status'), - 'point' - ), - 'classes': ( - 'show', - 'extrapretty', - 'wide' - ) - } - ), - ) - lat, lon = get_latlon() - default_lon = lon - default_lat = lat - default_zoom = 10 - - class Media: - js = ('image-loader.js', 'next-prev-links.js') - - - diff --git a/app/sketches/build.py b/app/sketches/build.py deleted file mode 100644 index e75b6fd..0000000 --- a/app/sketches/build.py +++ /dev/null @@ -1,36 +0,0 @@ -import os -from django.urls import reverse -from builder.base import BuildNew - - -class BuildSketches(BuildNew): - - def build(self): - self.build_detail_view() - self.build_list_view( - base_path=reverse("sketches:list"), - paginate_by=24 - ) - self.build_year_view("sketches:list_year") - self.build_month_view("sketches:list_month") - - def get_model_queryset(self): - return self.model.objects.all() - - def build_detail_view(self): - ''' - write out all the expenses for each trip - ''' - for obj in self.get_model_queryset(): - url = obj.get_absolute_url() - path, slug = os.path.split(url) - path = '%s/' % path - # write html - response = self.client.get(url) - print(path, slug) - self.write_file(path, response.content, filename=slug) - - -def builder(): - j = BuildSketches("sketches", "sketch") - j.build() diff --git a/app/sketches/migrations/0001_initial.py b/app/sketches/migrations/0001_initial.py deleted file mode 100644 index 1e034b4..0000000 --- a/app/sketches/migrations/0001_initial.py +++ /dev/null @@ -1,32 +0,0 @@ -# Generated by Django 2.0.1 on 2018-02-01 20:56 - -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): - - initial = True - - dependencies = [ - ('locations', '0002_checkin'), - ] - - operations = [ - migrations.CreateModel( - name='Sketch', - 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='pub_date')), - ('pub_date', models.DateTimeField(default=django.utils.timezone.now)), - ('body_html', models.TextField(blank=True)), - ('body_markdown', models.TextField(verbose_name='Note')), - ('point', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)), - ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=1)), - ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')), - ], - ), - ] diff --git a/app/sketches/migrations/0002_auto_20180208_0743.py b/app/sketches/migrations/0002_auto_20180208_0743.py deleted file mode 100644 index 664fcbc..0000000 --- a/app/sketches/migrations/0002_auto_20180208_0743.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 2.0.1 on 2018-02-08 07:43 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('sketches', '0001_initial'), - ] - - operations = [ - migrations.AlterModelOptions( - name='sketch', - options={'get_latest_by': 'pub_date', 'ordering': ('-pub_date',), 'verbose_name_plural': 'sketches'}, - ), - ] diff --git a/app/sketches/migrations/__init__.py b/app/sketches/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/sketches/models.py b/app/sketches/models.py deleted file mode 100644 index aa21678..0000000 --- a/app/sketches/models.py +++ /dev/null @@ -1,88 +0,0 @@ -import re -from django.contrib.gis.db import models -from django.utils import timezone -from django.conf import settings -from django import forms -from locations.models import Location -from django.urls import reverse - -from utils.util import render_images, parse_image, markdown_to_html -from locations.models import CheckIn - -def render_images(s): - s = re.sub('', parse_image, s) - return s - -class Sketch(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) - - class Meta: - ordering = ('-pub_date',) - get_latest_by = 'pub_date' - verbose_name_plural = 'sketches' - - def __str__(self): - return self.title - - def get_absolute_url(self): - return reverse("sketches:detail", kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug}) - - @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_pub_date() - - @property - def get_next_published(self): - return self.get_next_by_pub_date() - - @property - def get_previous_admin_url(self): - n = self.get_previous_by_pub_date() - return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[n.id] ) - - @property - def get_next_admin_url(self): - model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name) - try: - return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[self.get_next_by_pub_date().pk] ) - except model.DoesNotExist: - return '' - - 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(Sketch, self).save() diff --git a/app/sketches/urls.py b/app/sketches/urls.py deleted file mode 100644 index 465a0d2..0000000 --- a/app/sketches/urls.py +++ /dev/null @@ -1,39 +0,0 @@ -from django.urls import path, re_path - -from . import views - -app_name = "sketches" - -urlpatterns = [ - re_path( - r'(?P[0-9]{4})/$', - views.SketchYearArchiveView.as_view(), - name="list_year" - ), - path( - r'', - views.SketchListView.as_view(), - {'page': 1}, - name="list" - ), - path( - r'/', - views.SketchListView.as_view(), - name="list" - ), - path( - r'//.txt', - views.SketchDetailViewTXT.as_view(), - name="detail-txt" - ), - path( - r'//', - views.SketchDetailView.as_view(), - name="detail" - ), - path( - r'//', - views.SketchMonthArchiveView.as_view(month_format='%m'), - name="list_month" - ), -] diff --git a/app/sketches/views.py b/app/sketches/views.py deleted file mode 100644 index b696932..0000000 --- a/app/sketches/views.py +++ /dev/null @@ -1,40 +0,0 @@ -from django.views.generic.dates import YearArchiveView, MonthArchiveView -from django.views.generic.detail import DetailView - -from utils.views import PaginatedListView - -from .models import Sketch - - -class SketchListView(PaginatedListView): - """ - Return a list of Notes in reverse chronological order - """ - queryset = Sketch.objects.all().order_by('-pub_date') - template_name = "archives/sketches.html" - - -class SketchDetailView(DetailView): - model = Sketch - template_name = "details/note.html" - slug_field = "slug" - - -class SketchDetailViewTXT(SketchDetailView): - template_name = "details/entry.txt" - - -class SketchYearArchiveView(YearArchiveView): - queryset = Sketch.objects.all() - date_field = "pub_date" - make_object_list = True - allow_future = True - template_name = "archives/notes_date.html" - - -class SketchMonthArchiveView(MonthArchiveView): - queryset = Sketch.objects.all() - date_field = "pub_date" - allow_future = True - template_name = "archives/notes_date.html" - diff --git a/app/unused_apps/sketches/__init__.py b/app/unused_apps/sketches/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/unused_apps/sketches/admin.py b/app/unused_apps/sketches/admin.py new file mode 100644 index 0000000..0c59867 --- /dev/null +++ b/app/unused_apps/sketches/admin.py @@ -0,0 +1,42 @@ +from django.contrib import admin +from django.contrib.gis.admin import OSMGeoAdmin +from django.contrib.contenttypes.admin import GenericTabularInline + +from .models import Sketch +from utils.widgets import LGEntryForm, OLAdminBase +from utils.util import get_latlon + + +@admin.register(Sketch) +class SketchAdmin(OLAdminBase): + form = LGEntryForm + prepopulated_fields = {"slug": ('title',)} + list_display = ('title', 'slug', 'pub_date', 'location') + fieldsets = ( + ('Note', { + 'fields': ( + 'title', + 'subtitle', + 'body_markdown', + 'slug', + ('pub_date', 'status'), + 'point' + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + } + ), + ) + lat, lon = get_latlon() + default_lon = lon + default_lat = lat + default_zoom = 10 + + class Media: + js = ('image-loader.js', 'next-prev-links.js') + + + diff --git a/app/unused_apps/sketches/build.py b/app/unused_apps/sketches/build.py new file mode 100644 index 0000000..e75b6fd --- /dev/null +++ b/app/unused_apps/sketches/build.py @@ -0,0 +1,36 @@ +import os +from django.urls import reverse +from builder.base import BuildNew + + +class BuildSketches(BuildNew): + + def build(self): + self.build_detail_view() + self.build_list_view( + base_path=reverse("sketches:list"), + paginate_by=24 + ) + self.build_year_view("sketches:list_year") + self.build_month_view("sketches:list_month") + + def get_model_queryset(self): + return self.model.objects.all() + + def build_detail_view(self): + ''' + write out all the expenses for each trip + ''' + for obj in self.get_model_queryset(): + url = obj.get_absolute_url() + path, slug = os.path.split(url) + path = '%s/' % path + # write html + response = self.client.get(url) + print(path, slug) + self.write_file(path, response.content, filename=slug) + + +def builder(): + j = BuildSketches("sketches", "sketch") + j.build() diff --git a/app/unused_apps/sketches/migrations/0001_initial.py b/app/unused_apps/sketches/migrations/0001_initial.py new file mode 100644 index 0000000..1e034b4 --- /dev/null +++ b/app/unused_apps/sketches/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 2.0.1 on 2018-02-01 20:56 + +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): + + initial = True + + dependencies = [ + ('locations', '0002_checkin'), + ] + + operations = [ + migrations.CreateModel( + name='Sketch', + 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='pub_date')), + ('pub_date', models.DateTimeField(default=django.utils.timezone.now)), + ('body_html', models.TextField(blank=True)), + ('body_markdown', models.TextField(verbose_name='Note')), + ('point', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)), + ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=1)), + ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')), + ], + ), + ] diff --git a/app/unused_apps/sketches/migrations/0002_auto_20180208_0743.py b/app/unused_apps/sketches/migrations/0002_auto_20180208_0743.py new file mode 100644 index 0000000..664fcbc --- /dev/null +++ b/app/unused_apps/sketches/migrations/0002_auto_20180208_0743.py @@ -0,0 +1,17 @@ +# Generated by Django 2.0.1 on 2018-02-08 07:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('sketches', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='sketch', + options={'get_latest_by': 'pub_date', 'ordering': ('-pub_date',), 'verbose_name_plural': 'sketches'}, + ), + ] diff --git a/app/unused_apps/sketches/migrations/__init__.py b/app/unused_apps/sketches/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/unused_apps/sketches/models.py b/app/unused_apps/sketches/models.py new file mode 100644 index 0000000..f6df269 --- /dev/null +++ b/app/unused_apps/sketches/models.py @@ -0,0 +1,89 @@ +import re +from django.contrib.gis.db import models +from django.utils import timezone +from django.conf import settings +from django import forms +from locations.models import Location +from django.urls import reverse + +from utils.util import render_images, parse_image, markdown_to_html +from locations.models import CheckIn + +def render_images(s): + s = re.sub('', parse_image, s) + return s + +class Sketch(models.Model): + title = models.CharField(max_length=250, blank=True) + subtitle = models.CharField(max_length=250,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) + + class Meta: + ordering = ('-pub_date',) + get_latest_by = 'pub_date' + verbose_name_plural = 'sketches' + + def __str__(self): + return self.title + + def get_absolute_url(self): + return reverse("sketches:detail", kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug}) + + @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_pub_date() + + @property + def get_next_published(self): + return self.get_next_by_pub_date() + + @property + def get_previous_admin_url(self): + n = self.get_previous_by_pub_date() + return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[n.id] ) + + @property + def get_next_admin_url(self): + model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name) + try: + return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[self.get_next_by_pub_date().pk] ) + except model.DoesNotExist: + return '' + + 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(Sketch, self).save() diff --git a/app/unused_apps/sketches/urls.py b/app/unused_apps/sketches/urls.py new file mode 100644 index 0000000..465a0d2 --- /dev/null +++ b/app/unused_apps/sketches/urls.py @@ -0,0 +1,39 @@ +from django.urls import path, re_path + +from . import views + +app_name = "sketches" + +urlpatterns = [ + re_path( + r'(?P[0-9]{4})/$', + views.SketchYearArchiveView.as_view(), + name="list_year" + ), + path( + r'', + views.SketchListView.as_view(), + {'page': 1}, + name="list" + ), + path( + r'/', + views.SketchListView.as_view(), + name="list" + ), + path( + r'//.txt', + views.SketchDetailViewTXT.as_view(), + name="detail-txt" + ), + path( + r'//', + views.SketchDetailView.as_view(), + name="detail" + ), + path( + r'//', + views.SketchMonthArchiveView.as_view(month_format='%m'), + name="list_month" + ), +] diff --git a/app/unused_apps/sketches/views.py b/app/unused_apps/sketches/views.py new file mode 100644 index 0000000..b696932 --- /dev/null +++ b/app/unused_apps/sketches/views.py @@ -0,0 +1,40 @@ +from django.views.generic.dates import YearArchiveView, MonthArchiveView +from django.views.generic.detail import DetailView + +from utils.views import PaginatedListView + +from .models import Sketch + + +class SketchListView(PaginatedListView): + """ + Return a list of Notes in reverse chronological order + """ + queryset = Sketch.objects.all().order_by('-pub_date') + template_name = "archives/sketches.html" + + +class SketchDetailView(DetailView): + model = Sketch + template_name = "details/note.html" + slug_field = "slug" + + +class SketchDetailViewTXT(SketchDetailView): + template_name = "details/entry.txt" + + +class SketchYearArchiveView(YearArchiveView): + queryset = Sketch.objects.all() + date_field = "pub_date" + make_object_list = True + allow_future = True + template_name = "archives/notes_date.html" + + +class SketchMonthArchiveView(MonthArchiveView): + queryset = Sketch.objects.all() + date_field = "pub_date" + allow_future = True + template_name = "archives/notes_date.html" + diff --git a/design/templates/archives/notes.html b/design/templates/archives/notes.html index 8dc168e..9960fc8 100644 --- a/design/templates/archives/notes.html +++ b/design/templates/archives/notes.html @@ -14,7 +14,7 @@

Field Notes

Quick notes and images from the road

- {% autopaginate object_list 2 %}{% for object in object_list %} + {% autopaginate object_list 16 %}{% for object in object_list %}

{{object.title|safe|amp|smartypants}}

diff --git a/design/templates/archives/sketches.html b/design/templates/archives/sketches.html index cf53ac1..06fe311 100644 --- a/design/templates/archives/sketches.html +++ b/design/templates/archives/sketches.html @@ -4,61 +4,35 @@ {% load pagination_tags %} {% block pagetitle %} Field Notes | luxagraf {% endblock %} {% block metadescription %} Rough notes and sketches from the field {% endblock %} -{%block bodyid%}class="notes" id="notes-archive"{%endblock%} +{%block bodyid%}id="field-notes"{%endblock%} {% block primary %} -
-

Field Notes

-

Quick notes, sketches and images from the road (often literally)

- {% autopaginate object_list 8 %}{% for object in object_list %} -
- {% if object.title %}

{%endif%} -
- {{object.body_html|safe|smartypants}} -
- - - - - -
-{% endfor %} +
+
+

Field Notes

+

Quick notes, sketches and images from the road. This is the semi-orgnized brain dump that comes before the more organized journal entries and essays. If I used social media this is the stuff I'd probably put there, but I prefer to put it here, even if it means a lot few people read it.

+
+ {% autopaginate object_list 30 %} +