Skip to content

Commit

Permalink
Model Source added
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Jan 16, 2011
1 parent c47862c commit 523e6c1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
1 change: 0 additions & 1 deletion templates/web/layout.html
Expand Up @@ -2,7 +2,6 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" href="/style.css" />
<title>{% block title %}Passwords{% endblock %}</title>
</head>
<body>
Expand Down
5 changes: 3 additions & 2 deletions web/admin.py
@@ -1,4 +1,5 @@
from web.models import Password
from web.models import *
from django.contrib import admin

admin.site.register(Password)
admin.site.register(Source)
admin.site.register(Password)
Binary file modified web/admin.pyc
Binary file not shown.
10 changes: 8 additions & 2 deletions web/models.py
@@ -1,6 +1,12 @@
from django.db import models

class Source(models.Model):
name = models.CharField(max_length = 255)
def __unicode__(self):
return self.name

class Password(models.Model):
password = models.CharField(max_length = 255)
password = models.CharField(max_length = 1000)
Source = models.ForeignKey(Source)
def __unicode__(self):
return self.password
return self.password + " from " + self.Source.name
Binary file modified web/models.pyc
Binary file not shown.
11 changes: 4 additions & 7 deletions web/views.py
Expand Up @@ -6,21 +6,18 @@


def index(request):
# I don't really like .reverse()[:5] part but it will have to do for now
pass_count = Password.objects.all().count()

return render_to_response('web/index.html', {'pass_count': pass_count},
return render_to_response('web/index.html', {'pass_count': Password.objects.all().count()},
context_instance=RequestContext(request))

def add(request):
# This here is some really primitive error handling:
# I would use trim() but there is probably someone out there with a password containing only spaces :)

# I would use trim() but there is probably someone out there with a password containing only spaces :)
if(request.method != "POST" or len(request.POST['pw_pass']) == 0):
return HttpResponseBadRequest("You have made a nono, <a href=\"/\">go back</a>.")

#if(request.POST["cb_add"] == "on"):
p = Password(password=request.POST["pw_pass"])
# Source_id should not be hardcoded but it's late:
p = Password(password=request.POST["pw_pass"], Source_id=1)
p.save()

return HttpResponseRedirect('/id/' + str(p.id))
Expand Down
Binary file modified web/views.pyc
Binary file not shown.

0 comments on commit 523e6c1

Please sign in to comment.