diff options
author | luxagraf <sng@luxagraf.net> | 2019-03-03 15:42:30 -0600 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2019-03-03 15:42:30 -0600 |
commit | c24e6043db413f5722e7d378805da069698d64e7 (patch) | |
tree | 918a82522b1f2775bbdceb8abc3d0772c0c50f4a /app/unused_apps | |
parent | 16e406acfe5ae26b7f80fa6b7cb1a1c1194d4697 (diff) |
got rid of old sketches model
Diffstat (limited to 'app/unused_apps')
-rw-r--r-- | app/unused_apps/sketches/__init__.py | 0 | ||||
-rw-r--r-- | app/unused_apps/sketches/admin.py | 42 | ||||
-rw-r--r-- | app/unused_apps/sketches/build.py | 36 | ||||
-rw-r--r-- | app/unused_apps/sketches/migrations/0001_initial.py | 32 | ||||
-rw-r--r-- | app/unused_apps/sketches/migrations/0002_auto_20180208_0743.py | 17 | ||||
-rw-r--r-- | app/unused_apps/sketches/migrations/__init__.py | 0 | ||||
-rw-r--r-- | app/unused_apps/sketches/models.py | 89 | ||||
-rw-r--r-- | app/unused_apps/sketches/urls.py | 39 | ||||
-rw-r--r-- | app/unused_apps/sketches/views.py | 40 |
9 files changed, 295 insertions, 0 deletions
diff --git a/app/unused_apps/sketches/__init__.py b/app/unused_apps/sketches/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/unused_apps/sketches/__init__.py 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 --- /dev/null +++ b/app/unused_apps/sketches/migrations/__init__.py 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('<img(.*)/>', 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<year>[0-9]{4})/$', + views.SketchYearArchiveView.as_view(), + name="list_year" + ), + path( + r'', + views.SketchListView.as_view(), + {'page': 1}, + name="list" + ), + path( + r'<int:page>/', + views.SketchListView.as_view(), + name="list" + ), + path( + r'<int:year>/<int:month>/<str:slug>.txt', + views.SketchDetailViewTXT.as_view(), + name="detail-txt" + ), + path( + r'<int:year>/<int:month>/<str:slug>', + views.SketchDetailView.as_view(), + name="detail" + ), + path( + r'<int:year>/<int:month>/', + 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" + |