Re: Integrity Error on chained FKs

2011-03-27 Thread shofty
this is the view code...

u = get_object_or_404(UserProfile, user=request.user)
if request.method == "POST":
# submitted the add venue form
venue_form = VenueForm(request.POST)
venue_form.user = u
venue_form.slug = slugify(request.POST['name'])
if venue_form.is_valid():
venue_form.save()



-- 
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.



Newbie Problem with Django reverse()

2011-03-27 Thread Ajay
I am missing something really basic here.

I am trying to reuse django's change password views. I have following
in urls.py:

(r'^change-password/$', 'profile.views.change_password',
{},'change_password'),
url(r'^change-password-done/$', 'profile.views.password_change_done',
name='django.contrib.auth.views.password_change_done'),

and in corresponding views.py:

from django.contrib.auth.views import password_change,
password_change_done

def
change_password(request,template_name="password_change_form.html"):
"""Change Password"""
return password_change(request,template_name=template_name)

def password_change_done(request,
template_name="password_change_done.html"):
return render_to_response(template_name,(),context_instance=
RequestContext(request))

but I am getting following error:

Reverse for 'django.contrib.auth.views.password_change_done' with
arguments '()' and keyword arguments '{}' not found.

looked at the source and saw this line:

post_change_redirect =
reverse('django.contrib.auth.views.password_change_done')

If I change my urls.py entry to following , I do not get the above
error:

url(r'^change-password-done/$',
'django.contrib.auth.views.password_change_done', name='anything'),

but I am confused as reverse() should look-up using the "name"
parameter? What am I missing here?

I am using django 1.2.3

-- 
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.



url - hot to set properly?

2011-03-27 Thread galgal
I need to make some settings in urls. I want admin site enabled and 1 view 
method to catch rest of the request parts.
So if someone's url is :/admin - ADMIN panel is show, also if someone pass: 
/admin/ (/ <- is important)
If someone pass: /, /contact, gallery,. my custom method is activated.
The problem i have is / on the end.

My urls:

from django.conf.urls.defaults import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
(r'^', include('apps.textcontent.urls')),
)


My app url:

from django.conf.urls.defaults import *
urlpatterns = patterns('apps.textcontent.views',
url(r'^(?P.*)$', 'index', name='index'),
) 


when i pass: /admin/ all is ok, but when I pass /admin - 
 apps.textcontent.urls are executed, but why?

-- 
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: Integrity Error on chained FKs

2011-03-27 Thread shofty
been playing with this some more and i still can't work out what ive
done to cause this issue.

as i see it, when saving a Venue, the Survey model which is FK'd to
the Venue is complaining that the user_id isn't set.

However there is nothing being saved by the Survey model, so why is it
even getting involved?

Next step is to take the Survey model out of the equation, resync the
db, prove that the code works to save a venue I guess.

On Mar 27, 9:41 am, shofty  wrote:
> this is the view code...
>
>     u = get_object_or_404(UserProfile, user=request.user)
>     if request.method == "POST":
>         # submitted the add venue form
>         venue_form = VenueForm(request.POST)
>         venue_form.user = u
>         venue_form.slug = slugify(request.POST['name'])
>         if venue_form.is_valid():
>             venue_form.save()

-- 
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: url - hot to set properly?

2011-03-27 Thread Pascal Germroth

Hi,


urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
(r'^', include('apps.textcontent.urls')),
)



when i pass: /admin/ all is ok, but when I pass /admin -
apps.textcontent.urls are executed, but why?


Well because the URL pattern is a regular expression that is matched 
against the URL, and you explicitly stated that there has to be a / at 
the end.


Change it to url(r'^admin/?',…) and it will work both with '/admin' and 
'/admin/'.


But: this is bad URL etiquette. You should choose a schema (/ or not) 
and stick with it. Even better: create a view that matches the opposite 
of your chosen schema and permanently redirects to the correct URL (or 
enable normalisation in your webserver, that would be easier)


--
Pascal Germroth

--
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: Integrity Error on chained FKs

2011-03-27 Thread Daniel Roseman
On Sunday, March 27, 2011 9:41:53 AM UTC+1, shofty wrote:
>
> this is the view code... 
>
> u = get_object_or_404(UserProfile, user=request.user) 
> if request.method == "POST": 
> # submitted the add venue form 
> venue_form = VenueForm(request.POST) 
> venue_form.user = u 
> venue_form.slug = slugify(request.POST['name']) 
> if venue_form.is_valid(): 
> venue_form.save() 
>
>
The lines starting with `venue_form.user` and `venue_form.slug` aren't doing 
what you intend. They aren't setting the value of the form's fields to 
anything - they are just setting arbitrary attributes on the form, which are 
ignored.

What you mean to do is this:

venue_form = VenueForm(request.POST) 
if venue_form.is_valid(): 
venue = venue_form.save(commit=False) 
venue.user = u 
venue.slug = slugify(venue.name) 
venue.save()

To make this work, you'll probably need to add the user and slug fields to 
the form's `exclude` tuple.

I don't know what this has to do with "chained FKs", though.
--
DR.

-- 
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: images in a template

2011-03-27 Thread Vladimir
I have found a solution but it's very strange!
Remind I use Django 1.2.5, development web server, Windows 7.
Project level (named galiontours) urls.py:
import os
from django.conf.urls.defaults import *
from galiontours.galion import views
from galion.views import index
from galiontours import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^index/', 'galion.views.index'),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^static/(?P.*)$', 'django.views.static.serve',
{ 'document_root': os.path.join(settings.CURRENT_PATH,
'static') }),
)

