Commit 022853a8 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

there have been a couple of opportunities for puns, but dhaynes would...

there have been a couple of opportunities for puns, but dhaynes would literally murder me, and we're trying to be more professional in this here project-- the upgrade-django and consolidation merged, if gutted
parents 3e6657f2 d24d55f8
......@@ -10,5 +10,6 @@ build
apache
.ropeproject
whats_open/secret_key.py
website/static/admin/
whats_open/assets/
static/admin/
data
## Expected Behavior
Describe briefly what the app should be doing or, what the expected behavior would
be given a certain input or action.
## Actual Behavior
Describe briefly what actually occurs in the app given the input described above.
## Steps to Reproduce the Behavior
A numbered list of steps starting from the earliest possible moment up until the
bug occurs. Something that could be used by other developers to reproduce the bug
that is being reported.
## Summary
Here you should include two to three sentences explaining the thought process
about the current issue. Perhaps a picture? Some details that could best help someone,
especially someone new, understand the goal of the issue and how they should best
approach the problem.
## Helpful Links
Here you should include a bullet point list of links to documentation, stack overflow,
whatever, that could help guide someone on what it is they are trying to do.
Essentially, a list of links to point them in the right direction.
\ No newline at end of file
......@@ -300,4 +300,4 @@ then feel free to omit the footer.
[style-guide]: https://www.python.org/dev/peps/pep-0008/
[slack]:https://srct.slack.com/
[new-issue]:https://git.gmu.edu/srct/whats-open/issues/new
[merge-request]:https://git.gmu.edu/srct/whats-open/merge_requests
\ No newline at end of file
[merge-request]:https://git.gmu.edu/srct/whats-open/merge_requests
Django>=1.8,<1.9
South==1.0
argparse
django-autoslug==1.7.2
django-floppyforms==1.1.1
......
from django.contrib import admin
from website.models import Facility, Category, Schedule, OpenTime
from .models import Facility, Schedule, OpenTime, Category
class OpenTimeInline(admin.TabularInline):
model = OpenTime
fk_name = 'open_time_schedule'
fk_name = 'schedule'
class OpenTimeAdmin(admin.ModelAdmin):
pass
class FacilityAdmin(admin.ModelAdmin):
pass
class ScheduleAdmin(admin.ModelAdmin):
inlines = [OpenTimeInline, ]
class CategoryAdmin(admin.ModelAdmin):
pass
admin.site.register(Facility)
admin.site.register(Category)
admin.site.register(Facility, FacilityAdmin)
admin.site.register(Schedule, ScheduleAdmin)
#admin.site.register(OpenTime, OpenTimeAdmin)
admin.site.register(Category, CategoryAdmin)
from website.models import Facility
from models import Facility
import re
def export_data():
......
from django.db import models
from django.contrib.auth.models import User
from model_utils.models import TimeStampedModel
from autoslug import AutoSlugField
import datetime
class BaseModel(models.Model):
last_modified = models.DateTimeField('Last Modified', auto_now=True)
class Category(BaseModel):
class Category(TimeStampedModel):
name = models.CharField(max_length=100)
class Meta:
......@@ -15,13 +14,18 @@ class Category(BaseModel):
ordering = ['name']
def __unicode__(self):
return self.name
return '%s' % self.name
class Facility(BaseModel):
"""Represents a dining location on campus."""
class Facility(TimeStampedModel):
"""Represents a facility location on campus."""
name = models.CharField(max_length=100)
slug = AutoSlugField(populate_from='name',unique=True) # instead of id
facility_category = models.ForeignKey('Category', related_name="facilities", null=True, blank=True)
on_campus = models.BooleanField(default=True)
location = models.CharField(max_length=100, null=True, blank=True)
owners = models.ManyToManyField(User)
main_schedule = models.ForeignKey('Schedule',
related_name='facility_main')
special_schedules = models.ManyToManyField('Schedule',
......@@ -58,8 +62,7 @@ class Facility(BaseModel):
def __unicode__(self):
return self.name
class Schedule(BaseModel):
class Schedule(TimeStampedModel):
"""
Contains opening and closing times for each day in a week.
......@@ -88,7 +91,7 @@ class Schedule(BaseModel):
return self.name
class OpenTime(BaseModel):
class OpenTime(TimeStampedModel):
"""Represents a period time when a Facility is open"""
MONDAY = 0
......@@ -110,7 +113,7 @@ class OpenTime(BaseModel):
)
schedule = models.ForeignKey('Schedule', related_name='open_times')
start_day = models.IntegerField(default=0, choices=DAY_CHOICES)
start_day = models.IntegerField(default=0, choices=DAY_CHOICES) # 0-6, Monday == 0
start_time = models.TimeField()
end_day = models.IntegerField(default=0, choices=DAY_CHOICES)
end_time = models.TimeField()
......
......@@ -4,18 +4,18 @@ from website.models import Category, Facility, Schedule, OpenTime
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = '__all__'
#fields = '__all__'
class OpenTimeSerializer(serializers.ModelSerializer):
class Meta:
model = OpenTime
fields = '__all__'
#fields = '__all__'
class ScheduleSerializer(serializers.ModelSerializer):
open_times = OpenTimeSerializer(many=True, read_only=True)
class Meta:
model = Schedule
fields = ( 'id', 'open_times', 'last_modified', 'name', 'valid_start', 'valid_end' )
#fields = ( 'id', 'open_times', 'last_modified', 'name', 'valid_start', 'valid_end' )
class FacilitySerializer(serializers.HyperlinkedModelSerializer):
category = CategorySerializer(many=False, read_only=True)
......@@ -24,5 +24,5 @@ class FacilitySerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Facility
fields = ( 'id', 'category', 'main_schedule', 'special_schedules', 'location', 'last_modified', 'name' )
fields = ( 'id', 'category', 'main_schedule', 'special_schedules', 'location', 'modified', 'name' )
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
......@@ -8,9 +8,19 @@ router = DefaultRouter()
router.register(r'categories', CategoryViewSet)
router.register(r'facilities', FacilityViewSet)
router.register(r'schedules', ScheduleViewSet)
router.register(r'opentimes', OpenTimeViewSet)
#router.register(r'opentimes', OpenTimeViewSet)
urlpatterns = patterns('website.views',
url(r'^api/', include(router.urls)),
url(r'^$', 'facility_grid', name='facility_grid'),
) + static(settings_local.STATIC_URL, document_root=settings_local.STATIC_ROOT)
#url(r'^$', 'facility_grid', name='facility_grid'),
)
#facilities open urls
#url(r'^facilities/$', FacilityListView.as_view(), name='faciliites-list'),
#url(r'^facilities/(?P<category>)/$', FacilityCategoryListView.as_view(), name='facilities-list-by-cat'),
#url(r'^facilities/(?P<slug>)/$', FacilityDetailView.as_view(), name='facilities-detail'),
#url(r'^facilities/(?P<on_campus>)/$', FacilityStatusListView.as_view(), name='facilities-list-by-status'),
#schedules urls
#url(r'^schedule/(?P<pk>)/$', ScheduleDetailView.as_view(), name='schedule-detail'),
#opentime urls
#url(r'^open-time/(?P<pk>)/$', OpenTimeDetailView.as_view(), name='open-time-detail'),
#) + static(settings_local.STATIC_URL, document_root=settings_local.STATIC_ROOT)
from django.template import RequestContext
from website.models import Facility, OpenTime, BaseModel
from website.models import Facility, OpenTime
from website.api import export_data
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.views.decorators.http import condition
from django.views.generic import ListView, DetailView
from model_utils.models import TimeStampedModel
from website.models import Facility, OpenTime, Category, Schedule
from website.api import export_data
......@@ -48,25 +49,25 @@ class OpenTimeViewSet(viewsets.ModelViewSet):
queryset = OpenTime.objects.all()
serializer_class = OpenTimeSerializer
def facility_grid(request):
"""Display the facilities in a grid. Main page."""
if 'sort' in request.GET:
if request.GET['sort'] == 'location':
# Display the grid by location (instead of listing alphabetically)
pass # Not implemented yet
return render_to_response('facility_grid.html',
context_instance=RequestContext(request))
#def facility_grid(request):
# """Display the facilities in a grid. Main page."""
# if 'sort' in request.GET:
# if request.GET['sort'] == 'location':
# # Display the grid by location (instead of listing alphabetically)
# pass # Not implemented yet
# return render_to_response('facility_grid.html',
# context_instance=RequestContext(request))
def gen_etag(request):
return hashlib.sha1(str(OpenTime.objects.all())).hexdigest()
def gen_last_modified(request):
return BaseModel.objects.all().order_by('-last_modified')[0].last_modified
return TimeStampedModel.objects.all().order_by('-last_modified')[0].last_modified
@condition(etag_func=gen_etag, last_modified_func=gen_last_modified)
def ajax_schedule_data(request):
# Wrapping up in an object to avoid possible CSRF attack on top-level
# arrays in JSON objects
return HttpResponse(json.dumps({'data': export_data()}, indent=4),
content_type="application/json")
#@condition(etag_func=gen_etag, last_modified_func=gen_last_modified)
#def ajax_schedule_data(request):
# # Wrapping up in an object to avoid possible CSRF attack on top-level
# # arrays in JSON objects
# return HttpResponse(json.dumps({'data': export_data()}, indent=4),
# content_type="application/json")
......@@ -31,8 +31,9 @@ TEMPLATE_DEBUG = DEBUG
########## MANAGER CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
# Insert a ('Name', 'Email') inside ADMINS tuple
ADMINS = (
('Your Name', 'your_email@example.com'),
('SRCT Admin', 'srct@gmu.edu'),
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
......@@ -45,7 +46,7 @@ MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': normpath(join(DJANGO_ROOT, 'database.db')),
'NAME': normpath(join(DJANGO_ROOT, 'database/database.db')),
'USER': '',
'PASSWORD': '',
'HOST': '',
......@@ -58,39 +59,58 @@ DATABASES = {
########## GENERAL CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/New_York'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
SITE_ID = 1
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
########## END GENERAL CONFIGURATION
########## MEDIA CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = normpath(join(SITE_ROOT, 'media'))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/'
########## END MEDIA CONFIGURATION
########## STATIC FILE CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = normpath(join(SITE_ROOT, 'assets'))
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
......@@ -104,6 +124,7 @@ ADMIN_MEDIA_PREFIX = '/static/admin/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
########## END STATIC FILE CONFIGURATION
......@@ -116,7 +137,7 @@ SECRET_KEY = r"{{ secret_key }}"
########## SITE CONFIGURATION
# Hosts/domain names that are valid for this site
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['*']
########## END SITE CONFIGURATION
......@@ -187,6 +208,7 @@ ROOT_URLCONF = '%s.urls' % SITE_NAME
########## WSGI CONFIGURATION
# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = '%s.wsgi.application' % SITE_NAME
########## END WSGI CONFIGURATION
......@@ -225,6 +247,7 @@ DJANGO_APPS = (
# Apps specific for this project go here.
LOCAL_APPS = (
'website',
#'guardian',
'rest_framework',
)
......@@ -282,3 +305,16 @@ LOGGING = {
}
}
########## END LOGGING CONFIGURATION
########## MANAGEMENT CONFIGURATION
#CAS_GATEWAY=True
#ANONYMOUS_USER_ID = -1
#AUTHENTICATION_BACKENDS = (
# 'django.contrib.auth.backends.ModelBackend', # this is default
# 'cas.middleware.CASMiddleware',
# #'guardian.backends.ObjectPermissionBackend',
#)
#
#LOGIN_URL='/management/login/'
#LOGIN_REDIRECT='/management/'
########## END MANAGEMENT CONFIGURATION
......@@ -24,7 +24,7 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': normpath(join(DJANGO_ROOT, 'database.db')),
'NAME': normpath(join(DJANGO_ROOT, 'database/database.db')),
'USER': '',
'PASSWORD': '',
'HOST': '',
......
from django.conf.urls import patterns, include, url
from django.contrib.sites.models import Site
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'whats_open.views.home', name='home'),
# url(r'^whats_open/', include('whats_open.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^', include('website.urls')),
#url(r'management/', include('management.urls')),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^admin/', include(admin.site.urls)),
url(r'', include('website.urls')),
url(r'^logout/$', 'django.contrib.auth.views.logout', {
'next_page': '/'}),
)
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