summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/prompts/__init__.py0
-rw-r--r--app/prompts/admin.py30
-rw-r--r--app/prompts/migrations/0001_initial.py32
-rw-r--r--app/prompts/migrations/0002_auto_20190228_0941.py34
-rw-r--r--app/prompts/migrations/0003_prompt_prompt_type.py18
-rw-r--r--app/prompts/migrations/__init__.py0
-rw-r--r--app/prompts/models.py59
-rw-r--r--app/prompts/urls.py13
-rw-r--r--app/prompts/views.py11
9 files changed, 197 insertions, 0 deletions
diff --git a/app/prompts/__init__.py b/app/prompts/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/prompts/__init__.py
diff --git a/app/prompts/admin.py b/app/prompts/admin.py
new file mode 100644
index 0000000..f12c904
--- /dev/null
+++ b/app/prompts/admin.py
@@ -0,0 +1,30 @@
+from django.contrib import admin
+
+from utils.widgets import LGEntryForm
+from .models import Prompt
+
+
+@admin.register(Prompt)
+class PromptAdmin(admin.ModelAdmin):
+ form = LGEntryForm
+ prepopulated_fields = {"slug": ('title',)}
+ list_display = ('title', 'source', 'prompt_type')
+ list_filter = ('source', 'prompt_type')
+ fieldsets = (
+ ('Prompt', {
+ 'fields': (
+ 'title',
+ 'subtitle',
+ 'body_markdown',
+ ('pub_date', 'prompt_type'),
+ ('slug','source'),
+ 'meta_description'
+ ),
+ 'classes': (
+ 'show',
+ 'extrapretty',
+ 'wide'
+ )
+ }
+ ),
+ )
diff --git a/app/prompts/migrations/0001_initial.py b/app/prompts/migrations/0001_initial.py
new file mode 100644
index 0000000..c5a24ec
--- /dev/null
+++ b/app/prompts/migrations/0001_initial.py
@@ -0,0 +1,32 @@
+# Generated by Django 2.1.5 on 2019-02-20 22:52
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Prompt',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('title', models.CharField(max_length=200)),
+ ('subtitle', models.CharField(max_length=200)),
+ ('slug', models.SlugField(unique_for_date='pub_date')),
+ ('body_html', models.TextField(blank=True)),
+ ('body_markdown', models.TextField()),
+ ('pub_date', models.DateTimeField(verbose_name='Date published')),
+ ('meta_description', models.CharField(blank=True, max_length=256, null=True)),
+ ('source', models.CharField(max_length=350)),
+ ],
+ options={
+ 'ordering': ('-pub_date',),
+ 'get_latest_by': 'pub_date',
+ },
+ ),
+ ]
diff --git a/app/prompts/migrations/0002_auto_20190228_0941.py b/app/prompts/migrations/0002_auto_20190228_0941.py
new file mode 100644
index 0000000..5b66a99
--- /dev/null
+++ b/app/prompts/migrations/0002_auto_20190228_0941.py
@@ -0,0 +1,34 @@
+# Generated by Django 2.1.7 on 2019-02-28 09:41
+
+import datetime
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('prompts', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='prompt',
+ name='pub_date',
+ field=models.DateTimeField(default=datetime.datetime.now),
+ ),
+ migrations.AlterField(
+ model_name='prompt',
+ name='slug',
+ field=models.SlugField(blank=True, unique_for_date='pub_date'),
+ ),
+ migrations.AlterField(
+ model_name='prompt',
+ name='source',
+ field=models.CharField(blank=True, max_length=350),
+ ),
+ migrations.AlterField(
+ model_name='prompt',
+ name='subtitle',
+ field=models.CharField(blank=True, max_length=200),
+ ),
+ ]
diff --git a/app/prompts/migrations/0003_prompt_prompt_type.py b/app/prompts/migrations/0003_prompt_prompt_type.py
new file mode 100644
index 0000000..d027c6e
--- /dev/null
+++ b/app/prompts/migrations/0003_prompt_prompt_type.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.1.2 on 2020-07-05 22:04
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('prompts', '0002_auto_20190228_0941'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='prompt',
+ name='prompt_type',
+ field=models.IntegerField(choices=[(0, 'Meditation'), (1, 'Writing'), (2, 'Kids Writing')], default=0),
+ ),
+ ]
diff --git a/app/prompts/migrations/__init__.py b/app/prompts/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/prompts/migrations/__init__.py
diff --git a/app/prompts/models.py b/app/prompts/models.py
new file mode 100644
index 0000000..00ce3ce
--- /dev/null
+++ b/app/prompts/models.py
@@ -0,0 +1,59 @@
+import datetime
+from django.contrib.gis.db import models
+from django.urls import reverse
+from django.apps import apps
+
+from utils.util import render_images, markdown_to_html
+
+
+class Prompt(models.Model):
+ title = models.CharField(max_length=200)
+ subtitle = models.CharField(max_length=200, blank=True)
+ meta_description = models.CharField(max_length=256, null=True, blank=True)
+ slug = models.SlugField(unique_for_date='pub_date', blank=True)
+ body_markdown = models.TextField()
+ body_html = models.TextField(blank=True)
+ pub_date = models.DateTimeField(default=datetime.datetime.now)
+ source = models.CharField(max_length=350, blank=True)
+ PROMPT_TYPE = (
+ (0, 'Meditation'),
+ (1, 'Writing'),
+ (2, 'Kids Writing'),
+ )
+ prompt_type = models.IntegerField(choices=PROMPT_TYPE, default=0)
+
+ 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 save(self, *args, **kwargs):
+ md = render_images(self.body_markdown)
+ self.body_html = markdown_to_html(md)
+ super(Prompt, self).save(*args, **kwargs)
diff --git a/app/prompts/urls.py b/app/prompts/urls.py
new file mode 100644
index 0000000..7cbe09a
--- /dev/null
+++ b/app/prompts/urls.py
@@ -0,0 +1,13 @@
+from django.urls import path
+
+from . import views
+
+app_name = "prompts"
+
+urlpatterns = [
+ path(
+ r'',
+ views.RandomList.as_view(),
+ name="random-prompt"
+ ),
+]
diff --git a/app/prompts/views.py b/app/prompts/views.py
new file mode 100644
index 0000000..4744299
--- /dev/null
+++ b/app/prompts/views.py
@@ -0,0 +1,11 @@
+from django.views.generic.detail import DetailView
+
+from .models import Prompt
+
+
+class PromptList(DetailView):
+ model = Prompt
+
+ def get_object(self, queryset):
+ """ This might be faster: random.choice(Prompt.objects.all())"""
+ return Prompt.objects.order_by('?').first()