settings.py with:
CURRENT_PATH =
os.path.abspath(os.path.dirname(__file__).decode('utf-8')).replace('\
\', '/')

now in index.html:
 -
such case works when image file is in directory: /static/images/
products/thumbnails/
  - such case dosn't work when
image file is in directory: /static/images/products/
  -
such case dosn't work when image file is in directory: /static/images/
products/thumbnails/d/
and it doesn't work in my hands when image file has gif type.
Why?

-- 
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: url - hot to set properly?

2011-03-27 Thread Łukasz Rekucki
On 27 March 2011 14:51, Pascal Germroth  wrote:
> Hi,
>
>>    urlpatterns = patterns('',
>>    url(r'^admin/', include(admin.site.urls)),
>>    (r'^', include('apps.textcontent.urls')),
>>    )
>
>> when i pass: /admin/ all is ok, but when I pass /admin -
>> apps.textcontent.urls are executed, but why?
>
> Well because the URL pattern is a regular expression that is matched against
> the URL, and you explicitly stated that there has to be a / at the end.
>
> Change it to url(r'^admin/?',…) and it will work both with '/admin' and
> '/admin/'.
>
> But: this is bad URL etiquette. You should choose a schema (/ or not) and
> stick with it. Even better: create a view that matches the opposite of your
> chosen schema and permanently redirects to the correct URL (or enable
> normalisation in your webserver, that would be easier)

Good news, Django already provides a way to do this. See
APPEND_SLASH[1] setting and CommonMiddleware[2].

[1]: http://docs.djangoproject.com/en/1.3/ref/settings/#append-slash
[2]: 
http://docs.djangoproject.com/en/1.3/ref/middleware/#django.middleware.common.CommonMiddleware




-- 
Łukasz Rekucki

-- 
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: Integrity Error on chained FKs

2011-03-27 Thread shofty
Daniel,

thanks for pointing that out, the amended code now does what it was
supposed to do. makes perfect sense when you explained it.
i already had the slug and user excluded, which is why it allowed me
to add them but didn't validate them im guessing.

chained fk's was down to the error message. i thought that my link
from survey to venue to userprofile to user might have been the
issue.

On Mar 27, 2:03 pm, Daniel Roseman  wrote:
> On Sunday, March 27, 2011 9:41:53 AM UTC+1, shofty wrote:
>
> > this is the view code...
>
> >     u = get_object_or_404(UserProfile, user=request.user)
> >     if request.method == "POST":
> >         # submitted the add venue form
> >         venue_form = VenueForm(request.POST)
> >         venue_form.user = u
> >         venue_form.slug = slugify(request.POST['name'])
> >         if venue_form.is_valid():
> >             venue_form.save()
>
> The lines starting with `venue_form.user` and `venue_form.slug` aren't doing
> what you intend. They aren't setting the value of the form's fields to
> anything - they are just setting arbitrary attributes on the form, which are
> ignored.
>
> What you mean to do is this:
>
>         venue_form = VenueForm(request.POST)
>         if venue_form.is_valid():
>             venue = venue_form.save(commit=False)
>             venue.user = u
>             venue.slug = slugify(venue.name)
>             venue.save()
>
> To make this work, you'll probably need to add the user and slug fields to
> the form's `exclude` tuple.
>
> I don't know what this has to do with "chained FKs", though.
> --
> DR.

-- 
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: Newbie Problem with Django reverse()

2011-03-27 Thread Alendit
Hi,

if only one url is bound to a controller there is no need for a name
argument. When you are specifying a name for an expression and it have
got the same name as the controller a conflict arise. Just drop the
name argument and it should work.

Alendit.

On 27 Mrz., 09:54, Ajay  wrote:
> I am missing something really basic here.
>
> I am trying to reuse django's change password views. I have following
> in urls.py:
>
> (r'^change-password/$', 'profile.views.change_password',
> {},'change_password'),
> url(r'^change-password-done/$', 'profile.views.password_change_done',
> name='django.contrib.auth.views.password_change_done'),
>
> and in corresponding views.py:
>
> from django.contrib.auth.views import password_change,
> password_change_done
>
> def
> change_password(request,template_name="password_change_form.html"):
>     """Change Password"""
>     return password_change(request,template_name=template_name)
>
> def password_change_done(request,
> template_name="password_change_done.html"):
>     return render_to_response(template_name,(),context_instance=
> RequestContext(request))
>
> but I am getting following error:
>
>     Reverse for 'django.contrib.auth.views.password_change_done' with
> arguments '()' and keyword arguments '{}' not found.
>
> looked at the source and saw this line:
>
> post_change_redirect =
> reverse('django.contrib.auth.views.password_change_done')
>
> If I change my urls.py entry to following , I do not get the above
> error:
>
> url(r'^change-password-done/$',
> 'django.contrib.auth.views.password_change_done', name='anything'),
>
> but I am confused as reverse() should look-up using the "name"
> parameter? What am I missing here?
>
> I am using django 1.2.3

-- 
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: Django 1.3 - Question about static files

2011-03-27 Thread Sultan Imanhodjaev
Just set the static *STATIC_URL* copy your static files into you application
root e.g. *MY_APP/core and nothing like *
*
*
 r'^static/(?P.*)$',
 'django.views.static.serve',
{'document_root': os.path.join(PROJECT_ROOT, 'static')}

in *urls.py*

**run server this should work, down below my you can see the piece of *
settings.py*

*STATIC_URL = '/static/'*
*
*
*ADMIN_MEDIA_PREFIX = '/static/admin/'*
*
*
*STATICFILES_FINDERS = (*
*'django.contrib.staticfiles.finders.FileSystemFinder',*
*'django.contrib.staticfiles.finders.AppDirectoriesFinder',*
*'django.contrib.staticfiles.finders.DefaultStorageFinder',*
*)*
*
*
*STATICFILES_DIRS = ()*


On Sat, Mar 26, 2011 at 9:49 PM, Igor Nemilentsev  wrote:

> On 26-03-2011, Sandro Dutra  wrote:
> >Hello everyone!
>
> >I'm using Python 2.7.x with Django 1.3 and I've some questions about
> >the new way to set the static files for the dev server.
>
> >abspath = lambda *p: os.path.abspath(os.path.join(*p))
> >PROJECT_ROOT = abspath(os.path.dirname(__file__))
> >(...)
> >MEDIA_ROOT = abspath(PROJECT_ROOT, 'media')
> >MEDIA_URL = '/media/'
> >ADMIN_MEDIA_PREFIX = '/media/admin/'
>
> >STATIC_ROOT = abspath(PROJECT_ROOT, 'static')
> >STATIC_URL = '/static/'
> >STATICFILES_DIRS = (
> >abspath(STATIC_ROOT, 'css'),
> >abspath(STATIC_ROOT, 'javascript'),
> >abspath(STATIC_ROOT, 'images'),
> >)
> I had a similar problem.
> I do not remember, but what I have in my project now
> it is commented out STATIC_ROOT.
>
> If I uncomment STATIC_ROOT it do not work.
>
> STATIC_ROOT_FILES = os.path.join(os.path.dirname(__file__),
> 'static').replace('\\', '/')
> #STATIC_ROOT = STATIC_ROOT_FILES
> STATICFILES_DIRS = (
>STATIC_ROOT_FILES,
> )
> STATIC_URL = "/static/"
>
> --
> Practical politics consists in ignoring facts.
>-- Henry Adams
>
> --
> 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.
>
>


-- 
Kind regards,
Sultan Imanhodjaev
+996 779 230 968

-- 
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.



Paid 8 hour tutorial/mentoring/development gig

2011-03-27 Thread David Kovar
Good morning,

I could really benefit from about eight hours of intense tutoring in Django in 
the fairly near future. I'll pay $600 for those eight hours of time ($75/hour), 
or a bit more if necessary. You need to be within three hours of Central 
Illinois - Chicago, St. Louis, Indianapolis. I'll come to you and work around 
your schedule, but I'd like to get this done in two days if possible. Two hours 
in the morning, two in the evening each day, four hour blocks, or one eight 
hour day. Whatever works well for you.

I know Python relatively well and I've worked through the tutorial. I'm quite 
new to OOP, web frameworks, and some other critical issues. 

The time will be split between learning Django, introducing me to Django's 
design concepts, and walking through an existing UI and discussing how best to 
re-implement it with Django.

If you're interested, there will likely be some ongoing Django development work 
that could be done remotely. (Our existing two developers are both remote, why 
change now?)

If you're interested, please send me appropriate reference materials - code, 
sites you've done, resume, Twitter/LinkedIn/etc handle, blog posting I'm 
not concerned with your age or educational background, but your Django 
experience, design expertise, and ability to communicate well, at least for 
eight hours, is important.

Thanks very much.

-David

-- 
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.



Updating to Django 1.3 - how to preserve file field previous behaviour

2011-03-27 Thread -RAX-
Hi all,

According to 
http://docs.djangoproject.com/en/dev/releases/1.3/#filefield-no-longer-deletes-files
FileField fields no longer delete the related file when the instance
is deleted.

I understand the motivations behind this decision BUT this creates
several side effects in various websites which I have developed.

Is it there a way to keep the original behaviour?

If not, which one in your opinion is the best way to delete files when
the owning instance has been deleted?
A post delete signal? Will this suffer from the original problem for
which the file deletion has been removed?



-- 
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.



subclassing User: can't log in, can't change password

2011-03-27 Thread Kees Hink
I'm subclassing django.contrib.auth.models.User to create a custom
user type (Student) with extra fields, following
http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/.
(Is there no documentation on djangoproject.org on how to do this?)
Some relevant snippets of code: http://pastie.org/1721216

I've create a Student and given the account "staff" status, to be able
to log in to the admin interface. The Student can't log in there,
however. When i create a User in the same way, that User can log in.

Also i noticed the password is saved unhashed: i can read the password
i typed from the edit form. Password reset form doesn't work:
http://pastie.org/1721206 Another thing i noticed: adding a Student
also ads a User, but removing the Student doesn't remove the User.

What am i doing wrong?

Kees

-- 
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: subclassing User: can't log in, can't change password

2011-03-27 Thread Calvin Spealman
Do not subclass the User model. Create a profile model and register
that with the auth app, which is how the authentication documentation
tells you to go about this.

http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

On Sun, Mar 27, 2011 at 10:54 AM, Kees Hink  wrote:
> I'm subclassing django.contrib.auth.models.User to create a custom
> user type (Student) with extra fields, following
> http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/.
> (Is there no documentation on djangoproject.org on how to do this?)
> Some relevant snippets of code: http://pastie.org/1721216
>
> I've create a Student and given the account "staff" status, to be able
> to log in to the admin interface. The Student can't log in there,
> however. When i create a User in the same way, that User can log in.
>
> Also i noticed the password is saved unhashed: i can read the password
> i typed from the edit form. Password reset form doesn't work:
> http://pastie.org/1721206 Another thing i noticed: adding a Student
> also ads a User, but removing the Student doesn't remove the User.
>
> What am i doing wrong?
>
> Kees
>
> --
> 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.
>
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy

-- 
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: subclassing User: can't log in, can't change password

2011-03-27 Thread Kees Hink
Thanks. The blog post made it look like this was the "old" way, but i value
information from djangoprojects.org more. I'll go and create profiles, then.

Kees

On 03/27/2011 07:08 PM, Calvin Spealman wrote:
> Do not subclass the User model. Create a profile model and register
> that with the auth app, which is how the authentication documentation
> tells you to go about this.
> 
> http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users
> 
> On Sun, Mar 27, 2011 at 10:54 AM, Kees Hink  wrote:
>> I'm subclassing django.contrib.auth.models.User to create a custom
>> user type (Student) with extra fields, following
>> http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/.
>> (Is there no documentation on djangoproject.org on how to do this?)
>> Some relevant snippets of code: http://pastie.org/1721216
>>
>> I've create a Student and given the account "staff" status, to be able
>> to log in to the admin interface. The Student can't log in there,
>> however. When i create a User in the same way, that User can log in.
>>
>> Also i noticed the password is saved unhashed: i can read the password
>> i typed from the edit form. Password reset form doesn't work:
>> http://pastie.org/1721206 Another thing i noticed: adding a Student
>> also ads a User, but removing the Student doesn't remove the User.
>>
>> What am i doing wrong?
>>
>> Kees
>>
>> --
>> 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.
>>
>>
> 
> 
> 

-- 
Goldmund, Wyldebeast & Wunderliebe

+31 (0)50 5891 631 (Groningen)
+31 (0)20 7850 383 (Amsterdam)
www : http://www.gw20e.com/
mail: i...@gw20e.com

-- 
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.



Deploying Pinax to bluehost

2011-03-27 Thread Antik
I created a Pinax website on localhost and I have been trying to
deploy it to my hosting server at bluehost.com, but I am really lost
as to how this works. COuld anyone shed light on the process? Thanks!

-- 
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: Looking for development services

2011-03-27 Thread Aryeh Leib Taurog
On Mar 23, 6:22 pm, Aryeh Leib Taurog  wrote:
> My employer (not me) is looking for development services to build a
> relatively small site/service with django.

Let me explain what I mean by "relatively small."  I think this could
be a one or two month project for one individual.  Someone with a lot
of django/python experience or better yet a small django shop with
more code and programmer resources could probably do it in a month or
under, which is really what we're looking for.

It's an interesting project, and I wish I had time to take it on
myself.

> Required experience:
>    python
>    django
>    processing paypal payments
>
> advantageous:
>    deployment & sysadmin experience
>    experience developing workflow systems (in python)
>
> Please send sample work and pricing structure to
> dlev...@warmwisdompress.com.

-- 
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.



Twitter like graph with django model

2011-03-27 Thread Shamail Tayyab
Hi,

   Can you give me a hint on some model schema that can optimally
store a big social graph (follow/following type).

Tx

-- 
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: url - hot to set properly?

2011-03-27 Thread galgal
I have APPEND_SLASH True but / is not added :)

