comment_was_posted

2008-10-29 Thread sam

hello,

I try to redirect a user who comments a post on my blog to the same
page,
to do that, i need to use the signal : 'comment_was_posted'

i have put the code below in my blog 'models.py' to be sure it has
been loaded,
but when i post a new message, i'm not redirected to google ...

from django.contrib.comments.signals import comment_was_posted
from django.http import HttpResponseRedirect

def on_comment_was_posted(sender, comment, request, *args, **kwargs):
return HttpResponseRedirect('http://www.google.fr')

comment_was_posted.connect(on_comment_was_posted)

anybody got any ideas ?

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



securing /admin/

2009-09-18 Thread Sam

Hi Django peeps,

Right now, I am in the middle of trying to secure a django app's admin
and store areas (satchmo).

I have installed a self-signed certificate for testing purposes and I
am able to encrypt all pages just fine EXCEPT for the admin page. Here
is my setup:

ubuntu 8.04 and apache2 with Django 1.0 and satchmo

And here is my set of situations that work and do not work:

Working: Encrypting all pages except for the admin area. To do this, I
simply went into my apache sites-enabled to mysite.com and did the
following:

changed  to 

and added in these lines toward the bottom of the directory:
#SSLEngine On
#SSLCertificateFile /etc/apache2/ssl/server.crt
#SSLCertificateKeyFile /etc/apache2/ssl/server.key

I also included {'SSL' : True} in the django urls.py to any URL that I
wanted to be encrypted including the admin URL: (r'^admin/', include
(admin.site.urls), {'SSL' : True}),

After I restart apache and go to my page, everything is https with no
problem. However, when I try to go to my admin page, it redirects me
from https:mysite.com/admin to http://mysite.com/admin and gives a 404
url cannot be found error.

Something else I tried was the directions given at:
http://www.tangerinesmash.com/2009/red-robot-studios-part-3-securing-django-ssl/

Using these directions, I tried to encrypt only the admin area with
the rewrite rule and got the good old error:
"Looks like your browser isn't configured to accept cookies. Please
enable cookies, reload this page, and try again."

What seems to be happening to me, is  that django is forcing the admin
login to be http instead of https. Is there some setting that I am
missing out on?

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



Encrypting admin area (SSL) on nignx proxy with apache2

2009-09-24 Thread Sam

Hi everyone,

I am in the process of trying to encrypt with ssl through apache
anything that is done in /admin.

Right now, I have an nginx proxy on port 80 that forwards anything to
an apache virtual host listening on a different port. I also have
another apache vhost listening on 443 but is not forwarded to by the
nginx proxy.

I have looked around and tried a few of the common things that show up
when google-ing around or reading the django docs:

Of course, in settings.py set SESSION_COOKIE_SECURE=True. If I do this
and don't do anything else with apache or other settings, when I try
to login to the admin area (http://site.com/admin/) I get the
commonplace error:

"Looks like your browser isn't configured to accept cookies. Please
enable cookies, reload this page, and try again."

I would expect this because of the http:// and not https:// location
on the URL.

So the next thing I do is add a rewrite or redirect rule to the apache
or nginx  vhost that will send it to port 443. When I do this, I
usually get an error along the lines of:

"Firefox has detected that the server is redirecting the request for
this address in a way that will never complete."

Which I interpret to mean that although the vhost is redirecting to
port 443, Django is redirecting it back to 80 because SSL is not
enabled for the admin views. So, in my urls.py, I added in {'SSL' :
True} to the admin view, but get the same errors.

All that being said, I know that the ssl is working for the site
because when I add {'SSL' : True} to any of the views that I wrote, it
works just fine.

There must be a setting that I have overlooked or something that to
stop the admin page from redirecting from https to http.

On another note, even though the SSL seems to be working fine, when I
look at my satchmo log it says:

"2009-09-24 13:01:22,865 sslurllib   : WARNING  ssl is not installed,
please install it from http://pypi.python.org/pypi/ssl/";

Which I have not installed because when I do, I get an error about
something like some bluetooth headers not being installed. I don't
think this is causing a problem since I can encrypt some pages, but I
though I would mention it.

Thanks,

Sam

--~--~-~--~~~---~--~~
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: I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField

2010-06-13 Thread Sam
Hello,

Are you using MySQL and what is the collation of your database. I am
running 1.2.1 and encountering similar problems.

My issue involves utf8_bin collation on mysql 5.1.41-3ubuntu12.3. The
issue is thus: I create a model with an ImageField and save a new
instance to my utf8_bin collated mysql backend. This instance has a
file associated with non-ascii characters in it, e.g.
"Sinéad_OConnor.jpg". Next I attempt delete the file (via the admin)
and I get a:

'ascii' codec can't decode byte 0xc3 in position 18: ordinal not in
range(128)

FYI, MySQLdb does not return unicode strings with a utf8_bin collation
set.
for a brief description of that issue see:
http://code.djangoproject.com/ticket/8340#comment:4

The traceback from my exception reveals the exception being thrown in
"django/db/models/fields/files.py" in get_prep_value (line 248).
FileField is a subclass of Field, but implements the same backend
MySQL type (varchar) as a CharField. However it seems that FileField
and CharField have completely different implementations of
get_prep_db.

Here is CharField's implementation:
def to_python(self, value):
if isinstance(value, basestring) or value is None:
return value
return smart_unicode(value)

def get_prep_value(self, value):
return self.to_python(value)

Here is Filefield's:
def get_prep_value(self, value):
"Returns field's value prepared for saving into a database."
# Need to convert File objects provided via a form to unicode
for database insertion
if value is None:
return None
return unicode(value)

My experimentations revealed that if I replace the FileField
implementation of get_prep_value with the CharField, the exception
goes away. The issue is that the default encoding is ascii and so
unicode() called on a utf8 byte str blows up. The CharField
implementation simply checks if the value is an instance of basestring
and just passes it through. This latter approach seems better to me.
As it stands, I'm inclined to think this issue is a bug.

Thanks much,
-Sam





On Jun 13, 6:22 pm, Karen Tracey  wrote:
> On Sun, Jun 13, 2010 at 6:18 PM, MichaleHjulskov  wrote:
> > Hi Karen, I did not know there was a new release, sorry.
>
> > So if I just install the new release, it will solve the problem just
> > like that?
> > Or do I still need to do something, in order to make it work with
> > special chars in the filenames?
>
> No, with the current release you still need to ensure your environment is
> set properly to allow Django to pass unicode to file system functions. The
> behavior I am guessing you are seeing (absent the full traceback to be sure)
> is not a bug in Django, it's an error in your environment setup. I pointed
> to the place in the doc where this is mentioned, and where some details of
> properly setting things up for Apache is covered, in the first paragraph of
> my first response.
>
> I just mentioned upgrading from the alpha level of code because there are
> plenty of bugs that were fixed between alpha and release, and your life will
> likely be easier if you use release level code instead of alpha.
>
> Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: I experience problem with special chars like æ øå in filename when using models.ImageField. and models.Fi leField

2010-06-14 Thread Sam
Here it is!

http://code.djangoproject.com/ticket/13758

Any feedback on that ticket would be appreciated.

Regards,
Sam

On Jun 13, 11:20 pm, Karen Tracey  wrote:
> On Sun, Jun 13, 2010 at 8:22 PM, Sam  wrote:
> > As it stands, I'm inclined to think this issue is a bug.
>
> It sounds like it. Could you open a ticket for it?
>
> Karen
> --http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



"View on Site" for instance with Many-To-Many relation to the Site model

2010-06-29 Thread Sam
Hello,

I'm using a model with a many to many relationship to Site. I noticed
that the redirect from the admin site (the link "View on Site") is to
a domain that is not associated with the current SITE_ID. in other
words I have two sites, "devel.domain.com" and "www.domain.com." When
I select "View on Site" when using the admin on the www.domain.com
site, it sends me to the resource on the devel.domain.com instead.

Inspecting the admin code, I see the url conf for redirects on line
227 in
django/contrib/admin/sites.py

Tracing the code backwards I eventually get to
django.contrib.contenttypes.views.shortcut, the view that performs the
redirect. I see in that view, the model instance we are trying to
"View on Site" is inspected to determine if it has a relation (Many-to-
Many or Many-To-One) to the Site model.

starting on line 32 in django/contrib/contenttypes/views.py we see
this chunk of code dealing with the Many To Many:
*snip*

# First, look for an many-to-many relationship to Site.
for field in opts.many_to_many:
if field.rel.to is Site:
try:
# Caveat: In the case of multiple related Sites, this
just
# selects the *first* one, which is arbitrary.
object_domain = getattr(obj, field.name).all()
[0].domain
except IndexError:
pass
if object_domain is not None:
break

*endsnip*

What this code is doing is attempting to find a domain to concatenate
with the result of `get_absolute_url()`

My question is, why do we a arbitrarily select the first Site instance
in the many to many relationship? Wouldn't it make sense to pick the
Site instance associated with the running SITE_ID? The reason I ask
this is that it is confusing for the admin to redirect away from the
running site, to another site.

I believe this to be a question of correctness. Rather than choosing,
arbitrarily, a random site to redirect to, why not redirect, again
arbitrarily, to the current site? Anyways, I would appreciate any
feedback on this, it has come up and I am at a loss to explain this
behavior in the admin. Am I missing something?

Thanks much,
Sam

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: "View on Site" for instance with Many-To-Many relation to the Site model

2010-06-30 Thread Sam
tl;dr version:

admin "view on site" link returns the first Site associated with a
model, rather than the current Site. Is this correct? It seems that it
should return the current site (if it is picking one arbitrarily)

-Sam

On Jun 29, 11:19 pm, Sam  wrote:
> Hello,
>
> I'm using a model with a many to many relationship toSite. I noticed
> that the redirect from the adminsite(the link "ViewonSite") is to
> a domain that is not associated with the current SITE_ID. in other
> words I have two sites, "devel.domain.com" and "www.domain.com." When
> I select "ViewonSite" when using the admin on thewww.domain.comsite, it sends 
> me to the resource on the devel.domain.com instead.
>
> Inspecting the admin code, I see the url conf for redirects on line
> 227 in
> django/contrib/admin/sites.py
>
> Tracing the code backwards I eventually get to
> django.contrib.contenttypes.views.shortcut, theviewthat performs the
> redirect. I see in thatview, the model instance we are trying to
> "ViewonSite" is inspected to determine if it has a relation (Many-to-
> Many or Many-To-One) to theSitemodel.
>
> starting on line 32 in django/contrib/contenttypes/views.py we see
> this chunk of code dealing with the Many To Many:
> *snip*
>
>     # First, look for an many-to-many relationship toSite.
>     for field in opts.many_to_many:
>         if field.rel.to isSite:
>             try:
>                 # Caveat: In the case of multiple related Sites, this
> just
>                 # selects the *first* one, which is arbitrary.
>                 object_domain = getattr(obj, field.name).all()
> [0].domain
>             except IndexError:
>                 pass
>             if object_domain is not None:
>                 break
>
> *endsnip*
>
> What this code is doing is attempting to find a domain to concatenate
> with the result of `get_absolute_url()`
>
> My question is, why do we a arbitrarily select the firstSiteinstance
> in the many to many relationship? Wouldn't it make sense to pick 
> theSiteinstance associated with the running SITE_ID? The reason I ask
> this is that it is confusing for the admin to redirect away from the
> runningsite, to anothersite.
>
> I believe this to be a question of correctness. Rather than choosing,
> arbitrarily, a randomsiteto redirect to, why not redirect, again
> arbitrarily, to the currentsite? Anyways, I would appreciate any
> feedback on this, it has come up and I am at a loss to explain this
> behavior in the admin. Am I missing something?
>
> Thanks much,
> Sam

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: What is (?u) in r'^tags/(?P[^/]+)/(?u)$'

2007-06-04 Thread Sam

Thanks both of you.

To synthesize :

It is possible to put flags at the end of our urls match strings.

Those are (?iLmsux) corresponding to re.I, re.L, re.M, re.S, re.U,
re.X

In this case, re.U is for (source : http://docs.python.org/lib/node46.html
):
UNICODE
Make \w, \W, \b, \B, \d, \D, \s and \S dependent on the Unicode
character properties database. New in version 2.0.

This Thread is also interesting:
Forcing UTF8 data inside django ( through a middleware )
http://groups.google.com/group/django-users/browse_thread/thread/52349f0968f5b36b/07adcb5763a09a5a


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



Re: How is profile_callback in django-registration supposed to work?

2007-06-24 Thread Sam

This is how i use profile_callback with django-registration :

1. define the profile_callback function :
# profile/models.py

from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import gettext_lazy as _

class ProfileManager(models.Manager):
"""
Custom manager for the ``Profile`` model.

"""
def profile_callback(self, user):
"""
Creates user profile while registering new user
registration/urls.py

"""
new_profile = Profile.objects.create(user=user,)

class Profile(models.Model):
user = models.ForeignKey(User, verbose_name=_('user'),
unique=True)
# TODO : fill in profile fields

objects = ProfileManager()

2. Edit registration/urls.py :

# Import your profile object
from profile.models import Profile

# add the dict with your profile creation function
   url(r'^register/$',
   register,
   {'profile_callback':
Profile.objects.profile_callback},
   name='registration_register'),

That's it.

I'm still using 0.96 so i've added this on top of the registration/
urls.py file to make it work:
# TODO : remove when upgrading from 0.96
def url(*args, **kwargs):
return args


--
http://django-fr.org/ pour les francophones ! :P


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



Re: How is profile_callback in django-registration supposed to work?

2007-06-26 Thread Sam

The trunk version of django-registration has been modified and it is
now even more simple to create a profile object.

Edit registration/urls.py :

# Import your profile object
from profile.models import Profile

# add the dict with your profile creation function
   url(r'^register/$',
   register,
 
{'profile_callback':Profile.objects.create},
   name='registration_register'),


On Jun 24, 6:27 pm, Sam <[EMAIL PROTECTED]> wrote:
> This is how i use profile_callback with django-registration :
>
> 1. define the profile_callback function :
> # profile/models.py
>
> from django.db import models
> from django.contrib.auth.models import User
> from django.utils.translation import gettext_lazy as _
>
> class ProfileManager(models.Manager):
> """
> Custom manager for the ``Profile`` model.
>
> """
> def profile_callback(self, user):
> """
> Creates user profile while registering new user
> registration/urls.py
>
> """
> new_profile = Profile.objects.create(user=user,)
>
> class Profile(models.Model):
> user = models.ForeignKey(User, verbose_name=_('user'),
> unique=True)
> # TODO : fill in profile fields
>
> objects = ProfileManager()
>
> 2. Edit registration/urls.py :
>
> # Import your profile object
> from profile.models import Profile
>
> # add the dict with your profile creation function
>url(r'^register/$',
>register,
>{'profile_callback':
> Profile.objects.profile_callback},
>name='registration_register'),
>
> That's it.
>
> I'm still using 0.96 so i've added this on top of the registration/
> urls.py file to make it work:
> # TODO : remove when upgrading from 0.96
> def url(*args, **kwargs):
> return args
>
> --http://django-fr.org/pour les francophones ! :P


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



Re: newbie django vs. djangoamf

2007-07-10 Thread Sam

>From this URL http://djangoamf.sourceforge.jp/index.php?DjangoAMF_en :

Django AMF is a Middleware for Django web framework written in Python.
It enables Flash/Flex applications to invoke Django's view functions
using AMF(Action Message Format).

A MiddleWare is a piece of code that is hooked in an HTTP request.

The answer is you need both.

Install Django,
Download and add the middleware to your django project
configure django's settings.py with MIDDLEWARE_CLASSES containing
djangoamf.


On Jul 10, 3:21 pm, "Sells, Fred" <[EMAIL PROTECTED]> wrote:
> I'm a Pythonista, but new to django.  I am building my first Flex app.
> Using Flex 3.0Beta.  This is a rewrite of an Ajax prototype built with
> dojotoolkit.  I have completed the flex side, using static url's that point
> to xml files with expected responses.
>
> When I google 'flex python' I get alot of hits for djangoamf, but none of
> them say what it is or how it differs from django.
>
> I don't know if I should use django 0.96 or djangoamf.  I'm developing on XP
> but will deploy on Linux.  Using Python 2.4 for now.
>
> Could I get some enlightenment please?
>
> ---
> The information contained in this message may be privileged and / or
> confidential and protected from disclosure. If the reader of this message is
> not the intended recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited. If you
> have received this communication in error, please notify the sender
> immediately by replying to this message and deleting the material from any
> computer.
> ---


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



Re: Django serving static PDF file

2007-07-17 Thread Sam

import urllib

from django.http import HttpResponse

def output_file(request, file, mimetype):
f = urllib.urlopen(file)
data = f.read()
f.close()
return HttpResponse(data, mimetype=mimetype)


It is better to serve from static environments but sometimes, you want
to check user rights for download and you can't avoid the django env.



On Jul 17, 10:29 am, Arnold Chen <[EMAIL PROTECTED]> wrote:
> Besides, i want to revise my first question as:
>
> How to serve static file by "pushing" a PDF to client? In php, there
> is a way to serve PDF by pushing the file to the client, and client to
> choose "Save As" or "Open" the file directly.
>
> Adobe reader is very slow if they run in browsers, and most of the
> time, they hang the browser, so is there a way to push ?
>
> regards,
> Arnold
>
> On Jul 17, 4:03 pm, Arnold Chen <[EMAIL PROTECTED]> wrote:
>
> > Thanks Ben,
>
> > Besides, i've found thatwww.lawrence.comandwww.ljworld.com(which
> > are famous sites that use django) use ahttp://media.their-domain-name.com
> > to store the media files.
> > All static files, images, css are from thehttp://media.their-domain-name.com
> > server. Obviously the media subdomain is not a django environment, i
> > wonder if we can setup an environment like that, and can i still
> > upload image to the media subdomain from the django admin console?
>
> > Arnold
>
> > On Jul 17, 3:29 pm, Ben van Staveren <[EMAIL PROTECTED]> wrote:
>
> > > You're better off not doing it with Django, just make a directory
> > > that won't be handled by Django and stick all your static content in
> > > there. After all, the webserver is usually better at serving static
> > > files than Django is :)
>
> > > On 17/07/2007, at 2:26 PM, Arnold Chen wrote:
>
> > > > Can any one please tell me how to serve a static PDF in django ? The
> > > > file is located in the server, and do not need to be created on the
> > > > fly (by using report lab). I have done it in PHP by using header, but
> > > > i just don't know how to do it with django. 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



