Verified Commit 2e87e21e authored by David Haynes's avatar David Haynes 🙆
Browse files

Labels for Facilities

- tags are for search
- labels are for informative phrases
- classifiers are for choosing which site to display on (shopmason, sodoxo, etc.)

Closes #64
parent ddfab2cb
#!/bin/sh
until nc -z db 3306; do until nc -z db 3306; do
echo "waiting for database to start..." echo "waiting for database to start..."
sleep 1 sleep 1
......
...@@ -15,6 +15,7 @@ from django.contrib.gis.admin import OSMGeoAdmin ...@@ -15,6 +15,7 @@ from django.contrib.gis.admin import OSMGeoAdmin
# App Imports # App Imports
from .models import Facility, Schedule, OpenTime, Category, Location, Alert from .models import Facility, Schedule, OpenTime, Category, Location, Alert
@admin.register(Facility)
class FacilityAdmin(admin.ModelAdmin): class FacilityAdmin(admin.ModelAdmin):
""" """
Custom Admin panel for the Facility model. Custom Admin panel for the Facility model.
...@@ -27,9 +28,11 @@ class FacilityAdmin(admin.ModelAdmin): ...@@ -27,9 +28,11 @@ class FacilityAdmin(admin.ModelAdmin):
# We are basically reordering things to look nicer to the user here # We are basically reordering things to look nicer to the user here
fieldsets = ( fieldsets = (
(None, { (None, {
'fields': ('facility_name', 'logo', 'facility_category', 'facility_location', 'fields': ('facility_name', 'logo', 'facility_category',
'main_schedule', 'special_schedules', 'facility_location', 'main_schedule', 'special_schedules',
'facility_product_tags', 'tapingo_url','phone_number', 'note', 'owners'), ('facility_product_tags', 'facility_labels',
'facility_classifier'),
'tapingo_url', 'phone_number', 'note', 'owners'),
}), }),
) )
...@@ -54,6 +57,7 @@ class OpenTimeInline(admin.TabularInline): ...@@ -54,6 +57,7 @@ class OpenTimeInline(admin.TabularInline):
}), }),
) )
@admin.register(Schedule)
class ScheduleAdmin(admin.ModelAdmin): class ScheduleAdmin(admin.ModelAdmin):
""" """
Custom Admin panel for the Schedule model. Custom Admin panel for the Schedule model.
...@@ -79,10 +83,6 @@ class ScheduleAdmin(admin.ModelAdmin): ...@@ -79,10 +83,6 @@ class ScheduleAdmin(admin.ModelAdmin):
}), }),
) )
# Register the custom administration panels
# https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#modeladmin-objects
admin.site.register(Facility, FacilityAdmin)
admin.site.register(Schedule, ScheduleAdmin)
# https://docs.djangoproject.com/en/1.11/ref/contrib/gis/admin/#osmgeoadmin # https://docs.djangoproject.com/en/1.11/ref/contrib/gis/admin/#osmgeoadmin
OSMGeoAdmin.default_lon = -8605757.16502 OSMGeoAdmin.default_lon = -8605757.16502
OSMGeoAdmin.default_lat = 4697457.00333 OSMGeoAdmin.default_lat = 4697457.00333
......
...@@ -26,6 +26,7 @@ from django.utils import timezone ...@@ -26,6 +26,7 @@ from django.utils import timezone
from model_utils.models import TimeStampedModel from model_utils.models import TimeStampedModel
from autoslug import AutoSlugField from autoslug import AutoSlugField
from taggit.managers import TaggableManager from taggit.managers import TaggableManager
from taggit.models import GenericTaggedItemBase, TagBase
class Category(TimeStampedModel): class Category(TimeStampedModel):
""" """
...@@ -90,6 +91,15 @@ class Location(TimeStampedModel): ...@@ -90,6 +91,15 @@ class Location(TimeStampedModel):
self.address, self.address,
self.on_campus) self.on_campus)
# Look I didn't want to do this but APPARENTLY you cannot have two
# TaggableManager()s on a model and thus you have to make a WHOLE other model
# to have this work.
# https://neutron-drive.appspot.com/blog/multiple-tags
class StupidFacilityLabelHack(TagBase):
pass
class StupidLabelHack(GenericTaggedItemBase):
tag = models.ForeignKey(StupidFacilityLabelHack)
class Facility(TimeStampedModel): class Facility(TimeStampedModel):
""" """
Represents a specific facility location. A Facility is some type of Represents a specific facility location. A Facility is some type of
...@@ -142,9 +152,24 @@ class Facility(TimeStampedModel): ...@@ -142,9 +152,24 @@ class Facility(TimeStampedModel):
message='Invalid phone number', message='Invalid phone number',
code='invalid_phone_number')]) code='invalid_phone_number')])
# A comma seperate list of words that neatly an aptly describe the product # A comma seperate list of words that neatly and aptly describe the product
# that this facility produces. (ex. for Taco Bell: mexican, taco, cheap) # that this facility produces. (ex. for Taco Bell: mexican, taco, cheap)
facility_product_tags = TaggableManager() # These words are not shown to the use but are rather used in search.
facility_product_tags = TaggableManager(related_name="product_tags", help_text="A comma seperate list of words that neatly and aptly describe the product that this facility produces. These words are not shown to the use but are rather used in search.")
# Labels to describe the Facility that are displayed to the user and can be
# informative. "Takes Mason Money"
facility_labels = TaggableManager("labels", related_name="labels", through=StupidLabelHack, help_text="Labels to describe the Facility that are displayed to the user and can be informative.")
# Tag a Facility to be shown on the ShopMason or Sodoxo (or both)
# What's Open sites.
FACILITY_CLASSES = (
("shopmason", "shopMason Facility"),
("sodoxo", "Sodoxo Facility")
)
facility_classifier = models.CharField(choices=FACILITY_CLASSES,
help_text="Tag this facility to be shown on the ShopMason or Sodoxo What's Open sites.",
max_length=100, blank=True)
def is_open(self): def is_open(self):
""" """
......
...@@ -78,23 +78,20 @@ class FacilitySerializer(serializers.HyperlinkedModelSerializer): ...@@ -78,23 +78,20 @@ class FacilitySerializer(serializers.HyperlinkedModelSerializer):
than primary keys. than primary keys.
http://www.django-rest-framework.org/api-guide/serializers/#hyperlinkedmodelserializer http://www.django-rest-framework.org/api-guide/serializers/#hyperlinkedmodelserializer
""" """
# Append a serialized Category object # Append serialized objects
facility_category = CategorySerializer(many=False, read_only=True) facility_category = CategorySerializer(many=False, read_only=True)
# Append a serialized Location object
facility_location = LocationSerializer(many=False, read_only=True) facility_location = LocationSerializer(many=False, read_only=True)
# Append a serialized Schedule object to represent main_schedule
main_schedule = ScheduleSerializer(many=False, read_only=True) main_schedule = ScheduleSerializer(many=False, read_only=True)
# Append a serialized Schedule object to represent special_schedules
special_schedules = ScheduleSerializer(many=True, read_only=True) special_schedules = ScheduleSerializer(many=True, read_only=True)
# Append a serialized TagList object that represents the product tags for a
# Facility
facility_product_tags = TagListSerializerField() facility_product_tags = TagListSerializerField()
facility_labels = TagListSerializerField()
facility_classifier = TagListSerializerField()
class Meta: class Meta:
# Choose the model to be serialized # Choose the model to be serialized
model = Facility model = Facility
# List the fields that we are serializing # List the fields that we are serializing
fields = ('slug', 'facility_name', 'logo', 'facility_location', 'facility_category', fields = ('slug', 'facility_name', 'logo', 'facility_location',
'facility_product_tags', 'tapingo_url', 'note', 'facility_category', 'facility_product_tags',
'main_schedule', 'special_schedules', 'facility_labels', 'facility_classifier', 'tapingo_url',
'modified', ) 'note', 'main_schedule', 'special_schedules', 'modified', )
...@@ -363,10 +363,12 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet): ...@@ -363,10 +363,12 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
FILTER_FIELDS = ( FILTER_FIELDS = (
# Facility fields # Facility fields
'facility_name', 'facility_name',
'facility_classifier',
'logo', 'logo',
'tapingo_url', 'tapingo_url',
'note', 'note',
'facility_product_tags__name', 'facility_product_tags__name',
'facility_labels__name',
# Category fields # Category fields
'facility_category__name', 'facility_category__name',
# Location fields # Location fields
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment