diff options
Diffstat (limited to 'bak/unused_apps/recordings')
-rw-r--r-- | bak/unused_apps/recordings/__init__.py | 0 | ||||
-rw-r--r-- | bak/unused_apps/recordings/admin.py | 38 | ||||
-rw-r--r-- | bak/unused_apps/recordings/migrations/0001_initial.py | 34 | ||||
-rw-r--r-- | bak/unused_apps/recordings/migrations/0002_auto_20190325_1417.py | 26 | ||||
-rw-r--r-- | bak/unused_apps/recordings/migrations/__init__.py | 0 | ||||
-rw-r--r-- | bak/unused_apps/recordings/models.py | 71 |
6 files changed, 169 insertions, 0 deletions
diff --git a/bak/unused_apps/recordings/__init__.py b/bak/unused_apps/recordings/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/bak/unused_apps/recordings/__init__.py diff --git a/bak/unused_apps/recordings/admin.py b/bak/unused_apps/recordings/admin.py new file mode 100644 index 0000000..d972497 --- /dev/null +++ b/bak/unused_apps/recordings/admin.py @@ -0,0 +1,38 @@ +from django.contrib import admin +from django.contrib.contenttypes.admin import GenericTabularInline + +from .models import Audio +from utils.widgets import LGEntryForm, OLAdminBase +from utils.util import get_latlon + +@admin.register(Audio) +class NoteAdmin(OLAdminBase): + form = LGEntryForm + prepopulated_fields = {"slug": ('title',)} + list_display = ('title', 'pub_date', 'location') + fieldsets = ( + ('Note', { + 'fields': ( + 'title', + 'subtitle', + 'body_markdown', + 'slug', + 'pub_date', + ('mp3', 'ogg'), + '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/bak/unused_apps/recordings/migrations/0001_initial.py b/bak/unused_apps/recordings/migrations/0001_initial.py new file mode 100644 index 0000000..d70b7dc --- /dev/null +++ b/bak/unused_apps/recordings/migrations/0001_initial.py @@ -0,0 +1,34 @@ +# Generated by Django 2.1.7 on 2019-03-25 14:12 + +import datetime +from django.db import migrations, models +import recordings.models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Audio', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('subtitle', models.CharField(blank=True, max_length=200)), + ('slug', models.SlugField(blank=True, unique_for_date='pub_date')), + ('body_html', models.TextField(blank=True)), + ('body_markdown', models.TextField(blank=True)), + ('pub_date', models.DateTimeField(default=datetime.datetime.now)), + ('mp3', models.FileField(blank=True, null=True, upload_to=recordings.models.get_upload_path)), + ('ogg', models.FileField(blank=True, null=True, upload_to=recordings.models.get_upload_path)), + ], + options={ + 'get_latest_by': 'pub_date', + 'ordering': ('-pub_date',), + }, + ), + ] diff --git a/bak/unused_apps/recordings/migrations/0002_auto_20190325_1417.py b/bak/unused_apps/recordings/migrations/0002_auto_20190325_1417.py new file mode 100644 index 0000000..d5193d3 --- /dev/null +++ b/bak/unused_apps/recordings/migrations/0002_auto_20190325_1417.py @@ -0,0 +1,26 @@ +# Generated by Django 2.1.7 on 2019-03-25 14:17 + +import django.contrib.gis.db.models.fields +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('locations', '0017_auto_20190217_1849'), + ('recordings', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='audio', + name='location', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location'), + ), + migrations.AddField( + model_name='audio', + name='point', + field=django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326), + ), + ] diff --git a/bak/unused_apps/recordings/migrations/__init__.py b/bak/unused_apps/recordings/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/bak/unused_apps/recordings/migrations/__init__.py diff --git a/bak/unused_apps/recordings/models.py b/bak/unused_apps/recordings/models.py new file mode 100644 index 0000000..8da5c36 --- /dev/null +++ b/bak/unused_apps/recordings/models.py @@ -0,0 +1,71 @@ +import datetime +from django.contrib.gis.db import models +from django import forms +from django.urls import reverse +from django.apps import apps + +from utils.util import render_images, markdown_to_html + +from locations.models import Location, CheckIn + + +def get_upload_path(self, filename): + return "audio/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) + + +class Audio(models.Model): + title = models.CharField(max_length=200) + subtitle = models.CharField(max_length=200, blank=True) + slug = models.SlugField(unique_for_date='pub_date', blank=True) + body_html = models.TextField(blank=True) + body_markdown = models.TextField(blank=True) + pub_date = models.DateTimeField(default=datetime.datetime.now) + mp3 = models.FileField(blank=True, null=True, upload_to=get_upload_path) + ogg = models.FileField(blank=True, null=True, upload_to=get_upload_path) + point = models.PointField(blank=True, null=True) + location = models.ForeignKey(Location, on_delete=models.CASCADE, blank=True, null=True) + + class Meta: + ordering = ('-pub_date',) + get_latest_by = 'pub_date' + + def __str__(self): + return self.title + + def get_absolute_url(self): + return reverse("prompt:detail", kwargs={"slug": self.slug}) + + @property + def get_previous_published(self): + return self.get_previous_by_pub_date(status__exact=1) + + @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_published(self): + return self.get_next_by_pub_date(status__exact=1) + + @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 get_type(self): + return str(self.__class__.__name__) + + 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)) + super(Audio, self).save(*args, **kwargs) |