Re: Split models.py to smaller parts.

2009-05-03 Thread johan.uhIe

Thank you for the explanation. I think this trick is not in the
Documentation yet, I've opened a ticket for it ...
http://code.djangoproject.com/ticket/10985
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Need help first user of django..

2009-04-16 Thread johan.uhIe

You already know the Django Documentation. Another good ressource is
the Django Book. Have a look at this: http://djangobook.com/ Maybe you
should work through the entire book to get a good understanding how
forms and flatpages work.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How To Change App Label in Admin Pages

2009-04-09 Thread johan.uhIe

I'd also liked to know ...

On 8 Apr., 13:36, Burcu Hamamcıoğlu  wrote:
> I have a question about Internationalization; is there anyway to change the
> name of app name in admin pages. But I dont't want to override admin html
> pages. Can i add a new name to appp like verbose name in models?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Details

2009-04-09 Thread johan.uhIe

When you have a look at the error and at your urlsconf.py, you might
see that the error does not include your urlconf.py, which it actually
should, so the problem must be, that Django is not using your urlconf.
Have you included the urlconf in your projects urls.py?

Could be something like this:

urlpatterns = patterns('',
# other stuff
(r'^$', include('front.urls')),
)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to use email instead of username for user authentication?

2009-04-07 Thread johan.uhIe

The slugify function may also provide you with valid usernames, if you
feed it with first and last name for example. But always be certain,
that the username is unique, just as malcolm described.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to make a preview page for (dynamic) forms

2009-03-13 Thread johan.uhIe

Hello,

I have been thinking about a problem a bit, found a pretty nice
solution and would like to know, what others think of it and if there
are downsides I have forgotten about.

Starting point is a form, that has dynamically generated parts. In my
example, I generate a form from a model via ModelForm. Then I
dynamically add many-to-many-forms. So the actual html form is
combined of an unknown number of many-to-many forms.

Therefor I can not use FormPreview, because there is no static class
to inherit from FormPreview.

Okay, so I was at a point, where the form was genereated, rendered to
html, had a submit button, click on it, form gets processed and data
is saved. Now I had to integrate the preview page.

I thought about hidden fields and keeping form data in the user
session, but dismissed the ideas, because bounding the forms seemed to
complicated.

The idea of my solution is basically to always show the form, but hide
it via JavaScript and show a preview instead, if the data was found to
be valid. I'm going to try to sketch the flow.

-> First opening of form (method=get)
-> Submitting form with submit button 1 (method=post)
if not valid: show form again with error messages
if valid:
if submitted with submit button 1:
show preview with submit button 2
hide form
if submitted with submit button 2:
process form and redirect

The hiding of the form is done in the template. The structure looks
something like this:


{% if preview %}

# show form data with form.cleaned_data.name



{% endif %}


{% if preview %}

document.getElementById('form_box').style.display='none';

document.getElementById('edit_button').style.visibility='visible';

{% endif %}
# show form and errors and so on




So when somebody clicks on the submit_2 button, the normal form gets
posted regularly again, gets checked again, will be found valid and be
processed, because it got submitted by button_2. If someone
manipulates the hidden form, it just gets checked normally as if it
was a normal submission. No problem.

When somebody clicks the edit button, the preview box gets hidden and
the form is shown.

The only somehow evil hack thing is the javascript in the form_box. I
have done this, to also make the form available to browser that do not
support javascript. If javascript is not supported (or deactivated by
the user), the edit button does not appear and the form_box does not
get hidden, so it is still usable. If you do not care for javascript-
less user, you can just leave out the java-script part and alter the
form_box div to


I have only tested this on Firefox and Safari and actually do not want
to touch Internet Explorer ;)

Of course, css and javascript should be put into external files.

Maybe this helped some people. I am curious about opinions.

Cheers,
Johan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Strange behaviour with templates, dictionarys, key/value, tuple as key and nested for loop Bug?

2009-03-10 Thread johan.uhIe