unspecified date field

2008-05-13 Thread sam

hello,


i'm looking for a way to authorize user to add date like '2007-00-00',
or '2004-04-00', when he doesn't know precisely the day or the day and
the month of a date.

is someone has got a way to do 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Python HTML lib_filter

2007-03-07 Thread Sam

I have translated Cal Henderson's lib_filter.php to python.

If you need to filter your users HTML input, you might like it.

http://amisphere.com/contrib/python-html-filter/


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



Re: Python HTML lib_filter

2007-03-07 Thread Sam

I have updated the script to version 1.15.2 ( i started at the
translation version ) with two other features:

- turn text URLs into clickable URLs
http://www.djangoproject.com/ becomes http://www.djangoproject.com/

- blacklist regexp URLs
filter.forbidden_urls = ( r'^/delete-account/', )
Click to reply becomes Click to reply

James, i included the strip_tags() function because it was needed
inside other parts of the code and that code could be run outside of
Django. Now that you're reading : I love Django ! :)

Thanks a lot Bram

Jay, i will compile the regexps inside __init__ tomorrow





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



Re: Python HTML lib_filter

2007-03-07 Thread Sam

HTML Filter allows you to only accept specific protocols for html
links ( href, src )

self.allowed_protocols = (
'http',
'ftp',
'mailto',
)

so it will only parse clickable urls for those protocol.

I will have a look at django's regexp but i had to redo that function
because "HTML Filter" works as a group of connected filters.

Please read the explanations at :
http://amisphere.com/contrib/python-html-filter/

And the examples and parameters inside the source code:
http://amisphere.com/contrib/python-html-filter/html_filter.py



On Mar 7, 11:52 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Sam, there's a filter for clickable URLs built-into Django, too.
> Smacked my head when I found that one.
>


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



Re: Python HTML lib_filter

2007-03-07 Thread Sam

You can see the power of "HTML Filter" by looking at the unit tests.

http://amisphere.com/contrib/python-html-filter/html-filter-test.html


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



Re: Python HTML lib_filter

2007-03-09 Thread Sam

I have enhanced  and fixed some bugs inside "HTML Filter"

What it does :

html_filter removes HTML tags that do not belong to a white list
closes open tags and fixes broken ones
removes javascript injections and black listed URLs
makes text URLs and emails clickable
adds rel="no-follow" to links except for white list

default settings are based on Flickr's "Some HTML is OK"
http://www.flickr.com/html.gne

The latest version is available here :

http://amisphere.com/contrib/python-html-filter/


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



High Fidelity Slugify : support for international characters

2007-03-12 Thread Sam

I needed slugify to be more precise with accented characters and i
couldn't find some code to do it, so here it is :

http://amisphere.com/contrib/python-django/slughifi.py

http://amisphere.com/contrib/python-django/ for a quick overview

example :
>>> text = "C'est déjà l'été."
>>> slughifi(text, overwrite_char_map={u"'": "-",})
'c-est-deja-l-ete'

Any comments ?


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



Re: Restricting Access to Users

2007-03-13 Thread Sam

You should go with a MiddleWare.

http://www.djangoproject.com/documentation/middleware/

Here is a basic example:

from django.http import HttpResponseRedirect

class AccessMiddleware(object):
def process_request(self, request):

# Insert your Auth Code

if authorized:
return None
else:
return HttpResponseRedirect("/?access-forbidden")

Then in your settings.py :

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'my_project.my_app.middleware.AccessMiddleware', #  has to be
after common et session if you use them
)

Remember that this code will be called for every page of your site,
and you may need to add support for public zones, ...

Have fun !

On Mar 13, 4:10 pm, "Stephen Mizell" <[EMAIL PROTECTED]> wrote:
> I'm guessing this question has been answered somewhere, but I am
> having a hard time finding an answer.  I'll explain my question by way
> of an example.  Let's say I have a Weblog model which is related to a
> Post model.  I want many Weblogs on the site, and each Weblog can have
> many Posts.  My situation is, I want to be able to restrict access to
> certain Weblogs (and everything associated with that Weblog such as
> Posts) for certain people.  What is the best method to do this?  Would
> I use the Site framework for this, and if so, is there a good tutorial
> for this?  I don't really want to make a new app for each Weblog, but
> if that's the best way I'm down with it.
>
> If this has been posted somewhere, could someone kindly point me in
> that direction?
>
> Thanks for your help.
>
> Stephen


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



Re: Restricting Access to Users

2007-03-13 Thread Sam

It's up to your code inside the middleware to restrict or allow the
access.

For example, you could check the request.META['PATH_INFO'] for zones
where the middleware shouldn't do anything.

On Mar 13, 4:47 pm, "Stephen Mizell" <[EMAIL PROTECTED]> wrote:
> > You should go with a MiddleWare.
>
> Will this work for the Django admin as well?  I don't think I
> specified in my post that I was wanting to restrict the access in the
> admin for certain users, but still make each Weblog public.  Sorry for
> the confusion.


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



Re: Global model/view best practice help

2007-04-11 Thread Sam

Like Todd said,

1. Write a function :

def my_template_vars(request)
return {'var1': 'test', 'var2': 'test2'}

2. Edit your settings.py
TEMPLATE_CONTEXT_PROCESSORS = (
...
'project.app.file.my_template_vars',
)

3. Inside your views, load your templates with a RequestContext object
if you are using functions like render_to_response.

def my_view(request):
...
return render_to_response(template_name,
 
context_instance=RequestContext(request))

4. Inside your template, you can now access {{ var1 }} all the time




On 11 avr, 15:37, "Dave" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I was looking at middleware - so, thanks Todd for the pointer in the
> right direction. I can't seem to find anything much in docs or on the
> web about TEMPLATE_CONTEXT_PROCESSORS in Django. Anyone got any links?
>
> Cheers,
> Dave
>


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



Re: cannot get REQUEST_URI

2007-04-28 Thread Sam

Why don't you also use request.META['PATH_INFO'] at production level ?

uri = request.META.get('PATH_INFO')

On 28 avr, 12:53, "omat * gezgin.com" <[EMAIL PROTECTED]> wrote:
> I need to use the current request URI in a template. Thus, I am
> passing the uri as a context variable, which is:
>
> uri = request.META.get('REQUEST_URI') or request.META.get('PATH_INFO')
>
> When I use this expression in the test server, which uses the
> request.META.get('PATH_INFO'), everything is fine but at production
> server (apache, mod_python) the value of
> request.META.get('REQUEST_URI') is always '/' for any url like 'http://
> domain.com/something/'
>
> Thanks for any 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: geographical data in models

2007-05-16 Thread Sam

