summaryrefslogtreecommitdiff
path: root/usuarios
diff options
context:
space:
mode:
authorJoaquín Aguirrezabalaga <kinote@kinote.org>2014-01-03 01:06:22 +0100
committerJoaquín Aguirrezabalaga <kinote@kinote.org>2014-01-03 01:06:40 +0100
commitf05c5e2d8a705df1c94b63a978267b291c893bbb (patch)
treea8bd95e9cc2c0bd48be57893ccc4ddec63152d29 /usuarios
parent802a74102b9073e961ef1d7a487f99b962d76512 (diff)
downloadelgarito-master.tar.gz
elgarito-master.zip
django 1.6HEADmaster
Diffstat (limited to 'usuarios')
-rw-r--r--usuarios/admin.py2
-rw-r--r--usuarios/models.py10
-rw-r--r--usuarios/urls.py19
-rw-r--r--usuarios/views.py17
4 files changed, 29 insertions, 19 deletions
diff --git a/usuarios/admin.py b/usuarios/admin.py
index e6ce5ba..6ff171f 100644
--- a/usuarios/admin.py
+++ b/usuarios/admin.py
@@ -1,7 +1,7 @@
# vim: set fileencoding=utf-8 ts=4 shiftwidth=4 softtabstop=4 expandtab:
from django.contrib import admin
-from elgarito.usuarios.models import UserProfile
+from usuarios.models import UserProfile
class UserProfileAdmin(admin.ModelAdmin):
diff --git a/usuarios/models.py b/usuarios/models.py
index 3f5b3c7..f63de7a 100644
--- a/usuarios/models.py
+++ b/usuarios/models.py
@@ -1,9 +1,10 @@
# vim: set fileencoding=utf-8 ts=4 shiftwidth=4 softtabstop=4 expandtab:
-from elgarito.tablon.models import PermisoForo
+from tablon.models import PermisoForo
from django.db import models
from django.contrib.auth.models import User
from django import forms
+
class UserProfile(models.Model):
user = models.OneToOneField(User)
show_email = models.BooleanField("Mostrar e-mail", blank=True)
@@ -29,24 +30,27 @@ class UserProfile(models.Model):
pass
return False
+
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
- exclude = ('user')
+ exclude = ('user',)
+
class UserForm(forms.ModelForm):
class Meta:
model = User
fields = ('first_name', 'last_name', 'email')
+
class UserProfileCreateForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ('show_email', 'url', 'msn_id', 'jabber_id', 'imagen')
+
class UserCreateForm(forms.ModelForm):
class Meta:
model = User
fields = ('username', 'password', 'first_name', 'last_name', 'email')
-
diff --git a/usuarios/urls.py b/usuarios/urls.py
index 2b09146..1552882 100644
--- a/usuarios/urls.py
+++ b/usuarios/urls.py
@@ -1,14 +1,15 @@
-from django.conf.urls.defaults import *
+from django.conf.urls import patterns, url
-urlpatterns = patterns('',
- (r'^$', 'elgarito.usuarios.views.index'),
+urlpatterns = patterns(
+ '',
+ url(r'^$', 'usuarios.views.index'),
- (r'^lista/$', 'elgarito.usuarios.views.lista'),
- (r'^nuevo/$', 'elgarito.usuarios.views.nuevo'),
- (r'^ver/(?P<usuario_id>\w+)/$', 'elgarito.usuarios.views.ver'),
- (r'^mi_perfil/$', 'elgarito.usuarios.views.mi_perfil'),
+ url(r'^lista/$', 'usuarios.views.lista'),
+ url(r'^nuevo/$', 'usuarios.views.nuevo'),
+ url(r'^ver/(?P<usuario_id>\w+)/$', 'usuarios.views.ver'),
+ url(r'^mi_perfil/$', 'usuarios.views.mi_perfil'),
- (r'^login/', 'django.contrib.auth.views.login'),
- (r'^logout/', 'django.contrib.auth.views.logout'),
+ url(r'^login/', 'django.contrib.auth.views.login'),
+ url(r'^logout/', 'django.contrib.auth.views.logout'),
)
diff --git a/usuarios/views.py b/usuarios/views.py
index 331cfae..48b5cd7 100644
--- a/usuarios/views.py
+++ b/usuarios/views.py
@@ -1,5 +1,5 @@
# vim: set fileencoding=utf-8 ts=4 shiftwidth=4 softtabstop=4 expandtab:
-from elgarito.usuarios.models import UserProfile, UserProfileForm, UserForm
+from usuarios.models import UserProfile, UserProfileForm, UserForm
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.shortcuts import render_to_response, get_object_or_404
@@ -7,9 +7,11 @@ from django.template import RequestContext
from django.contrib.auth.decorators import user_passes_test
from django.http import HttpResponseRedirect
+
def index(request):
return lista(request)
+
def lista(request):
lista_usuarios = User.objects.all()
return render_to_response('usuarios/lista.html',
@@ -18,6 +20,7 @@ def lista(request):
'user': request.user,
}))
+
def ver(request, usuario_id):
usuario = get_object_or_404(User, username=usuario_id)
if usuario == request.user:
@@ -30,6 +33,7 @@ def ver(request, usuario_id):
'show_edit': show_edit
}))
+
def nuevo(request):
"""Crear un nuevo usuario"""
# Si el usuario ya está autenticado lo redirigimos a su perfil
@@ -38,16 +42,17 @@ def nuevo(request):
# Si es un POST, creamos el usuario
if request.POST:
userform = UserCreationForm(request.POST)
- user = userform.save()
+ userform.save()
return HttpResponseRedirect('../mi_perfil/')
# Si no es un POST, mostramos formulario para crear el usuario
else:
userform = UserCreationForm()
return render_to_response('usuarios/nuevo.html',
RequestContext(request, {
- 'userform' : userform
+ 'userform': userform
}))
+
@user_passes_test(lambda u: u.is_authenticated(),
login_url='/usuarios/login/')
def mi_perfil(request):
@@ -57,7 +62,7 @@ def mi_perfil(request):
profile = UserProfile.objects.get(user=request.user)
except UserProfile.DoesNotExist:
profile = UserProfile(user=request.user)
- if request.POST.has_key('show_email'):
+ if 'show_email' in request.POST:
profile.show_email = True
else:
profile.show_email = False
@@ -83,7 +88,7 @@ def mi_perfil(request):
form = UserProfileForm(instance=usuario)
return render_to_response('usuarios/mi_perfil.html',
RequestContext(request, {
- 'userform' : userform,
- 'form' : form,
+ 'userform': userform,
+ 'form': form,
'usuario': usuario
}))