1. powersurge360
  2. share_search

Commits

Zach Woodward  committed 0c8a8cb

Completely rewrote the products page to override the chump stuff before

  • Participants
  • Parent commits 591969a
  • Branches master

Comments (0)

Files changed (9)

File share_search/reviews/forms.py

View file
 from django import forms
 
-from reviews.models import Store
+from reviews.models import Store, Product
 
 
 class StoreForm(forms.ModelForm):
     class Meta:
         model = Store
         fields = ("name", "description", "image")
+
+class ProductForm(forms.ModelForm):
+    class Meta:
+        model = Product
+        fields = ("name", "description", "image")
+

File share_search/reviews/models.py

View file
 class Product(ProfileModel):
     image = models.ImageField(upload_to="product_profile")
 
+    @models.permalink
+    def get_absolute_url(self):
+        return ("reviews:product", (self.pk,))
+
 
 class ProductReview(ReviewModel):
     store = models.ForeignKey(Store, related_name="product_reviews")

File share_search/reviews/templates/reviews/product_detail.html

View file
+{% extends "_layouts/base.html" %}
+
+{% block title %}{{ block.super }} - {{ object.name }}{% endblock %}
+
+{% block content %}
+    <div class="row">
+        <hgroup class="span12">
+            <h1>{{ object.name }}</h1>
+            {% if user.is_authenticated %}
+                <p>
+                    Product details not quite right?
+                    <a href="{% url "reviews:product_edit" object.id %}" class="btn btn-inverse">Edit Product</a>
+                </p>
+            {% endif %}
+        </hgroup>
+    </div>
+    <div class="row">
+        <div class="span4">
+            <div class="row-fluid">
+                <div class="span12">
+                    <img src="{{ object.image.url }}">
+                </div>
+            </div>
+        </div>
+        <div class="span8">
+            {{ object.description }}
+        </div>
+    </div>
+    <div class="row">
+        <div class="span12">
+            <center>List of stores with the product...</center>
+        </div>
+    </div>
+{% endblock %}

File share_search/reviews/templates/reviews/product_form.html

View file
+{% extends "_layouts/base.html" %}
+{% load crispy_forms_tags %}
+
+{% block content %}
+    <div class="row">
+        <div class="offset4 span4 well">
+            <form enctype="multipart/form-data" method="post">
+                {% csrf_token %}
+                {{ form|crispy }}
+                <input type="submit" class="btn" value="{% if object %}Edit{% else %}Create{% endif %} Product">
+            </form>
+        </div>
+    </div>
+{% endblock %}

File share_search/reviews/templates/reviews/products.html

View file
 {% extends "_layouts/base.html" %}
+{% load gridify %}
 
 {% block title %} {{ block.super }} - Products{% endblock %}
 
 {% block content %}
-    <div class="row">
-        <div class="offset1">
-            <div class="span3">
-                <a href="#">
-                    <img src="{{ STATIC_URL }}img/Pound_layer_cake.jpg">
-                </a>
-            </div>
-            <div class="span3">
-                <a href="#">
-                    <img src="{{ STATIC_URL }}img/vintage-book.jpg">
-                </a>
-            </div>
-            <div class="span3">
-                <a href="#">
-                    <img src="{{ STATIC_URL }}img/top10_food_bourbon.jpg">
-                </a>
+    {% if object_list %}
+        <div class="row">
+            <div class="span9 offset2">
+                <h1>{{ object_list.count }} products found</h1>
+                {% if user.is_authenticated %}
+                    <p>
+                        Not seeing the product you're looking for? Add a product now!
+                        <a href="{% url "reviews:store_create" %}" class="btn btn-inverse">Add a product</a>
+                    </p>
+                {% else %}
+                    <p>
+                        Register now to get started adding products
+                        <a href="{% url "site:register" %}" class="btn btn-inverse">Register</a>
+                    </p>
+                {% endif %}
             </div>
         </div>
-    </div>
+    {% endif %}
     <div class="row">
-        <div class="offset1">
-            <div class="span3">
-                <a href="#">
-                    <img src="{{ STATIC_URL }}img/top10_food_bourbon.jpg">
-                </a>
-            </div>
-            <div class="span3">
-                <a href="#">
-                    <img src="{{ STATIC_URL }}img/vintage-book.jpg">
-                </a>
+        {% if object_list %}
+            {% gridify object_list 3 as grid %}
+            <div class="grid">
+                {% for row in grid %}
+                    <div class="row">
+                        <div class="offset2">
+                            {% for column in row %}
+                                <div class="span3">
+                                    <a href="{{ column.get_absolute_url }}">
+                                        <img src="{{ column.image.url }}">
+                                        <center>{{ column.name }}</center>
+                                    </a>
+                                </div>
+                            {% endfor %}
+                        </div>
+                    </div>
+                {% endfor %}
             </div>
