2
0
David Ray 8 жил өмнө
parent
commit
e059e5d6de

+ 62 - 0
bakerydemo/locations/migrations/0001_initial.py

@@ -0,0 +1,62 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-09 16:05
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import modelcluster.fields
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+        ('wagtailimages', '0017_reduce_focal_point_key_max_length'),
+        ('wagtailcore', '0032_add_bulk_delete_page_permission'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='LocationOperatingHours',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
+                ('day', models.CharField(choices=[('MON', 'MON'), ('TUE', 'TUE'), ('WED', 'WED'), ('THU', 'THU'), ('FRI', 'FRI'), ('SAT', 'SAT'), ('SUN', 'SUN')], default='MON', max_length=3)),
+                ('opening_time', models.TimeField()),
+                ('closing_time', models.TimeField()),
+            ],
+            options={
+                'abstract': False,
+                'ordering': ['sort_order'],
+            },
+        ),
+        migrations.CreateModel(
+            name='LocationPage',
+            fields=[
+                ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
+                ('address', models.TextField()),
+                ('lat_long', models.CharField(max_length=36)),
+                ('image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')),
+            ],
+            options={
+                'abstract': False,
+            },
+            bases=('wagtailcore.page',),
+        ),
+        migrations.CreateModel(
+            name='LocationsLandingPage',
+            fields=[
+                ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
+            ],
+            options={
+                'abstract': False,
+            },
+            bases=('wagtailcore.page',),
+        ),
+        migrations.AddField(
+            model_name='locationoperatinghours',
+            name='location',
+            field=modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='hours_of_operation', to='locations.LocationPage'),
+        ),
+    ]

+ 109 - 0
bakerydemo/locations/models.py

@@ -0,0 +1,109 @@
+from django.db import models
+
+from modelcluster.fields import ParentalKey
+
+from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel
+from wagtail.wagtailcore.models import Orderable, Page
+from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
+from wagtail.wagtailsearch import index
+
+
+class OperatingHours(models.Model):
+    '''
+    Django model to capture operating hours for a Location
+    '''
+    MONDAY = 'MON'
+    TUESDAY = 'TUE'
+    WEDNESDAY = 'WED'
+    THURSDAY = 'THU'
+    FRIDAY = 'FRI'
+    SATURDAY = 'SAT'
+    SUNDAY = 'SUN'
+
+    DAY_CHOICES = (
+        (MONDAY, 'MON'),
+        (TUESDAY, 'TUE'),
+        (WEDNESDAY, 'WED'),
+        (THURSDAY, 'THU'),
+        (FRIDAY, 'FRI'),
+        (SATURDAY, 'SAT'),
+        (SUNDAY, 'SUN'),
+    )
+
+    day = models.CharField(
+        max_length=3,
+        choices=DAY_CHOICES,
+        default=MONDAY,
+    )
+    opening_time = models.TimeField()
+    closing_time = models.TimeField()
+
+    panels = [
+        FieldPanel('day'),
+        FieldPanel('opening_time'),
+        FieldPanel('closing_time'),
+    ]
+
+    class Meta:
+        abstract = True
+
+    def __str__(self):
+        return '{}: {} - {}'.format(self.day, self.opening_time, self.closing_time)
+
+
+class LocationOperatingHours(Orderable, OperatingHours):
+    '''
+    Operating Hours entry for a Location
+    '''
+    location = ParentalKey(
+        'LocationPage',
+        related_name='hours_of_operation'
+    )
+
+
+class LocationsLandingPage(Page):
+    '''
+    Home page for locations
+    '''
+
+    pass
+
+
+class LocationPage(Page):
+    '''
+    Detail for a specific location
+    '''
+
+    address = models.TextField()
+    image = models.ForeignKey(
+        'wagtailimages.Image',
+        null=True,
+        blank=True,
+        on_delete=models.SET_NULL,
+        related_name='+'
+    )
+    lat_long = models.CharField(
+        max_length=36,
+        help_text="Comma separated lat/long. (Ex. 64.144367, -21.939182) \
+                   Right click Google Maps and click 'What\'s Here'"
+
+
+    )
+
+    # Search index configuration
+
+    search_fields = Page.search_fields + [
+        index.SearchField('address'),
+    ]
+
+    # Editor panels configuration
+
+    content_panels = Page.content_panels + [
+        FieldPanel('address', classname="full"),
+        FieldPanel('lat_long'),
+        ImageChooserPanel('image'),
+        InlinePanel('hours_of_operation', label="Hours of Operation")
+    ]
+
+    def __str__(self):
+        return self.name

+ 1 - 0
requirements.txt

@@ -1,4 +1,5 @@
 Django
 elasticsearch
 wagtail
+wagtailfontawesome
 Pillow