diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/sketches/__init__.py | 0 | ||||
-rw-r--r-- | app/sketches/admin.py | 34 | ||||
-rw-r--r-- | app/sketches/build.py | 36 | ||||
-rw-r--r-- | app/sketches/migrations/0001_initial.py | 32 | ||||
-rw-r--r-- | app/sketches/migrations/__init__.py | 0 | ||||
-rw-r--r-- | app/sketches/models.py | 68 | ||||
-rw-r--r-- | app/sketches/urls.py | 39 | ||||
-rw-r--r-- | app/sketches/views.py | 40 |
8 files changed, 249 insertions, 0 deletions
diff --git a/app/sketches/__init__.py b/app/sketches/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/sketches/__init__.py diff --git a/app/sketches/admin.py b/app/sketches/admin.py new file mode 100644 index 0000000..9f3c087 --- /dev/null +++ b/app/sketches/admin.py @@ -0,0 +1,34 @@ +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 + + +@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' + ) + } + ), + ) + class Media: + js = ('image-loader.js',) + + + diff --git a/app/sketches/build.py b/app/sketches/build.py new file mode 100644 index 0000000..ac016c2 --- /dev/null +++ b/app/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 = BuildNotes("sketches", "sketch") + j.build() diff --git a/app/sketches/migrations/0001_initial.py b/app/sketches/migrations/0001_initial.py new file mode 100644 index 0000000..1e034b4 --- /dev/null +++ b/app/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/sketches/migrations/__init__.py b/app/sketches/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/sketches/migrations/__init__.py diff --git a/app/sketches/models.py b/app/sketches/models.py new file mode 100644 index 0000000..310bcd1 --- /dev/null +++ b/app/sketches/models.py @@ -0,0 +1,68 @@ +from django.contrib.gis.db import models +from django.utils import timezone +from django.conf import settings +from locations.models import Location + +from utils.widgets import markdown_to_html +from locations.models import CheckIn +from jrnl.models import render_images + + + +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) + + def __str__(self): + return self.title + + def get_absolute_url(self): + return reverse("sketch: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() + + + 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 new file mode 100644 index 0000000..4bade9b --- /dev/null +++ b/app/sketches/urls.py @@ -0,0 +1,39 @@ +from django.urls import path + +from . import views + +app_name = "sketches" + +urlpatterns = [ + 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" + ), + path( + r'<int:year>/', + views.SketchYearArchiveView.as_view(), + name="list_year" + ), +] diff --git a/app/sketches/views.py b/app/sketches/views.py new file mode 100644 index 0000000..b2ae3d7 --- /dev/null +++ b/app/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 SketchList(PaginatedListView): + """ + Return a list of Notes in reverse chronological order + """ + queryset = Sketch.objects.all().order_by('-pub_date') + template_name = "archives/notes.html" + + +class SketchDetailView(DetailView): + model = Sketch + template_name = "details/note.html" + slug_field = "slug" + + +class NoteDetailViewTXT(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" + |