I have the following hierarchical data structure making use of the
datetime-object, dictionarys, arrays and tuples all at once.

{ datetime :
{ (datetime, datetime) :
[,]
}
}

So a dictionary, holding datetime objects as keys and another
dictionary as value. The second dictionary has tuples consisting of
two datetime objects as keys and an array as value.

Reason for this complicated structure is the supposed easy handling in
the template with three for-loops to iterate over the two dictionarys
and the array. The first datetime object holds a specific day whereas
the tuple is holding a time period. The array holds the objects
related to the time period.

So I used this in a template as following:

{% for key,value in dictionary.items %}
{{key|date:"Y-m-d"}}
{% for key,value in value %}
{{ key.0|date:"H.i" }} - {{ key.1|date:"H.i" }}
{{ value }} // Array handling
{% endfor %}
{% endfor %}

But the problem is, that inside the second for loop the key/value
assignment does not work properly. I expected the tuple to be in key,
so I can access it via key.0 and key.1 and the array to be in value.
What actually happens is, that my first datetime object from the tupel
is in key and the second datetime is in value but the array is nowhere
to be found.

Renaming the variables like key1,value1 had no effect.

I start to think, that this might be a bug in django but I hope that I
just missed something.

Feedback is highly appreciated.

(Using Django 1.0.2. final and Python 2.5.1.)



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



With inheritance extended User Model + admin.ModelAdmin = Change Password does not work

2009-03-09 Thread johan.uhIe

Hi,

i'm having some problems with the following.

Set-Up:
I am extending the User Model with inheritance just as descirbed
here:
http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/
I think it is working pretty well since it is pretty powerfull and
authentication and so on works fine. My extended Model is called
"user_extra_data".

Problem:
The only problem I am having is that if you create a new user in the
contrib.admin with the "user_extra_data" you can not just simply add a
plain password twice just as in the regular "User" section, but get
only one field with the notice "Use '[algo]$[salt]$[hexdigest]' or use
the change password form.". Fair enough, there is link with "change
password form" that links to /admin/user_extra_data/customuserdata/add/
password/ but throws a "Warning: Truncated incorrect DOUBLE value:
'add/password'". Because non technical persons shall also add
passwords later, it is no solution to create the password hashes by
hand.

What not worked out:
Actually there has been a ticket for this. 
http://code.djangoproject.com/ticket/8916
But I was not able to get the stuff running. Changing
"admin.ModelAdmin" to "UserAdmin" has not worked out, since I get an
Error: "ImproperlyConfigured: 'CustomUserDataAdmin.fieldsets[2][1]
['fields']' refers to field 'titel' that is missing from the form".

Simplified Code (left out a lot of hopefully irrelevant parts):

models.py in user_extra_data

from django.db import models
from django.contrib.auth.models import User, UserManager

class CustomUserData(User):

# New Extra Data being saved with every User
titel = models.CharField(max_length = 20, blank=True)
SEX_CHOICE = (
('Male','Mr'),
('Female','Mrs'),
)
sex = models.CharField(max_length = 5, choices = SEX_CHOICE)
last_change_date = models.DateTimeField(auto_now=True, )

# Use NewUserManager to get the create_user method
objects = NewUserManager()


--

admin.py in user_extra_data

from django.contrib.auth.admin import UserAdmin
from django.contrib import admin
from user_extra_data.models import CustomUserData

class CustomUserDataAdmin(UserAdmin):
fieldsets = [
(None,  {'fields': ('titel', 'sex', 'first_name', 'last_name',
'password')}),
('More',{'fields': ('username', 
'date_joined','last_login',
'is_staff','is_active', 'is_superuser', 'groups', 'user_permissions'),
'classes': ('collapse',)}),
]
prepopulated_fields = {"username": ("last_name", "first_name",)}
radio_fields = {"sex": admin.HORIZONTAL}

admin.site.register(CustomUserData, CustomUserDataAdmin)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Extending the User Model with Inheritance | How to save extended data

2008-11-10 Thread johan.uhIe

