Commit db203f90 authored by David Haynes's avatar David Haynes 🙆
Browse files

Merge branch '64-facility-tagging' into '2.1-dev'

Resolve "Add 'Shown Tags' field and change tags to 'Hidden Tags'"

See merge request srct/whats-open!36
parents ddfab2cb 2e87e21e
#!/bin/sh
until nc -z db 3306; do
echo "waiting for database to start..."
sleep 1
......
......@@ -15,6 +15,7 @@ from django.contrib.gis.admin import OSMGeoAdmin
# App Imports
from .models import Facility, Schedule, OpenTime, Category, Location, Alert
@admin.register(Facility)
class FacilityAdmin(admin.ModelAdmin):
"""
Custom Admin panel for the Facility model.
......@@ -27,9 +28,11 @@ class FacilityAdmin(admin.ModelAdmin):
# We are basically reordering things to look nicer to the user here
fieldsets = (
(None, {
'fields': ('facility_name', 'logo', 'facility_category', 'facility_location',
'main_schedule', 'special_schedules',
'facility_product_tags', 'tapingo_url','phone_number', 'note', 'owners'),
'fields': ('facility_name', 'logo', 'facility_category',
'facility_location', 'main_schedule', 'special_schedules',
('facility_product_tags', 'facility_labels',
'facility_classifier'),
'tapingo_url', 'phone_number', 'note', 'owners'),
}),
)
......@@ -54,6 +57,7 @@ class OpenTimeInline(admin.TabularInline):
}),
)
@admin.register(Schedule)
class ScheduleAdmin(admin.ModelAdmin):
"""
Custom Admin panel for the Schedule model.
......@@ -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
OSMGeoAdmin.default_lon = -8605757.16502
OSMGeoAdmin.default_lat = 4697457.00333
......
......@@ -26,6 +26,7 @@ from django.utils import timezone
from model_utils.models import TimeStampedModel
from autoslug import AutoSlugField
from taggit.managers import TaggableManager
from taggit.models import GenericTaggedItemBase, TagBase
class Category(TimeStampedModel):
"""
......@@ -90,6 +91,15 @@ class Location(TimeStampedModel):
self.address,
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):
"""
Represents a specific facility location. A Facility is some type of
......@@ -142,9 +152,24 @@ class Facility(TimeStampedModel):
message='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)
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):
"""
......
......@@ -78,23 +78,20 @@ class FacilitySerializer(serializers.HyperlinkedModelSerializer):
than primary keys.
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)
# Append a serialized Location object
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)
# Append a serialized Schedule object to represent special_schedules
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_labels = TagListSerializerField()
facility_classifier = TagListSerializerField()
class Meta:
# Choose the model to be serialized
model = Facility
# List the fields that we are serializing
fields = ('slug', 'facility_name', 'logo', 'facility_location', 'facility_category',
'facility_product_tags', 'tapingo_url', 'note',
'main_schedule', 'special_schedules',
'modified', )
fields = ('slug', 'facility_name', 'logo', 'facility_location',
'facility_category', 'facility_product_tags',
'facility_labels', 'facility_classifier', 'tapingo_url',
'note', 'main_schedule', 'special_schedules', 'modified', )
......@@ -363,10 +363,12 @@ class FacilityViewSet(viewsets.ReadOnlyModelViewSet):
FILTER_FIELDS = (
# Facility fields
'facility_name',
'facility_classifier',
'logo',
'tapingo_url',
'note',
'facility_product_tags__name',
'facility_labels__name',
# Category fields
'facility_category__name',
# 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