diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/figments/models.py | 14 | ||||
-rw-r--r-- | app/income/migrations/0005_invoice_slug.py | 19 | ||||
-rw-r--r-- | app/income/parser.py | 19 | ||||
-rw-r--r-- | app/income/views.py | 38 | ||||
-rw-r--r-- | app/jrnl/models.py | 12 | ||||
-rw-r--r-- | app/jrnl/views.py | 2 | ||||
-rw-r--r-- | app/locations/admin.py | 1 | ||||
-rw-r--r-- | app/locations/migrations/0011_campsite_campsite_price.py | 18 | ||||
-rw-r--r-- | app/photos/models.py | 4 | ||||
-rw-r--r-- | app/photos/urls.py | 28 | ||||
-rw-r--r-- | app/photos/views.py | 17 | ||||
-rw-r--r-- | app/unused_apps/bird.html | 47 | ||||
-rw-r--r-- | app/utils/util.py | 4 |
13 files changed, 188 insertions, 35 deletions
diff --git a/app/figments/models.py b/app/figments/models.py index d871f4d..8b22049 100644 --- a/app/figments/models.py +++ b/app/figments/models.py @@ -59,20 +59,6 @@ class Figment(models.Model): def get_series(self): return "\n".join([s.title for s in self.series.all()]) - @classmethod - def from_db(cls, db, field_names, values): - # default implementation of from_db() (could be replaced - # with super()) - if cls._deferred: - instance = cls(**zip(field_names, values)) - else: - instance = cls(*values) - instance._state.adding = False - instance._state.db = db - # customization to store the original field values on the instance - instance._loaded_values = dict(zip(field_names, values)) - return instance - def save(self, *args, **kwargs): if not self.id and not self.pub_date: self.pub_date = datetime.datetime.now() diff --git a/app/income/migrations/0005_invoice_slug.py b/app/income/migrations/0005_invoice_slug.py new file mode 100644 index 0000000..3b6dfb2 --- /dev/null +++ b/app/income/migrations/0005_invoice_slug.py @@ -0,0 +1,19 @@ +# Generated by Django 2.1.1 on 2018-09-03 19:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('income', '0004_invoice_invoiceitem'), + ] + + operations = [ + migrations.AddField( + model_name='invoice', + name='slug', + field=models.SlugField(default='slug'), + preserve_default=False, + ), + ] diff --git a/app/income/parser.py b/app/income/parser.py new file mode 100644 index 0000000..9524902 --- /dev/null +++ b/app/income/parser.py @@ -0,0 +1,19 @@ +with open('timesheet.csv', newline='') as csvfile: + reader = csv.reader(csvfile, delimiter=';') + counter = 0 + f = "%Y-%m-%d %H:%M:%S" + for row in reader: + if counter > 0: + timer = row[0]+' '+row[1] + timerer = row[0]+' '+row[2] + time_start = datetime.datetime.strptime(timer, f) + time_end = datetime.datetime.strptime(timerer, f) + print(row[4]) + print(timerer, time_end) + InvoiceItem.objects.get_or_create( + time_start=time_start, + time_end=time_end, + work_done=row[4] + ) + counter = counter +1 +f = "%Y-%m-%d %H:%M:%S" diff --git a/app/income/views.py b/app/income/views.py new file mode 100644 index 0000000..69ca1fd --- /dev/null +++ b/app/income/views.py @@ -0,0 +1,38 @@ +import datetime +from django.views.generic.detail import DetailView + +from templated_docs import fill_template +from templated_docs.http import FileResponse + +from .models import Invoice, InvoiceItem + + +class MonthlyInvoiceView(DetailView): + model = Invoice + template_name = "admin/income/monthly.html" + slug_field = "slug" + + def get_context_data(self, **kwargs): + context = super(MonthlyInvoiceView, self).get_context_data(**kwargs) + context['object_list'] = InvoiceItem.objects.filter(time_start__range=[self.object.date_start, self.object.date_end]) + total_time = [] + for item in context['object_list']: + total_time.append(item.rounded_total) + duration = (sum(total_time, datetime.timedelta())) + hours = duration.total_seconds() // 3600 + context['total_hours'] = hours + context['total_billed'] = int(hours * 100) + context['invoice_number'] = self.object.id+21 + return context + + +class DownloadMonthlyInvoiceView(MonthlyInvoiceView): + model = Invoice + slug_field = "slug" + + def get(self, *args, **kwargs): + self.object = self.get_object() # assign the object to the view + obj = self.get_context_data() + filename = fill_template('invoice.odt', obj, output_format='pdf') + visible_filename = 'invoice.{}'.format('pdf') + return FileResponse(filename, visible_filename) diff --git a/app/jrnl/models.py b/app/jrnl/models.py index 8952eef..809353c 100644 --- a/app/jrnl/models.py +++ b/app/jrnl/models.py @@ -115,6 +115,16 @@ class Entry(models.Model): else: return self.image.url + def get_featured_image_thumb(self): + if self.featured_image: + return self.featured_image.get_image_by_size("tn") + else: + print(self.image.url) + image_dir, img = self.image.url.split('post-images/')[1].split('/') + print(image_dir, img) + return '%spost-images/%s/%s' % (settings.IMAGES_URL, image_dir, img) + + @property def state(self): return self.location.state @@ -179,7 +189,9 @@ class Entry(models.Model): old = type(self).objects.get(pk=self.pk) if self.pk else None if old and old.featured_image != self.featured_image: # Field has changed s = LuxImageSize.objects.get(name="featured_jrnl") + ss = LuxImageSize.objects.get(name="picwide-med") self.featured_image.sizes.add(s) + self.featured_image.sizes.add(ss) self.featured_image.save() super(Entry, self).save(*args, **kwargs) diff --git a/app/jrnl/views.py b/app/jrnl/views.py index ed8efcf..cd63482 100644 --- a/app/jrnl/views.py +++ b/app/jrnl/views.py @@ -103,7 +103,7 @@ class HomepageList(ListView): queryset = Entry.objects.filter(status__exact=1).exclude(pk=exclude.featured.pk)[:8] def get_template_names(self): - obj = HomepageCurrator.objects.get(pk=1) + obj = Home.objects.get(pk=1) return ['%s' % obj.template_name] def get_context_data(self, **kwargs): diff --git a/app/locations/admin.py b/app/locations/admin.py index 01da84d..4298761 100644 --- a/app/locations/admin.py +++ b/app/locations/admin.py @@ -164,7 +164,6 @@ class LocationAdmin(OSMGeoAdmin): list_display = ('name', 'pub_date', 'parent', 'state', 'slug') prepopulated_fields = {'slug': ('name',)} search_fields = ('name', 'state') - ordering = ('pub_date', 'name') list_filter = ('pub_date', 'state__country__lux_region', 'state') save_as = True search_fields = ['name'] diff --git a/app/locations/migrations/0011_campsite_campsite_price.py b/app/locations/migrations/0011_campsite_campsite_price.py new file mode 100644 index 0000000..c3251e0 --- /dev/null +++ b/app/locations/migrations/0011_campsite_campsite_price.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.1 on 2018-09-05 11:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('locations', '0010_merge_20180708_1047'), + ] + + operations = [ + migrations.AddField( + model_name='campsite', + name='campsite_price', + field=models.IntegerField(blank=True, null=True), + ), + ] diff --git a/app/photos/models.py b/app/photos/models.py index 5a41182..9f78ac9 100644 --- a/app/photos/models.py +++ b/app/photos/models.py @@ -179,7 +179,7 @@ class LuxImage(models.Model): self.location = apps.get_model('locations', 'Location').objects.filter( geometry__contains=self.point ).get() - except DoesNotExist: + except apps.get_model('locations', 'Location').DoesNotExist: raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL)) super(LuxImage, self).save() @@ -337,7 +337,7 @@ class Photo(models.Model): return '%sflickr/med/%s/%s.jpg' % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.flickr_id) def get_local_orig_url(self): - return '%sflickr/full/%s/%s.jpg' % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.flickr_id) + return '%s/flickr/full/%s/%s.jpg' % (settings.IMAGES_ROOT, self.pub_date.strftime("%Y"), self.flickr_id) def get_local_slideshow_url(self): return '%sslideshow/%s/%s.jpg' % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), self.flickr_id) diff --git a/app/photos/urls.py b/app/photos/urls.py index 1da29a6..8c51d60 100644 --- a/app/photos/urls.py +++ b/app/photos/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import url +from django.urls import path, re_path from django.views.generic.base import RedirectView from . import views @@ -6,57 +6,57 @@ from . import views app_name = "photos" urlpatterns = [ - url( - r'data/(?P<slug>[-\w]+)/$', + path( + r'data/(<str:slug>/$', views.photo_json ), - url( + re_path( r'data/admin/preview/(?P<pk>\d+)/$', views.photo_preview_json, name="admin_image_preview" ), - url( + re_path( r'data/admin/tn/(?P<pk>\d+)/$', views.thumb_preview_json, name="admin_thumb_preview" ), - url( + re_path( r'galleries/private/(?P<slug>[-\w]+)$', views.PrivateGallery.as_view(), name="private" ), - url( + re_path( r'galleries/private/(?P<page>\d+)/$', views.PrivateGalleryList.as_view(), name="private_list" ), - url( + re_path( r'galleries/private/$', RedirectView.as_view(url="/photos/galleries/private/1/", permanent=False) ), - url( + re_path( r'galleries/(?P<slug>[-\w]+)$', views.Gallery.as_view(), name="private" ), - url( + re_path( r'galleries/(?P<page>\d+)/$', views.GalleryList.as_view(), name="private_list" ), - url( + re_path( r'galleries/$', RedirectView.as_view(url="/photos/galleries/1/", permanent=False) ), - url( + re_path( r'(?P<page>\d+)/$', views.gallery_list, ), - url( + re_path( r'(?P<slug>[-\w]+)/$', RedirectView.as_view(url="/photos/%(slug)s/1/", permanent=False) ), - url( + re_path( r'', RedirectView.as_view(url="/photos/1/", permanent=False) ), diff --git a/app/photos/views.py b/app/photos/views.py index 87cc996..ec4ba61 100644 --- a/app/photos/views.py +++ b/app/photos/views.py @@ -1,5 +1,5 @@ import json -from django.shortcuts import render_to_response +from django.shortcuts import render_to_response, render from django.template import RequestContext from django.http import Http404, HttpResponse from django.core import serializers @@ -49,6 +49,19 @@ class GalleryList(PaginatedListView): return context +class OldGalleryList(PaginatedListView): + template_name = 'archives/gallery_list.html' + model = PhotoGallery + + def get_queryset(self): + return PhotoGallery.objects.filter(is_public=True) + + def get_context_data(self, **kwargs): + # Call the base implementation first to get a context + context = super(OldGalleryList, self).get_context_data(**kwargs) + return context + + def gallery_list(request, page): request.page_url = '/photos/%d/' request.page = int(page) @@ -56,7 +69,7 @@ def gallery_list(request, page): 'object_list': PhotoGallery.objects.all(), 'page': page, } - return render_to_response("archives/photos.html", context, context_instance=RequestContext(request)) + return render(request, "archives/photos.html", context) def gallery(request, slug): diff --git a/app/unused_apps/bird.html b/app/unused_apps/bird.html new file mode 100644 index 0000000..43877fe --- /dev/null +++ b/app/unused_apps/bird.html @@ -0,0 +1,47 @@ +{% extends 'base.html' %} +{% load get_image_by_size %} +{% block extrahead %} +<style> +#detail-map-canvas { height: 100%;} +</style> +{% endblock %} +{% block bodyid %}class="birds"{%endblock%} +{% block primary %} +<main> +<article> +<h1>{{object.common_name}}</h1> +<h2 class="sci">{{object.scientific_name}}</h2> +<h3 class="sci">Family {{object.bird_class.scientific_name}} ({{object.bird_class}})</h3> +{% load get_image_by_size %} +{% load get_image_width %} +<div class="post--image"> +<figure> +<img class="picfull" sizes="(max-width: 680px) 100vw, (min-width: 681) 680px" srcset="{% for size in sighting.image.sizes.all%}{% get_image_by_size sighting.image size.name %} {{size.width}}w{% if forloop.last%}"{%else%}, {%endif%}{%endfor%} + {% for size in sighting.image.sizes.all%}{%if forloop.first %} src="{% get_image_by_size sighting.image size.name %}"{%endif%}{%endfor%} alt="{{sighting.image.alt}} photographed by {% if sighting.image.photo_credit_source %}{{sighting.image.photo_credit_source}}{%else%}luxagraf{%endif%}" > +{% if sighting.image.photo_credit_source %}<figcaption>photo by <a href="{{sighting.image.photo_credit_url}}">{{sighting.image.photo_credit_source}}</a></figcaption>{%endif%} +</figure> +</div> +{%if recording %} +<div class="audio-figure"> +<audio autoplay="autoplay" controls="controls"> + <source src="/media/{{recording.audio}}" /> +</audio> +<small>Audio recorded by {{recording.recorder}} on {{recording.pub_date|date:"F j, Y"}} in {{recording.location}}. <a href="{{recording.link}}">© {{recording.copyright}}</a></small> +</div> +{%endif%} +<p id="endnode">Seen at {{sighting.location}}, {{sighting.location.comma_name}} in {{sighting.date|date:"M Y"}} by {% for person in sighting.seen_by.all %}<a href="/birds/{{person}}/">{% if person.username == "luxagraf"%}Scott{%else%}{{person.username|capfirst}}{%endif%}</a>{%if forloop.last %}{%else%}{% if forloop.revcounter == 2 %}, and {%else%}, {%endif%}{%endif%}{%endfor%}</p> +{% if recording.audio %} +{%endif%} +</article> +</main> +{% endblock %} + +{% block js %} +<script src="/media/js/leaflet-master/leaflet-mod.js"></script> +<script src="/media/js/detail.min.js"></script> +<script type="text/javascript"> +window.onload = function() { + createBirdMap({{sighting.latitude}},{{sighting.longitude}}, 12, { type:'point', lat:'{{sighting.latitude}}', lon:'{{sighting.longitude}}'}); return false; +} +</script> +{% endblock %} diff --git a/app/utils/util.py b/app/utils/util.py index 4cc7d31..1ceb699 100644 --- a/app/utils/util.py +++ b/app/utils/util.py @@ -57,9 +57,11 @@ def parse_image(s): caption = False exif = False cluster_class = None + is_cluster = False extra = None if cl[0] == 'cluster': css_class = cl[0] + is_cluster = True cluster_class = cl[1] try: if cl[2] == 'caption': @@ -89,7 +91,7 @@ def parse_image(s): print('caption'+str(caption)) else: css_class = cl[0] - return render_to_string("lib/img_%s.html" % css_class, {'image': i, 'caption': caption, 'exif': exif, 'cluster_class': cluster_class, 'extra':extra}) + return render_to_string("lib/img_%s.html" % css_class, {'image': i, 'caption': caption, 'exif': exif, 'is_cluster': is_cluster, 'cluster_class': cluster_class, 'extra': extra}) def render_images(s): |