From c29586b5ddf030ebc406aa7008ebfefc858a0af4 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Wed, 29 Jul 2015 18:33:04 -0700 Subject: Sync from server --- greenbox/settings.py | 23 +------- greenbox/urls.py | 6 +- greenbox/wsgi.py | 32 +++++++++++ recipe/admin.py | 33 ----------- ..._add_field_unit_grams__add_field_unit_liters.py | 66 ---------------------- recipe/models.py | 66 ++++++++++++++++------ recipe/urls.py | 9 ++- recipe/views.py | 12 +--- requirements.txt | 6 +- 9 files changed, 97 insertions(+), 156 deletions(-) create mode 100644 greenbox/wsgi.py delete mode 100644 recipe/admin.py delete mode 100644 recipe/migrations/0002_auto__add_field_unit_grams__add_field_unit_liters.py diff --git a/greenbox/settings.py b/greenbox/settings.py index a0096ed..939f396 100644 --- a/greenbox/settings.py +++ b/greenbox/settings.py @@ -1,20 +1,12 @@ import os -PROJECT_DIR = os.path.dirname(__file__) -PUBLIC_DIR = os.path.join(PROJECT_DIR, 'site_media') +PROJECT_DIR = os.path.abspath(os.path.dirname(__file__)) +PUBLIC_DIR = os.path.join(os.path.dirname(__file__), 'site_media') SITE_ID = 1 USE_I18N = False -DEBUG = True -TEMPLATE_DEBUG = DEBUG - -PROJECT_DIR = os.path.abspath(os.path.dirname(__file__)) - -ADMINS = ( - ('Mike Crute', 'mcrute@gmail.com'), -) +TEMPLATE_DEBUG = DEBUG = True -MANAGERS = ADMINS DATABASES = { 'default': { @@ -27,10 +19,6 @@ TIME_ZONE = 'America/New_York' LANGUAGE_CODE = 'en-us' ROOT_URLCONF = 'greenbox.urls' - -MEDIA_ROOT = os.path.join(PUBLIC_DIR, 'media') -MEDIA_URL = '/site_media/media/' - STATIC_ROOT = os.path.join(PUBLIC_DIR, 'static') STATIC_URL = '/site_media/static/' @@ -60,8 +48,3 @@ INSTALLED_APPS = ( 'south', 'recipe', ) - -try: - from settings_local import * -except ImportError: - pass diff --git a/greenbox/urls.py b/greenbox/urls.py index fb38894..1e6b755 100644 --- a/greenbox/urls.py +++ b/greenbox/urls.py @@ -1,5 +1,7 @@ -from django.conf.urls.defaults import patterns, include, url -from django.contrib import admin; admin.autodiscover() +from django.conf.urls import patterns, include, url + +from django.contrib import admin +admin.autodiscover() urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), diff --git a/greenbox/wsgi.py b/greenbox/wsgi.py new file mode 100644 index 0000000..0e2d030 --- /dev/null +++ b/greenbox/wsgi.py @@ -0,0 +1,32 @@ +""" +WSGI config for imd project. + +This module contains the WSGI application used by Django's development server +and any production WSGI deployments. It should expose a module-level variable +named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover +this application via the ``WSGI_APPLICATION`` setting. + +Usually you will have the standard Django WSGI application here, but it also +might make sense to replace the whole Django WSGI application with a custom one +that later delegates to the Django one. For example, you could introduce WSGI +middleware here, or combine a Django application with an application of another +framework. + +""" +import os + +# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks +# if running multiple sites in the same mod_wsgi process. To fix this, use +# mod_wsgi daemon mode with each site in its own daemon process, or use +# os.environ["DJANGO_SETTINGS_MODULE"] = "imd.settings" +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "greenbox.settings") + +# This application object is used by any WSGI server configured to use this +# file. This includes Django's development server, if the WSGI_APPLICATION +# setting points here. +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() + +# Apply WSGI middleware here. +# from helloworld.wsgi import HelloWorldApplication +# application = HelloWorldApplication(application) diff --git a/recipe/admin.py b/recipe/admin.py deleted file mode 100644 index 12bf0fa..0000000 --- a/recipe/admin.py +++ /dev/null @@ -1,33 +0,0 @@ -from django.contrib import admin -from recipe.models import Unit, Ingredient, Recipe, RecipeIngredient - - -class UnitAdmin(admin.ModelAdmin): - - list_display = ('name', 'abbreviation') - ordering = ('name',) - - -class IngredientInline(admin.TabularInline): - - model = RecipeIngredient - extra = 12 - - -class RecipeAdmin(admin.ModelAdmin): - - list_display = ('title',) - inlines = (IngredientInline,) - search_fields = ('title',) - prepopulated_fields = { "slug": ("title",) } - - -class IngredientAdmin(admin.ModelAdmin): - - list_display = ('name',) - search_fields = ('name',) - - -admin.site.register(Unit, UnitAdmin) -admin.site.register(Ingredient, IngredientAdmin) -admin.site.register(Recipe, RecipeAdmin) diff --git a/recipe/migrations/0002_auto__add_field_unit_grams__add_field_unit_liters.py b/recipe/migrations/0002_auto__add_field_unit_grams__add_field_unit_liters.py deleted file mode 100644 index 215c81c..0000000 --- a/recipe/migrations/0002_auto__add_field_unit_grams__add_field_unit_liters.py +++ /dev/null @@ -1,66 +0,0 @@ -# -*- coding: utf-8 -*- -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - - -class Migration(SchemaMigration): - - def forwards(self, orm): - # Adding field 'Unit.grams' - db.add_column('recipe_unit', 'grams', - self.gf('django.db.models.fields.DecimalField')(null=True, max_digits=10, decimal_places=10, blank=True), - keep_default=False) - - # Adding field 'Unit.liters' - db.add_column('recipe_unit', 'liters', - self.gf('django.db.models.fields.DecimalField')(null=True, max_digits=10, decimal_places=10, blank=True), - keep_default=False) - - - def backwards(self, orm): - # Deleting field 'Unit.grams' - db.delete_column('recipe_unit', 'grams') - - # Deleting field 'Unit.liters' - db.delete_column('recipe_unit', 'liters') - - - models = { - 'recipe.ingredient': { - 'Meta': {'ordering': "('name',)", 'object_name': 'Ingredient'}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}) - }, - 'recipe.recipe': { - 'Meta': {'ordering': "('title',)", 'object_name': 'Recipe'}, - 'cook_time': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), - 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'instructions': ('django.db.models.fields.TextField', [], {}), - 'oven_temp': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), - 'prep_time': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), - 'servings': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), - 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150'}), - 'title': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - }, - 'recipe.recipeingredient': { - 'Meta': {'object_name': 'RecipeIngredient'}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'ingredient': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['recipe.Ingredient']"}), - 'quantity': ('django.db.models.fields.FloatField', [], {}), - 'recipe': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['recipe.Recipe']"}), - 'units': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['recipe.Unit']"}) - }, - 'recipe.unit': { - 'Meta': {'ordering': "('name',)", 'object_name': 'Unit'}, - 'abbreviation': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}), - 'grams': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '10', 'decimal_places': '10', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'liters': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '10', 'decimal_places': '10', 'blank': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) - } - } - - complete_apps = ['recipe'] \ No newline at end of file diff --git a/recipe/models.py b/recipe/models.py index 1db7f42..548536e 100644 --- a/recipe/models.py +++ b/recipe/models.py @@ -1,4 +1,6 @@ from django.db import models +from django.contrib import admin +from django.db.models import fields class Unit(models.Model): @@ -6,14 +8,8 @@ class Unit(models.Model): class Meta: ordering = ('name',) - name = models.CharField(max_length=100) - abbreviation = models.CharField(max_length=10, blank=True, null=True) - grams = models.DecimalField(max_digits=10, decimal_places=10, - blank=True, null=True, - help_text="Conversion from this unit to grams (dry measure)") - liters = models.DecimalField(max_digits=10, decimal_places=10, - blank=True, null=True, - help_text="Conversion from this unit to liters (liquid measure)") + name = fields.CharField(max_length=100) + abbreviation = fields.CharField(max_length=10, blank=True, null=True) def __unicode__(self): return "{0} ({1})".format(self.name, self.abbreviation) @@ -24,14 +20,14 @@ class Recipe(models.Model): class Meta: ordering = ('title',) - title = models.CharField(max_length=100) - slug = models.SlugField(max_length=150) - description = models.TextField(blank=True, null=True) - servings = models.IntegerField(blank=True, null=True) - instructions = models.TextField() - oven_temp = models.IntegerField(blank=True, null=True) - cook_time = models.IntegerField(blank=True, null=True, help_text="In minutes") - prep_time = models.IntegerField(blank=True, null=True, help_text="In minutes") + title = fields.CharField(max_length=100) + slug = fields.SlugField(max_length=150) + description = fields.TextField(blank=True, null=True) + servings = fields.IntegerField(blank=True, null=True) + instructions = fields.TextField() + oven_temp = fields.IntegerField(blank=True, null=True) + cook_time = fields.IntegerField(blank=True, null=True, help_text="In minutes") + prep_time = fields.IntegerField(blank=True, null=True, help_text="In minutes") def __unicode__(self): return self.title @@ -42,7 +38,7 @@ class Ingredient(models.Model): class Meta: ordering = ('name',) - name = models.CharField(max_length=100, unique=True) + name = fields.CharField(max_length=100, unique=True) def __unicode__(self): return self.name @@ -52,8 +48,42 @@ class RecipeIngredient(models.Model): ingredient = models.ForeignKey(Ingredient) units = models.ForeignKey(Unit) - quantity = models.FloatField() + quantity = fields.FloatField() recipe = models.ForeignKey(Recipe) def __unicode__(self): return "{0} in {1}".format(self.ingredient.name, self.recipe.title) + + +class UnitAdmin(admin.ModelAdmin): + + list_display = ('name', 'abbreviation') + ordering = ('name',) + + +class IngredientInline(admin.TabularInline): + + model = RecipeIngredient + extra = 12 + + +class RecipeAdmin(admin.ModelAdmin): + + list_display = ('title',) + inlines = (IngredientInline,) + search_fields = ('title',) + prepopulated_fields = { "slug": ("title",) } + + +class IngredientAdmin(admin.ModelAdmin): + + list_display = ('name',) + search_fields = ('name',) + + +try: + admin.site.register(Unit, UnitAdmin) + admin.site.register(Ingredient, IngredientAdmin) + admin.site.register(Recipe, RecipeAdmin) +except admin.sites.AlreadyRegistered: + pass diff --git a/recipe/urls.py b/recipe/urls.py index 4c937a0..00bc44a 100644 --- a/recipe/urls.py +++ b/recipe/urls.py @@ -1,7 +1,10 @@ -from django.conf.urls.defaults import patterns, url +from django.conf.urls import patterns, url +from django.views.generic import DetailView, ListView + +from recipe.models import Recipe urlpatterns = patterns('recipe.views', - url(r'^(?P[^/]+)', 'recipe_details'), - url(r'^$', 'recipe_list'), + url(r'^(?P[^/]+)', DetailView.as_view(model=Recipe)), + url(r'^$', ListView.as_view(model=Recipe)), ) diff --git a/recipe/views.py b/recipe/views.py index 3efdb9e..7e324b4 100644 --- a/recipe/views.py +++ b/recipe/views.py @@ -1,11 +1 @@ -from models import Recipe -from django.views.generic import list_detail - - -def recipe_list(request): - data = Recipe.objects.all() - return list_detail.object_list(request, queryset=data) - - -def recipe_details(request, slug): - return list_detail.object_detail(request, queryset=Recipe.objects.all(), slug=slug) +# Views go here diff --git a/requirements.txt b/requirements.txt index 9ae3a99..b632dff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -Django==1.4 -gunicorn==0.17.2 -South==0.7.6 +Django>=1.6 +South>=0.8 +gunicorn>=18.0 -- cgit v1.2.3