Skip to content

Commit

Permalink
Add fields in Election's Model, create view and template of create ne…
Browse files Browse the repository at this point in the history
…w election from user'
  • Loading branch information
Daniel Ortega Norambuena committed Nov 17, 2011
1 parent ba31148 commit 2c6c6a0
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 5 deletions.
2 changes: 1 addition & 1 deletion elections/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CandidateInline(admin.StackedInline):


class ElectionAdmin(admin.ModelAdmin):
list_display = ('name', 'owner', 'slug')
list_display = ('name', 'owner', 'description', 'slug', 'admin_image')
inlines = [CandidateInline]


Expand Down
17 changes: 16 additions & 1 deletion elections/models.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import os
from django.db import models
from django.conf import settings
from django.forms import ModelForm
from django_extensions.db.fields import AutoSlugField

# Create your models here.


class Election(models.Model):
name = models.CharField(max_length=255)
slug = AutoSlugField(max_length=50, unique=True, populate_from=('name',))
#slug = AutoSlugField(max_length=50, unique=True, populate_from=('slug_edit',))
slug = models.CharField(max_length=255)
owner = models.ForeignKey('auth.User')
description = models.TextField(max_length=10000)
logo = models.ImageField(upload_to = 'logos/', null =True, blank = True)

created_at = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False)

class Meta:
unique_together = ('slug', 'owner')

def admin_image(self):
#return '<img src = "%s"/>' % self.logo
img_dir = os.path.join(settings.USER_FILES, str(self.logo))
return '<img src = "%s"/>' % img_dir
admin_image.allow_tags = True

def __unicode__(self):
return u"%s" % self.name

class ElectionForm(ModelForm):
class Meta:
model = Election

class Candidate(models.Model):
first_name = models.CharField(max_length=255)
Expand Down
13 changes: 13 additions & 0 deletions elections/templates/elections/create_election.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html>
<head>
<title></title>
</head>
<body>
<form action="." method="post">{% csrf_token %}
<table>
{{form.as_table}}
</table>
<input type="submit" value="Crear Elección" />
</form>
</body>
</html>
8 changes: 8 additions & 0 deletions elections/templates/elections/success_create_election.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title></title>
</head>
<body>
<h1>Felicidades, has creado una elección</h1>
</body>
</html>
18 changes: 17 additions & 1 deletion elections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
from django.template.context import RequestContext
from django.contrib.auth.models import User

from models import Election, Candidate, Answer, PersonalInformation, Link, Category, Question
<<<<<<< HEAD
from models import Election, Candidate, Answer, PersonalInformation, Link, Category, Question, ElectionForm
from forms import CategoryForm



@login_required
@require_http_methods(['GET', 'POST'])
def associate_answer_to_candidate(request, slug, election_slug):
Expand All @@ -27,6 +29,20 @@ def associate_answer_to_candidate(request, slug, election_slug):
'elections/associate_answer.html', {'candidate': candidate, 'categories': election.category_set},
context_instance=RequestContext(request))

@login_required
@require_http_methods(['GET','POST'])
def create_election(request, my_user):
if request.POST:
form = ElectionForm(request.POST)
if form.is_valid():
form.save()
return redirect('/elections/success_create_election/')
else:
return render_to_response('elections/create_election.html', {'form': form}, context_instance = RequestContext(request))
return render_to_response('elections/create_election.html', {'form': ElectionForm}, context_instance = RequestContext(request))

def success_create_election(request):
return render_to_response('elections/success_create_election.html')

def medianaranja1(request, my_user, election_slug):

Expand Down
Binary file added logos/cool_face-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logos/cool_face-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logos/cool_face-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logos/cool_face-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ httplib2==0.7.1
ipython==0.11
oauth2==1.5.170
pep8==0.6.1
pygraphviz==1.1
python-openid==2.2.5
wsgiref==0.1.2
pil==1.1.7
5 changes: 4 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'logos')


# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

USER_FILES = 'static-files'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
Expand Down
6 changes: 6 additions & 0 deletions urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
(r'^profiles/', include('profiles.urls')),

url(r'^elections/', include('elections.urls')),
url(r'^elections/success_create_election/$','candidator.elections.views.success_create_election'),
url(r'^(?P<my_user>[a-zA-Z0-9-]+)/elections/create_election/$', 'elections.views.create_election',name='create_election'),
url(r'^(?P<my_user>[a-zA-Z0-9-]+)/(?P<election_slug>[a-zA-Z0-9-]+)/medianaranja/$', 'candidator.elections.views.medianaranja1',name='medianaranja1'),
url(r'^(?P<election_slug>[-\w]+)/add_category/$', add_category, name='add_category' ),

Expand All @@ -32,3 +34,7 @@


)
from django.conf import settings
from django.conf.urls.static import static

urlpatterns += static( settings.USER_FILES, document_root=settings.STATIC_ROOT )

0 comments on commit 2c6c6a0

Please sign in to comment.