I didn't go with PostGIS because i only needed basic functionality and
approximative data.

In my models, i have :
lat = models.FloatField(max_digits=7, decimal_places=4, blank=True,
null=True)
lng = models.FloatField(max_digits=7, decimal_places=4, blank=True,
null=True)

I'm using it together with GeoPy to find distances
http://exogen.case.edu/projects/geopy/

For locations in a neighbourhood, i only use less and greater than on
both fields.

I'm also interested to see how others dealt with geolocation.




On 16 mai, 09:48, omat <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I am developing an application with django that requires some
> geographical data, both some points and tracks. I have some questions
> regarding the model design.
>
> I know Postgres and MySQL have geographic extensions. I have used
> MySQL's in the past but now I am mostly interested in Postgres.
>
> Should I design using those db extension? They provide some handy
> geographical calculations but maybe those should be better done in the
> views, not in the db. But, I guess, the indexing in the db will be
> optimized for geo data, which can improve the db performance.
>
> Also, using those extensions, points and tracks can all be defined as
> the same geo type column, which will allow me to store both points and
> tracks (list of points) in one single table. A workaround to avoid
> using geo specific db extensions but keeping data in one single table
> can be pickling the list of points and storing it, but I don't have
> much practical experience. My application will be using Google Maps
> API. The API supports a method of encoding point arrays which convert
> a track info into an ascii sequence. I may be storing this encoded
> data in a text field in the db.
>
> One more: Is the best way of defining a geographical point in a model
> defining lat / lng fields separately? Postgres has a Point data type.
> Can I use it in my models?
>
> I feel like avoiding db specific extensions and going with the basic
> model types would be the best. And ideas and experiences to share?


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



Re: Best-practices for form with image

2007-05-22 Thread Sam

Your request is called a "captcha"

You can find examples in the groups or there :

http://code.google.com/p/django-captcha/
http://www.djangosnippets.org/tags/captcha/


On 22 mai, 09:59, Xin Xic <[EMAIL PROTECTED]> wrote:
> Hello,
>
> First, sorry for my english.
>
> Well, I want out a form for a human verification with an image and an
> input field. But I don't know how is the best practice for make this.
> How do you do it?
>
> I need print:
>   - An image (different in each case)
>   - An hidden input with data relationated with the image.
>   - An input field for write de response.
>
> I have thank 3 options:
>1.- Create a extended hidden widget for print the image.
>2.- Create a multi-field that verify itself image, hidden and
> response fields
>3.- Print the image within a form function with hidden and input
> fields, and verify data in form
>4.- Option 3 but verify data out of form.
>
> What do you think?
> Thanks
>
> Salut i força al canut,


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



Cannot update model instance in views but works in admin ( UnicodeEncodeError ) - FIXED

2007-05-24 Thread Sam

I use .96, UTF-8.

I couldn't update a user instance with strings containing unicode
special characters in my views but it worked with the admin interface.

Some of you may encounter this problem, so here is the solution...

I got this error :

UnicodeEncodeError at /profile/xxx/edit/
'ascii' codec can't encode character u'\xe8' in position 6: ordinal
not in range(128)

The fix is to encode your unicode clean_data with utf8 inside your
views when you update your model:

edit_user.first_name = form.clean_data['first_name'].encode('utf8')


The reason is because the edit_user instance contains non unicode data
>>> edit_user.username
'admin'
>>> form.clean_data['first_name']
u'J\xe9rome'
>>> form.clean_data['first_name'].encode('utf8')
'J\xc3\xa9rome'

The error is triggered here because u'\xe9' cannot be encoded in
ascii :
'UPDATE "auth_user" SET "username"=%s,"first_name"=%s ..."' %
('admin', u'J\xe9rome' ... )

When you encode() correctly your clean_data values, the query is doing
fine
'UPDATE "auth_user" SET "username"=%s,"first_name"=%s ..."' %
('admin', 'J\xc3\xa9rome'... )

The problem doesn't show up with unicode strings containing [a-z]
strings because the default ascii encode function can handle the
characters.


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



Re: Unicode-branch: testers wanted

2007-05-25 Thread Sam

Most of the table mapping is taken from a GPL project.

I've just emailed the authors to see if they would relicense the file
to include it inside django.

I'll update as soon as i have their replies.

On 25 mai, 10:44, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> On Fri, 2007-05-25 at 10:31 +0200, David Larlet wrote:
> > 2007/5/24, Malcolm Tredinnick <[EMAIL PROTECTED]>:
>
> > > Hi folks,
>
> > > The unicode branch, [1], is now at a point where it is essentially
> > > feature-complete and could do with a bit of heavy testing from the wider
> > > community.
>
> > Thank you so much for this branch!
>
> > > Similarly, the slugify filter still behaves as it did before. At some
> > > point it will be extended to handle a _few_ more non-ASCII characters,
> > > but it's never going to be a full transliteration function. They are the
> > > two big items I expect people would otherwise try to extend beyond what
> > > is intended. There may be others and I'm sure we'll discover what they
> > > are as the questions pop up.
>
> > Why don't we use the slughifi function:
> >http://amisphere.com/contrib/python-django/?
> > I already use it to replace the django one and it's very useful (at
> > least for french titles).
>
> If the author wanted to contribute that under a new-BSD license, we
> could use something like that, certainly (at least as the Python
> replacement; the Javascript enhancement should probably be smaller so
> that we don't have to ship so much data around, but that's a minor
> issue). There's been a lot of work put into that table of mappings,
> which is the bit we can really use.
>
> If you are the author, or you know the author and think they want to
> submit it for inclusion, please open a ticket in Trac. We really only
> need the table of mappings.
>
> Regards,
> Malcolm


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



Re: Newforms makes unicode String from a dictonary

2007-05-25 Thread Sam

I couldn't find ImageField validation in .96

To validate your images, just try to open it with PIL

from PIL import Image
from cStringIO import StringIO
try:
image = Image.open(StringIO(request.FILES['picture']
['content']))
except:
# raise error here


In practice, I handle pictures in views because there are less
constraints.

All the pictures are saved in JPEG and the filename is a combination
of the md5 and sha hexdigest

import md5, sha
picture_hash = "%s%s" % ( md5.new(picture['content']).hexdigest(),
sha.new(picture['content']).hexdigest())
picture_filename = "%s.jpg" % picture_hash[4:]
picture_path = "/media/pic/%s/%s/" % (picture_hash[:2],
picture_hash[2:4])

This way the same picture never gets written twice.

I have a model for the picture with methods like get_url() and
get_file()


On 25 mai, 11:29, Christian Schmidt <[EMAIL PROTECTED]>
wrote:
> ok, thats the fact. But I can not imagine whats wrong in my code. I
> have nearly copy and paste all of it from
>
> http://www.oluyede.org/blog/2007/03/18/django-image-uploading-validat...
>
> There, it seems to work... how do you validate files or images with
> django newforms? Is there something strange in the way I do it or does
> something special changed in the django svn repo?
>
> In my opinion the code seems to be neary similar 
> tohttp://www.djangosnippets.org/snippets/95/
> I've no idea what went wrong.
>
> Regards,
> Christian


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



Re: Newforms makes unicode String from a dictonary

2007-05-25 Thread Sam

It looks ugly to me but did you try:

>>> ustr
u"{'var': 'val'}"
>>> dic = eval(ustr)
>>> dic
{'var': 'val'}

On 25 mai, 12:40, Christian Schmidt <[EMAIL PROTECTED]>
wrote:
> > To validate your images, just try to open it with PIL
>
> When I said I validate the image then did I mean that I try to open it
> with PIL. I do this in the view an if something went wrong I would
> save an error variable in the postdata. It is the same like 
> inhttp://www.oluyede.org/blog/2007/03/18/django-image-uploading-validat...
> . The filename is not my problem - that works fine, but i cannot read
> the content-type in def clean_bild(self), because it is not a
> MultiValueDict but an unicode String...?!
> The error appears when I try to read some some values from the
> dict ->  (   content_type = image.get('content-type')  ). The
> image upload works fine when I use the django admin.


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



What is (?u) in r'^tags/(?P[^/]+)/(?u)$'

2007-06-04 Thread Sam

Found there :
Non-ASCII Tag Names in URLs
http://code.google.com/p/django-tagging/wiki/UsefulTips

I thought it is used to convert to unicode but it doesn't seem
effective.

Anyone knows about other flags ?


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



Re: user restrictions in admin interface

2007-11-27 Thread sam

thx for your answer

ok, the problem, in my case, is that I have got 2 types of users :
- data entry user, who write the content
- admin user, who valid, the content

what I need, finally, is a sort of workflow system, so that my
question is now :
is http://django-goflow.blogspot.com/ able to do this ?

sam

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



user restrictions in admin interface

2007-11-27 Thread sam

hello,

so, I'm new user of django, and I would like to know (or understand)
how to make some fields invisible to some users.
For example, if a model with this 3 fields :  publish_status, title &
content,
I would like that all users logged could modify the title and content
field (in the standard django admin)
and I would like that just a category of user can modify the
publish_status (always in the standard django admin).

?

thx

sam
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: user restrictions in admin interface

2007-11-28 Thread sam

thx for your answer,

so, I have found a translation of goFlow in english, may be it could
be more understandable to you ?
http://code.djangoproject.com/wiki/GoFlow


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



Re: AttributeError: 'WSGIRequest' object has no attribute 'user'

2007-01-15 Thread Sam


I had this error because i'm not using the auth module.

If that's you case, comment it out in your settings.py file:

TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
# "django.core.context_processors.auth",
)

On Jan 5, 5:40 am, "Brian Beck" <[EMAIL PROTECTED]> wrote:

It would seem that something is happening between the authentication
middleware setting request.__class__.userand the context processor
reading it.

Couple things to try if you're in a debugging mood:

After line 11 in django/contrib/admin/middleware.py:
 request.__class__.user= LazyUser()
+print 'Middleware:', request.user

Add that line to see if it's actually being set.

Now as the first line in whatever view this is happening in, do the
same thing:

def index_view(request):
+print 'View:', request.user

This should at least narrow down where in the code request.useris
being obliterated...



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



_post_save() problem with an empty file field

2006-05-04 Thread sam

Django version 0.91. I was trying to generate a thumbnail for an image
upload. The image is a FileField. I want to generate thumbnail in
_post_save() of the model object. The code is something like the
following:

class Item(meta.Model):
...
file = meta.FileField(upload_to="files",blank=True)
...

def _post_save(self):
path = self.get_file_filename()
im = Image.open(path)
im.thumbnail((128,128))
(p1,p2) = path.split('.')
im.save(p1+"_tn."+p2)

What I found is everytime I do "add item" in admin interface,
self.get_file_filename() returns the path of MEDIA_ROOT, not the full
path of the image file uploaded. How to solve this problem? 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



how to reference another function inside mode class

2006-02-03 Thread sam

I was tring to write a custom function inside a mode class, say X:

class X(meta.Model):
i = meta.IntegerField()
...
def foo(self):
return bar(self.i)

If I define bar() in the same model file, django complained the
"NameError -- global name bar does not exist". How do I get around
this?

What if I want to define bar() in another file under the same
app/models directory -- how do I refer it in my model file?

Thanks,

Sam



Re: how to reference another function inside mode class

2006-02-03 Thread sam

Amit,

