diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/app/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/app/tests.py b/app/tests.py new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/app/tests.py @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff --git a/app/views.py b/app/views.py new file mode 100644 index 0000000..55c003d --- /dev/null +++ b/app/views.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 +from datetime import datetime + +from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404 +from django.template import RequestContext +from django.conf import settings +from django.http import HttpResponse, HttpResponseRedirect +from django.contrib import auth +from django.contrib.auth.models import User, Group +from django.contrib.auth import authenticate +from django.core.mail import send_mail +from django.core.cache import cache + +from ox.django.shortcuts import render_to_json_response + + +def login(request): + message = '' + if 'username' in request.POST and 'password' in request.POST: + user = authenticate(username=request.POST['username'], password=request.POST['password']) + if user and user.is_active: + auth.login(request, user) + return HttpResponseRedirect(settings.PREFIX+'/') + else: + message = 'Login failed.' + context = RequestContext(request, { + 'settings': settings, + 'message': message + }) + return render_to_response('login.html', context) + +def logout(request): + auth.logout(request) + return HttpResponseRedirect(settings.PREFIX+'/') + +def register(request): + message = '' + if 'username' in request.POST and 'password' in request.POST: + username = request.POST['username'] + password = request.POST['password'] + email = request.POST['email'] + #fixme validate email + if User.objects.filter(username__iexact=username).count() > 0: + message = 'Username already exists' + elif User.objects.filter(email__iexact=email).count() > 0: + message = 'Email address already exits' + elif not password: + message = 'Password can not be empty' + else: + user = User(username=username, email=email) + user.set_password(password) + user.save() + user = authenticate(username=username, password=password) + auth.login(request, user) + return HttpResponseRedirect(settings.PREFIX+'/') + + context = RequestContext(request, { + 'settings': settings, + 'message': message + }) + return render_to_response('register.html', context) diff --git a/item/views.py b/item/views.py index 33352eb..fea162d 100644 --- a/item/views.py +++ b/item/views.py @@ -85,9 +85,13 @@ def add(request): return HttpResponseRedirect('/') def index(request): + items = None + if not request.user.is_anonymous(): + items = request.user.items.order_by('filename') context = RequestContext(request, { 'PREFIX': settings.PREFIX, 'anonymous': request.user.is_anonymous(), + 'items': items, }) return render_to_response('index.html', context) diff --git a/templates/index.html b/templates/index.html index d38acb9..791ae43 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,7 +13,10 @@ var UPLOAD_URL = "{{PREFIX}}/add";