Permalink
Browse files

Updates and bug fixes for the functional_split example.

  • Loading branch information...
1 parent 6d5ae95 commit 69d6d7c452a95f0c36aff262cf73f7132397192b @malcolmt committed Sep 5, 2010
View
7 TODO
@@ -1,6 +1,7 @@
- Update README.rst to show recommended order
- Add slides for talk
-- Better styling of pages
- - layout on Chrome is a bit funky ("ol" ordinals are on the far left)
-- Add functional_split/README.rst
+- README.rst files:
+ - function_split
+ - access_split
+
@@ -2,5 +2,5 @@
from products import models
-admin.site.register([models.Product, models.Stock])
+admin.site.register(models.Product)
@@ -10,16 +10,3 @@ class Product(models.Model):
def __unicode__(self):
return self.name
-class Stock(models.Model):
- """
- Track the inventory of a single product.
- """
- product = models.OneToOneField(Product)
- quantity = models.PositiveIntegerField() # (Django permits 0 here)
-
- class Meta:
- verbose_name_plural = "stock"
-
- def __unicode__(self):
- return u"%s, quantity %d" % (self.product, self.quantity)
-
@@ -13,9 +13,6 @@ def db_for_write(self, model, **hints):
return "reviews"
return None
-# FIXME
-# def allow_relation(obj1, obj2, **hints):
-
def allow_syncdb(self, db, model):
this_app = (model._meta.app_label == "reviews")
reviews_db = (db == "reviews")
@@ -1,8 +1,13 @@
from django.conf.urls.defaults import * # pylint: disable-msg=W0401,W0614
+from django.shortcuts import redirect
from reviews import views
+def redirect_to(request, **kwargs):
+ return redirect(**kwargs)
+
urlpatterns = patterns("",
+ url("^$", redirect_to, {"to": "product-reviews", "permanent": True}),
url("review/products/(?:(?P<product_id>\d+)/)?$", views.product_reviews,
name="product-reviews"),
url("review/(?:(?P<review_id>\d+)/)?$", views.show_review,
@@ -42,8 +42,9 @@ def add_review(request, product_id=None):
form = ReviewForm(request.POST)
if form.is_valid():
data = form.cleaned_data
+ user = request.user
review = reviews.models.Review.objects.create(
- author_id = request.user.id,
+ author_id = user.is_authenticated() and user.id or -1,
product_id = data["product"],
rating = data["rating"],
text = data["review"]
@@ -77,7 +78,10 @@ def show_review(request, review_id=None):
return http.HttpResponseNotFound(loader.render_to_string(
"reviews/missing.html",
context_instance=RequestContext(request)))
- user = auth_models.User.objects.get(id=review.author_id)
+ if review.author_id == -1:
+ user = auth_models.AnonymousUser()
+ else:
+ user = auth_models.User.objects.get(id=review.author_id)
product = products.models.Product.objects.get(id=review.product_id)
data = {
"title": "Reviews",
@@ -95,6 +99,7 @@ def product_reviews(request, product_id=None):
review_ids = [obj.id for obj in review_qs]
users = dict(auth_models.User.objects.filter(id__in=review_ids). \
values_list("id", "username"))
+ users[-1] = "Anonymous"
for review in review_qs:
review.reviewer = users[review.author_id]
review_dict.setdefault(review.product_id, []).append(review)
@@ -21,7 +21,7 @@
DATABASE_ROUTERS = ["reviews.router.ReviewRouter"]
-TIME_ZONE = 'Australia/Sydney'
+TIME_ZONE = None
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
@@ -53,10 +53,12 @@
)
ROOT_URLCONF = 'main_urls'
-
TEMPLATE_DIRS = (
os.path.join(PROJ_ROOT, "..", "templates"),
)
+FIXTURE_DIRS = (
+ os.path.join(PROJ_ROOT, "..", "fixtures"),
+)
INSTALLED_APPS = (
'django.contrib.auth',
View
@@ -17,7 +17,7 @@ body {
#content {
background: #d7e2e5;
color: #38322a;
- padding-top: 1em;
+ padding: 1em;
}
a {
@@ -37,3 +37,6 @@ a:hover {
font-weight: bold;
}
+ul li {
+ list-style: none;
+}

0 comments on commit 69d6d7c

Please sign in to comment.