My bar() is a pure function defined outside all model classes but that
gave me the error. (If I defined it inside the same class from which it
was called, then it's OK). How do I deal with this?

To import, what package path should I use?

Sam



post_save_redirect in update_object generic view

2006-02-06 Thread sam

In "update_object" generic view, I want to go back to the object_detail
page whose URL is like /app/obj//, after the update operation. How
do I specify post_save_redirect to do that?



integer field's type?

2006-02-09 Thread sam

I observed a weird thing with the integer field defined inside a model
class. Suppose I have

SEX_TYPE_CHOICES = (
(1, 'male),
(2, 'female'),
)

class Person(meta.Model):
sex = meta.Integerfield(choices=SEX_TYPE_CHOICES)
def is_male(self):
if self.sex == 1:
return True
else:
return False

The problem I have is if I try this method is_male() under django
python shell, it works perfectly fine. But it always fails when invoked
from web "views". I have to change self.sex ==1 to self.sex == "1". Did
I miss something completely or is it a bug?



limiting foreign key choices in a selection field

2006-02-28 Thread sam

I have a model such as:

class Part:
maker = ForeignKey(Maker)
..

When I make a form to enter the "part" information, if I user standard
AddManipulator, maker will become a selection list of all possible
makers. What if I only want to show a sub-list of makers that belong to
a specific "category". I suppose I should use custom manipulators, but
don't know exactly how to do. Pls 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: limiting foreign key choices in a selection field

2006-02-28 Thread sam

My problem is the "category" is determined at run-time, not at module
definition time. How to do that? 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: limiting foreign key choices in a selection field

2006-03-01 Thread sam

Nesh:

Your method works. Thanks very much!

Now a tougher situation:

I want to have the same form to enter "part" information, except the
maker field I want to split into two fields: "category" and "maker". I
want to show different selections in the "maker" field based on what
was selected in the category. The objective is to reduce the number of
options user has to deal with when making a selection. How can this be
done? (Do I have to use javascripts?) 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



how to implement admin's filter interface in my own view

2006-03-03 Thread sam

Hi there

I'd like to add the filter function to my own view much in the same way
admin interface does it - i.e. filter based on the values of multiple
model fields. I am puzzled how to define the URL pattern and how the
matched pattern data gets passed to the view. Let's say I have 3
fields, each field is a choice type. How do I define the URL to handle
all kinds of filtering combinations? It doesn't seem very obvious as I
may have 0/1/2/3 fields selected for filtering. If there are ready-made
example/wiki that'll be great!


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



session auto-logout

2006-03-20 Thread sam

A newbie question:

I am using Django admin's authentication to do login/logout for my own
application. I want to automatically log user out if no activity for 5
minutes. I read the session tutorial and played a bit with
SESSION_COOKIE_AGE -- but it doesn't work for me. Any suggestion
appreciated.


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



How to change naming convention when creating models?

2006-03-24 Thread sam

Hi All,

I'd like to change the naming convention when creation Django models.
For instance I don't want to append "_id" to the foreign key field
name. It is apparently possible to change this behavior.

Thanks in advance.
Regards,
Sam


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



Re: How to change naming convention when creating models?

2006-03-24 Thread sam

Adrian,

Thanks for your reply.

Waht about the table names? I'd like to remove the 's' at the end of
each name.

Regards,
Sam


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



Re: How to change naming convention when creating models?

2006-03-24 Thread sam

Thanks for the pointer.

I'm a little tired today. Should have found it myself ...


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



FileField permissions

2006-03-25 Thread sam

I want to use FileField to upload files but I don't want the file URIs
directly visible to the user. Rather, I want to service the access to
the uploaded files via "views", so that I can exercise file access
permission (I implemented access permission myself, without using
django admin's). I think what this boils down to is to map a logical
URL such as myapp/ to a view that checks permission first
then retrieves the file from MEDIA_ROOT/. But how to do
that? Appreciate 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



how to do this kind of JOIN

2006-03-30 Thread sam

I would like to get help on how to use Django DB API to accomplish the
equivalent of the following SQL statement:

select a from X, Y where X.f = Y.id and Y.c=123;

X has field a, f and Y has field id, c.
f is foreign key of Y and Y's primary key is id.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



complex Q bug

2006-03-31 Thread sam

I was trying complex Q and notices if I do:

complex=(Q1 | Q2)

and

complex = (Q1 or Q1)

the results are not the same. I got right result using "or" but not
with "|". Is this a bug or I did something wrong? What is the
difference between these two operators?


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



get_list() with a ManyToMany relationship

2006-04-27 Thread sam

I have the following problem:

Give two models and a M2M relationship:

class Product(meta.Model):
category =meta.IntegerField()
...

class Part(meta.Model):
products = meta.ManyToManyField(Product)
...

I want to find all products that belongs to a certain category (say
"3") and includes a particular part "p"; furthermore I'd like to use
limit&offset in the search parameters. How to do that?


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



Fetching data from related tables

2013-05-09 Thread Sam


I have 3 tables: Continent, Country and Story.

Country has ForeignKey(Continent) and Story has ManyToManyField(Country, 
blank=True) field.

What I need is to get a list of countries which at least have one story 
belonging to it, and I need these countries grouped by continents.

How can I achieve that?


Thanks.

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




Test, RunPython, Datamigrations with Django 1.7.5

2015-03-04 Thread sam
Hello, 

I have an issue trying to run tests.
My application use a migration to have default fixtures (created using 
migrations.RunPython from a migration file). 
The problem is when I launch manage.py test, the fixtures from the 
migration are created on the "production" database and not on the test_* 
database.

Is there a way to solve this issue ? Is this a known issue or nobody has 
this problem ?

Here is the migration

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


def create_bars(apps, schema_editor):
Bar = apps.get_model("foo", "Bar")
db_alias = schema_editor.connection.alias
Bar.objects.using(db_alias).bulk_create([
Bar(label="AAA"),
Bar(label="BBB")
])

class Migration(migrations.Migration):

dependencies = [
('foo', '0001_initial'),
]

operations = [
migrations.RunPython(create_bars),
]


Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/748acda0-18dc-45e8-b79b-923b394d80dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Test, RunPython, Datamigrations with Django 1.7.5

2015-03-04 Thread sam
Well, answer is here: 
https://docs.djangoproject.com/en/1.7/topics/testing/overview/#rollback-emulation
Need to use serialized_rollback = True in TransactionTestCase

Le mercredi 4 mars 2015 18:24:34 UTC+1, sam a écrit :
>
> Hello, 
>
> I have an issue trying to run tests.
> My application use a migration to have default fixtures (created using 
> migrations.RunPython from a migration file). 
> The problem is when I launch manage.py test, the fixtures from the 
> migration are created on the "production" database and not on the test_* 
> database.
>
> Is there a way to solve this issue ? Is this a known issue or nobody has 
> this problem ?
>
> Here is the migration
>
> # -*- coding: utf-8 -*-
> from __future__ import unicode_literals
>
> from django.db import models, migrations
>
>
> def create_bars(apps, schema_editor):
> Bar = apps.get_model("foo", "Bar")
> db_alias = schema_editor.connection.alias
> Bar.objects.using(db_alias).bulk_create([
> Bar(label="AAA"),
> Bar(label="BBB")
> ])
>
> class Migration(migrations.Migration):
>
> dependencies = [
> ('foo', '0001_initial'),
> ]
>
> operations = [
> migrations.RunPython(create_bars),
> ]
>
>
> Thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/71ae45b7-3f74-4e93-ae3c-0935da4c7742%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Creating serializer for foreign key of foreign key

2020-03-07 Thread Sam


I have 3 models. Question, Choice, and ChoiceColor.

class Question(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
question= models.CharField(max_length=200)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice = models.CharField(max_length=120)
vote_count = models.IntegerField(default=0)
class ChoiceColor(models.Model):
choice = models.OneToOneField(Choice, on_delete=models.CASCADE, null=True)
color = models.CharField(max_length=7)

I have a serializer that looks like this:


class CreateQuestionSerializer(serializers.ModelSerializer):
choice_set = ChoiceSerializer(many=True)

class Meta:
model = Question
fields = ('user', 'status', 'choice_set')

def create(self, validated_data):
choices_validated_data = validated_data.pop('choice_set')
question = Question.objects.create(**validated_data)
choices_serializer = self.fields['choice_set']

for choice in choices_validated_data:
choice['question'] = question

choices_serializer.create(choices_validated_data)
return question

And another that looks like this:

class ChoiceColorSerializer(serializers.ModelSerializer):
class Meta:
model = ChoiceColor
fields = ('color',)

class ChoiceSerializer(serializers.ModelSerializer):
color_set = ChoiceColorSerializer(many=False)

class Meta:
model = Choice
fields = ('choice', 'color_set')

For some reason, when I put in the data it does not work. I need to define 
a create method for ChoiceSerializer but i'm unsure how to do that?


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/778d4352-b2c0-4268-811f-24e3f8a5cd54%40googlegroups.com.


Re: One to Many+foreign key Query: best way to build the optimal result

2009-06-25 Thread Sam Walters
Thanks for the help.

I think you are on the right track however i could not get this to work.
Maybe an example query using cursor.execute would help so you can see what i
am trying to do.

def sqlAllEventsMenu():
cursor = connection.cursor()
cursor.execute("""
SELECT events_event.id, events_event.start, events_event.title,
events_location.state_id, events_location.name
FROM events_event LEFT JOIN events_location
ON events_event.id = events_location.id
""")
return convertToDictionary(cursor)


On Fri, Jun 19, 2009 at 4:11 PM, BenW  wrote:

>
> I'm not sure I completely understand the problem, but I'll give it a
> stab:
>
> events = Event.objects.filter(start__gte=datetime.today())
> locations = Location.objects.filter(location__in=events)
>
> results = [
>   {'start': loc.location.start, 'title': loc.location.title, 'id':
> loc.location.id, 'state_id': loc.state.id, 'name': loc.name} \
>   for loc in locations.iterator()
> ]
>
> render_to_response('template.htm', {'results': results})
>
> I run a query similar to this one on a 50,000 record table and it only
> takes ~0.30 seconds, and that includes Json serialization!
>
> On Jun 17, 5:00 pm, Sam Walters  wrote:
> > Here is the essentials from my models.py file:
> >
> 
> > class Event (models.Model):
> > contact = models.CharField(max_length=100)
> > email = models.CharField(max_length=100)
> > url = models.CharField(max_length=100)
> > title = models.CharField(max_length=100)
> > start = models.DateTimeField('date time when')
> > end = models.DateTimeField('date till')
> >
> > class Location (models.Model):
> > name = models.CharField(max_length=50)
> > state = models.ForeignKey(State)
> > location = models.ForeignKey(Event)
> >
> 
> > This is a One-to-Many Relationship where an Event can have one or more
> > Locations.
> >
> > The problem i need to solve is in the 'views.py' I want to be able to
> > query 'Event' such that i retrieve an arbitrary subset of events AND
> > any associated Locations and return only the relevant fields to the
> > template layer.
> >
> > The most standard use for this database will be to get all events from
> > today into the future and their associated locations. On average there
> > would be say 25 event rows returned and perhaps 27 locations as some
> > events have more than one location.
> >
> 
> > e_future = Event.objects.filter(start__gte = datetime.today())
> >
> 
> > having readhttp://docs.djangoproject.com/en/dev/topics/db/queries/
> >
> > i realise i can use a reverse foreign key to access an item in the
> > Location table:
> >
> 
> > for e in e_future:
> > e_location=e.location_set.all()
> >
> 
> > From here it gets messy as i have to deal with the individual event
> > elements 'e' out of a queryset 'e_future' and then reassemble the
> > elements back into a queryset *i dont know how to do this* so my
> > method can return the selected columns:
> >
> 
> > e_future_subset = e_future.values('start', 'title','id',)
> > e_location_subset = e_location.values('state_id', 'name',)
> >
> 
> > Then i have to combine the two objects 'e_future_subset' and
> > 'e_location_subset' (which i believe are dictionaries) and return the
> > result.
> >
> 
> > e_all = e_future_subset + e_location_subset
> > return render_to_response('events.html', { 'e_all': e_all,})
> >
> -

Help using the django queries API to select columns from multiple tables

2009-06-28 Thread Sam Walters
Hi
I am using django 1.0 to redevelop a website.
I have read http://docs.djangoproject.com/en/1.0/topics/db/queries/ and cant
work out how to do my query except using raw sql. It would be great to be
able to use the django query api so i can stack queries more easily.

Just one working example would be enough for me to be able to figure out the
rest of the syntax i need.
In this case the model is using a ForeignKey relationship between two
tables, thus is a one to many relationship.

the model.py code exists here:
http://pastebin.com/m7ddf3bb8

the views.py code exists here:
http://pastebin.com/m78daa247

I would like to be able to replace the customer sql cursor.generate methods.

Any help would be appreciated and allow me to discover a lot more about
django queries.

--~--~-~--~~~---~--~~
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: Help using the django queries API to select columns from multiple tables

2009-06-29 Thread Sam Walters
Hi Daniel
Thank you very much for your help.
The reasons why the foreign key is in the other table is because an event
can have multiple locations, its unusual however the Aviation industry has
an event which will fly from location A to B. Yes it seems counter-intuitive
at first glance.

The other reason is If do move the foreign key to the Events table then i
cant get the admin.py to work. The admin has to  be able to edit all the
fields (in effect see columns from multiple tables using inlines) from the
same page:

in admin.py:

class LocationInline(admin.StackedInline):
model=Location
extra = 0

class EventAdmin(admin.ModelAdmin):
inlines = [PeriodInline, LocationInline, InviteGroupInline,
CategoryInline,]
list_display = ('added','title','email',)
list_per_page = 50
list_filter = ('added','start','end',)
search_fields = ('contact', 'email', 'phoneBH', 'phoneAH', 'phoneFax',
'phoneM', 'url','title','description')

admin.site.register(Event, EventAdmin)

Nevertheless if there is no way to make the foreign key relationship work
with the current schema then I will move it as you have suggested.

Do you know how to build the admin.py to circumvent this issue?


On Mon, Jun 29, 2009 at 6:51 PM, Daniel Roseman wrote:

>
> On Jun 29, 4:57 am, Sam Walters  wrote:
> > Hi
> > I am using django 1.0 to redevelop a website.
> > I have readhttp://docs.djangoproject.com/en/1.0/topics/db/queries/andcant
> > work out how to do my query except using raw sql. It would be great to be
> > able to use the django query api so i can stack queries more easily.
> >
> > Just one working example would be enough for me to be able to figure out
> the
> > rest of the syntax i need.
> > In this case the model is using a ForeignKey relationship between two
> > tables, thus is a one to many relationship.
> >
> > the model.py code exists here:http://pastebin.com/m7ddf3bb8
> >
> > the views.py code exists here:http://pastebin.com/m78daa247
> >
> > I would like to be able to replace the customer sql cursor.generate
> methods.
> >
> > Any help would be appreciated and allow me to discover a lot more about
> > django queries.
>
> You don't need to explicitly join the tables - that's the whole point
> of having a foreignkey field in the model. However, there is one
> problem. It seems like your foreign key is on the wrong model. Surely
> each event has a single location, but a location can have many events?
> In which case, the FK should be from event to location.
>
> class Event (models.Model):
>
>location = models.ForeignKey(Event)
>
> Now, you can get the events like this:
>
> events = Event.objects.filter(start__gte=datetime.datetime.now
> ()).select_related()
>
> and iterate through in your template:
>
> {% for event in events %}
>{{ event.title }} - {{ event.location.name }}
> {% endfor %}
>
> The select_related() on the initial query is optional, but will get
> all the joined location data in one query and so cut down on database
> access.
> --
> 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: Best distro for django

2009-07-03 Thread Sam Walters
It should not matter. Any modern Linux Distro which supports the
dependencies will be no different.

The only conceivable way this question makes sense is if you want to make
install or deployment easy. In which case use something thats based on a
debian, fedora type distro where there is heaps of help/tutorials for things
like installing web server packages. So the issue becomes one of package
manager choice.

Keyboard Issues? Would be easier to solve the keyboard issue without
switching distro, ubuntu community is great for these things.

On Sat, Jul 4, 2009 at 8:31 AM, Dhruv Adhia  wrote:

> I ve been PC user for almost a decade, getting enough frustration , I
> shifted to mac osx and I am happy with it. Much less configuration required.
> I ve just installed Linux Ubuntu yesterday. Lets see how it goes with
> Linux.
>
> Cheers,
>
>
> On Fri, Jul 3, 2009 at 2:41 PM, Evandro Viana  wrote:
>
>> Debian or Slackware
>> more
>>
>> the best for developer is OSX
>>
>>
>>
>> On Fri, Jul 3, 2009 at 6:28 PM, Tim Chase > > wrote:
>>
>>>
>>> > Looking for opinion of the best distro for a developer machine for
>>> > django.
>>> >
>>> > I'm on ubuntu now, its going ok. I'm having keyboard issues, and
>>> > wondering if I should put the time in on fixing it, or just ditch it
>>> > for say, pc-bsd, if thats what the cool django kids are using.
>>>
>>> I've done Django development on multiple OSes and found 3 tiers
>>> of experience:
>>>
>>> Top Tier: any Linux or BSD I've played with (Debian, Ubuntu,
>>> OpenBSD).  I expect other variants will be equally facile (Red
>>> Hat, Suse, Slack, Gentoo, PC BSD, FreeBSD, etc)
>>>
>>> Mid Tier:  Mac OS X -- Doable, but a few more hoops to jump
>>> through.  Easiest since Python2.5's added built-in sqlite3 which
>>> previously you had to build yourself
>>>
>>> Bottom Tier:  Win32.  It's feasible (especially once Python2.5
>>> added sqlite3), but I've found this a notably more painful
>>> experience than on the other two tiers of platforms.
>>>
>>>
>>> I haven't tinkered with Solaris in *years* so I don't know
>>> whether that would be top- or middle-tier.
>>>
>>>
>>> However, once you've got the base configuration done, development
>>> is pretty easy no matter where you do it.
>>>
>>> My $0.02
>>>
>>> -tim
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>
>
> --
> Dhruv Adhia
> http://thirdimension.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
-~--~~~~--~~--~--~---



Re: MEDIA_URL and ADMIN_MEDIA_PREFIX

2009-07-12 Thread Sam Lai

Yes, because unless you copy the admin site's media over to your
MEDIA_URL (or vice-versa), Django won't be able to find the admin
media.

>From http://docs.djangoproject.com/en/dev/ref/settings/

ADMIN_MEDIA_PREFIX

Default: '/media/'

The URL prefix for admin media -- CSS, JavaScript and images used by
the Django administrative interface. Make sure to use a trailing
slash, and to have this be different from the MEDIA_URL setting (since
the same URL cannot be mapped onto two different sets of files).

2009/7/13 sjtirtha :
> Hi,
>
> I found out that MEDIA_URL and ADMIN_MEDIA_PREFIX may not have the same
> value, otherwise images that is located in this MEDIA_URL cannot be
> displayed in browser.
> I did not found about this anywhere in the documentation. Is my assumption
> correct?
>
> Regards,
> Steve
>
> >
>

--~--~-~--~~~---~--~~
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: MEDIA_URL and ADMIN_MEDIA_PREFIX

2009-07-12 Thread Sam Lai

Forgot to add - the usual trick is to symlink the admin media in your
MEDIA_URL; that way you don't have to set up two different aliases in
your web server config.

2009/7/13 Sam Lai :
> Yes, because unless you copy the admin site's media over to your
> MEDIA_URL (or vice-versa), Django won't be able to find the admin
> media.
>
> From http://docs.djangoproject.com/en/dev/ref/settings/
>
> ADMIN_MEDIA_PREFIX
>
> Default: '/media/'
>
> The URL prefix for admin media -- CSS, JavaScript and images used by
> the Django administrative interface. Make sure to use a trailing
> slash, and to have this be different from the MEDIA_URL setting (since
> the same URL cannot be mapped onto two different sets of files).
>
> 2009/7/13 sjtirtha :
>> Hi,
>>
>> I found out that MEDIA_URL and ADMIN_MEDIA_PREFIX may not have the same
>> value, otherwise images that is located in this MEDIA_URL cannot be
>> displayed in browser.
>> I did not found about this anywhere in the documentation. Is my assumption
>> correct?
>>
>> Regards,
>> Steve
>>
>> >>
>>
>

--~--~-~--~~~---~--~~
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: home page caching

2009-07-13 Thread Sam Tregar
On Mon, Jul 13, 2009 at 3:34 PM, Ramdas S  wrote:

> I have a web site where around 15 SQL semi complex queries run on the home
> page. Traffic is increasing and the page loads are getting slower. What is
> the best way to cache just the home page. I have already done standard
> memcached on the server.
>
> Please suggest the best caching options, where we can have page loads (home
> page is about 100 K with the ads). I have fine tuned everything possible
> from client side, like minimifying javascripts/css files and using right
> graphic formats.
>

I'm a beginner with Django, so I'm curious to hear about Django-specific
approaches.  However, a more general approach would be to put your site
behind a caching proxy like Squid (http://www.squid-cache.org/).  Then all
you need to do is configure Squid to cache your home-page output for
whatever period you require.  One way to do that is entirely with Squid, but
another would be to modify your app to output HTTP cache control headers
(Expires, Cache-Control, etc).  I'm not sure how to do that in Django but I
imagine it shouldn't be too hard.

-sam

--~--~-~--~~~---~--~~
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 get this value

2009-07-13 Thread Sam Lai

Try:

getattr(eachalert, criteria1_metric1) or something similar. look up
the getattr python function.

On 7/14/09, David  wrote:
>
> still no lucky...
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/home/dwang/alert/../alert/message/models.py", line 245, in
> check_criteria1
> metric11 = eachalert.get(criteria1_metric1)
> AttributeError: 'Alert' object has no attribute 'get'

>
>
>
>
> On Jul 13, 3:53 pm, Javier Guerra  wrote:
>> On Mon, Jul 13, 2009 at 5:48 PM, David wrote:
>> > TypeError: 'Alert' object is unsubscriptable
>>
>> sorry, i was mixing languages.
>>
>> try "e_metric1 = eachalert.get (criteria1_metric1)"
>>
>> --
>> Javier
> >
>

-- 
Sent from my mobile device

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



AttributeError when trying to save and access models

2009-07-14 Thread Sam Walters
Hi Django world
I keep getting problems accessing and storing data in foreignkey and
one-to-one relationships.
Error is basically of the form:
 "AttributeError
Exception Value: 'DirectoryAdmin' object has no attribute 'abbrev'"

The models.py file is here:
http://pastebin.com/mcc4ee45
The SQL it produces is here:
http://pastebin.com/m5b70bce5

I don't think the problem is in here but you can see what I am trying to
achieve. At the moment i am just trying to save multiple records in 'class
DirectoryType' which relate through a foreignkey to Directory.

MAIN CULPRIT:
Views.py
http://pastebin.com/m10eac87f

I seem to be able to .save() new instances of Directory, DirectoryAdmin,
DirectoryType

However i cant get Directory to associate with multiple instances of
DirectoryType or even DirectoryAdmin.
At a more fundamental level the .add() method says:

'DirectoryType' object has no attribute 'add'

And if i try to see an attribute in another table:

 var = dirdir.admin.abbrev #error: 'DirectoryAdmin' object has no attribute
'name'

However i seem to be able to access the database for id's.
var = dirdir.admin.id #works

Any help would be greatly appreciated as i dont know what is going wrong
beyond this.

--~--~-~--~~~---~--~~
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 implement a custom field (or relation) which supports List of Strings

2009-07-17 Thread Sam Tregar
On Fri, Jul 17, 2009 at 3:23 PM, Dudley Fox  wrote:

>
> Should I have posted this to the developer's list? I ask because I
> have received no responses yet. Not even a "...you shouldn't do that."
> :)


I can help you with that - you shouldn't do that.   Instead you should
create a new model for friends and link users to friends with a one-to-many
relation.  Each friend can have a single character field for their name,
which will give you a list of strings (friends) attached to each user.

Does that make sense?

-sam

--~--~-~--~~~---~--~~
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: Windows development server problem

2009-07-21 Thread Sam Lai

Did you forget any imports?

Maybe your code snippet's identifiers clashed with the default django ones?

Are there any errors in stdout?

2009/7/21 cwurld :
>
> Hi,
>
> I have a snippet of code that runs fine as a standalone program. But
> when I incorporate it into a view and access that view w the
> development server, the snippet no longer works.
>
> What is the difference between the python interpreter and the
> development server?
>
> Thanks,
> Chuck
>
> >
>

--~--~-~--~~~---~--~~
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: IDE for Django and Ext JS

2009-07-28 Thread Sam Lai

There's also the free Komodo Edit (and the more featureful Komodo IDE)
from ActiveState, which supports python and the django template
language among other things, and is cross-platform too.

2009/7/29 Jamie :
>
> On the mac, there's textmate (an editor, not an IDE), which has a
> language plugin architecture, and a couple of django-specific plugins
> that do syntax highlighting, one for django apps, one for django
> templates.
>
> On Jul 28, 2:20 pm, Jonas Obrist  wrote:
>> Maybe a good question would be is there any IDE that supports the django
>> template language? Because I use eclipse (pydev+webtools) but I really
>> dislike it that it complains about my HTML files being invalid because
>> of the django tags. Also a highlighting mode might reduce the amount of
>> errors one (=me) does...
>>
>> Luke Seelenbinder wrote:
>> > -BEGIN PGP SIGNED MESSAGE-
>> > Hash: SHA1
>>
>> > I personally use Eclipse w/ PyDEV and web dev tools. I absolutely love
>> > it. I tried netbeans a while ago, and didn't see an advantage to switch
>> > to it.
>>
>> > That being said, IDEs are really a matter of personal preference, I know
>> > of a lot of people that just use vim. My recommendation is try out the
>> > ones that interest you and have the features you need, give them a week
>> > of development and decide for yourself. That is really the only way to
>> > find "your" IDE. We could start a fight really quickly if "the best IDE"
>> > discussion got started. :)
>>
>> > Luke S.
>>
>> > Amir Habibi wrote:
>>
>> >> Hi All,
>>
>> >> What  development environment do you suggest for Django and Ext JS
>> >> based large projects?
>> >> Is Netbeans the best choice out there?
>>
>> >> Thanks
>> >> Amir
>>
>> > -BEGIN PGP SIGNATURE-
>> > Version: GnuPG v1.4.9 (GNU/Linux)
>>
>> > iEUEARECAAYFAkpvO84ACgkQXQrGVCncjPxT1wCbBHbDNr19IJ/oI4ZR6VnMOZie
>> > jOkAlik7heMvG6xoxqhyq+Cjt0fywe0=
>> > =Tnav
>> > -END PGP SIGNATURE-
>
> >
>

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



Help building a custom RadioSelect widget.

2009-08-03 Thread Sam Walters

Hi fellow Django users.

This is the first time necessity has required me to look at overriding
functionality in the django code.

I need to replace the  and  tags in a choicefield using radio
buttons with  tags as my project has very specific formatting
requirements for this form.

I basically don't know much about overloading in python and of course
this would not help with overloading the
Django RadioSelect class so it will instantiate an overloaded version
of the RadioFieldRenderer class to return different tags.

Here is the code, i dont know if im close or not.
http://pastebin.com/m67363386

Any help completing/explaining this would be greatly appreciated and
open the floodgates towards understanding how to do this for all sorts
of pythonic/django overloading scenarios.

cheers

-Sam

--~--~-~--~~~---~--~~
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: Help building a custom RadioSelect widget.

2009-08-04 Thread Sam Walters

Thanks David

This example is exactly what i was hoping for.
I hope something like this gets put into a tutorial because i guess
many people would need to control exactly what their form looks like.

Cheers

-Sam

On Tue, Aug 4, 2009 at 11:00 PM, David De La Harpe
Golden wrote:
>
> Sam Walters wrote:
>
>> Any help completing/explaining this would be greatly appreciated and
>> open the floodgates towards understanding how to do this for all sorts
>> of pythonic/django overloading scenarios.
>>
>
> I had to do something similar a while back -
> http://python.pastebin.com/f7a905977
>
> Proved unexpectedly involved because also wanted to use it for model
> fields with choices specified - the form field used if you supply
> choices on modelfields is hardcoded in django.  Was going to
> raise a bug about it, but turns out it's bug #9245 ...
>
>
> >
>

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



checking if db schema and model match

2009-08-05 Thread Sam Lai

I hope this hasn't been asked before; had a quick look through the
archives and docs but couldn't find anything.

Is it possible to get django (e.g. via manage.py) to CHECK if the db
schema and model match? I don't want it to change anything, just to
tell me if there is a mismatch, and what that is.

I thought syncdb did this, but it doesn't seem to. I think this would
be quite useful to have, and could pre-empt errors later on when
non-existent fields are used in views etc.

Sam

--~--~-~--~~~---~--~~
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: Multiple data formats for one view

2009-08-05 Thread Sam Lai

I have a piece of middleware which assigns the right MIME type based
on URL extension, then I have templates for XML, JSON and HTML. My
view function simply gets the required context objects, then passes it
to the appropriate template.

This could probably be generified to make it more reusable.

I believe there's an XML and JSON serializer in-built too, so you can
easily write a generic view that simply uses those serializers; saves
you writing the templates for XML/JSON.

I'd be interested to know if there are better ways of doing this.

2009/8/5 krylatij :
>
> Why not?
> You can simply specify mimetype in HttpResponse object
> urls.py
> (r'^articles.xml/$', my_view_function, {'format': 'xml'}),
> (r'^articles.html/$', my_view_function, {'format': 'html'}),
>
> views.py
> def my_view_function(request, format='json'):
>  if format == 'xml':
>      mimetype = '.'
>      data = 
>  elif format == 'html':
>      
> return HttpResponse(content=data, mimetype=mimetype)
> >
>

--~--~-~--~~~---~--~~
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: checking if db schema and model match

2009-08-06 Thread Sam Lai

Thanks for that, I'll take a look at it. I just thought given
manage.py has the ability to inspectdb, it shouldn't be that much of a
stretch to just check if the model and DB schema match.

Cheers

2009/8/6 kmike :
>
> That's a question about database migration. Django doesn't have built-
> in solution for that.
> Try using South (http://bitbucket.org/andrewgodwin/south/overview/),
> it is a very good db migration app. I suggest using development
> version because (based on my experience) it is more robust than last
> official release (0.5).
>
> On 5 авг, 18:28, Sam Lai  wrote:
>> I hope this hasn't been asked before; had a quick look through the
>> archives and docs but couldn't find anything.
>>
>> Is it possible to get django (e.g. via manage.py) to CHECK if the db
>> schema and model match? I don't want it to change anything, just to
>> tell me if there is a mismatch, and what that is.
>>
>> I thought syncdb did this, but it doesn't seem to. I think this would
>> be quite useful to have, and could pre-empt errors later on when
>> non-existent fields are used in views etc.
>>
>> Sam
> >
>

--~--~-~--~~~---~--~~
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 documentation site is SLOW

2009-08-07 Thread Sam Walters

Hi
Its probably not the browser. I am using firefox 3.5 on an eee pc and
the documentation is fine. This is with Javascript disabled using
noscript however i just turned it on again and no noticable difference
in top readings

*You should look at the install addons of firefox, eg: some plugin
which is slowing it.
*save the page and view it offline see if there is still an issue.
*CSS+cheap video card. This is unusual however some sites really run
slow on very old video cards. Try removing the css from a docs
page+save it runoffline.

I just cant see it being firefox unless its not configured properly.
Especially considering eee pc atom cpu is puny compared too even a p4.
:)



On Fri, Aug 7, 2009 at 10:09 PM, Mirat Bayrak wrote:
> without javascript ?
>
>
> >
>

--~--~-~--~~~---~--~~
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: Javascript with built-in templates tags

2009-08-08 Thread Sam Lai

Can you show us the generated template HTML, and if possible, the
expected result?

That way we can work out the issue with your django templates, rather
than trying to guess your code.

2009/8/9 WilsonOfCanada :
>
> I tried that before, but it only seems to work when it is used on
> the .html file.
>
> onchange="changeArea('{{ list_areas.BC|safe|escapejs}}')
>
> I need it to be onchange="changeArea('{{ list_areas|safe|escapejs}}')
> so the function can use list_areas (My javascript and html are on
> separate files).
>
> On .js file,
>
> If I use:
> function changeArea(selectedAreas)
> {
>        alert({{list_areas.BC}});
> }
>
> with or without the |escapejs would cause the entire javascript not to
> work.
>
> If I use:
> function changeArea(selectedAreas)
> {
>        alert(selectedAreas.BC);
> }
>
> or
>
> function changeArea(selectedAreas)
> {
>        alert(selectedAreas["BC"]);
> }
> would be undefined.
>
> However, if it is:
>
> function changeArea(selectedAreas)
> {
>        alert(selectedAreas[0]);
> }
>
> I will get "{"
>
> Thanks again.  (If I missed the answer in the docs, sorry :) )
> >
>