-            <div class="span3">
-                <a href="#">
-                    <img src="{{ STATIC_URL }}img/Pound_layer_cake.jpg">
-                </a>
+        {% else %}
+            <div class="offset1 span12">
+                <h1>No results found</h1>
+                {% if user.is_authenticated %}
+                    <p>
+                        Not seeing the product you're looking for? Add a product now!
+                        <a href="{% url "reviews:store_create" %}" class="btn btn-inverse">Add a product</a>
+                    </p>
+                {% else %}
+                    <p>
+                        Register now to get started adding products
+                        <a href="{% url "site:register" %}" class="btn btn-inverse">Register</a>
+                    </p>
+                {% endif %}
             </div>
-        </div>
+        {% endif %}
     </div>
 {% endblock %}

File share_search/reviews/templates/reviews/store_detail.html

View file
             <h1>{{ object.name }}</h1>
             {% if user.is_authenticated %}
                 <p>
-                    Details not quite right?
-                    <a href="{% url "reviews:store_edit" object.id %}" class="btn btn-primary">Edit Store</a>
+                    Store details not quite right?
+                    <a href="{% url "reviews:store_edit" object.id %}" class="btn btn-inverse">Edit Store</a>
                 </p>
             {% endif %}
         </hgroup>
             </div>
             <div class="row-fluid">
                 <div class="span12">
-                    <a href="#" class="btn btn-block">Promote</a>
+                    <a href="#" class="btn btn-block btn-success">Promote</a>
                 </div>
             </div>
         </div>
     </div>
     <div class="row">
         <div class="span12">
-            Hello, I am a thing
+            <center>List of products available...</center>
         </div>
     </div>
 {% endblock %}

File share_search/reviews/templates/reviews/store_list.html

View file
                 {% if user.is_authenticated %}
                     <p>
                         Not seeing the store you're looking for? Add a store now!
-                        <a href="{% url "reviews:store_create" %}" class="btn btn-success">Add a store</a>
+                        <a href="{% url "reviews:store_create" %}" class="btn btn-inverse">Add a store</a>
                     </p>
                 {% else %}
                     <p>
                         Register now to get started adding stores
-                        <a href="{% url "site:register" %}" class="btn btn-success">Register</a>
+                        <a href="{% url "site:register" %}" class="btn btn-inverse">Register</a>
                     </p>
                 {% endif %}
             </div>
                 {% if user.is_authenticated %}
                     <p>
                         Not seeing the store you're looking for? Add a store now!
-                        <a href="{% url "reviews:store_create" %}" class="btn btn-success">Add a store</a>
+                        <a href="{% url "reviews:store_create" %}" class="btn btn-inverse">Add a store</a>
                     </p>
                 {% else %}
                     <p>
                         Register now to get started adding stores
-                        <a href="{% url "site:register" %}" class="btn btn-success">Register</a>
+                        <a href="{% url "site:register" %}" class="btn btn-inverse">Register</a>
                     </p>
                 {% endif %}
             </div>

File share_search/reviews/urls.py

View file
 from django.views.generic import TemplateView
 
 from reviews.views import (StoreDetailView, StoreListView,
-                           StoreUpdateView,
-                           ProductDetailView, StoreCreateView)
+                           StoreUpdateView, ProductListView,
+                           ProductDetailView, StoreCreateView,
+                           ProductCreateView, ProductUpdateView)
 
 
 urlpatterns = patterns(
         StoreUpdateView.as_view(),
         name="store_edit"
     ),
+    url(
+        r'^products/edit/(?P<pk>\d+)/$',
+        ProductUpdateView.as_view(),
+        name="product_edit"
+    ),
     url(r'^stores/create/$', StoreCreateView.as_view(), name="store"),
-    url(r'^products/$', TemplateView.as_view(template_name="reviews/products.html"), name="product_list"),
+    url(r'^products/$', ProductListView.as_view(template_name="reviews/products.html"), name="product_list"),
     url(r'^stores/create/$', StoreCreateView.as_view(), name="store_create"),
+    url(r'^products/create/$', ProductCreateView.as_view(), name="product_create"),
     url(
-        r'^products/(?P<id>\d+)/$',
+        r'^products/(?P<pk>\d+)/$',
         ProductDetailView.as_view(),
         name="product",
     ),

File share_search/reviews/views.py

View file
 from braces.views import LoginRequiredMixin
 from django.views.generic import DetailView, ListView, CreateView, UpdateView
 
-from reviews.forms import StoreForm
+from reviews.forms import StoreForm, ProductForm
 from reviews.models import Store, Product
 
 
 
 class ProductListView(ListView):
     model = Product
+
+class ProductCreateView(LoginRequiredMixin, CreateView):
+	model = Product
+	form_class = ProductForm
+
+class ProductUpdateView(LoginRequiredMixin, UpdateView):
+    model = Product
+    form_class = StoreForm