From 3aa22ec4cd4e8c80a6b3269d86a00912542462dd Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Sat, 20 Apr 2013 10:56:32 -0400 Subject: Move recipe to the top level --- greenbox/recipe/__init__.py | 0 greenbox/recipe/models.py | 90 ------------------------ greenbox/recipe/templatetags/__init__.py | 4 -- greenbox/recipe/templatetags/ingredientformat.py | 31 -------- greenbox/recipe/tests.py | 23 ------ greenbox/recipe/urls.py | 7 -- greenbox/recipe/views.py | 11 --- recipe/__init__.py | 0 recipe/models.py | 90 ++++++++++++++++++++++++ recipe/templatetags/__init__.py | 4 ++ recipe/templatetags/ingredientformat.py | 31 ++++++++ recipe/tests.py | 23 ++++++ recipe/urls.py | 7 ++ recipe/views.py | 11 +++ 14 files changed, 166 insertions(+), 166 deletions(-) delete mode 100644 greenbox/recipe/__init__.py delete mode 100644 greenbox/recipe/models.py delete mode 100644 greenbox/recipe/templatetags/__init__.py delete mode 100644 greenbox/recipe/templatetags/ingredientformat.py delete mode 100644 greenbox/recipe/tests.py delete mode 100644 greenbox/recipe/urls.py delete mode 100644 greenbox/recipe/views.py create mode 100644 recipe/__init__.py create mode 100644 recipe/models.py create mode 100644 recipe/templatetags/__init__.py create mode 100644 recipe/templatetags/ingredientformat.py create mode 100644 recipe/tests.py create mode 100644 recipe/urls.py create mode 100644 recipe/views.py diff --git a/greenbox/recipe/__init__.py b/greenbox/recipe/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/greenbox/recipe/models.py b/greenbox/recipe/models.py deleted file mode 100644 index 8463447..0000000 --- a/greenbox/recipe/models.py +++ /dev/null @@ -1,90 +0,0 @@ -from django.db import models -from django.contrib import admin -from django.db.models import fields - - -class Unit(models.Model): - - class Meta: - ordering = ('name',) - - 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) - - -class Recipe(models.Model): - - class Meta: - ordering = ('title',) - - 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) - prep_time = fields.IntegerField(blank=True, null=True) - - - def __unicode__(self): - return self.title - - -class Ingredient(models.Model): - - class Meta: - ordering = ('name',) - - name = fields.CharField(max_length=100, unique=True) - - def __unicode__(self): - return self.name - - -class RecipeIngredient(models.Model): - - ingredient = models.ForeignKey(Ingredient) - units = models.ForeignKey(Unit) - 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/greenbox/recipe/templatetags/__init__.py b/greenbox/recipe/templatetags/__init__.py deleted file mode 100644 index 9bd6204..0000000 --- a/greenbox/recipe/templatetags/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from django import template - - -register = template.Library() diff --git a/greenbox/recipe/templatetags/ingredientformat.py b/greenbox/recipe/templatetags/ingredientformat.py deleted file mode 100644 index fa75633..0000000 --- a/greenbox/recipe/templatetags/ingredientformat.py +++ /dev/null @@ -1,31 +0,0 @@ -from recipe.templatetags import register -from django.template.defaultfilters import stringfilter - - -@register.filter(name="format_ingredient_quantity") -@stringfilter -def format_ingredient_quantity(value): - fractions = { - 0.125: '1/8', - 0.25 : '1/4', - 0.33 : '1/3', - 0.50 : '1/2', - 0.66 : '2/3', - 0.75 : '3/4', - } - - value = float(value) - remainder = round(value % 1, 2) - whole = int(value - remainder) - - if whole <= 0: - whole = "" - else: - whole = str(whole) - - if remainder <= 0: - remainder = "" - else: - remainder = fractions.get(remainder, str(remainder)) - - return "{0} {1}".format(whole, remainder) diff --git a/greenbox/recipe/tests.py b/greenbox/recipe/tests.py deleted file mode 100644 index 2247054..0000000 --- a/greenbox/recipe/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these 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.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/greenbox/recipe/urls.py b/greenbox/recipe/urls.py deleted file mode 100644 index 4c937a0..0000000 --- a/greenbox/recipe/urls.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.conf.urls.defaults import patterns, url - - -urlpatterns = patterns('recipe.views', - url(r'^(?P[^/]+)', 'recipe_details'), - url(r'^$', 'recipe_list'), -) diff --git a/greenbox/recipe/views.py b/greenbox/recipe/views.py deleted file mode 100644 index 3efdb9e..0000000 --- a/greenbox/recipe/views.py +++ /dev/null @@ -1,11 +0,0 @@ -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) diff --git a/recipe/__init__.py b/recipe/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/recipe/models.py b/recipe/models.py new file mode 100644 index 0000000..8463447 --- /dev/null +++ b/recipe/models.py @@ -0,0 +1,90 @@ +from django.db import models +from django.contrib import admin +from django.db.models import fields + + +class Unit(models.Model): + + class Meta: + ordering = ('name',) + + 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) + + +class Recipe(models.Model): + + class Meta: + ordering = ('title',) + + 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) + prep_time = fields.IntegerField(blank=True, null=True) + + + def __unicode__(self): + return self.title + + +class Ingredient(models.Model): + + class Meta: + ordering = ('name',) + + name = fields.CharField(max_length=100, unique=True) + + def __unicode__(self): + return self.name + + +class RecipeIngredient(models.Model): + + ingredient = models.ForeignKey(Ingredient) + units = models.ForeignKey(Unit) + 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/templatetags/__init__.py b/recipe/templatetags/__init__.py new file mode 100644 index 0000000..9bd6204 --- /dev/null +++ b/recipe/templatetags/__init__.py @@ -0,0 +1,4 @@ +from django import template + + +register = template.Library() diff --git a/recipe/templatetags/ingredientformat.py b/recipe/templatetags/ingredientformat.py new file mode 100644 index 0000000..fa75633 --- /dev/null +++ b/recipe/templatetags/ingredientformat.py @@ -0,0 +1,31 @@ +from recipe.templatetags import register +from django.template.defaultfilters import stringfilter + + +@register.filter(name="format_ingredient_quantity") +@stringfilter +def format_ingredient_quantity(value): + fractions = { + 0.125: '1/8', + 0.25 : '1/4', + 0.33 : '1/3', + 0.50 : '1/2', + 0.66 : '2/3', + 0.75 : '3/4', + } + + value = float(value) + remainder = round(value % 1, 2) + whole = int(value - remainder) + + if whole <= 0: + whole = "" + else: + whole = str(whole) + + if remainder <= 0: + remainder = "" + else: + remainder = fractions.get(remainder, str(remainder)) + + return "{0} {1}".format(whole, remainder) diff --git a/recipe/tests.py b/recipe/tests.py new file mode 100644 index 0000000..2247054 --- /dev/null +++ b/recipe/tests.py @@ -0,0 +1,23 @@ +""" +This file demonstrates two different styles of tests (one doctest and one +unittest). These will both pass when you run "manage.py test". + +Replace these 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.failUnlessEqual(1 + 1, 2) + +__test__ = {"doctest": """ +Another way to test that 1 + 1 is equal to 2. + +>>> 1 + 1 == 2 +True +"""} + diff --git a/recipe/urls.py b/recipe/urls.py new file mode 100644 index 0000000..4c937a0 --- /dev/null +++ b/recipe/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls.defaults import patterns, url + + +urlpatterns = patterns('recipe.views', + url(r'^(?P[^/]+)', 'recipe_details'), + url(r'^$', 'recipe_list'), +) diff --git a/recipe/views.py b/recipe/views.py new file mode 100644 index 0000000..3efdb9e --- /dev/null +++ b/recipe/views.py @@ -0,0 +1,11 @@ +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) -- cgit v1.2.3