--~--~-~--~~~---~--~~
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 in Vista

2009-08-15 Thread Sam Lai

You need to install python then django first before trying the
tutorial - start here
http://docs.djangoproject.com/en/dev/intro/install/

2009/8/16 Thiago511 :
>
> I went to that link you gave me. I tried it, and I go the same error
> message.
>
> they told me to:
>
> "From the command line, cd into a directory where you’d like to store
> your code, then run the command django-admin.py startproject mysite. "
>
> I  cd into the folder I have set up but when I type: django-admin.py
> startproject mysite
> I get this:
>
> "django-admin.py" not recognized as an internal or external command,
> operable program or batch file.
>
>
> On Aug 15, 8:21 am, Daniel Roseman  wrote:
>> On Aug 15, 4:05 pm, Thiago511  wrote:
>>
>> > Hi guys, I am trying to start a Django project in Vista(I am not even
>> > sure I know how to start one!)
>> > here is what I try to do:
>>
>> > I don't think I even activated Django-admin
>>
>> > How would I go about doing that?
>>
>> > The Django website tells me to add django.contrib.admin to my
>> > INSTALLED_APPS settings
>>
>> > ok. what is django.contrib.admin? where can I get it?
>> > and how to I add it to my INSTALLED_APPS settings?
>>
>> Please read the tutorial, which explains how to start a project, and
>> come back if you have any 
>> issues.http://docs.djangoproject.com/en/dev/intro/tutorial01/
>> --
>> 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: Django in Vista