So I have just had a try with a new written UserManager and it works.

My model looks the following way now:

from django.db import models
from django.contrib.auth.models import User, UserManager
import datetime

class NewUserManager(models.Manager):
def create_user(self, username, email, password, extradata):
"""Creates and saves a User with the given username, 
e-mail and
password.
The extradata dictionary set as attributes to the 
model"""
now = datetime.datetime.now()
user = self.model(None, username, '', '', 
email.strip().lower(),
'placeholder', False, True, False, now, now)
user.set_password(password)
# username email and password do not have to be saved 
again
del extradata['username']
del extradata['email']
del extradata['password']
for key in extradata:
setattr(user, key, extradata[key])
user.save()
return user

class CustomUserData(User):
# New Extra Data being saved with every User
city = models.CharField(max_length = 255)
[...]
# Use UserManager to get the create_user method, etc.
objects = NewUserManager()


and the save() changed to

def save(self):
CustomUserData.objects.create_user(
username=self.cleaned_data['username'],

email=self.cleaned_data['email'],

password=self.cleaned_data['password'],

extradata=self.cleaned_data)


So this looks pretty nice to me. Anyone having another suggestion?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Extending the User Model with Inheritance | How to save extended data

2008-11-09 Thread johan.uhIe

Hello People,

I'm just getting started with Django and am currently trying to get my
head around the User/Authenticating-Backend. I want to save extra data
to the User Model so i followed the inheritance way described here:
http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/

Things are pretty well working, I'm generating a sign-up-form but i'm
not able to save the inherited model to the database. I'm using Django
1.0 and mysql.

This is the set-up:

I'm creating a model that is inheriting from the User Model

from django.db import models
from django.contrib.auth.models import User, UserManager

class CustomUserData(User):
# New Extra Data being saved with every User
city = models.CharField(max_length = 255)
[...]
# Use UserManager to get the create_user method, etc.
objects = UserManager()

Now I'm doing the registration process as described in the "Practical
Django Projects"-Book by James Bennett

from django.http import HttpResponseRedirect
from django import forms
from django.forms import ModelForm
from django.shortcuts import render_to_response
from benutzerextradata.models import CustomUserData

class RegistrationForm(ModelForm):

class Meta:
model = CustomUserData
exclude = ['username', 'date_joined','last_login',
'is_staff','is_active', 'is_superuser', 'groups', 'user_permissions']

def clean(self):
# do some stuff with the data
return self.cleaned_data

def save(self):
new_user = CustomUserData.objects.create_user(
username=self.cleaned_data['username'],

email=self.cleaned_data['email'],

password=self.cleaned_data['password'])
# I'm lazy so i want all the extra data being added to 
the object
automatically
# except the ones that are already saved at creating
del self.cleaned_data['username']
del self.cleaned_data['email']
del self.cleaned_data['password']
for key in self.cleaned_data:
setattr(new_user, key,
self.cleaned_data[key])
new_user.save()

def register(request):
if request.method == 'POST':
form = RegistrationForm(data=request.POST)
if form.is_valid():
new_user = form.save()
return HttpResponseRedirect('sign_up_success')
else:
form = RegistrationForm()
return render_to_response('register_form.html', { 'form': form,
'add': True })

So I'm having a form, providing all the neccessary data, pass it to
clean which returns a perfect cleaned_data dictionary when valid. but
when it comes to save the stuff, i get a mysql error saying "(1048,
"Column 'city' cannot be null")" which makes sense with from debug sql-
query "'INSERT INTO `customuserdata_customuserdata` (`user_ptr_id`,
`city`) VALUES (%s)'"

So I see, that I have to get my extra user data somehow into this sql-
query via the create_user method. I thought of overriding the
create_user method in the CustomUserData or saving a normal user first
and inserting my CustomUserData into the Database by hand, but both
ways aren't the nicest to use i think.

So whats the best way to do this? Help is appreciated a lot. I'm
looking forward to your answers.

Greetings from Berlin/Germany

Johan UhIe


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---