Commits

Michele Orrù committed 3d334bb Merge

merge

  • Participants
  • Parent commits 42f92ed, 2a9103f

Comments (0)

Files changed (6)

File seedswap/seed/forms.py

 # -*- coding: utf-8 -*-
 
 from django import forms
-from django.forms import ModelForm
+#from django.forms import ModelForm
+from seed.models import *
 
 
 class SearchForm(forms.Form):
-    Requested = forms.ChoiceField(data)
+    #Requested = forms.ChoiceField(data)
     Species = forms.ModelMultipleChoiceField(queryset=Species.objects.all())
-    
+    
+class InsertSeedForm(forms.ModelForm):
+    class Meta:
+        model = Seed

File seedswap/seed/models.py

 
 PHONE_REGEX="[\d ]+"
 
-class ModelForm(forms.ModelForm):
-    def __new__(cls, model):
-        cls.Meta = model
-
-        return cls
-
-    Meta = object()
-
 # Create your models here.
 class UserProfile(models.Model):
     """
     def interested():
         raise NotImplementedError
 
-UserForm = ModelForm(User)
+    @property
+    def reputation(self):
+        """
+        The reputation of a purchaser/costumer is defined by how many items
+        he/she bought weighted with the time of activity.
+
+        It is supposed to be in range(5)
+        """
+        return 5 # XXX: change
 
 class Species(models.Model):
     """

File seedswap/seed/templates/base.html

 	<div id="header">
 		<div id="menu">
 			<ul>
-				<li><a href="#" class="first">Home</a></li>
-				<li><a href="#">About</a></li>
-				<li><a href="#">Contact</a></li>
+				<li><a href="/" class="first">Home</a></li>
+				<li><a href="/about">About</a></li>
+				<li><a href="/contacts">Contact</a></li>
 			</ul>
 		</div>
 		<!-- end #menu -->
             {% endblock %}
 		</div>
 		<!-- end #content -->
-		<div id="sidebar">
-            <!-- Something -->
+        <div id="sidebar">
+            {% if logged %}
+            {% else %}
+            <ul>
+                <li>
+                    <h2><a href="/user/signup">Sign up</a></h2>
+                </li>
+                <li>
+                    <ul>
+                        <li><a href="#">A few links</a></li>
+                    </ul>
+                </li>
+            </ul>
+            {% endif %}
 		</div>
 		<!-- end #sidebar -->
 		<div style="clear: both;">&nbsp;</div>
 	</div>
 	<!-- end #page -->
 	<div id="footer">
-		<p>SeedSwapApp is released under GLP licence. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
+		<p>SeedSwapApp is released under GPL licence. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
 	</div>
 	<!-- end #footer -->
 </div>

File seedswap/seed/templates/insertSeed.html

+{% extends "base.html" %}
+{% block page_title %}
+Insert new seed offer
+{% endblock %}
+{% block content %}
+    {{ form.as_p }}
+{% endblock %}

File seedswap/seed/views.py

 from django.contrib import auth
 
 from seed.models import *
+from seed.forms import *
 
 
-def add(request):
+def add_seeds(request):
     """
     A simple form to add a stock of seeds.
     """
     if request.method == 'POST':
+        myForm = InsertSeedForm(request.POST)
+        if myForm.is_valid():
+            myForm.save()
+            return HttpResponse('Record correctly inserted.')
+    else:
+        myForm = InsertSeedForm()
+    return render_to_response("insertSeed.html", {"form": myForm})
+
+def index(request):
+    return render_to_response('index.html', {'logged' : request.user.is_authenticated()})
+
+def contacts(request):
+    return render_to_response('contacts.html', {'logged' : request.user.is_authenticated()})
+
+def about(request):
+    return render_to_response('about.html', {'logged' : request.user.is_authenticated()})
+
+def register(request):
+    return render_to_response('register.html', {'logged' : request.user.is_authenticated()})
+
+def add_user(request):
+    if request.method == 'POST':
         form = UserForm(request.POST)
         if form.is_valid():
             form.save()
 
-    return HttpResponse('This is a HttResponse!')
-
-def index(request):
-    return render_to_response('index.html', {'logged' : request.user.is_authenticated()})
-
+    return HttpResponse('User added!')
 
 def search(request):
     all_seeds = Seed.objects.all()

File seedswap/urls.py

 urlpatterns += patterns('seed.views',
         url(r'^seed/add$', 'add'),
         url(r'^seed/search$', 'search'),
+        url(r'^contacts$', 'contacts'),
+        url(r'^about$', 'about'),
+        url(r'^user/sign_up$', 'register'),
+        url(r'^user/add$', 'add_user'),
         url(r'^$', 'index'),
         url(r'^seed/(?P<seed_id>\d{10})$', 'view'),
         url(r'^user/dashboard$', 'dashboard'),