2009-08-15 Thread Sam Lai

>From the tutorial:

"django-admin.py should be on your system path if you installed Django
via python setup.py."

This might be different for Windows - it might not be on the system path. Try:

python django-admin.py startproject mysite

If that doesn't work, use the full path to your python executable.

To make things easier later, add the directory containing the python
executable to your system path (Control Panel -> System -> Advanced ->
Environment Variables -> PATH).

2009/8/16 Thiago511 :
>
> python and Django are both installed already
>
> On Aug 15, 9:11 am, Sam Lai  wrote:
>> You need to install python then django first before trying the
>> tutorial - start herehttp://docs.djangoproject.com/en/dev/intro/install/
>>
>> 2009/8/16 Thiago511 :
>>
>>
>>
>> > I went to that link you gave me. I tried it, and I go the same error
>> > message.
>>
>> > they told me to:
>>
>> > "From the command line, cd into a directory where you’d like to store
>> > your code, then run the command django-admin.py startproject mysite. "
>>
>> > I  cd into the folder I have set up but when I type: django-admin.py
>> > startproject mysite
>> > I get this:
>>
>> > "django-admin.py" not recognized as an internal or external command,
>> > operable program or batch file.
>>
>> > On Aug 15, 8:21 am, Daniel Roseman  wrote:
>> >> On Aug 15, 4:05 pm, Thiago511  wrote:
>>
>> >> > Hi guys, I am trying to start a Django project in Vista(I am not even
>> >> > sure I know how to start one!)
>> >> > here is what I try to do:
>>
>> >> > I don't think I even activated Django-admin
>>
>> >> > How would I go about doing that?
>>
>> >> > The Django website tells me to add django.contrib.admin to my
>> >> > INSTALLED_APPS settings
>>
>> >> > ok. what is django.contrib.admin? where can I get it?
>> >> > and how to I add it to my INSTALLED_APPS settings?
>>
>> >> Please read the tutorial, which explains how to start a project, and
>> >> come back if you have any 
>> >> issues.http://docs.djangoproject.com/en/dev/intro/tutorial01/
>> >> --
>> >> 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: Django in Vista

2009-08-16 Thread Sam Lai

You added the directory containing django-admin.py to your PATH right,
not the path of django-admin.py itself?

If you want, type 'set path' (without quotes) into your command prompt
and paste the result here and we'll see if you did it right.

2009/8/16 Thiago511 :
>
> UPDATE:
> Well I added django-admin.py to my PATH and I still get an error
> message:
>
> python: cannot open 'django-admin.py' : [Errno 2] No such file to
> directory
>
> On Aug 15, 11:30 am, CLIFFORD ILKAY 
> wrote:
>> On 15/08/09 01:43 PM, Thiago511 wrote:
>>
>> > mark how do I add a file to %PATH% ?
>>
>> This isn't a Django issue so much as a (very basic) system
>> administration issue. I suggest you read about the PATH environment
>> variable and grasp that instead of blindly following someone else's
>> instructions about how to do something as simple as adding something to
>> the PATH. This isn't something that started with Vista. It dates back to
>> the earliest days of DOS so there are plenty of resources on the web
>> explaining this. Better yet, you should strive for understanding of
>> environment variables in general. If you fixate on PATH alone and don't
>> understand what an environment variable is, you'll have difficulties
>> with PYTHONPATH as well.
>>
>> Once you understand these concepts, they're universally-applicable, with
>> minor variations, to DOS/Windows, OS X, Linux, and a host of other
>> operating systems. When you decide to deploy your completed Django
>> project on the server of a hosting provider, in all likelihood, that
>> server won't be running Windows anyway so it helps to develop this
>> understanding.
>>
>> One of our Django hosting clients asked why he was getting import errors
>> for Reportlab on our VPS when he wasn't on his local development
>> environment. He suspected it was because Reportlab wasn't installed. He
>> was right. We replied to him:
>>
>> "We've installed:
>>
>> python-reportlab - ReportLab library to create PDF documents using Python
>>
>> python-reportlab-accel - C coded extension accelerator for the ReportLab
>> Toolkit
>>
>> For future reference, you don't necessarily have to wait for us to
>> install Python libraries into the global Python site-packages. You could
>> install the Python libraries somewhere in your home directory and put
>> that directory in PYTHONPATH, as you did with Django itself."
>>
>> He replied:
>>
>> "Thanks for that. I should have realised I have access to the Python
>> installation."
>>
>> In response, we replied:
>>
>> "You don't have access to the Python installation in /usr/lib/python.
>> You have access to your home directory into which you can put Python
>> libraries and add to PYTHONPATH. There is a big difference. The former
>> is global. The latter can be different even on a per project basis so I
>> hesitate to say it's local. If you build another Django project for
>> another client, nothing stops you from having a different PYTHONPATH for
>> that project. In fact, we do exactly that because we may have different
>> versions of Django, or other Python libraries on which we depend, for
>> each project."
>>
>> If you understood what I wrote above, you may be wondering, "How can you
>> have a different PYTHONPATH for each application?" The excerpt below
>> from the shell script that we use to start|stop|restart the fcgi(*) will
>> illustrate.
>>
>> PROJDIR="/home/someuser/projects/someproject/"
>> PYTHONPATH="/home/someuser/django/:/home/someuser/:/home/someuser/lib/"
>>
>> /usr/bin/python $PROJDIR/manage.py runfcgi umask=000 pidfile=$PIDFILE
>> socket=$SOCKET method=$METHOD --pythonpath=$PYTHONPATH
>>
>> (Watch the line wrapping above. Everything from /usr/bin to PYTHONPATH
>> below it is on one line.)
>>
>> (*) The above is for deployment via fcgi using the nginx web server.
>> --
>> Regards,
>>
>> Clifford Ilkay
>> Dinamis
>> 1419-3266 Yonge St.
>> Toronto, ON
>> Canada  M4N 3P6
>>
>> 
>> +1 416-410-3326
> >
>