-- 
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: Initial Data SQL not sticking?

2011-03-27 Thread fdo
Hmm, I see your commit; Did you get a confirmation message from your
database that the commit worked?
Perhaps you could try inserting the data via a python script.

import sqlite3
# create/connect to a permanent file database
con = sqlite3.connect("pyfitness2.db")
# establish the cursor, needed to execute the connected db
cur = con.cursor()
cur.execute("INSERT INTO repository_date  etc.. ;")
con.commit()
con.close()

Note that my example is specifically for sqlite.

On Mar 26, 7:42 pm, Daniel Pugh  wrote:
> Forgive if this is totally obvious, but I'm having a bit of trouble
> getting data into my first prototype with django.
>
> I am prototyping an application called repository, syncdb builds my
> tables and all seems to work in the admin interface.
>
> However, I have 600 lines of data I want to use as the seed for my
> main table.  I have a sql file with INSERT commands stored in sql
> folder named after the model (sql/date.sql)
>
> Immediately after running syncdb, I insert the data with either
>  or  repository>.  This seems to work, it reads through the SQL and ends
> with this:
>
> INSERT INTO repository_date
> (`labno`,`siteno`,`site`,`material`,`materialcomment`,`technique`,`d13`,`rcybp`,`error`,`ref`,`provtype`,`provenience`,`provenience2`,`generalcult`,`taxon`,`comments`)
> VALUES
> ('ISGS-4242','14CM406','','CHG','','CNV','-26.7','430','70','Bevitt
> 1999','','','','','WLM','');
>
> INSERT INTO repository_date
> (`labno`,`siteno`,`site`,`material`,`materialcomment`,`technique`,`d13`,`rcybp`,`error`,`ref`,`provtype`,`provenience`,`provenience2`,`generalcult`,`taxon`,`comments`)
> VALUES
> ('unk','14RH301','','MAZ','','AMS','-25.3','600','40','','','','','','WLM','');
> CREATE INDEX "repository_date_5b0c863a" ON
> "repository_date" ("siteno_id");
> CREATE INDEX "repository_reference_6223029" ON
> "repository_reference" ("site_id");COMMIT;
>
> Problem is that when I try to access these data in the admin interface
> or do dumpdata, nothing is there.  I'm at a loss for why the data
> aren't populating my database.
>
> I appollogize if this is completely obvious, it's my first hack at web
> development and as much as I love it, some things totally mystify my.
>
> Thanks!

-- 
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.



Seeking Django Counsel when adding a new model using South and a custom field for my ProtectedFileField subclass

2011-03-27 Thread Matteius
I've read the documentation at South and I would really like to take
this opportunity to say this project would be way better with improved
documentation or maybe I'm just missing something. I recently added a
new model to my project which is using South, which means syndcb no
longer simply adds the model to the database.   So Now I'm faced with
these errors regarding my custom ProtectedFileField for generating
time-expiry links, therefore I followed the instructions adding this
code to my fields.py :

from south.modelsinspector import add_introspection_rules

# We need to add introspection rules to our custom fields for south to
function properly.
add_introspection_rules([], ["^student_portal\.fields
\.ProtectedFileField"])

def gen_sec_link(rel_path):
"""
Generate a temporary authorized link to download a file @param
rel_path.
This function is used with Apache mod_auth_token to serve up
secure content.

"""
secret = settings.AUTH_TOKEN_PASSWORD
uri_prefix = '/media/uploads/'
rel_path = rel_path[7:]
hextime = "%08x" % time.time()
token = hashlib.md5(secret + rel_path + hextime).hexdigest()
return '%s%s/%s%s' % (uri_prefix, token, hextime, rel_path)
# EndDef

class ProtectedFieldFile(FieldFile):
"""
This subclass of FieldFile (which is FileField's underlying
storage class)
overrides the url API method to implement mod_auth_token secure
links for all ProtectedFileFields.
Reason this is great: it fixes all broken links in applications
that use this models.file_field.url and
allows the template language to be simplified and less prone
to errors.

"""
def _get_url(self):
self._require_file()
return gen_sec_link(self.name)
url = property(_get_url)
# EndClass

class ProtectedFileField(FileField):
"""
This class class is the model field label you would declare in
models.py

"""
attr_class = ProtectedFieldFile
description = ugettext_lazy("File path with Auth_Token support.")


I've added the south specific code to models.py, __init__.py and as
mentioned fields.py.

from south.modelsinspector import add_introspection_rules

# We need to add introspection rules to our custom fields for south to
function properly.
add_introspection_rules([], ["^student_portal\.fields
\.ProtectedFileField"])

but still get the error:

matteius@classcomm-dev:/var/django_projects/classcomm$ sudo python
manage.py schemamigration classcomm.student_portal
auto_add_extra_credit --add-model ExtraCredit
 ! Cannot freeze field 'student_portal.assignment.provided_files'
 ! (this field has class
classcomm.student_portal.fields.ProtectedFileField)
 ! Cannot freeze field 'student_portal.grade.returned_files'
 ! (this field has class
classcomm.student_portal.fields.ProtectedFileField)
 ! Cannot freeze field 'student_portal.submission.file'
 ! (this field has class
classcomm.student_portal.fields.ProtectedFileField)

 ! South cannot introspect some fields; this is probably because they
are custom
 ! fields. If they worked in 0.6 or below, this is because we have
removed the
 ! models parser (it often broke things).
 ! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork


By far the main blocking point of my day and finishing adding this
ExtraCredit model to my project.

-- 
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: Seeking Django Counsel when adding a new model using South and a custom field for my ProtectedFileField subclass

2011-03-27 Thread Ian Clelland
On Sun, Mar 27, 2011 at 1:47 PM, Matteius  wrote:
> add_introspection_rules([], ["^student_portal\.fields
> \.ProtectedFileField"])
...
>  ! Cannot freeze field 'student_portal.assignment.provided_files'
>  ! (this field has class
> classcomm.student_portal.fields.ProtectedFileField)


Without looking too carefully at whether your introspection rules are
correct, the first thing that jumps out at me is that South sees the
field class as "classcomm.student_portal.fields.ProtectedFileField",
while you have registered an introspection rule for
"^student_portal\.fields\.ProtectedFileField".

The "^" at the beginning of your regex anchors the expression to the
start of the string, so it will only match if your class name begins
with "student_portal".

Try changing the regex in your add_introspection_rules call to either:

"student_portal\.fields\.ProtectedFileField" -- removing the "^" so
that it can match anywhere within the string, or

"^classcomm\.student_portal\.fields\.ProtectedFileField" -- preserving
the "^", but adding the "classcomm." that South sees as the start of
the full class name.

-- 
Regards,
Ian Clelland


-- 
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.



Two way many-to-many relationships

2011-03-27 Thread Dilan
Hi All,

I'm working on a model similar to
http://docs.djangoproject.com/en/1.3/topics/db/models/#extra-fields-on-many-to-many-relationships
.

Say, I need to add the field, groups = models.ManyToManyField(Group,
through='Membership') to Person class

Two questions:
1. In Django, is this allowed?
2. In Python, how do you forward declare Group class for this code to
work?

If this is possible this could save lot of time and reduce code
complexity a lot.  In this group there were few similar questions
asked before but without any good answers.

Thank you

-- 
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: Read-only fields and complex relationships in admin

2011-03-27 Thread Micah Carrick
Thank you Jacob. That's actually the answer I was hoping for.

On Fri, Mar 25, 2011 at 8:48 PM, Jacob Kaplan-Moss wrote:

> On Fri, Mar 25, 2011 at 6:39 PM, Micah Carrick 
> wrote:
> > I have an application which handles a typical "checkout" process for an
> > e-commerce website. Orders from online customers end up in several models
> [... snip complex problem ...]
>
> > Anybody have any tips, links to articles, etc. that
> > might help me research the best approach for this project?
>
> Yes: don't use the admin for this.
>
> Really, I know it's tempting because the admin gives you like 50% of
> what you want for free. But trust me when I tell you that if you go
> down the path of trying to kludge the admin into supporting your
> custom workflow you will be very unhappy. You'll get to 90% very
> quickly, and then you'll spend a ridiculous amount of time trying to
> close the final gap. You never quite will, and your app won't "feel"
> right. Sooner or later you'll give up and write custom views from
> scratch, throwing away all that hard work.
>
> Really: I've seen this happen more times than I can count. Don't go
> down this path.
>
> Just write custom views. Try out some apps that reproduce certain
> admin features -- apps like django-tables
> (https://github.com/miracle2k/django-tables), django-filter
> (https://github.com/alex/django-filter), django-pagination
> (https://github.com/ericflo/django-pagination), and
> django.contrib.formwizard or perhaps django-formwizard
> (https://github.com/stephrdev/django-formwizard). They might save you
> a bit of time, but you'll save the most time by not trying to force
> the admin into doing something it's not good at.
>
> Jacob
>
> --
> 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.
>
>


-- 
*Green Tackle* - *Environmentally Friendly Fishing Tackle*
www.GreenTackle.com 

 Email: mi...@greentackle.com
 Phone: 971.270.2206
 Toll Free: 877.580.9165
 Fax: 503.946.3106

-- 
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: Updating to Django 1.3 - how to preserve file field previous behaviour

2011-03-27 Thread Russell Keith-Magee
On Sun, Mar 27, 2011 at 6:20 PM, -RAX-  wrote:
> Hi all,
>
> According to 
> http://docs.djangoproject.com/en/dev/releases/1.3/#filefield-no-longer-deletes-files
> FileField fields no longer delete the related file when the instance
> is deleted.
>
> I understand the motivations behind this decision BUT this creates
> several side effects in various websites which I have developed.
>
> Is it there a way to keep the original behaviour?
>
> If not, which one in your opinion is the best way to delete files when
> the owning instance has been deleted?
> A post delete signal? Will this suffer from the original problem for
> which the file deletion has been removed?

As was suggested when you raised this on django-dev, if you want the
old behavior, write a subclass of FileField that reintroduces the old
behavior.

The changeset that removed the old behavior is fairly simple to
understand, and can be easily used as a template for the changes you
need to make:

http://code.djangoproject.com/changeset/15321

This code attaches a post-delete signal to any model that uses the
field (using the contribute_to_class method), and provides a deletion
method to remove the file.

Yours,
Russ Magee %-)

-- 
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.



simple friends template help

2011-03-27 Thread justin jools
need some help setting up templates for friends list:

how do I iterate a list of invited friends and are friends? I have
tried:


  {% for friends in Friendship.objects.are_friends %}

 target_user: {{ friends.target_user}}
 current_user:{{ friends.current_user}}
 are_friends: {{ friends.are_friends}}
 is_invited: {{ friends.is_invited}}

  {% endfor %}

gives me nothing but:

{{ is_invited }}
{{ are_friends }}
{{ target_user }}
{{ current_user }}


output:

false
false
name
name

I have been trying to figure this out for months. Please help.

-- 
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.



django-simple-friends template help

2011-03-27 Thread justin jools
need some help setting up templates for friends list:

how do I iterate a list of invited friends and are friends? I have
tried:


  {% for friends in Friendship.objects.are_friends %}

 target_user: {{ friends.target_user}}
 current_user:{{ friends.current_user}}
 are_friends: {{ friends.are_friends}}
 is_invited: {{ friends.is_invited}}

  {% endfor %}

gives me nothing but:

{{ is_invited }}
{{ are_friends }}
{{ target_user }}
{{ current_user }}


output:

false
false
name
name

I have been trying to figure this out for months. Please help.

-- 
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 parse string in django

2011-03-27 Thread django beginner
hi django experts,

how do I strip the following string in python (Charfield format)

14:00
3:00

wherein I could compare the results - convert in integer:

if 14 > 3 . . .

thanks in advance!

-- 
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 parse string in django

2011-03-27 Thread django beginner
hi django experts,

how do I strip the following string in python (Charfield format)

14:00
3:00

wherein I could compare the results - convert in integer:

if 14 > 3 . . .

thanks in advance!

-- 
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 parse string in django

2011-03-27 Thread django beginner
hi django experts,

how do I strip the following string in python (Charfield format)

14:00
3:00

wherein I could compare the results - convert in integer:

if 14 > 3 . . .

thanks in advance!

-- 
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 parse string in django

2011-03-27 Thread Mike Dewhirst

On 28/03/2011 1:38pm, django beginner wrote:

hi django experts,

how do I strip the following string in python (Charfield format)

14:00
3:00

Do you also keep am and pm? What about UTC offsets?

You need a helper method to interpret the numbers, convert them to 
seconds, do the comparison and return True or False to your view or 
model depending on when you need to know.


If the data is entered by humans you might have a different problem. 
Somehow you need to make sure the users enter what they actually meant 
rather than what you see in the charfield.


It would be good to insist on 03:00 rather than 3:00 for a start. Look 
at properly formatting the data before saving it.


I would try to do a bit of error detection and perhaps any easy 
corrections (like 3 to 03) in client-side javascript or a widget before 
the server sees it. Depends where your performance bottlenecks will be.


Mike

wherein I could compare the results - convert in integer:

if 14>  3 . . .

thanks in advance!



--
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 parse string in django

2011-03-27 Thread Mike Ramirez
On Sunday, March 27, 2011 07:38:46 pm django beginner wrote:
> hi django experts,
> 
> how do I strip the following string in python (Charfield format)
> 
> 14:00
> 3:00
> 
> wherein I could compare the results - convert in integer:
> 
> if 14 > 3 . . .
> 
> thanks in advance!

a = "14:00"
b = "3:00"

def parseTime(s)
# split them at ":"
try:
split = s.split(':')
except:
   raise ValueError("{0} is not in the right format.".format(s)

if split[0].isdigit():
# explicitly cast string val to an int to get an int.
i = int(split[0])
else:
raise TypeError("{0} is not an int.".format(split[0])

return i

if parseTime(a) > parseTime(b):
  # do stuff.


string methods are cool: http://docs.python.org/library/stdtypes.html#string-
methods


Mike

-- 
We can defeat gravity.  The problem is the paperwork involved.

-- 
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 parse string in django

2011-03-27 Thread Mike Dewhirst

On 28/03/2011 1:38pm, django beginner wrote:

hi django experts,

how do I strip the following string in python (Charfield format)

14:00
3:00

wherein I could compare the results - convert in integer:



Further to my earlier reply ...

>>> x = 3
>>> y = '%02d' % x
>>> y
'03'
>>>


if 14>  3 . . .

thanks in advance!



--
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: Two way many-to-many relationships

2011-03-27 Thread Mike Ramirez
On Sunday, March 27, 2011 02:32:15 pm Dilan wrote:
> Hi All,
> 
> I'm working on a model similar to
> http://docs.djangoproject.com/en/1.3/topics/db/models/#extra-fields-on-many
> -to-many-relationships .
> 
> Say, I need to add the field, groups = models.ManyToManyField(Group,
> through='Membership') to Person class
> 
> Two questions:
> 1. In Django, is this allowed?

Yes.  But you'll want to have a unique related_name also, iirc.

> 2. In Python, how do you forward declare Group class for this code to
> work?
> 

This isn't really a python way but a django way [1]

ManyToManyField('Group', ...)

In python you can't forward declare outside of the module the object is in. 
there is no equivalent to Class Test; as in c++. (you can dynamically import 
with the imp module though but this isn't forward declaring).

Django models load in such a way that it doesn't know modules that come after 
it in the same module/file and this was to address that.

scroll down just a tad on the link below to get info on the related_name 
attribute.

HTH,

Mike

[1] http://docs.djangoproject.com/en/1.3/ref/models/fields/#lazy-relationships
-- 
Adults die young.

-- 
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: TemplateDoesNotExist at /admin/ - admin/login.html

2011-03-27 Thread Jimmy
Thank you tracey, I already allow web server to read the files and it
works.

-- 
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: Seeking Django Counsel when adding a new model using South and a custom field for my ProtectedFileField subclass

2011-03-27 Thread Matteius
Ah most excellent, I certainly was missing something.  Well this
documentation was OK, but the having the schema migration auto-
generate is priceless.  I must have left my regex thinking mind
elsewhere this morning ... blaming Nascar.  Thanks for taking the time
this solved my issue and the new model is showing up.

-Matteius

On Mar 27, 4:04 pm, Ian Clelland  wrote:
> On Sun, Mar 27, 2011 at 1:47 PM, Matteius  wrote:
> > add_introspection_rules([], ["^student_portal\.fields
> > \.ProtectedFileField"])
> ...
> >  ! Cannot freeze field 'student_portal.assignment.provided_files'
> >  ! (this field has class
> > classcomm.student_portal.fields.ProtectedFileField)
>
> Without looking too carefully at whether your introspection rules are
> correct, the first thing that jumps out at me is that South sees the
> field class as "classcomm.student_portal.fields.ProtectedFileField",
> while you have registered an introspection rule for
> "^student_portal\.fields\.ProtectedFileField".
>
> The "^" at the beginning of your regex anchors the expression to the
> start of the string, so it will only match if your class name begins
> with "student_portal".
>
> Try changing the regex in your add_introspection_rules call to either:
>
> "student_portal\.fields\.ProtectedFileField" -- removing the "^" so
> that it can match anywhere within the string, or
>
> "^classcomm\.student_portal\.fields\.ProtectedFileField" -- preserving
> the "^", but adding the "classcomm." that South sees as the start of
> the full class name.
>
> --
> Regards,
> Ian Clelland
> 

-- 
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.



validate user input on templates

2011-03-27 Thread django beginner
Hi django experts,

just want to know your opinion on how to validate the user input
(example: the user input field should be integer, but the user
accidentally inputs any character), here is my code:

FYI; the numberofapples field is IntegerField

here is my sample code:

def apples_edit(request):
if request.POST['id']:
 id = request.POST['id']
 numberofapples = request.POST['numberofapples']
 conn = psycopg2.connect("dbname=my_db user=user password=pass
host=localhost")
 cur = conn.cursor()

try:
   if isDigit(playerid):
pass
   else:
template_name = 'err_template.html'
t = loader.get_template(template_name)
c = RequestContext(request, {"err_msg":"number of
apples should be integer, Please correct your input"})
return HttpResponse(t.render(c))
except ValueError:
template_name = 'err_template.html'
t = loader.get_template(template_name)
c = RequestContext(request, {"err_msg":"number of apples
should be integer, Please correct your input"})
return HttpResponse(t.render(c))

 sql = """ UPDATE my_db SET "numberofapples"='%s' where "id"='%s'
""" % (numberofapples,id)
 cur.execute(sql)
 conn.commit()
 conn.close()

--
My problem is that, the error template does not appear after I type in
any character for numberofapples field.
What would be the correct code for this?

Thanks.

-- 
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: validate user input on templates

2011-03-27 Thread Sam Walters
hey

use:
str.isdigit()
http://www.tutorialspoint.com/python/string_isdigit.htm


what is idDigit() ? is that a call to a method somewhere else.
and arent you trying to validate numberofapples = request.POST['numberofapples']
not playerid?

Personally if this is form data you are trying to validate i'd write a
form class and use the form clean() method to evaluate them as
integerfields:

http://docs.djangoproject.com/en/1.2/ref/forms/fields/
http://docs.djangoproject.com/en/1.2/topics/forms/

Also you can verify using regular expressions *good to get comfortable
with if you're new to django.

cheers

sam_w

On Mon, Mar 28, 2011 at 4:59 PM, django beginner  wrote:
> Hi django experts,
>
> just want to know your opinion on how to validate the user input
> (example: the user input field should be integer, but the user
> accidentally inputs any character), here is my code:
>
> FYI; the numberofapples field is IntegerField
>
> here is my sample code:
>
> def apples_edit(request):
>    if request.POST['id']:
>         id = request.POST['id']
>         numberofapples = request.POST['numberofapples']
>         conn = psycopg2.connect("dbname=my_db user=user password=pass
> host=localhost")
>         cur = conn.cursor()
>
>        try:
>           if isDigit(playerid):
>                pass
>           else:
>                template_name = 'err_template.html'
>                t = loader.get_template(template_name)
>                c = RequestContext(request, {"err_msg":"number of
> apples should be integer, Please correct your input"})
>                return HttpResponse(t.render(c))
>        except ValueError:
>            template_name = 'err_template.html'
>            t = loader.get_template(template_name)
>            c = RequestContext(request, {"err_msg":"number of apples
> should be integer, Please correct your input"})
>            return HttpResponse(t.render(c))
>
>         sql = """ UPDATE my_db SET "numberofapples"='%s' where "id"='%s'
> """ % (numberofapples,id)
>         cur.execute(sql)
>         conn.commit()
>         conn.close()
>
> --
> My problem is that, the error template does not appear after I type in
> any character for numberofapples field.
> What would be the correct code for this?
>
> Thanks.
>
> --
> 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.
>
>

-- 
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: extend User Model for custom fields

2011-03-27 Thread Derek
On Mar 26, 12:53 pm, Antonio Sánchez  wrote:
> Yeah sure, i should have used "recommended" word instead of correct.
>
> The difference between link i wrote and b-list is that the last one
> uses a foreign-key, while first uses one-to-one, and this is the way
> is recommended in doc, so... I think i will follow that post
> recommendations.
>
> Thanks again!
>
> p.d.: in this case, recommendation is not no use heritange, but, in
> cases where i want to extend ANOTHER app (3rd apps), how do you do it?
> using inheritange?
>
> On Mar 25, 9:30 pm, Mike Ramirez  wrote:
>
>
>
>
>
>
>
> > On Friday, March 25, 2011 01:16:51 pm Nick Serra wrote:> Andre's solution 
> > is out of date. Calvin is correct, use the user
> > > profile model that is built into django auth. OP, the link you found
> > > is correct.
>
> > > >http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-m...
>
> > > > > > > here:
> > > > > > >http://docs.djangoproject.com/en/1.2//topics/auth/#storing-
>
> > additional-information-about-users
>
> > and:
>
> >http://docs.djangoproject.com/en/1.3/topics/auth/#storing-additional-
> > information-about-users
>
> > What's different about these pages, except that b-list goes into a bit more
> > detail?
>
> > Hint: Nothing.
>
> > But I don't think there is a "correct" way, just a recommended way.  I use 
> > the
> > recommended way, but it's definately not the only way or 'better'.  
> > 'correct',
> > 'better' in this case are subjective to the needs of the dev and/or project.
>
> > Mike.
>
> > --
> > Reality is just a convenient measure of complexity.
> >                 -- Alvy Ray Smith

The b-list approach works just fine, whether you use a OneToOne or
ForeignKey (with unique=True).

-- 
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.