--~--~-~--~~~---~--~~
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 do you display custom permissions on admin site?

2009-08-16 Thread sam lee

Hi,

I have the following model;

class MyModel(models.Model):
class Meta:
permissions = (('test_perm', 'a test permission'),)

I run syncdb and runserver

Then I go to /admin/auth/user/1/

But I don't see the myapp | test_perm listed under Permissions field.
Do I need to do some extra step to make my custom permissions
available to admin site?
Or am I completely missing the point of custom permissions?

Thank you.
Sam.

--~--~-~--~~~---~--~~
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 do you display custom permissions on admin site?

2009-08-17 Thread sam lee

Ah thank you!
I was also putting permissions inside BaseModel.Meta.permissions
where BaseModel.Meta.abstract = True.
When I put permissions inside MyModel.Meta.permissions, it showed up
after flushing out and re-syncdb.

I guess I will repeat permissions for each derived model class.

Thank you again.
Sam.


On Mon, Aug 17, 2009 at 3:47 AM, fabrix wrote:
>
> On Aug 16, 2:29 pm, sam lee  wrote:
>> I run syncdb and runserver
> [...]
>> But I don't see the myapp | test_perm listed under Permissions field.
>
> permissions are stored in db, syncdb doesn't alter existing tables, so
> your permission will not  show up in your admin.
>
> As the Fu..Funny Maunal say:
>
> http://docs.djangoproject.com/en/dev/ref/django-admin/#syncdb
>
> "Syncdb will not alter existing tables
>
> syncdb will only create tables for models which have not yet been
> installed. It will never issue ALTER TABLE statements to match changes
> made to a model class after installation. Changes to model classes and
> database schemas often involve some form of ambiguity and, in those
> cases, Django would have to guess at the correct changes to make.
> There is a risk that critical data would be lost in the process.
>
> If you have made changes to a model and wish to alter the database
> tables to match, use the sql command to display the new SQL structure
> and compare that to your existing table schema to work out the
> changes.
> "
>
> or.. you can try discarding the permission table and redo a syncdb,
> but i can't assicure you that preexisting permissions assigned to
> users will be conserved...
>
> >
>

--~--~-~--~~~---~--~~
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 and CouchDB

2009-08-18 Thread Sam Lai

Would be easy enough if you just wanted to use the routing, views and
template parts of Django though.

Sorry, no experience though something that I've been wanting to try
for a while. Unfortunately, the current project doesn't call for that
kind of db.

2009/8/18 Joshua Partogi :
>
>
> On Tue, Aug 18, 2009 at 8:17 PM, sjtirtha  wrote:
>>
>> Hi,
>>
>> i found some Python API to access couchDB.
>> I'm asking here for experience.
>
> Django model is really tight to RDBMS. You are going to have a hard time
> making django model work with non-RDBMS
>
>
>
> --
> http://blog.scrum8.com
> http://twitter.com/scrum8
>
> >
>

--~--~-~--~~~---~--~~
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: Best practice on data security .. on record, table (model) db or url

2009-08-21 Thread Sam Lai

2009/8/21 Gerard :
>
> Hi All,
>
> I'm working on an invoice system, currently deployed the single user version
>  in house. Next one is gonna be a full blown multi user setup. Having
> fairly good knowledge of security, I was wondering what would be best
> practice in Django for data separation. So user A only sees his customer
> data and not the data from user B.
>
> Some side notes:
> - Since there's a good auth system in Django I would like to take full
> advantage of that.
> - User session info will be used so al app users see the same url. Thus not
> http://example.com/userid/customers but http://example.com/customers
> - Fixating security on record level, seems error prone, coding wise
> - Fixating on database seems badly manageble in the long run, since there
> will be a lot of users, but not an incredible amount of data per user.
>

Interesting stuff; I'm interested in knowing what the best practices are too.

One thing I'm considering doing is overriding the default manager in
each model so that the current user is considered when making queries.
This makes it harder for you to accidentally return all user's data in
the view.

Of course, you can still have the default manager in the model; just
name it something else so you have to consciously use it.

--~--~-~--~~~---~--~~
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: dump data using json

2009-08-21 Thread Sam Lai

2009/8/22 ashish tiwari :
> hi Friends
>
> i heared about the json format
> django provided utility of dumpdata, loaddata which dumps and loads data in
> json format.
>
> but i dont know,how to use it..
>
> i want to dumpdata...from my app
>
> name of  iFriends
> name of  People
>
> iFriends>People>models.py
>
> class Person.
>

In your project directory,

python manage.py dumpdata People.Person

http://docs.djangoproject.com/en/dev/ref/django-admin/#dumpdata

--~--~-~--~~~---~--~~
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: print PDF on windows

2009-08-25 Thread Sam Lai

Use python to call a PDF reader via the command line -

http://support.adobe.com/devsup/devsup.nsf/docs/52080.htm

http://foxit.vo.llnwd.net/o28/pub/foxit/manual/enu/FoxitReader30_Manual.pdf
(see the Command Line section)

Depending on the complexity of your PDFs, I'd recommend using Foxit
instead; Adobe Reader on windows isn't the most stable especially when
it comes to open many PDFs - you might have to manually manage
instances to make sure it doesn't eat up all your memory. Foxit Reader
however doesn't render all PDFs perfectly, or at least the same way
that Adobe Reader does. YMMV though.

2009/8/26 mettwoch :
>
> How do the Django people handle printing directly on Windows? I
> remembered about http://timgolden.me.uk/python/win32_how_do_i/print.html,
> but unfortunately his method for PDFs only print on the default
> printer. I need the server to produce the PDF, save it (works already)
> and send it to a specific shared printer on the network. The printer
> should be determined from a table that holds 'host' - 'printer' pairs
> e.g. ('PC01', '\\PC01\PR01'). The host ('PC01') determined from the
> http request allows to choose the right printer ('\\PC01\PR01') from
> that table.
>
> Printing should be executed directly when the user has submitted the
> request. Any solution that pops up the document locally in a PDFReader
> and where the user has to hit the print button is not viable.
>
> Kindly Yours
> Marc
> >
>

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



Executing a queryset with MySQL's SSCursor cursor class

2009-08-26 Thread Sam Tregar
Hello all.  I'm wondering how I can tell Django to use
MySQLdb.cursors.SSCursor instead of the default MySQLdb.cursors.Cursor.  The
critical difference here is that SSCursor uses mysql_use_result and streams
data from the server rather than loading it all into memory at once.
Anybody know if that's possible?  My searches of the docs and code haven't
turned up much yet.

Thanks,
-sam

--~--~-~--~~~---~--~~
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: print PDF on windows

2009-08-26 Thread Sam Lai

2009/8/27 mettwoch :
>
> I'm now using Foxit Reader. Thanks for the tip. The following works
> perfectly in the Django shell and prints the document in
> attachment.file.path to the specified network printer:
>
> p = Popen (['C:\\Program Files\\Foxit Software\\Foxit Reader\\Foxit
> Reader.exe',
>        '/t',
>        attachment.file.path,
>        'SM03\\HPCOMPTOIR0'])
>
> The same code works silently in a Apache / mod_wsgi context but does
> not produce any result on the printer. Do You have any ideas?

Could be a permissions issue - what user is apache running under?

Also, you might want to try enabling the 'allow service to interact
with desktop' option to see if that works. If it does, you might have
to look at another solution or somehow impersonating another user to
do the printing as there are security risks associated with this
option.

>
> Marc
>
> On Aug 26, 1:46 am, Sam Lai  wrote:
>> Use python to call a PDF reader via the command line -
>>
>> http://support.adobe.com/devsup/devsup.nsf/docs/52080.htm
>>
>> http://foxit.vo.llnwd.net/o28/pub/foxit/manual/enu/FoxitReader30_Manu...
>> (see the Command Line section)
>>
>> Depending on the complexity of your PDFs, I'd recommend using Foxit
>> instead; Adobe Reader on windows isn't the most stable especially when
>> it comes to open many PDFs - you might have to manually manage
>> instances to make sure it doesn't eat up all your memory. Foxit Reader
>> however doesn't render all PDFs perfectly, or at least the same way
>> that Adobe Reader does. YMMV though.
>>
>> 2009/8/26 mettwoch :
>>
>>
>>
>> > How do the Django people handle printing directly on Windows? I
>> > remembered abouthttp://timgolden.me.uk/python/win32_how_do_i/print.html,
>> > but unfortunately his method for PDFs only print on the default
>> > printer. I need the server to produce the PDF, save it (works already)
>> > and send it to a specific shared printer on the network. The printer
>> > should be determined from a table that holds 'host' - 'printer' pairs
>> > e.g. ('PC01', '\\PC01\PR01'). The host ('PC01') determined from the
>> > http request allows to choose the right printer ('\\PC01\PR01') from
>> > that table.
>>
>> > Printing should be executed directly when the user has submitted the
>> > request. Any solution that pops up the document locally in a PDFReader
>> > and where the user has to hit the print button is not viable.
>>
>> > Kindly Yours
>> > Marc
> >
>

--~--~-~--~~~---~--~~
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 control which DB connection and cursor a queryset will use

2009-08-27 Thread Sam Tregar
I'm trying to get a queryset to issue its query over a different DB
connection, using a different cursor class.  Does anyone know if that's
possible and if so how it might be done?  In psuedo-code:

  # setup a new db connection:
  db = db_connect(cursorclass=AlternateCursor)

  # setup a generic queryset
  qset = blah.objects.all()

  # tell qset to use the new connection:
  qset.use_db(db)

  # and then apply some filters
  qset = qset.filter(...)

  # and execute the query:
  for object in qset:
     ...

-sam

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



QuerySet without result_cache?

2009-08-27 Thread Sam Tregar
Hey all.  So, I figured out how to run my QuerySet through MySQLdb's
SSCursor!  Woo!

Bad news: it's still using a ton of memory.  As far as I can tell it's being
used by QuerySet's internal _result_cache which is holding all the rows
retrieved by the query.  Is there any way to turn this cache off?  Looking
at the code leads me to think no, but I thought I'd ask.

-sam

--~--~-~--~~~---~--~~
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: QuerySet without result_cache?

2009-08-27 Thread Sam Tregar
On Thu, Aug 27, 2009 at 5:47 PM, Alex Gaynor  wrote:

>
> Instead of iterating over the QuerySet itself, use
> QuerySet.iterator(), this will avoid populating the result cache.
>

Thanks, works great!  This would make a good addition to the manual section
that describes how the QuerySet cache system works.  Maybe I'll see about a
patch.

-sam

--~--~-~--~~~---~--~~
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: print PDF on windows

2009-08-28 Thread Sam Lai

2009/8/27 mettwoch :
>
> Apache is running under a system account. A quick test of running
> Apache under my user account enabled printing indeed. I'll follow your
> suggestion and create a dedicated user with restricted rights to run
> Apache under.

I'd leave Apache running under the system account - that's how it is
by default, and I would think that there are good reasons for it.

Try using python to impersonate another user to launch foxit/adobe
reader in another user account context, or the easier way is to
leverage the 'runas' command to run an app under another user account.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true

> Thanks so much for your help
>
> Marc
>
> On Aug 27, 2:42 am, Sam Lai  wrote:
>> 2009/8/27 mettwoch :
>>
>>
>>
>> > I'm now using Foxit Reader. Thanks for the tip. The following works
>> > perfectly in the Django shell and prints the document in
>> > attachment.file.path to the specified network printer:
>>
>> > p = Popen (['C:\\Program Files\\Foxit Software\\Foxit Reader\\Foxit
>> > Reader.exe',
>> >        '/t',
>> >        attachment.file.path,
>> >        'SM03\\HPCOMPTOIR0'])
>>
>> > The same code works silently in a Apache / mod_wsgi context but does
>> > not produce any result on the printer. Do You have any ideas?
>>
>> Could be a permissions issue - what user is apache running under?
>>
>> Also, you might want to try enabling the 'allow service to interact
>> with desktop' option to see if that works. If it does, you might have
>> to look at another solution or somehow impersonating another user to
>> do the printing as there are security risks associated with this
>> option.
>>
>>
>>
>> > Marc
>>
>> > On Aug 26, 1:46 am, Sam Lai  wrote:
>> >> Use python to call a PDF reader via the command line -
>>
>> >>http://support.adobe.com/devsup/devsup.nsf/docs/52080.htm
>>
>> >>http://foxit.vo.llnwd.net/o28/pub/foxit/manual/enu/FoxitReader30_Manu...
>> >> (see the Command Line section)
>>
>> >> Depending on the complexity of your PDFs, I'd recommend using Foxit
>> >> instead; Adobe Reader on windows isn't the most stable especially when
>> >> it comes to open many PDFs - you might have to manually manage
>> >> instances to make sure it doesn't eat up all your memory. Foxit Reader
>> >> however doesn't render all PDFs perfectly, or at least the same way
>> >> that Adobe Reader does. YMMV though.
>>
>> >> 2009/8/26 mettwoch :
>>
>> >> > How do the Django people handle printing directly on Windows? I
>> >> > remembered abouthttp://timgolden.me.uk/python/win32_how_do_i/print.html,
>> >> > but unfortunately his method for PDFs only print on the default
>> >> > printer. I need the server to produce the PDF, save it (works already)
>> >> > and send it to a specific shared printer on the network. The printer
>> >> > should be determined from a table that holds 'host' - 'printer' pairs
>> >> > e.g. ('PC01', '\\PC01\PR01'). The host ('PC01') determined from the
>> >> > http request allows to choose the right printer ('\\PC01\PR01') from
>> >> > that table.
>>
>> >> > Printing should be executed directly when the user has submitted the
>> >> > request. Any solution that pops up the document locally in a PDFReader
>> >> > and where the user has to hit the print button is not viable.
>>
>> >> > Kindly Yours
>> >> > Marc
> >
>

--~--~-~--~~~---~--~~
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: QuerySet without result_cache?

2009-08-28 Thread Sam Tregar
On Thu, Aug 27, 2009 at 8:18 PM, Alex Gaynor  wrote:

>
> On Thu, Aug 27, 2009 at 5:56 PM, Sam Tregar wrote:
> > On Thu, Aug 27, 2009 at 5:47 PM, Alex Gaynor 
> wrote:
> >>
> >> Instead of iterating over the QuerySet itself, use
> >> QuerySet.iterator(), this will avoid populating the result cache.
> >
> > Thanks, works great!  This would make a good addition to the manual
> section
> > that describes how the QuerySet cache system works.  Maybe I'll see about
> a
> > patch.
> >
> > -sam
> >
> >
> > >
> >
>
> Note that the iterator() method is documented in the QuerySet
> documentation:
> http://docs.djangoproject.com/en/dev/ref/models/querysets/#iterator


Good point.  If the description had used the word "cache" I might have even
found it when I was searching for a workaround.

-sam

--~--~-~--~~~---~--~~
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 getting the company I work for to go with django

2009-09-01 Thread Sam Lai

2009/9/2 Kenneth Gonsalves :
>
> On Tuesday 01 Sep 2009 10:55:18 pm mrsource wrote:
>> - It has many tools for safety, with a normal opensource CMS you have
>> many more issues with security holes because all the code is public.
>
> this is sheer FUD to say that 'many more issues with security holes because
> all the code is public.' Openssl code is public, linux code is public, apache
> code is public ... does one have many more issues with security holes???

That was my first thought, but I think he means that unlike standard
PHP, you don't have to place your django files in /var/www, where bad
configuration might expose your code. But still, bad argument.

--~--~-~--~~~---~--~~
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: Editors of choice

2009-09-10 Thread Sam Walters

Vim in conjunction with Git - most powerful + extensible editor out
there in my humble opinion.

On Thu, Sep 10, 2009 at 7:46 PM, boyombo  wrote:
>
> Vim + pydiction + django.vim
>
> On Sep 10, 1:31 pm, eka  wrote:
>> Vim + RopeVim + Omincompletion + taglist + tasklist + python_fn
>>
>> On Sep 10, 8:30 am, slafs  wrote:
>>
>> > Vim
>> > with omnicompletion (CTRL+X, CTRL+O), filetype=htmldjango, TList and
>> > NERDTree
>>
>> > Regards
>>
>> > On Sep 9, 9:31 am, Benjamin Buch  wrote:
>>
>> > > I second that.
>>
>> > > > Vim
> >
>

--~--~-~--~~~---~--~~
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: removing fields in modelformset

2009-05-11 Thread Sam Chuparkoff

On Mon, 2009-05-11 at 07:55 -0700, eric.frederich wrote:
> Hello,
> 
> I need to set up a view for administrators of an application that I am
> writing where they can edit a subset of fields on a particular model.
> It was pretty simple...
> 
> EnrollmentFormSet = modelformset_factory(Enrollment, extra=2)
> 
> def offering_admin(request, offering_id):
> offering = get_object_or_404(Offering, id=offering_id)
> formset = EnrollmentFormSet(queryset=offering.enrollment_set.all
> ())
> return render_to_response('train/offering_admin_form.html', {
> 'formset': formset,
> })
> 
> The problem now is that there is too many fields being exposed.  I
> want to pick and choose what fields are there.  Is there a way for me
> to do this without going completely custom?

Yes, modelformset_factory takes arguments 'fields' and 'exclude'. See:

http://docs.djangoproject.com/en/1.0/topics/forms/modelforms/#controlling-which-fields-are-used-with-fields-and-exclude

sdc

> Thanks,
> ~Eric



--~--~-~--~~~---~--~~
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: removing fields in modelformset

2009-05-11 Thread Sam Chuparkoff

On Mon, 2009-05-11 at 10:59 -0700, eric.frederich wrote:
> Hmm, thats almost what I need.  I guess I didn't fully explain what I
> need.
> I do need to limit the number of fields that are shown, but I also
> need to make some of them view only.

I don't think this "view only" feature exists. Google 'django read
only'. Note that if you're going to allow creating new Enrollment s on
this page the extra forms will have to allow User selection.

> For example, this is on a relation table between an Offering object
> and a User object called Enrollment.
> I don't want them to be able to edit the Offering or the User (which
> appear as combo boxes), only some of the other fields on the
> Enrollment object like a status field and some boolean fields.
> While editing the each Enrollment object they will need to be able to
> see who the user is but they don't need to see the Offering (since
> this view is all enrollments for a particular offering).

The rest of this sounds like the functionality present in admin:

http://docs.djangoproject.com/en/1.0/ref/contrib/admin/#working-with-many-to-many-intermediary-models

Also check out inline formsets:

http://docs.djangoproject.com/en/1.0/topics/forms/modelforms/#inline-formsets

> Is this too specialized, will I need to re-invent the wheel here?

Maybe customize the wheel a bit. Good luck.

sdc



--~--~-~--~~~---~--~~
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: Design Question

2009-05-11 Thread Sam Chuparkoff

On Mon, 2009-05-11 at 17:31 -0700, Glen Jarvis wrote:
> Both forms have a 'name' attribute. And, both forms are in a template
> together. (I mean that both form instances are created for the
> specific instance of the model in question, and are displayed together
> (very interleaved) in a template). The response that I get back, via
> request.POST instantiates both forms: 
> 
> form1 = Form1(request.POST, instance=blah1) form2 =
> Form2(request.POST, instance=blah2) 
> 
> [Note I'm translating this from a domain specific problem to generic
> (form1, form2, etc.) on the fly. There's room for error] 
> 
> Now, if request.POST has only one 'name' then form1 and form2 are
> getting the same name, obviously causing a problem.

You're looking for form prefix:

http://docs.djangoproject.com/en/1.0/ref/forms/api/#django.forms.Form.prefix

sdc



--~--~-~--~~~---~--~~
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: temporarily log in as another user

2009-05-14 Thread Sam Chuparkoff

On Wed, 2009-05-13 at 05:21 -0700, Dave Brueck wrote:
> Has anyone in this group implemented any sort of login-as-another-user
> functionality with Django?

I implemented "sticky superuser logins" about a year ago (the last
time I worked with django until now), so I can attest it is a neat
trick, at least for demos. But I probably don't undertand it
anymore. And unfortunately, a brief look at the code shows some
changes since django-gis r7229, which I was using then.

I was working under the premise that the only special priviledge the
superuser retains after changing effective id to another user is the
ability to login as another user without a password. But nothing
prevents granting other special powers. Anyhow I too suspect someone
else has thought about this, no?

My approach was to hack a new SUPERUSER_SESSION_KEY and
SUPERUSER_BACKEND_SESSION_KEY into contrib/auth/__init__.py , and add
a new 'superuser' attribute in AuthenticationMiddleware. I guessed
this wasn't the most clever way but didn't want to confuse myself too
much, because I still had a logical consequences to deal with. If
you're interested in seeing some of this code, reply directly.

sdc



--~--~-~--~~~---~--~~
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: Problem debugging with pdb

2009-05-15 Thread Sam Chuparkoff

On Fri, 2009-05-15 at 14:00 -0700, Joshua Russo wrote:
> I can't seem to get pdb to stop at my break points for a page request.
> I start it like so:
> 
> (from the directory containing manage.py) python -m pdb manage.py
> runserver

Have you tried this?

python -m pdb manage.py runserver --noreload

If that's not the problem I don't have a clue.

sdc



--~--~-~--~~~---~--~~
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: User profile get_profile() error

2009-05-15 Thread Sam Chuparkoff

On Fri, 2009-05-15 at 19:53 -0400, Joshua Williams wrote:
> When trying to access a user defined profile, using get_profile, I
> am  
> getting an error when accessing the profile for a user.  Just so I  
> have my bases covered, here is my model class:
> 
> class UserDetail(models.Model):
>  Position =  models.ManyToManyField(Position, blank=True)
>  pkUser = models.ForeignKey(User, unique=True)

You must name your ForeignKey field 'user' instead of 'pkUser'. I don't
see that in the doc, but it is clear in get_profile().

sdc



--~--~-~--~~~---~--~~
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: Integer Max/Min Values

2009-05-16 Thread Sam Kuper
2009/5/17 sampablokuper 

> I've been encountering the same problem. It's especially frustrating
> because it seems model validation used to be much easier in Django
> (see
> http://www.cotellese.net/2007/12/11/adding-model-field-validation-to-the-django-admin-page/
> ).
> [...]
>
> Are the Django devs working to re-create model validation in a way
> that would bring this missing functionality back to Django, or do they
> think that people really ought to be breaking DRY by having to put
> this stuff in every form that references a model for which you have
> custom (though not uncommon) validation requirements? Or is there some
> other way to do this that is better than both the aforementioned
> options?


I've just found some discussion of the issue over here:
http://groups.google.com/group/django-users/browse_thread/thread/6b2c1df18b73bf55/3ef0cdc1d3039fbc?lnk=raot

I'm pretty astonished that this feature has been pushed back to v1.1 - to my
mind, model validation is an absolutely core ability for a web framework to
possess. My faith in Django has just been shaken, *hard*.

:(

--~--~-~--~~~---~--~~
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: Formatting a Foreign key combo box in admin change form

2009-05-16 Thread Sam Chuparkoff

On Fri, 2009-05-15 at 15:12 -0700, nih wrote:
> in the admin change form the select box only shows name.username (eg
> nih)
> is it possible to show the full name in the select box

You are looking to override label_from_instance(). See here

http://docs.djangoproject.com/en/1.0/ref/forms/fields/#modelchoicefield

sdc



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



  1   2   3   4   5   6   >