Re: can Django's views call on several programs to run at the same time?

2009-01-13 Thread Jeff Anderson
Victor wrote:
> Hi,
>
> I was planning to use Django to create a webapp that runs several
> Python applications in parallel with user input data. The applications
> take a while to run (>2 minutes) when they work in parallel, so I want
> to make a page that says "Processing..." and show the output of each
> of the applications as they finish. Is there a way to do this without
> using threading? Does Django even support this functionality?
>   
There are a few ways to implement this. After working in an environment
with similar requirements and restrictions, this is how I would do it:

Your site will accept jobs via the web interface. It only stores the
*request* for whatever is needed in a database. It won't try to execute
the request on its own, or in a thread.

An external script periodically checks the database for jobs. If it sees
a new job, it sets the status, and begins processing. If your worker
script is smart enough, it could even update the percentage complete, or
store what is being done specifically in the database. I've always
thought that threading could be a viable way to do this type of task,
but the more I've read about it, and the more I've seen its pitfalls
I've decided that it's evil. If the webserver crashes, it's more
difficult to resume the task. The external script doesn't care if the
webserver is even running, and having the jobs in a database is a
built-in error recovery mechanism. I've even added jobs to the queue
manually at times.

The user's "processing" page should likely be ajax-driven. It'd poll the
site for the status every few seconds until the job is done, or there is
an error.

The external script will either need to be a daemon or a cronjob that is
periodically run. I prefer making the external script its own daemon. We
have a system that usually only gets one job every few minutes, and the
job won't take more than a minute to complete. Most jobs will take less
than a second to complete. Occasionally, we need to run hundreds of jobs
all at once. Since it uses a "polling" model, a delay between checking
the database is usually a good idea, but even a two second delay between
each job of 500 will put a huge performance hit for when we need the
large jobs. The solution is to check the database for new jobs, and then
run *all* new jobs that are currently in the database. After processing
all jobs, it waits two seconds and polls again. The 500 jobs (most of
which take a fraction of a second) get done very quickly, and the
database won't get over-hammered by our polling.

If daemonizing your own script isn't an option, a similar objective can
be achieved with a cron job. I'd suggest using a lock file to prevent
the system(s) from being bogged down with too many requests.

The external script can still use your models and the Django ORM, even
though it isn't a web application.

I'm working on a set of examples of things I've implemented using
Django, but I haven't gotten my example for this one running quite yet.
Hopefully this is enough to give you an idea as to how to design things.
I don't really have any code that is sharable, but the concept is fairly
straightforward (I hope.) I'm happy to clarify anything if needed.

Happy Coding!


Jeff Anderson



signature.asc
Description: OpenPGP digital signature


Re: How to add tinyMCE to django 1.0.2 admin

2009-01-13 Thread Oleg Oltar
Ok, I read the doc...But not sure if I done everything correctly, as the
tinyMCE is still not in my admin

So what I've done:

beryl:TECHNOBUD oleg$ cp
/Users/oleg/src/django1.0/django/contrib/admin/templates/admin/change_form.html
./TEMPLATES/admin/

Then I edited copied file and added:



tinyMCE.init({
mode: "textareas",
theme:"simple"
});


after the line:



(I read this solution in practical-django-projects book)



That's all what I've done so far. But the editor still didn't appear

Thanks,
Oleg
On Wed, Jan 14, 2009 at 12:18 AM, Brian Neal  wrote:

>
> On Jan 13, 3:43 pm, "Oleg Oltar"  wrote:
> > Hi!
> >
> > I want to add tinyMCE to my project's admin site.
>
> You didn't list any admin.py code. Check out the docs on the admin
> interface:
>
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#module-django.contrib.admin
>
> After you read through that, pay attention to the ModelAdmin media
> definitions:
>
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-media-definitions
>
> It is there you specify the tinymce javascript files. When the admin
> displays the form for your models it will generate the appropriate
> script tags to the javascript files.
>
> Good luck!
> BN
> >
>

--~--~-~--~~~---~--~~
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: dynamic / updating foreign key choices

2009-01-13 Thread raj

One possible way seems to override the render_change_form in
AdminClass as pointed in this post:
http://groups.google.com/group/django-users/browse_thread/thread/94bdf5d7eeefc99b/9cbdb25672387c33?lnk=gst=select+foreign+key+list#9cbdb25672387c33

On Jan 12, 8:34 pm, GuyBowden  wrote:
> Hi,
>
> I am writing a resource booking system in django using the admin
> functionality.
>
> I have a "Booking" model, a "ResourceType" model, and a "Resource"
> model.
>
> The booking model has date from and to fields,  aforeignkeyfield toselectthe 
> ResourceType, and a ManyToManyField to link to the Resource
> model.
>
> I would like the user to be able to enter the dates to and from, andselectthe 
> resource type. Then from these choices this would only show
> those resources available that belong to the specific resource type.
>
> I have defined an "is_available" method on the Resource, and am able
> to pass to and from dates and return True/False if they are available.
>
> My problem is updating the form with this limited set of Resources to
> choose from.
>
> I am happy to press "Save and continue editing" in order to process
> the dates (no need for ajax)
>
> My question is how to get the dates and resource type in to my form
> Model and then into the admin
>
> Any pointers as to how to do this?
>
> My attempt below - fails :(
>
> class BookingAdminForm(forms.ModelForm):
>
>         def __init__(self, *args, **kwargs):
>                 super(BookingAdminForm, self).__init__(*args, **kwargs)
>
>                 if self.is_valid():
>                         resourcesChoices = 
> self.getAvailableResources(self.cleaned_data
> ['booked_from'], self.cleaned_data['booked_until'])
>                         self.fields['resources'] = forms.MultipleChoiceField
> (choices=resourcesChoices)
>                 else:
>                         pass
>                         #del self.fields['resources']
>
>         def getAvailableResources(self, booked_from, booked_until):
>                 allResources = Resource.objects.all()
>                 choices = ((0,'none',),)
>                 for resource in allResources:
>                         if resource.is_available(booked_from, booked_until):
>                                 choices += ((resource.id, resource.name,),)
>                 return choices
>
>         class Meta:
>                 model = Booking
>
> class BookingAdmin(admin.ModelAdmin):
>         list_display = ('customer',
> 'resource_type','number_of_resources','booked_from','booked_until',)
>         list_filter = ('resource_type', 'created_on',)
>         date_hierarchy = 'booked_from'
>         search_fields = ['group_leader']
>         filter_horizontal = ('resources',)
>         form = BookingAdminForm
>
>         inlines = [NoteInline]
>         save_on_top = True
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Potential django configuration issues

2009-01-13 Thread Robocop

I'm importing old projects into a new django install (same version, no
problems there), and it's seems to be boiling down to a mysql (running
with the same version of mysql) issue.  When i try to visit the main
page of a specific project i get an error like:

OperationalError at /
(1017, "Can't find file: './skysale/customers_customer.frm' (errno:
13)")

Which is telling me django can't access the database associated with
this project, now when i run mysqlshow i see all the databases i'd
expect.  My questions is: are there any additional permissions/
configuration steps with my mysql server that i need to run to allow
it to communicate with django?  Sorry if this seems a dumb question,
but i have very little experience with mysql, and am in the process of
learning now.  Thanks for any suggestions!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



can Django's views call on several programs to run at the same time?

2009-01-13 Thread Victor

Hi,

I was planning to use Django to create a webapp that runs several
Python applications in parallel with user input data. The applications
take a while to run (>2 minutes) when they work in parallel, so I want
to make a page that says "Processing..." and show the output of each
of the applications as they finish. Is there a way to do this without
using threading? Does Django even support this functionality?

Thanks!
-Victor

--~--~-~--~~~---~--~~
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: 'No such file or directory' error, but not in shell or development server?

2009-01-13 Thread OwenK

The paths weren't absolute AND the permissions were wrong. Both good
lessons. Thanks!

On Jan 13, 10:58 pm, Malcolm Tredinnick 
wrote:
> On Tue, 2009-01-13 at 19:51 -0800, OwenK wrote:
> > I've made a dictionary site that relies on a text file to look up
> > entries. The function that calls it works fine in the shell or in the
> > development server, but when I try to use it with mod_python/apache it
> > gives me an IOError errno 2, No such file or directory. Why the
> > difference? Is there a better/nicer way to call the file then with the
> > file() function?
>
> I'll make a guess that either you're using a relative path to the file
> or directory, which happens to work by accident (based on your starting
> location) when using the dev server.
>
> Another possibility is that the web server doesn't have permission to
> read the file, although I would guess that that returns a different
> error message (permission denied or something like that).
>
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django-OAuth Issue

2009-01-13 Thread Chris

Well I plugged in my variables into the example client and it still
seems to break on the same segment:
token = client.fetch_request_token(oauth_request)

I am using code from this repository to handle the server sided
portion:
http://code.larlet.fr/django-oauth/
Perhaps there is an issue with this library.  I will look into this.

example documentation:
http://code.larlet.fr/doc/django-oauth-provider.html
This example seems to do things slightly different.



Chris



On Jan 13, 7:29 pm, Malcolm Tredinnick 
wrote:
> On Tue, 2009-01-13 at 18:54 -0800, Chris wrote:
> > Hello,
>
> > I have been using django-oauth and am getting the below error using
> > this codehttp://dpaste.com/108808/
>
> > I get this when running the dpaste code in the python shell.
> > Traceback (most recent call last):
> >   File "", line 1, in 
> >   File "", line 7, in get_unauthorised_request_token
> >   File "/usr/lib/python2.5/site-packages/oauth.py", line 70, in
> > from_string
> >     key = params['oauth_token'][0]
> > KeyError: 'oauth_token'
>
> > so when I make a request to /oauth/request_token/, it initializes the
> > oauth classes and methods using:
> > oauth_server, oauth_request = initialize_server_request(request)
>
> > next, this call which seems to be where it breaks:
> > token = oauth_server.fetch_request_token(oauth_request)
>
> > so the oauth_request does not have the oauth_token key (as the error
> > describes) which after traversing through the oauth library and the
> > django-oauth app I do not see where an oauth_token is being generated
> > and added to the oauth_request.
>
> It looks like the server you're talking to might not be returning the
> right data. The data you're getting back from the fetch_response() call
> should contain information that can be passed to from_string(). Your
> fetch_response() isn't too different from the sample client
> implementation at [1], so you might want to check out the minor
> difference there, to verify you've omitted it intentionally. Then check
> out whatever is printed in fetch_response() to see why it isn't what
> you're expecting (you're printing that information out already).
>
> [1]http://oauth.googlecode.com/svn/code/python/oauth/example/client.py
>
> If I understand the code correctly, the key that from_string() is
> looking for is the token and secret that the oauth server returns to you
> (the client) that is your (temporary) authorisation to access some data
> on the server. So it's server-side generated.
>
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Media Temple GridService

2009-01-13 Thread Seattle Daniel

Is anyone hosting a Django site on MediaTemple's GridService without
using the Django container? If so, e-mail me off list.

Daniel Lathrop
--~--~-~--~~~---~--~~
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: 'No such file or directory' error, but not in shell or development server?

2009-01-13 Thread Malcolm Tredinnick

On Tue, 2009-01-13 at 19:51 -0800, OwenK wrote:
> I've made a dictionary site that relies on a text file to look up
> entries. The function that calls it works fine in the shell or in the
> development server, but when I try to use it with mod_python/apache it
> gives me an IOError errno 2, No such file or directory. Why the
> difference? Is there a better/nicer way to call the file then with the
> file() function?

I'll make a guess that either you're using a relative path to the file
or directory, which happens to work by accident (based on your starting
location) when using the dev server.

Another possibility is that the web server doesn't have permission to
read the file, although I would guess that that returns a different
error message (permission denied or something like that).

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



'No such file or directory' error, but not in shell or development server?

2009-01-13 Thread OwenK

I've made a dictionary site that relies on a text file to look up
entries. The function that calls it works fine in the shell or in the
development server, but when I try to use it with mod_python/apache it
gives me an IOError errno 2, No such file or directory. Why the
difference? Is there a better/nicer way to call the file then with the
file() function?
--~--~-~--~~~---~--~~
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-OAuth Issue

2009-01-13 Thread Malcolm Tredinnick

On Tue, 2009-01-13 at 18:54 -0800, Chris wrote:
> Hello,
> 
> I have been using django-oauth and am getting the below error using
> this code http://dpaste.com/108808/
> 
> I get this when running the dpaste code in the python shell.
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 7, in get_unauthorised_request_token
>   File "/usr/lib/python2.5/site-packages/oauth.py", line 70, in
> from_string
> key = params['oauth_token'][0]
> KeyError: 'oauth_token'
> 
> so when I make a request to /oauth/request_token/, it initializes the
> oauth classes and methods using:
> oauth_server, oauth_request = initialize_server_request(request)
> 
> next, this call which seems to be where it breaks:
> token = oauth_server.fetch_request_token(oauth_request)
> 
> so the oauth_request does not have the oauth_token key (as the error
> describes) which after traversing through the oauth library and the
> django-oauth app I do not see where an oauth_token is being generated
> and added to the oauth_request.

It looks like the server you're talking to might not be returning the
right data. The data you're getting back from the fetch_response() call
should contain information that can be passed to from_string(). Your
fetch_response() isn't too different from the sample client
implementation at [1], so you might want to check out the minor
difference there, to verify you've omitted it intentionally. Then check
out whatever is printed in fetch_response() to see why it isn't what
you're expecting (you're printing that information out already).

[1] http://oauth.googlecode.com/svn/code/python/oauth/example/client.py

If I understand the code correctly, the key that from_string() is
looking for is the token and secret that the oauth server returns to you
(the client) that is your (temporary) authorisation to access some data
on the server. So it's server-side generated.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Any reason to not extend User model using model inheritance (vs UserProfile approach)?

2009-01-13 Thread Karen Tracey
On Tue, Jan 13, 2009 at 9:14 PM, ldm999  wrote:

>
> I need some extra fields on User and my first assumption was I could
> subclass user (yes, I am a newbie). Then I read the docs and they talk
> about using UserProfile. This article (http://scottbarnham.com/blog/
> 2008/08/21/extending-the-django-user-model-with-inheritance/
> #comment-621)
> seems to say that following some recent improvements in
> inheritance support, inheritance is now the better way to go. It
> certainly sounds attractive to me. Eg I only need one form to edit
> profiles instead of two.
>
> My immediate requirements are:
>
> 1) Extend the User model and provide custom forms to add/edit my
> custom users
> 2) Use groups to create user groups
>
> So, here's my question: What are the specific reasons, if any, why I
> should NOT use model inheritance to extend my User model?
>

Malcolm's recent reply on a different thread seems relevant to what you are
asking:

http://groups.google.com/group/django-users/msg/baa3afd55b14ad68

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-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 find out more info about "Error: No module named ..."

2009-01-13 Thread Karen Tracey
On Tue, Jan 13, 2009 at 1:21 PM, jhill10110  wrote:

>
> I am getting a module load error but I can't tell what is causing it.
>
> Running `./django-admin.py validate --verbosity 2` returns "Error: No
> module named config".
>
> I have no idea what is trying to load this module and can't find any
> reference to it after doing several greps. How can I find out more
> information on what is actually looking for this config module?


Try

python -v  django-admin.py validate

and you should be able to see (once you sift through all the output) what's
trying to pull in this nonexistant config.

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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django-OAuth Issue

2009-01-13 Thread Chris

Hello,

I have been using django-oauth and am getting the below error using
this code http://dpaste.com/108808/

I get this when running the dpaste code in the python shell.
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 7, in get_unauthorised_request_token
  File "/usr/lib/python2.5/site-packages/oauth.py", line 70, in
from_string
key = params['oauth_token'][0]
KeyError: 'oauth_token'

so when I make a request to /oauth/request_token/, it initializes the
oauth classes and methods using:
oauth_server, oauth_request = initialize_server_request(request)

next, this call which seems to be where it breaks:
token = oauth_server.fetch_request_token(oauth_request)

so the oauth_request does not have the oauth_token key (as the error
describes) which after traversing through the oauth library and the
django-oauth app I do not see where an oauth_token is being generated
and added to the oauth_request.

Is there something obvious that I am doing wrong? Am I supposed to
generate this key somewhere, assuming that django-OAuth takes care of
this. Thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Forcing content_types.json to be loaded before any other fixtures

2009-01-13 Thread Russell Keith-Magee

On Wed, Jan 14, 2009 at 9:34 AM, Giovannetti, Mark
 wrote:
>
> Is there a way to force a fixture to be loaded first
> when running manage.py test?
>
> I'd like to load a content_types.json fixture immediately
> before any other fixtures are loaded.
>
> This might fix some of the vexing problems with using
> content_types and tests.

As far as I can make out, this would fix exactly none of the content
type problems. The problem with content types is that content types
are dynamically generated, and as a result they are not produced with
predictable or consistent key values. As long as you serialize all
your content types in your fixture, and you haven't added any new
content types since producing the fixture, you shouldn't have any
problems deserializing data.

> Anyone know if this is possible?

No, it isn't possible, and it doesn't really make much sense, either.
Fixtures are all loaded in a single database transaction, so the order
in which fixtures are loaded doesn't matter.

The only exception to this is if you're using InnoDB tables under
MySQL, in which case the problem is MySQL's implementation of
transactions (specifically, InnoDB doesn't allow deferring of
referential integrity checks to the end of the transaction boundary as
it should).

Of course, it's entirely possible you've found an new class of problem
that I wasn't previously aware of, in which case I'd be interested to
hear exactly what you've done and how fixture order fixes the problem.

Yours,
Russ Magee %-)

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



Re: ValidationError in a ModelForm with a DateTimeField in the Model

2009-01-13 Thread Cortland Klein

Got it.

Should be models.DateTimeField(blank=True, null=True, default=None)

I shouldn't use default = "" on a DateTimeField.

On Jan 12, 9:29 pm, "Cortland Klein"  wrote:
> Update: It looks like it's a DateTimeField (lastsenttotranslation) that's
> not included in the form, hence the form is_valid() but the actual save()
> fails. But I'm still confused why...
>
> In models.py, its defined as:
>
> > lastsenttotranslation = models.DateTimeField(_("Last sent to Translation"),
> > blank=True, default="")
>
> Do I need to set this to null=True instead?

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



Any reason to not extend User model using model inheritance (vs UserProfile approach)?

2009-01-13 Thread ldm999

I need some extra fields on User and my first assumption was I could
subclass user (yes, I am a newbie). Then I read the docs and they talk
about using UserProfile. This article (http://scottbarnham.com/blog/
2008/08/21/extending-the-django-user-model-with-inheritance/
#comment-621) seems to say that following some recent improvements in
inheritance support, inheritance is now the better way to go. It
certainly sounds attractive to me. Eg I only need one form to edit
profiles instead of two.

My immediate requirements are:

1) Extend the User model and provide custom forms to add/edit my
custom users
2) Use groups to create user groups

So, here's my question: What are the specific reasons, if any, why I
should NOT use model inheritance to extend my User model?

Thanks.

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



Re: Django Continuous Integration

2009-01-13 Thread felix
On Tue, Jan 13, 2009 at 7:45 PM, mguthrie  wrote:

>
> Revision Control: How do you layout your development repository?  I'm
> using Subversion for my setup but would be interested in hearing what
> else others are using (Mercurial, Bazaar, Git, etc)



I have django and third party apps checked out via svn into my development
folder.
so I can update those when I want to.

then I git that whole stack

I push that to a (bare) git repos on one of my servers
(bare means that it isn't a working copy, its just the files, like an svn
server)

and use fab / fabric to do the deployment.

that means on my local machine:

fab pushpull

does a git push (from local checked in changes up to the repository)
does a git pull (from the respository on the remote server into my actual
deployment folder incidentally on the same server)
and then restarts apache


does the deployment.
fab is in alpha and is changing, but I like its direct simplicity.


later I will probably do different branches on the git stack that include /
exclude different sites / apps

so that whatever I'm deploying is just the code that that site (or cluster
of sites) needs

I'm still not completely at peace with this solution but it has worked quite
well so far.

-fx





>
>
> Packaging:  Django has an aversion to using setuptools and opts to
> stick with the basics in distutils.  What are you using for packaging
> your application?  What's the best way to deploy a Django project that
> would make it easy on the end user to install and configure?  I don't
> really care about providing individual apps.  I wish to deploy my
> application in it's entirety.  It would be nice if this could be
> worked into the development process.  Pylons and Turbogears seem to
> have a nice process setup using Paste and virtualenv that works well
> for the development and testing process.  Do Django users have
> something similar?
>
> Buildbot:  Do you use Buildbot or something similar for your Django
> development?  How does that work for you?  What other options are
> there that would work well?
>
> Versioning: How do you mark versions of your Django project?  Meaning,
> how can you create your Django app so it has a version that you can
> track within the application itself as well as for setting up
> upgrades, etc?  I can create something in __init__.py in the root of
> my project but how does that work with the SCM?  Since trunk is always
> in development it would make sense to have something in there.  Do you
> keep it is a tag or branch?  I'm new to this so hopefully I'm making
> sense.
>
> Migrations: What do you use to track database migrations?  I know of
> django-evolution, South and a few others but I really have no idea how
> these function and which is the most mature.  What do you have
> experience with?
>
> That's probably plenty for this post.  Sorry it's so long but this is
> difficult stuff and it's spread out across the internet.  Not to
> mention that it's not specific to Django development.
>
> I've recently worked with a Java developer and got a chance to see his
> development process and was really impressed.  Java seems to have more
> tools available that tie in nicely with each other for continuous
> integration.  He was using Trac, Buildbot, Unit testing (JUnit) and
> had scripts to deploy to a new server immediately.  It was pretty
> impressive and I would like to know if anyone has something similar
> setup for their Django projects.
>
> Thanks in advance for any input.
> >
>

--~--~-~--~~~---~--~~
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: Decoupling between projects and app in 4-part tutorial.

2009-01-13 Thread felix
this was for me also a slight trick to learn.  I got more from blog posts
than the docs
(and I love the django docs)

the trick is that your PYTHONPATH (and don't forget the python path of your
deployment server)
should point to the dir above your project dir and the dir above your apps
dir.


I have
echo $PYTHONPATH
/Users/crucial/Sites/gitpo.git/djapps:/Users/crucial/Sites/gitpo.git/pluggables

djapps
   app1
   app2
pluggables
   thirdpartyapp1
   thirdpartyapp2

site1
   manage.py
site2
   manage.py

site1www
   images


so in development when I run site1, due to PYTHONPATH I also have djapps and
pluggables in my path

from app1.models import *



(I agree keeping the intro tutorial very simple is best.
perhaps it could then link to a best practices of folder layout so that you
can grow
  when I try out a system I am really on a first date.
I don't want to know about the maintenance issues. )




On Sun, Jan 11, 2009 at 10:41 PM, dahpgjgamgan wrote:

>
> Hi,
>
> In the 4-part tutorial on Django's main site, there's a lot of advice
> on how to decouple apps and projects, but when I look at the import
> statements in most of the tutorial's files, it's always "from
> projectname.appname import ." - not very decoupled for me. Am
> I missing something, is there a good reason why those imports look
> like that and not simply "from appname... import ..."?
>
> Thanks!
>
> >
>

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



Re: Decoupling between projects and app in 4-part tutorial.

2009-01-13 Thread Malcolm Tredinnick

On Tue, 2009-01-13 at 08:53 -0800, dahpgjgamgan wrote:
[...]
> > People experienced in Python realise that import statements are
> > flexible, so what's written in the tutorial is only a guide. People
> > needing to follow every line of code in the tutorial and just learning
> > Python don't need the extra baggage of worrying about that stuff in the
> > first tutorial they do.
> 
> So making the imports don't include project name would make them more
> worried?

No. It will make precisely no difference. Which is why claims about how
terrible this all is are such low-value.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: MultipleChoiceField initial data

2009-01-13 Thread Malcolm Tredinnick

On Tue, 2009-01-13 at 02:12 -0800, Thierry wrote:
> This doesn't seem to work:
> auto_open_choices = forms.MultipleChoiceField(choices=( ('google',
> 'Google'), ('msn', 'MSN'), ('yahoo', 'Yahoo')), required=False,
> initial=['google'])
> 
> From what i read in the discussions here it should...
> What am i doing wrong?

Could you clarify what "doesn't deem to work" means in your case? If I
type this into a file:

from django import forms

class MyForm(forms.Form):
auto_open_choices = forms.MultipleChoiceField(choices=(
('google', 'Google'), ('msn', 'MSN'), ('yahoo',
'Yahoo')),
required=False, initial=['google'])

and try this at the "./manage.py shell" interactive prompt (which is the
same as using the form in a template), it has the "google" choice
selected in the initial form display.

In [1]: import sample

In [2]: print sample.MyForm()
Auto open 
choices:
Google
MSN
Yahoo


So you've either trimmed a critical piece of code that is causing the
problem, or you have different expectations from what is intended to
happen.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Forcing content_types.json to be loaded before any other fixtures

2009-01-13 Thread Giovannetti, Mark

Is there a way to force a fixture to be loaded first
when running manage.py test?

I'd like to load a content_types.json fixture immediately
before any other fixtures are loaded.  

This might fix some of the vexing problems with using
content_types and tests.

Anyone know if this is possible?

Thanks
Mark

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



Combining form fields into a single MultiWidget and getting all field data returned

2009-01-13 Thread SnappyDjangoUser

Hi All,

Is there a way to "link" 2 form fields or use a create a MultiWidget
consisting of 2 fields so they are logically displayed together?  I
have a search form which asks the user for a date range to search and
I am trying to figure out the best way to display them.  The obvious
option would be to make two separate form fields, a start_date and
end_date, but I don't like that option. I would much rather have both
selects show up on the same line, which is not the behavior you get
with two separate fields.

I am aware of how to do this with a MultiWidget and a MultiValueField,
but a MultiValueField requires that you compress the data into a
single value.  I want to return both values, the start_date and
end_date of the date range, to the view for searching.

Thanks for your input!

-Brian
--~--~-~--~~~---~--~~
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: Putting pieces back together again

2009-01-13 Thread Mark Jones

Thanks, formsets was the answers, and smartly enough, they didn't name
all the fields the exact same name, but reassemble them afterwards.

On Jan 12, 9:04 am, Jeff FW  wrote:
> Mark,
>
> You should really use Forms and FormSets--they'll make this problem
> essentially go away.
>
> http://docs.djangoproject.com/en/dev/topics/forms/#topics-forms-indexhttp://docs.djangoproject.com/en/dev/topics/forms/formsets/
>
> -Jeff
>
> On Jan 12, 12:46 am, Mark Jones  wrote:
>
> > I have some fields on my page that have more than one attribute for
> > simplification, lets say two attributes
>
> > answer = {'txt':'something', 'allowblank':0}
>
> > laid out on the page as:
> > {% for answer in quiz_question.answers %}
> >   
> >    > value="{{ answer.allowblank }}" />
> > {% endfor %}
>
> > the first is pulled from an input field, and if !allowblank, needs to
> > have some text.
>
> > I write some OnSubmit() javascript on my page to check this field, and
> > if it is blank, check the allowblank attribute in the following hidden
> > field to see if this is OK.  If is isn't ok, I ask the user "you sure
> > you wanna leave this field blank?"  If the user says "YES, I want to
> > leave it blank, the JS changes allowblank to 1 and we submit the form.
>
> > If the backend gets the form and the field is blank, but the
> > allowblank is true, then I know the user said OK, no problem, I let it
> > be blank, otherwise I validate it on the server side (in case they use
> > noscript like I do) and if allowblank=0 and the field is blank, I send
> > the form back to them with a checkbox like this
>
> > {% for answer in question.answers %}
> >   
> >    > value="{{ answer.allowblank }}" /> I
> > really want to leave this field blank
> > {% endfor %}
>
> > My problem comes about because a nice list of dict objects has been
> > broken apart by the html form and needs to be reassembled.  While I
> > can do this like so:
>
> >           for i in range(len(qqanswers)-1,0, -1):
> >               qqanswers[i] = {'txt':answers[i], 'allowblank':int
> > (allowblank[i])}
> >               if answers[i] == '' and allowblank[i]:
> >                   del qqanswers[i]
>
> > I don't like how ugly this looks.  I tried changing the names of the
> > input objects to:
>
> > answers.txt and answers.allowblank, but that didn't work, I got POST
> > lists back that were names answers.txt and answers.allowblank that
> > looked like:
>
> >  > u'answers.answer': [u'1', u'2', u'3', u'4']}>
>
> > of course all of this ignores the fact that checkboxes that aren't
> > checked aren't sent back to the server anyway which is where the need
> > for a more elegant solution comes from in the first place..
>
> > Is there a nice elegant way to solve this, or does it just have to be
> > done the way I've done 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
-~--~~~~--~~--~--~---



Fwd: Referencing models.User in my models

2009-01-13 Thread Devraj Mukherjee

Hi all,

I have a few models classes that refer to the logged in user (such as
NoticeBoardPost), at the moment I am using the "username" to record
who created each object. Is this the right way of doing it in Django?

Or can I refer to models.User as a ForeignKey?

Thanks.

-- 
"The secret impresses no-one, the trick you use it for is everything"
- Alfred Borden (The Prestiege)

--~--~-~--~~~---~--~~
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: specify widget in "Admin"

2009-01-13 Thread BabySnakes

Thanks .

I joust found it in the train on the way home  :)



On 13 jan, 21:57, Andy McKay  wrote:
> On 13 Jan 2009, at 12:05, BabySnakes wrote:
>
> > I just want to use same kind of widget like the one used while I edit
> > User permissions in /admin/auth/user for my own model.
>
> Add filter_horizontal to the admin class for that model, specifying  
> your field name.
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#filter-horizo...
> --
>    Andy McKay
>    www.clearwind.ca|www.agmweb.ca/blog/andy
--~--~-~--~~~---~--~~
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 Continuous Integration

2009-01-13 Thread Rachel Willmer

An interesting set of questions, and one I've been thinking about myself.

So here's my tuppence-worth.

Background: I've written a set of 3 websites, which I've developed
incrementally, some shared code, some separate - done for my own
benefit, no external customer, so I can change things as I see fit.

It's a small project but one of the purposes is to work out how best
to manage a larger project or set of websites which use a common base.

> Revision Control: How do you layout your development repository?  I'm
> using Subversion for my setup but would be interested in hearing what
> else others are using (Mercurial, Bazaar, Git, etc)

svn for revision control.

This is a very interesting article from James Bennett who's always
worth listening to...

http://www.b-list.org/weblog/2006/sep/10/django-tips-laying-out-application/

> Packaging:  Django has an aversion to using setuptools and opts to
> stick with the basics in distutils.  What are you using for packaging
> your application?  What's the best way to deploy a Django project that

My packaging is very simple - an upload script which does an svn
update to get the current code, rips out the .svn stuff and any
unwanted directories, then rsync up to the live host. No other
packaging needed since I'm the only user :-)

> Buildbot:  Do you use Buildbot or something similar for your Django
> development?  How does that work for you?  What other options are
> there that would work well?

I run my test prog regularly from a cron job.

The test prog runs unit tests through the common code, and functional
tests for the various websites.

> Versioning: How do you mark versions of your Django project?  Meaning,
> how can you create your Django app so it has a version that you can
> track within the application itself as well as for setting up
> upgrades, etc?  I can create something in __init__.py in the root of
> my project but how does that work with the SCM?  Since trunk is always
> in development it would make sense to have something in there.  Do you
> keep it is a tag or branch?  I'm new to this so hopefully I'm making
> sense.

I'd do a svn tag.

> Migrations: What do you use to track database migrations?  I know of
> django-evolution, South and a few others but I really have no idea how
> these function and which is the most mature.  What do you have
> experience with?

Haven't found a good answer to this yet, although django-evolution
looks interesting.

I'm interested to hear how others do it all

Rachel

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



Re: Newbie questions concerning nesting blocks, for loop and super

2009-01-13 Thread dr.mob...@googlemail.com

Ah, I see - thanks Karen - your explanation clarifies/(puts to rest) a
number of points I had in my head when experimenting with the
templates! Reading it again now, I think the thing with super, could
do with being explained a bit differently (putting a for loop in was
irrelevant, and misleading). I may try again with it if still I can't
work out the answer, and phrase the question better next time.

I have to say though, having worked with ASP.NET, the templating
system is a much better approach - it's a lot more intuitive, and
certainly more transparent (which is a godsend when trying  to add
javascripts and ajax stuff!) I've even got a MochiKit demo working
now :-)

Thanks again,

Mobeus.

On Jan 13, 7:24 pm, "Karen Tracey"  wrote:
> On Tue, Jan 13, 2009 at 12:31 PM, dr.mob...@googlemail.com <
>
> dr.mob...@googlemail.com> wrote:
>
> > Hello,
> > I'm new to DJango, but I'm already lovin' it. I have a few questions
> > however - can someone offer any guidance, please?
>
> > Is the possible following in a template:
> > { inherits ... }
>
> I take it you mean extends, not inherits, here.
>
>
>
> > {% for item in items %}
>
> >    {% block A %}
> >       some text here
> >    {% endblock A %}
>
> >    {% block B %}
> >      some other text here
> >    {% endblock %}
>
> > {% endfor %}
>
> > without there being another block wrapping the for loop?
>
> No.
>
> > I've tried it
> > and I cannot get it working, but I think I remember some an example
> > doing so... I guess the general point of my question is  - do all
> > constructs have to be wrapped in a block?
>
> Yes, in a template that is extending another, everything has to be in a
> block.  Fromhttp://docs.djangoproject.com/en/dev/topics/templates/#id1:
>
> The {% extends %} tag is the key here. It tells the template engine that
> this template "extends" another template. When the template system evaluates
> this template, first it locates the parent -- in this case, "base.html".
> At that point, the template engine will notice the three {% block %} tags in
> base.html and replace those blocks with the contents of the child template.
>
> Thus, the only thing relevant in a child template is text contained in {%
> block %} elements that were previously defined in a parent template.  There
> isn't any place for text outside of such {% block %} tags in a child
> template to go -- where would it be logically placed in a parent template?
>
> I'll leave the block.super question for someone else to answer, as it's not
> immediately obvious to me what you are asking and I've run out of time right
> now.
>
> 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-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
-~--~~~~--~~--~--~---



temporary user model

2009-01-13 Thread Mengsong Chen
Just wonder if anyone have achieved such a temporary user model to allow
unregistered user to use some features,but will clean up the data after the
session completed if the user is not going to register.

Thanks in advanced.

M

--~--~-~--~~~---~--~~
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 add tinyMCE to django 1.0.2 admin

2009-01-13 Thread Brian Neal

On Jan 13, 3:43 pm, "Oleg Oltar"  wrote:
> Hi!
>
> I want to add tinyMCE to my project's admin site.

You didn't list any admin.py code. Check out the docs on the admin
interface:

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

After you read through that, pay attention to the ModelAdmin media
definitions:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-media-definitions

It is there you specify the tinymce javascript files. When the admin
displays the form for your models it will generate the appropriate
script tags to the javascript files.

Good luck!
BN
--~--~-~--~~~---~--~~
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 add tinyMCE to django 1.0.2 admin

2009-01-13 Thread Oleg Oltar
Hi!

I want to add tinyMCE to my project's admin site. I downloaded the latest
version of the editor, added the js/tiny_mce to my media files

Added following to my urls.py
from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('django.views.generic.simple',
   (r'^contacts$',
'direct_to_template',{'template':'visitcard/contacts.html'} ),
   (r'^construction$',
'direct_to_template',{'template':'visitcard/construction.html'}),
   (r'^portfolio1$',
'direct_to_template',{'template':'visitcard/portfolio.html'}),
   (r'^partners$',
'direct_to_template',{'template':'visitcard/partners.html'}),
   (r'^articles$',
'direct_to_template',{'template':'visitcard/artilcles.html'}),
   (r'^portfolio$',
'direct_to_template',{'template':'visitcard/portfolio1.html'}),
   (r'^dom_karkasnij$', 'direct_to_template',
{'template':'visitcard/dom_karkas.html'}),
   (r'^$',
'direct_to_template',{'template':'visitcard/index.html'} ),


   )


urlpatterns +=  patterns('',

(r'^tiny_mce/(?P.*)$','django.views.static.serve',
  {'document_root':
'/Users/oleg/Desktop/TECHNOBUD/TEMPLATES/static_media/js/tiny_mce' }),
 (r'^admin/', include('cms.admin_urls')),
 (r'^admin/(.*)', admin.site.root),
 )


Also created the config for tinyMCE: textareas.js
tinyMCE.init({
mode : "textareas",
theme : "advanced",
//content_css : "/appmedia/blog/style.css",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_buttons1 :
"fullscreen,separator,preview,separator,bold,italic,underline,strikethrough,separator,bullist,numlist,outdent,indent,separator,undo,redo,separator,link,unlink,anchor,separator,image,cleanup,help,separator,code",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
auto_cleanup_word : true,
plugins :
"table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu,fullscreen",
plugin_insertdate_dateFormat : "%m/%d/%Y",
plugin_insertdate_timeFormat : "%H:%M:%S",
extended_valid_elements :
"a[name|href|target=_blank|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
fullscreen_settings : {
theme_advanced_path_location : "top",
theme_advanced_buttons1 :
"fullscreen,separator,preview,separator,cut,copy,paste,separator,undo,redo,separator,search,replace,separator,code,separator,cleanup,separator,bold,italic,underline,strikethrough,separator,forecolor,backcolor,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,help",
theme_advanced_buttons2 :
"removeformat,styleselect,formatselect,fontselect,fontsizeselect,separator,bullist,numlist,outdent,indent,separator,link,unlink,anchor",
theme_advanced_buttons3 :
"sub,sup,separator,image,insertdate,inserttime,separator,tablecontrols,separator,hr,advhr,visualaid,separator,charmap,emotions,iespell,flash,separator,print"
}
});

My models file:
from django.db import models

class Article(models.Model):
title = models.CharField(max_length=60)
body = models.TextField(max_length=3000)
slug = models.SlugField(unique=True)

The editor is still not appearing on my admin interface, when I am trying to
add articles... Did I miss something? Please help me to understand the
problem

Thanks,
Oleg

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



Dealing with 'date' ranges in template?

2009-01-13 Thread Manfred

Hello,

I wrote a special kind of blog- or news application. One of the
specialities of this application is, that authors are able to make
entries visible/invisible by a date range or by a simple switch to
hide the entry. This works well. But (the authors are not supposed to
use the admin interface) authors need to be able to change the state
of 'invisible' entries if they are in editing mode. Therefore, the
view selects _all_ entries if one is logged in but only visible ones
if one is not logged in.

To support authors and show them if an entry is visible for the normal
user or not, invisible entries have a different layout than visible
ones. Using a booelan field 'entry.hide' in the template is easy by {%
if entry.hide %}...

But how can I deal with the date range? I have two fields: 'show_from'
and 'show_until' to restrict the visible date range for each entry.
The essence of what I need is something like this:

IF entry.hide == True OR entry.show_from > date.today() OR
entry.show_until < date.today() THEN ...

In my template currently I use a statement like this: {% if entry.hide
%} class="hidden"{% endif %} to change the section layout for
invisible sections. But if the entry is "invisible" because of the
date range, I had no success to mark the entry 'hidden' in the
templete.

Currently my application runs on Django 0.96, but I did not found any
solution to this question even in Django 1.0

Is there a solution?

Many thanks in advance,
Manfred.

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

2009-01-13 Thread Wai Yi Leung

You should rewite the method:

def commodity(request, commodity_id):
p = get_object_or_404(Commodity, pk=commodity_id)
return render_to_response('fsafety/commodity_detail.html', 
{'commodity': p})

to

def commodity(request):
commodity_id = request.POST['commodity'] # this variable comes from 
the form (select value)
p = get_object_or_404(Commodity, pk=commodity_id)
return render_to_response('fsafety/commodity_detail.html', 
{'commodity': p})

Best regards,

Wai Yi

May schreef:
> Hello All,
>
> Thank you for the suggestions.  I am getting closer to figuring it
> out.  Now my error is this:
>
> commodity() takes exactly 2 arguments (1 given)
>
> My URL is:
> (r'^commodity/$', 'commodity'),
>
> The Form statement:
> 
>
> Thank you!
>
> May
>
> On Jan 13, 10:56 am, Wai Yi Leung  wrote:
>   
>> Hi May,
>>
>> Try to debug in shell, this will give you more information.
>> Lets print the 'p' value after having it set with get_object_or_404 ...
>>
>> And I think you are a bit messing with which method to call. You are
>> generating the page with the form that contains errors. So lets check
>> your index() method also.
>> This method doesn't assign commodity to any variable in the response.
>>
>> Good luck in bughunting.
>>
>> Wai Yi
>>
>> May schreef:
>>
>> 
>>> Hello,
>>>   
>>> I tried the URL and still received this error:
>>> Page not found (404)
>>> Request Method:POST
>>> Request URL:  http://127.0.0.1:8000/fsafety//commodity_detail/
>>>   
>>> I think now that the ID is not getting passed to this line:
>>> 
>>>   
>>> Thank you for any help you can give.
>>>   
>>> May
>>>   
>>> On Jan 13, 10:25 am, Santiago  wrote:
>>>   
 replace in your url.py:
 
 (r'^(?P\d+)$/commodity_detail/', 'commodity'),
 
 by
 
 (r'^(?P\d+)/commodity_detail/$', 'commodity'),
 
 this _should_ work
 
 2009/1/14 May :
 
> My error is not being able to get the ID passed to the next
> template.
>   
> The code:
>   
> http://dpaste.com/108580/
>   
> Thank you,
>   
> May
>   
>> 
> >
>
>   


--~--~-~--~~~---~--~~
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: specify widget in "Admin"

2009-01-13 Thread Andy McKay

On 13 Jan 2009, at 12:05, BabySnakes wrote:
> I just want to use same kind of widget like the one used while I edit
> User permissions in /admin/auth/user for my own model.

Add filter_horizontal to the admin class for that model, specifying  
your field name.

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#filter-horizontal
--
   Andy McKay
   www.clearwind.ca | www.agmweb.ca/blog/andy







--~--~-~--~~~---~--~~
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: Login form on every page and session weirdness

2009-01-13 Thread Brandon Taylor

Turns out I had my session backend specified wrong, so my sessions
were never being saved. However, I did run into a new problem - it
doesn't seem that a form object can be put into session?

Can anyone verify that this is true? When trying to stuff the form
object into session, I ran into pickling errors.

On Jan 13, 11:43 am, Brandon Taylor  wrote:
> Hi everyone,
>
> I have a login form on every page and want to leverage the
> AuthenticationForm from contrib.auth. So, I thought I would have a
> middleware tier to process the request and check for a GET or POST and
> create the appropriate form, either bound or un-bound. Here is my
> middleware:
>
> from django.http import HttpResponse, HttpResponseRedirect
> from django.contrib.auth.forms import AuthenticationForm
> from django.contrib.auth import logout, authenticate, login
>
> class LoginMiddleware(object):
>     def process_request (self, request):
>         if request.method == 'POST':
>             if request.POST.get('login', False):
>                 authentication_form = AuthenticationForm
> (data=request.POST)
>
>                 if authentication_form.is_valid():
>                     login(request, authentication_form.get_user())
>                 else:
>                     request.session['authentication_form'] =
> authentication_form
>
>             if request.POST.get('logout', False):
>                 logout(request)
>
>             return HttpResponseRedirect(request.path)
>
>         else:
>             try:
>                 authentication_form = request.session
> ['authentication_form']
>             except KeyError:
>                 request.session['authentication_form'] =
> AuthenticationForm(request)
>
> This part works as expected. However, the really challenging part has
> been displaying the errors for the form. I added a Context Processor:
>
> def get_login_messages(request):
>
>     new_dict = {
>         'authentication_form' : request.session
> ['authentication_form'],
>     }
>
>     return new_dict
>
> To return the form instance that was set in session and pass it to the
> template. If I print the session 'authentication_form' from the
> console in my middleware if the form is invalid, the session is
> correct. It contains an instance of the form with all of the error
> messages.
>
> But, when I print the session from the Context Processor, I get the un-
> bound instance of the form, *without* error messages.
>
> Can anyone see what I'm doing wrong here? I have no idea what's
> happening to the "authenticated_form" session from the time it is set
> by the middleware and reaches the context processor.
>
> Help GREATLY appreciated,
> Brandon
--~--~-~--~~~---~--~~
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 URL help

2009-01-13 Thread May

Hello All,

Thank you for the suggestions.  I am getting closer to figuring it
out.  Now my error is this:

commodity() takes exactly 2 arguments (1 given)

My URL is:
(r'^commodity/$', 'commodity'),

The Form statement:


Thank you!

May

On Jan 13, 10:56 am, Wai Yi Leung  wrote:
> Hi May,
>
> Try to debug in shell, this will give you more information.
> Lets print the 'p' value after having it set with get_object_or_404 ...
>
> And I think you are a bit messing with which method to call. You are
> generating the page with the form that contains errors. So lets check
> your index() method also.
> This method doesn't assign commodity to any variable in the response.
>
> Good luck in bughunting.
>
> Wai Yi
>
> May schreef:
>
> > Hello,
>
> > I tried the URL and still received this error:
> > Page not found (404)
> > Request Method:    POST
> > Request URL:      http://127.0.0.1:8000/fsafety//commodity_detail/
>
> > I think now that the ID is not getting passed to this line:
> > 
>
> > Thank you for any help you can give.
>
> > May
>
> > On Jan 13, 10:25 am, Santiago  wrote:
>
> >> replace in your url.py:
>
> >> (r'^(?P\d+)$/commodity_detail/', 'commodity'),
>
> >> by
>
> >> (r'^(?P\d+)/commodity_detail/$', 'commodity'),
>
> >> this _should_ work
>
> >> 2009/1/14 May :
>
> >>> My error is not being able to get the ID passed to the next
> >>> template.
>
> >>> The code:
>
> >>>http://dpaste.com/108580/
>
> >>> Thank you,
>
> >>> May
>
>
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



specify widget in "Admin"

2009-01-13 Thread BabySnakes

I just want to use same kind of widget like the one used while I edit
User permissions in /admin/auth/user for my own model.

My model has a "ManyToManyField" relationship (with
through='sometable' specified).

The widget is probably "FilteredSelectMultiple", but I just can't find
the way to specify that that's the one I want to use.





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

2009-01-13 Thread msmtotti

Si me serviria para formularios, me podrias explicar como ?? o alguna
ayuda

Gracias
--~--~-~--~~~---~--~~
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: Slow view causing timeout errors

2009-01-13 Thread Adam

It doesn't need to be accessed in real-time, so you're totally right.
I'm going to try a session key set by the loop as it iterates.  That
way ajax will know when the final iteration is done. Thanks!

On Jan 13, 8:23 am, Roy  wrote:
> Is it dynamic data that needs to be accessed in real-time? If not, you
> could cache it in your own database (using a cron job), so that the
> view doesn't have to take too long.
>
> On Jan 13, 10:53 am, Adam Tucker  wrote:
>
> > I am working on a site where a page is loaded which replaces part of itself
> > with another view using a simple ajax replacement (the load funciton in
> > jQuery.) The view that is called iterates a loop anywhere from 3 to 10 times
> > before getting to a render_to_response.  Unfortunately, the view pulls data
> > from a very slow source which I can't control, so a single interation can
> > take up to 30 seconds to complete, and after 60 seconds it times out.  I am
> > looking for some pointers on ways that I could work around this, either by
> > returning partial data at each iteration or some other method. Thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Slow view causing timeout errors

2009-01-13 Thread Adam

The timeout is happening on the nginx that is hosting static content.
I'm not entirely sure why, but I have figured out a way to properly
handle the view.  Instead of having ajax replace part of the page I'm
just going to have it check a session key that I will have the loop
update.  I probably should have thought of that before.

On Jan 13, 4:38 am, Daniel Roseman 
wrote:
> On Jan 13, 2:53 am, Adam Tucker  wrote:
>
> > I am working on a site where a page is loaded which replaces part of itself
> > with another view using a simple ajax replacement (the load funciton in
> > jQuery.) The view that is called iterates a loop anywhere from 3 to 10 times
> > before getting to a render_to_response.  Unfortunately, the view pulls data
> > from a very slow source which I can't control, so a single interation can
> > take up to 30 seconds to complete, and after 60 seconds it times out.  I am
> > looking for some pointers on ways that I could work around this, either by
> > returning partial data at each iteration or some other method. Thanks!
>
> The basic jQuery.ajax() method has an optional timeout parameter which
> allows you to increase the default timeout on a per-request 
> basis:http://docs.jquery.com/Ajax/jQuery.ajax#options
> Does that help?
> --
> 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: Importing old projects into a fresh django installation

2009-01-13 Thread Patrick Taylor

Just tossing this out, but it might be worth checking to see what
manage.py or django-admin.py reports as the version of Django
installed:

  http://docs.djangoproject.com/en/dev/ref/django-admin/#determining-the-version

At least then you'll be certain whether it's 0.96, 0.97svn or 1.0.

On Jan 12, 7:42 pm, Robocop  wrote:
> Well i definitely have code written for .96 (i may be running .96 or
> a .97 svn checkout).  My problem here is i'm trying to replicate the
> old environment (i.e. i have .96 installed currently), yet something
> is going haywire.  So as of right now, there is no issue with porting
> to 1.0, however if what you're telling me is along the lines of "No
> you jerk, you don't have to do anything special with old projects if
> you're running them with the same version of Django" then i'm in
> business and can at take some other approaches to trying to get my old
> projects up.  Thanks for the input!
>
> On Jan 12, 3:37 pm, "Karen Tracey"  wrote:
>
> > On Mon, Jan 12, 2009 at 6:20 PM, Robocop  wrote:
>
> > > Esteemed colleagues:
>
> > > I've just built a small web server running django .97, with python
> > > 2.4, mysql-python-1.2, and mod_python 3.2.8.
>
> > There was never a Django 0.97 release.  Anything that reports itself as
> > Django 0.97-pre is an SVN checkout from sometime between 0.96 and 1.0 (which
> > spans rather a lot of ground in terms of changes).
>
> > > I've tested and can
> > > start new django applications just fine (haven't fleshed any out to do
> > > further testing), so it looks like the django install is properly
> > > configured.  However, when i try to run any of my old projects via
> > > "python manage.py runserver blah blah blah" i get these strange mysql
> > > errors, things like:
>
> > > File "/home/minh/skysale/../skysale/products/models.py", line 35, in
> > > Product
> > >    name = models.CharField(max_length=64, core=True)
> > > TypeError: __init__() got an unexpected keyword argument 'core'
>
> > 'core' was an oldforms-admin parameter.  It meant nothing (had no effect)
> > after newforms-admin was merged to trunk, and was removed entirely at some
> > point soon before 1.0.
>
> > > I get different errors in different projects, but they all have this
> > > same keyword argument error, when i know they're valid keywords.  Is
> > > there some special procedure for running previously created projects
> > > in a fresh Django environment (using the same version of Django for
> > > the fresh install and the old projects)?  Any help would be great.
>
> > If you've got code written for 0.96 then you'll need to do some migration to
> > get it running on 1.0:
>
> >http://docs.djangoproject.com/en/dev/releases/1.0-porting-guide/
>
> > Alternatively you can keep running on the older level, but you'll need to
> > install what matches that code you've written, and you don't seem to have
> > the matching level installed at present.
>
> > 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django / memcached / pickle / Unicode = confusion + UnicodeDecodeError

2009-01-13 Thread Rachel Willmer

I've just upgraded some code to Django 1.0 and the caching stopped working.

I have found a fix but I don't understand what's happening so if
anyone can explain, I'd be grateful.

My code used to look somthing like this (simplified for clearer reading)

cached=cache.get(key)
if cached:
list=pickle.loads(cached)
else:
list = Banks.objects()
pickled = pickle.dumps(list,pickle.HIGHEST_PROTOCOL)
cache.set(key,pickled)

pickled is of type 'str', my default encoding appears to be 'ascii'.

When I call cache.set, I get a UnicodeDecodeError.

So to fix it, I add:

cached=smart_str(cached,encoding='iso_8859_1')

before the call to pickle.loads()

and

pickled=smart_unicode(pickled,encoding='iso_8859_1')

before the call to cache.set()

So what I don't understand is, why 'iso_8859_1'? As far as I know, the
python default encoding is 'ascii' and the django DEFAULT_CHARSET is
'utf-8'. So where's this coming from?

Any pointers welcome!

Rachel

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



Re: Newbie questions concerning nesting blocks, for loop and super

2009-01-13 Thread Karen Tracey
On Tue, Jan 13, 2009 at 12:31 PM, dr.mob...@googlemail.com <
dr.mob...@googlemail.com> wrote:

>
> Hello,
> I'm new to DJango, but I'm already lovin' it. I have a few questions
> however - can someone offer any guidance, please?
>
> Is the possible following in a template:
> { inherits ... }
>

I take it you mean extends, not inherits, here.


>
> {% for item in items %}
>
>{% block A %}
>   some text here
>{% endblock A %}
>
>{% block B %}
>  some other text here
>{% endblock %}
>
> {% endfor %}
>
> without there being another block wrapping the for loop?


No.


> I've tried it
> and I cannot get it working, but I think I remember some an example
> doing so... I guess the general point of my question is  - do all
> constructs have to be wrapped in a block?
>

Yes, in a template that is extending another, everything has to be in a
block.  From http://docs.djangoproject.com/en/dev/topics/templates/#id1:

The {% extends %} tag is the key here. It tells the template engine that
this template "extends" another template. When the template system evaluates
this template, first it locates the parent -- in this case, "base.html".
At that point, the template engine will notice the three {% block %} tags in
base.html and replace those blocks with the contents of the child template.

Thus, the only thing relevant in a child template is text contained in {%
block %} elements that were previously defined in a parent template.  There
isn't any place for text outside of such {% block %} tags in a child
template to go -- where would it be logically placed in a parent template?

I'll leave the block.super question for someone else to answer, as it's not
immediately obvious to me what you are asking and I've run out of time right
now.

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-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 URL help

2009-01-13 Thread Wai Yi Leung

Hi May,

Try to debug in shell, this will give you more information.
Lets print the 'p' value after having it set with get_object_or_404 ...

And I think you are a bit messing with which method to call. You are 
generating the page with the form that contains errors. So lets check 
your index() method also.
This method doesn't assign commodity to any variable in the response.

Good luck in bughunting.

Wai Yi



May schreef:
> Hello,
>
> I tried the URL and still received this error:
> Page not found (404)
> Request Method:   POST
> Request URL:  http://127.0.0.1:8000/fsafety//commodity_detail/
>
> I think now that the ID is not getting passed to this line:
> 
>
> Thank you for any help you can give.
>
> May
>
> On Jan 13, 10:25 am, Santiago  wrote:
>   
>> replace in your url.py:
>>
>> (r'^(?P\d+)$/commodity_detail/', 'commodity'),
>>
>> by
>>
>> (r'^(?P\d+)/commodity_detail/$', 'commodity'),
>>
>> this _should_ work
>>
>> 2009/1/14 May :
>>
>>
>>
>> 
>>> My error is not being able to get the ID passed to the next
>>> template.
>>>   
>>> The code:
>>>   
>>> http://dpaste.com/108580/
>>>   
>>> Thank you,
>>>   
>>> May
>>>   
>> 
> >
>
>   


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

2009-01-13 Thread Santiago

2009/1/14 May :
>
> Hello,
>
> I tried the URL and still received this error:
> Page not found (404)
> Request Method: POST
> Request URL:http://127.0.0.1:8000/fsafety//commodity_detail/

Yep... sorry i just checked for the url didnt read the form part in detail :p

> I think now that the ID is not getting passed to this line:
> 

Yes this is the problem... since at this point, you _dont_ have the
comunity id... :)

when you're doing:

{% for commodity in commodity_list %}
{{commodity.commodity}}
{% endfor %}

here's when you have the data... so you sould change some code:

change the following lines:
(r'^(?P\d+)/commodity_detail/$', 'commodity'),


by

(r'/commodity_detail/$', 'commodity'),







tho... i guess that would work like this (i aint an expert :P)


> Thank you for any help you can give.
>
> May
>
> On Jan 13, 10:25 am, Santiago  wrote:
>> replace in your url.py:
>>
>> (r'^(?P\d+)$/commodity_detail/', 'commodity'),
>>
>> by
>>
>> (r'^(?P\d+)/commodity_detail/$', 'commodity'),
>>
>> this _should_ work
>>
>> 2009/1/14 May :
>>
>>
>>
>> > My error is not being able to get the ID passed to the next
>> > template.
>>
>> > The code:
>>
>> >http://dpaste.com/108580/
>>
>> > Thank you,
>>
>> > May
>>
>>
> >
>

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



template does not exist

2009-01-13 Thread Bobby Roberts

Hi everyone.  I have checked and re-checked my path for my templates
in the settings file.  I have also confirmed at my template is sitting
in the right directory:  I'm trying to do a direct to template in my
urls.py file as follows:


from django.conf.urls.defaults import *

urlpatterns = patterns('django.views.generic.simple',
(r'^test/$','direct_to_template',{'template': 'base.html'}),
)



The Traceback I get is:

TemplateDoesNotExist
base.html

Django tried loading these templates, in this order:

* Using loader
django.template.loaders.filesystem.load_template_source:
* Using loader
django.template.loaders.app_directories.load_template_source:
  o /usr/lib/python2.5/site-packages/django/contrib/admin/
templates/base.html (File does not exist)


any idea why it's looking in the admin/templates directory?

Using python 2.5 and django 0.97x...





--~--~-~--~~~---~--~~
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 practices for multiple sites

2009-01-13 Thread shacker

On Jan 12, 3:05 pm, felix  wrote:
> I'm running 3 sites on a shared db right now.
>
> I would say your option 2

Thanks for the feedback Felix. My initial concern was that two
projects sharing a database would not have any awareness of one
another and that things could potentially get tangled up in
unanticipated ways. But it sounds like you haven't hit any situations
like that. Your examples on custom permissions are useful. OK, we're
going with that approach. Thanks again.

./s


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



Django Continuous Integration

2009-01-13 Thread mguthrie

I've been working on understanding "agile" programming practices as
well as setting up a proper development/testing/release environment.

There are several good resources out there for getting these things
configured for Python projects in general but nothing really specific
to Django.

What has worked for other Django developers/shops?  How have you
managed your processes?  Any information on the following would be
great:

Revision Control: How do you layout your development repository?  I'm
using Subversion for my setup but would be interested in hearing what
else others are using (Mercurial, Bazaar, Git, etc)

Packaging:  Django has an aversion to using setuptools and opts to
stick with the basics in distutils.  What are you using for packaging
your application?  What's the best way to deploy a Django project that
would make it easy on the end user to install and configure?  I don't
really care about providing individual apps.  I wish to deploy my
application in it's entirety.  It would be nice if this could be
worked into the development process.  Pylons and Turbogears seem to
have a nice process setup using Paste and virtualenv that works well
for the development and testing process.  Do Django users have
something similar?

Buildbot:  Do you use Buildbot or something similar for your Django
development?  How does that work for you?  What other options are
there that would work well?

Versioning: How do you mark versions of your Django project?  Meaning,
how can you create your Django app so it has a version that you can
track within the application itself as well as for setting up
upgrades, etc?  I can create something in __init__.py in the root of
my project but how does that work with the SCM?  Since trunk is always
in development it would make sense to have something in there.  Do you
keep it is a tag or branch?  I'm new to this so hopefully I'm making
sense.

Migrations: What do you use to track database migrations?  I know of
django-evolution, South and a few others but I really have no idea how
these function and which is the most mature.  What do you have
experience with?

That's probably plenty for this post.  Sorry it's so long but this is
difficult stuff and it's spread out across the internet.  Not to
mention that it's not specific to Django development.

I've recently worked with a Java developer and got a chance to see his
development process and was really impressed.  Java seems to have more
tools available that tie in nicely with each other for continuous
integration.  He was using Trac, Buildbot, Unit testing (JUnit) and
had scripts to deploy to a new server immediately.  It was pretty
impressive and I would like to know if anyone has something similar
setup for their Django projects.

Thanks in advance for any input.
--~--~-~--~~~---~--~~
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 URL help

2009-01-13 Thread May

Hello,

I tried the URL and still received this error:
Page not found (404)
Request Method: POST
Request URL:http://127.0.0.1:8000/fsafety//commodity_detail/

I think now that the ID is not getting passed to this line:


Thank you for any help you can give.

May

On Jan 13, 10:25 am, Santiago  wrote:
> replace in your url.py:
>
> (r'^(?P\d+)$/commodity_detail/', 'commodity'),
>
> by
>
> (r'^(?P\d+)/commodity_detail/$', 'commodity'),
>
> this _should_ work
>
> 2009/1/14 May :
>
>
>
> > My error is not being able to get the ID passed to the next
> > template.
>
> > The code:
>
> >http://dpaste.com/108580/
>
> > Thank you,
>
> > May
>
>
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Forms: Datetime and Microseconds

2009-01-13 Thread Kottiyath

Hi,
   I want to submit date and time data (upto microsecond) to the DB
(postgres) in Django - Field - DateTimeField.
   But, during validating the form, I got the error 'Enter a valid
date/time'.
   I checked the Django code and it looks as follows:

DEFAULT_DATETIME_INPUT_FORMATS = (
'%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59'
'%Y-%m-%d %H:%M',# '2006-10-25 14:30'
'%Y-%m-%d',  # '2006-10-25'
'%m/%d/%Y %H:%M:%S', # '10/25/2006 14:30:59'
'%m/%d/%Y %H:%M',# '10/25/2006 14:30'
'%m/%d/%Y',  # '10/25/2006'
'%m/%d/%y %H:%M:%S', # '10/25/06 14:30:59'
'%m/%d/%y %H:%M',# '10/25/06 14:30'
'%m/%d/%y',  # '10/25/06'
)

class DateTimeField(Field):
widget = DateTimeInput
default_error_messages = {
'invalid': _(u'Enter a valid date/time.'),
}

def __init__(self, input_formats=None, *args, **kwargs):
super(DateTimeField, self).__init__(*args, **kwargs)
self.input_formats = input_formats or
DEFAULT_DATETIME_INPUT_FORMATS

   Now, these formats are used as part of strptime - and I cannot find
any mechanism to add microseconds to that too. Is it possible to
somehow pass in microsecond data to Django?

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



Re: Extending Admin Interface - Image Manipulation After Upload

2009-01-13 Thread Ty

Thanks for the help, much appreciated.

On Jan 13, 1:28 pm, Brian Neal  wrote:
> On Jan 13, 12:06 pm, Ty  wrote:
>
>
>
> > I've started creating a photo blog project to get familiar with Python
> > and Django. I'm using Python 2.6.1 and Django 1.0.2. I'm working on
> > the models and the administration first, before I tackle the front end
> > side of the site. I have everything working fine, for the exception of
> > an image upload field in the administration.
>
> > I assume I'm just going to have to add an "ImageField" in the model.
> > That I get, however, every time a new image is uploaded I want to
> > resize and save a few copies of the images for thumbnail use, and I
> > don't know how to go about extending an administration form like that.
>
> > I've been looking around and I've seen the save method in the model
> > class. For example I'm using this to come up with the post title slug:
>
> >     def save(self):
> >         self.name_slug = re.sub('[^a-zA-Z0-9]', '_', self.name).strip
> > ('_').lower()
> >         self.name_slug = re.sub('[-]+', '_', self.name_slug)
> >         super(Entry, self).save()
>
> > Should I add the image manipulation code in the save method? What is
> > the best way to go about this issue?
>
> Yeah I would (and have) done that type of stuff there. See also the
> documentation for the admin interface and overriding the save_model
> method on admin.ModelAdmin. You can hang custom behavior there also,
> if you only want that behavior when you save a model from the admin
> interface.
>
>
>
> > On another note, is there a good resource for image manipulation in
> > Python?
>
> I've used the PIL (Python Imaging Library) to manipulate images. Be
> aware that there are other django pluggable applications that you
> could use also: search for django Photologue, django-thumbs, and
> django-sorl. It is fairly easy to manipulate images with PIL so I just
> rolled my own. I used Photologue in a previous project, it is a
> fantastic full-blown gallery app for django.
>
> Have fun!
> BN
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Extending Admin Interface - Image Manipulation After Upload

2009-01-13 Thread Brian Neal

On Jan 13, 12:06 pm, Ty  wrote:
> I've started creating a photo blog project to get familiar with Python
> and Django. I'm using Python 2.6.1 and Django 1.0.2. I'm working on
> the models and the administration first, before I tackle the front end
> side of the site. I have everything working fine, for the exception of
> an image upload field in the administration.
>
> I assume I'm just going to have to add an "ImageField" in the model.
> That I get, however, every time a new image is uploaded I want to
> resize and save a few copies of the images for thumbnail use, and I
> don't know how to go about extending an administration form like that.
>
> I've been looking around and I've seen the save method in the model
> class. For example I'm using this to come up with the post title slug:
>
>     def save(self):
>         self.name_slug = re.sub('[^a-zA-Z0-9]', '_', self.name).strip
> ('_').lower()
>         self.name_slug = re.sub('[-]+', '_', self.name_slug)
>         super(Entry, self).save()
>
> Should I add the image manipulation code in the save method? What is
> the best way to go about this issue?

Yeah I would (and have) done that type of stuff there. See also the
documentation for the admin interface and overriding the save_model
method on admin.ModelAdmin. You can hang custom behavior there also,
if you only want that behavior when you save a model from the admin
interface.

>
> On another note, is there a good resource for image manipulation in
> Python?

I've used the PIL (Python Imaging Library) to manipulate images. Be
aware that there are other django pluggable applications that you
could use also: search for django Photologue, django-thumbs, and
django-sorl. It is fairly easy to manipulate images with PIL so I just
rolled my own. I used Photologue in a previous project, it is a
fantastic full-blown gallery app for django.

Have fun!
BN
--~--~-~--~~~---~--~~
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 URL help

2009-01-13 Thread Santiago

replace in your url.py:

(r'^(?P\d+)$/commodity_detail/', 'commodity'),

by

(r'^(?P\d+)/commodity_detail/$', 'commodity'),

this _should_ work


2009/1/14 May :
>
> My error is not being able to get the ID passed to the next
> template.
>
> The code:
>
> http://dpaste.com/108580/
>
> Thank you,
>
> May
>
>
>
>
> >
>

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



'datetime.datetime' object is unsubscriptable

2009-01-13 Thread garagefan

I'm attempting to install diamanda forum, and so far things are
looking promising.

however, i am receiving the above error, in the subject, at line 140
of dimandas.pages.feedupdate

specifically, the line is: 'date': date[:10] located within a Context.

This occurs on save of a new topic. w/o the query limit this file
works, but then i get an error:

 Data truncated for column 'rss' at row 1

the full code for the context itself is:

 c = Context({
 'user_id': author_system_id,
 'username': author[0:14],
 'date': date[:10],
 'cssclass': cssclass,
 'pagination_page': last_pagination_page,
 'topic_id': topic_id,
 'prefix': prefix,
 'topic_title': self.stripper.strip(name),
 'text': fbc(text),
 'author_anonymous': author_anonymous
 })


--~--~-~--~~~---~--~~
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 find out more info about "Error: No module named ..."

2009-01-13 Thread jhill10110

I am getting a module load error but I can't tell what is causing it.

Running `./django-admin.py validate --verbosity 2` returns "Error: No
module named config".

I have no idea what is trying to load this module and can't find any
reference to it after doing several greps. How can I find out more
information on what is actually looking for this config module?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Extending Admin Interface - Image Manipulation After Upload

2009-01-13 Thread Ty

I've started creating a photo blog project to get familiar with Python
and Django. I'm using Python 2.6.1 and Django 1.0.2. I'm working on
the models and the administration first, before I tackle the front end
side of the site. I have everything working fine, for the exception of
an image upload field in the administration.

I assume I'm just going to have to add an "ImageField" in the model.
That I get, however, every time a new image is uploaded I want to
resize and save a few copies of the images for thumbnail use, and I
don't know how to go about extending an administration form like that.

I've been looking around and I've seen the save method in the model
class. For example I'm using this to come up with the post title slug:

def save(self):
self.name_slug = re.sub('[^a-zA-Z0-9]', '_', self.name).strip
('_').lower()
self.name_slug = re.sub('[-]+', '_', self.name_slug)
super(Entry, self).save()

Should I add the image manipulation code in the save method? What is
the best way to go about this issue?

On another note, is there a good resource for image manipulation in
Python?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Login form on every page and session weirdness

2009-01-13 Thread Brandon Taylor

Hi everyone,

I have a login form on every page and want to leverage the
AuthenticationForm from contrib.auth. So, I thought I would have a
middleware tier to process the request and check for a GET or POST and
create the appropriate form, either bound or un-bound. Here is my
middleware:

from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import logout, authenticate, login

class LoginMiddleware(object):
def process_request (self, request):
if request.method == 'POST':
if request.POST.get('login', False):
authentication_form = AuthenticationForm
(data=request.POST)

if authentication_form.is_valid():
login(request, authentication_form.get_user())
else:
request.session['authentication_form'] =
authentication_form

if request.POST.get('logout', False):
logout(request)

return HttpResponseRedirect(request.path)

else:
try:
authentication_form = request.session
['authentication_form']
except KeyError:
request.session['authentication_form'] =
AuthenticationForm(request)


This part works as expected. However, the really challenging part has
been displaying the errors for the form. I added a Context Processor:

def get_login_messages(request):

new_dict = {
'authentication_form' : request.session
['authentication_form'],
}

return new_dict

To return the form instance that was set in session and pass it to the
template. If I print the session 'authentication_form' from the
console in my middleware if the form is invalid, the session is
correct. It contains an instance of the form with all of the error
messages.

But, when I print the session from the Context Processor, I get the un-
bound instance of the form, *without* error messages.

Can anyone see what I'm doing wrong here? I have no idea what's
happening to the "authenticated_form" session from the time it is set
by the middleware and reaches the context processor.

Help GREATLY appreciated,
Brandon
--~--~-~--~~~---~--~~
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: Getting url/host/domain info in settings.py

2009-01-13 Thread Donn

On Tuesday, 13 January 2009 19:28:01 Tom Dyson wrote:
> We do something like this with middleware in the Carbon Account[1]:

I have not used middleware yet, so will look into it. I am not sure if it can 
supply request.META *within* settings.py though.

I want to set certain variables depending on what visits the settings.py file 
in my project. For example: 
UPLOAD_DIR would be 'www' when the browser comes from www.mydomain.com and it 
would be 'comics' when from comics.mydomain.com

Or am I getting this all muddled? I have the vaguest notion that settings.py 
and some other files are run once and kept in memory after that -- so perhaps 
my idea won't work anyway.

\d

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



Newbie questions concerning nesting blocks, for loop and super

2009-01-13 Thread dr.mob...@googlemail.com

Hello,
I'm new to DJango, but I'm already lovin' it. I have a few questions
however - can someone offer any guidance, please?

Is the possible following in a template:
{ inherits ... }

{% for item in items %}

{% block A %}
   some text here
{% endblock A %}

{% block B %}
  some other text here
{% endblock %}

{% endfor %}

without there being another block wrapping the for loop? I've tried it
and I cannot get it working, but I think I remember some an example
doing so... I guess the general point of my question is  - do all
constructs have to be wrapped in a block?

Secondly, with {{ super }}, if I had the following in my base
template..

{% block Z %}
  TITLE:
  {% block A %}
  {% endblock A %}
DESC:
  {% block B %}
  {% endblock B %}
   THE END
{% endblock Z %}

and used an inheriting template thus, where there was only 1 item:

{ inherits ... }

{% block Z %}
{% for item in items %}

   {{ block.super }}

{% block A %}
   some text here
{% endblock A %}

   {{ block.super }}

{% block B %}
  some other text here
{% endblock %}

   {{ block.super }}

{% endfor %}

{% endblock Z %}

would I get something like..

  TITLE:
this is my only item
DESC:
a test item it is
   THE END

It may sound mad, but my experiments (under not so ideal conditions)
led me to think that super takes the gap *between* blocks, if you see
what I mean, as opposed to ignoring inner blocks and returning
*everything* in block Z. But I was having other issues and I could be
wrong?

Apologies if these  questions seem silly or obscure, I'm probably
trying to sprint before I can walk..

Many thanks,

Mobeus.

--~--~-~--~~~---~--~~
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: Error with PGSQL and not with SQLite with count() ?

2009-01-13 Thread Nicolas Steinmetz

alex.gay...@gmail.com a écrit :

> You're problem is you are testing identity with `is` when you want to
> test equality, which you should do with ==, this is likely causing the
> condition expect to pass to fail, and therefore your function returns
> None, which plainly isn't an HttpResponse object.

That's it, exactly. I did not think about checking "is" as it did not 
fail with SQLite.

Thanks a lot,
Nicolas


--~--~-~--~~~---~--~~
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: Getting url/host/domain info in settings.py

2009-01-13 Thread Tom Dyson

We do something like this with middleware in the Carbon Account[1]:

http://code.thecarbonaccount.com/trac/browser/trunk/calculator/middleware/autobrand.py

Hope this helps

Tom

[1] http://www.thecarbonaccount.com

On Jan 13, 3:10 pm, Donn  wrote:
> Hi,
> Can anyone help me get some extra info in settings.py?
>
> I have a domain that I want to point to various different Django apps
> depending on the 'hostname' portion of the domain name.
>
> ***.mydomain.com has (for ***):
> www
> comics
> stuff
>
> I want that first portion (www, comics, stuff) available in settings.py so I
> can tweak some vars for the apps within the project. How do I do that?
>
> I have tried:
> import socket
> blah=socket.gethostname()
>
> But that returns the hostname of the server, which does not seem related to
> the "virtual" names above. (I confess to being totally out of my depth when
> it comes to apache and so forth, but have I got it working to a point.)
>
> Thanks,
> \d
--~--~-~--~~~---~--~~
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: Error with PGSQL and not with SQLite with count() ?

2009-01-13 Thread alex.gay...@gmail.com

On Jan 13, 12:17 pm, Nicolas Steinmetz  wrote:
> Hello,
>
> The following view works well with SQLite but since I switched to
> PostgreSQL 8.3, I have the following error :
>
> ValueError at /start/
> The view start.views.index didn't return an HttpResponse object.
>
> Views is :
>
> def index(request):
>      """
>      Try to see if there is a default theme to display. For the matching
>      case, get all category for the given theme and for each category,
> display
>      related bookmarks
>      """
>      default_theme=Theme.objects.filter(is_default=True)
>      if default_theme.count() is 1:
>          theme=Theme.objects.get(is_default=True)
>          return HttpResponseRedirect('%s' % theme.slug)
>
> Model is :
>
> class Theme(models.Model):
>      """
>      A theme is a general point of view - within theme there would be
> category
>      and within category, there will be bookmarks
>      """
>      name = models.CharField(max_length=50)
>      slug = models.SlugField()
>      order = models.IntegerField()
>      is_default = models.BooleanField(default=False)
>
>      class Meta:
>          ordering = ['order']
>          verbose_name, verbose_name_plural = "Theme", "Themes"
>
>      def __unicode__(self):
>          return self.name
>
> I do not understand wht it fails or why it is dependant on the SGBD.
> Through the shell, the theme.slug is correct but I noticed that count()
> answers me 1L for PGSQL and just 1 for SQLite - could it explain my issue ?
>
> Regards,
> Nicolas

You're problem is you are testing identity with `is` when you want to
test equality, which you should do with ==, this is likely causing the
condition expect to pass to fail, and therefore your function returns
None, which plainly isn't an HttpResponse object.

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



Error with PGSQL and not with SQLite with count() ?

2009-01-13 Thread Nicolas Steinmetz

Hello,

The following view works well with SQLite but since I switched to 
PostgreSQL 8.3, I have the following error :

ValueError at /start/
The view start.views.index didn't return an HttpResponse object.

Views is :

def index(request):
 """
 Try to see if there is a default theme to display. For the matching
 case, get all category for the given theme and for each category, 
display
 related bookmarks
 """
 default_theme=Theme.objects.filter(is_default=True)
 if default_theme.count() is 1:
 theme=Theme.objects.get(is_default=True)
 return HttpResponseRedirect('%s' % theme.slug)

Model is :

class Theme(models.Model):
 """
 A theme is a general point of view - within theme there would be 
category
 and within category, there will be bookmarks
 """
 name = models.CharField(max_length=50)
 slug = models.SlugField()
 order = models.IntegerField()
 is_default = models.BooleanField(default=False)

 class Meta:
 ordering = ['order']
 verbose_name, verbose_name_plural = "Theme", "Themes"

 def __unicode__(self):
 return self.name

I do not understand wht it fails or why it is dependant on the SGBD. 
Through the shell, the theme.slug is correct but I noticed that count() 
answers me 1L for PGSQL and just 1 for SQLite - could it explain my issue ?

Regards,
Nicolas


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



Need URL help

2009-01-13 Thread May

My error is not being able to get the ID passed to the next
template.

The code:

http://dpaste.com/108580/

Thank you,

May




--~--~-~--~~~---~--~~
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: Decoupling between projects and app in 4-part tutorial.

2009-01-13 Thread dahpgjgamgan

On Jan 13, 1:51 am, Malcolm Tredinnick 
wrote:

> [...]
>
> Look, if you aren't going to be moving the applications around, the
> imports in the tutorial aren't horrible. It's the beginner's tutorial.

That's a big if, regarding that tutorial does stress decoupling
between project and apps on several occasions.

> People experienced in Python realise that import statements are
> flexible, so what's written in the tutorial is only a guide. People
> needing to follow every line of code in the tutorial and just learning
> Python don't need the extra baggage of worrying about that stuff in the
> first tutorial they do.

So making the imports don't include project name would make them more
worried?

--~--~-~--~~~---~--~~
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: What's the best configuration for Apache + mod_wsgi + nginx

2009-01-13 Thread lenin

On 9 ene, 19:18, Graham Dumpleton  wrote:
> You thus perhaps should not be doing video conversion within the same
> process, but executing a separate application to perform the
> conversion. Even then, you may need a queueing system or otherwise
> some way of restricting how many conversions can occur at a time,
> because even though performed by a separate application, it may still
> take up a lot of transient memory while running.

I'm using an ffmpeg call with commans.getoutput for the conversion, I
don't know if this means it runs in a separate process. I could put
another simple pure wsgi application running on some other port for
the conversion, but I don't know if this is what you mean.

> Also, from what I understand Django's abilities to serve up static
> files or streamed data, isn't that excellent. In particular, if
> hosting with WSGI capable server, it doesn't use the wsgi.file_wrapper
> extension. This extension ensures that files are streamed in blocks
> and the file is not read all into memory first in order to be able to
> send it. Also, if operating system provides it, Apache will use
> sendfile() or memory mapping techniques to return data in a much more
> efficient way. So, how exactly are you returning the converted data
> for Django to respond with?

At this moment I read the file and return the response from django, so
I guess this is a problem too. I think I could just serve the file
with nginx.

On 10 ene, 02:19, "Stefan Tunsch"  wrote:
> I was suggesting to give a shot of using ONLY nginx with Django.
> If you search in Google you'll find docs that help you setting that up.

Is this better than running django on apache? I mean, wouldn't nginx
be serving static files and running django at the same time? I thought
this was something to avoid.
--~--~-~--~~~---~--~~
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: What's the best configuration for Apache + mod_wsgi + nginx

2009-01-13 Thread lenin

On 9 ene, 19:18, Graham Dumpleton  wrote:
> You thus perhaps should not be doing video conversion within the same
> process, but executing a separate application to perform the
> conversion. Even then, you may need a queueing system or otherwise
> some way of restricting how many conversions can occur at a time,
> because even though performed by a separate application, it may still
> take up a lot of transient memory while running.

I'm using an ffmpeg call with commans.getoutput for the conversion, I
don't know if this means it runs in a separate process. I could put
another simple pure wsgi application running on some other port for
the conversion, but I don't know if this is what you mean.

> Also, from what I understand Django's abilities to serve up static
> files or streamed data, isn't that excellent. In particular, if
> hosting with WSGI capable server, it doesn't use the wsgi.file_wrapper
> extension. This extension ensures that files are streamed in blocks
> and the file is not read all into memory first in order to be able to
> send it. Also, if operating system provides it, Apache will use
> sendfile() or memory mapping techniques to return data in a much more
> efficient way. So, how exactly are you returning the converted data
> for Django to respond with?

At this moment I read the file and return the response from django, so
I guess this is a problem too. I think I could just serve the file
with nginx.

On 10 ene, 02:19, "Stefan Tunsch"  wrote:
> I was suggesting to give a shot of using ONLY nginx with Django.
> If you search in Google you'll find docs that help you setting that up.

Is this better than running django on apache? I mean, wouldn't nginx
be serving static files and running django at the same time? I thought
this was something to avoid.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Bad rendering of forms with tabular inlines

2009-01-13 Thread mathieu

Hi,

I'm trying to put a tabular inline for an admin form, but I'm getting
this:

http://picasaweb.google.com/mathieu.longtin/Screenshots#5290805795328611874

The ID field is overlapping the name of the entry.

I also tried to remove the id field from the form, since it shouldn't
be edited, but I get this error:

Exception Type: TemplateSyntaxError
Exception Value:Caught an exception while rendering: Key 'serv_id'
not found in Form

This is using today's trunk version or v1.02 of Django. It happens
either if I remove the serv_id field from the "fields" setting of the
inline admin class.

Please help!

-Mathieu


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



Getting url/host/domain info in settings.py

2009-01-13 Thread Donn

Hi,
Can anyone help me get some extra info in settings.py?

I have a domain that I want to point to various different Django apps 
depending on the 'hostname' portion of the domain name.

***.mydomain.com has (for ***):
www
comics
stuff

I want that first portion (www, comics, stuff) available in settings.py so I 
can tweak some vars for the apps within the project. How do I do that?

I have tried:
import socket
blah=socket.gethostname()

But that returns the hostname of the server, which does not seem related to 
the "virtual" names above. (I confess to being totally out of my depth when 
it comes to apache and so forth, but have I got it working to a point.)

Thanks,
\d

--~--~-~--~~~---~--~~
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 template language + greater than? does it exist?

2009-01-13 Thread Stratos

I don't think so, but you can do without it. Use {% ifequal %} and
initialize your variable in your views.

On Jan 12, 3:44 pm, rabbi  wrote:
> is there a greater than method in the template language?

--~--~-~--~~~---~--~~
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: can't get a model in the admin

2009-01-13 Thread Bobby Roberts

can anyone help me on this issue?
--~--~-~--~~~---~--~~
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: Slow view causing timeout errors

2009-01-13 Thread Roy

Is it dynamic data that needs to be accessed in real-time? If not, you
could cache it in your own database (using a cron job), so that the
view doesn't have to take too long.

On Jan 13, 10:53 am, Adam Tucker  wrote:
> I am working on a site where a page is loaded which replaces part of itself
> with another view using a simple ajax replacement (the load funciton in
> jQuery.) The view that is called iterates a loop anywhere from 3 to 10 times
> before getting to a render_to_response.  Unfortunately, the view pulls data
> from a very slow source which I can't control, so a single interation can
> take up to 30 seconds to complete, and after 60 seconds it times out.  I am
> looking for some pointers on ways that I could work around this, either by
> returning partial data at each iteration or some other method. Thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django template language + greater than? does it exist?

2009-01-13 Thread Matías Costa

Advice: Think twice before adding comparisons in the templates.
Conditions and all Bussines Rules(tm) *must* be in the model or the
view.

Time shows this advice punching your face.

On Tue, Jan 13, 2009 at 12:54 PM, Mengsong Chen  wrote:
> FYI,
>
> http://www.djangosnippets.org/snippets/12/
>
> On Tue, Jan 13, 2009 at 11:03 AM, Matías Costa 
> wrote:
>>
>> Fast answer: No
>>
>> Better awswer: No, but you can get one on djangosnippets.org
>>
>> On Mon, Jan 12, 2009 at 2:44 PM, rabbi  wrote:
>> >
>> > is there a greater than method in the template language?
>> > >
>> >
>>
>>
>
>
> >
>

--~--~-~--~~~---~--~~
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: new django user - no images appear on my site :(

2009-01-13 Thread django_fo...@codechimp.net

You know, its really sad to see the disdain like this thrust upon a
newbie.  We all know you are superior, and that your understanding of
Django and python is massive, and we bow to your intellect, but there
are hundreds if not thousands of pages of reading, and we newbs are
sorry if we don't read and consume and comprehend each and every last
page and morsel of information that you have so painstakingly labored
to make available, but this is what it means to be a novice.  If we
had the answers, you wouldn't need documentation or forums or mailing
groups.

Hitting us over the head with a big stick and telling us we are stupid
is NOT the right approach, and not how you get your beloved framework
into the main stream.

On Jan 12, 1:43 pm, Daniel Roseman 
wrote:
> On Jan 12, 6:35 pm, jazztpt  wrote:
>
>
>
> > I'm building my first django app and having a few problems in my dev
> > environment.  I have a couple of images that I want to use in my
> > base.html template.  I have tried various configurations, but none of
> > my images show up.  I've tried putting the images in /media, in /media/
> > img, and in the main project folder.  I have tried each of those paths
> > in my settings.py MEDIA_ROOT.  I have also tried importing os and
> > using relative paths in my settings.py file.  Here are some examples
> > of my settings:
>
> > # MEDIA_ROOT = '/Users/anna/Documents/Projects/autodiags/media/'
> > # IMAGE_ROOT = '/Users/anna/Documents/Projects/autodiags/media/img/'
> > MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')
> > MEDIA_URL = 'http://autodiagnostics.com/media/'
>
> > In my templates I am trying to access these with a regular img tag:
> > 
>
> > I have also tried src="/autodiag_title.jpg" and without the slash.
> > None of my images have ever shown up.  What am I doing wrong?
>
> > Thanks for your help!
>
> What you are doing wrong is failing to read the 
> documentation:http://docs.djangoproject.com/en/dev/howto/static-files/
>
> --
> 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: Change password form

2009-01-13 Thread Leslie Maclachlan
Thank you very much Roland - it is now working as required!

Best regards,
Leslie

Roland van Laar wrote:
> Leslie Maclachlan wrote:
>   
>> Hello everyone,
>>
>> I have written a template and view to allow users to change their password.
>> As soon as it hits the if pForm.is_valid, I get an error that there is a 
>> required field (username) missing - I don't understand why it is asking 
>> for this field, as I have not created it, but am assigning the username 
>> in the view.  Could someone please explain what I am missing.
>>   
>> 
>
> Look in the code at: /django/contrib/auth/forms.py and other files in 
> that directory
> for information about how django handles it.
>
>   
>> Regards,
>> Leslie
>>
>> The View:
>> class PasswordForm(forms.Form):
>>password = forms.CharField(max_length=20, widget=forms.PasswordInput())
>>password2 = forms.CharField(max_length=20, widget=forms.PasswordInput())
>>
>> @login_required
>> def Change_Password(request, next='/'):
>>message = 'Change Password'
>>pForm = PasswordForm()
>>
>>if request.method == 'POST':
>>if request.POST['submit'] == 'Change':
>>postDict = request.POST.copy()
>>   
>> 
> You are using LoginForm and not PasswordForm here.
>   
>>pForm = LoginForm(postDict)
>>if pForm.is_valid():
>>   
>> 
> No indent after the if statement.  This should raise an error.
>   
>>uPass1 = request.POST['password']
>>uPass2 = request.POST['password1']
>>if uPass1 == uPass2:
>>user = get_object_or_404(Employee.objects.get(name__exact 
>> = request.session['uid']))
>>#user = request.session['uid']
>>print 'User: ' + user
>>user.set_password(uPass1)
>>user.save()
>>return HttpResponseRedirect(next)
>>else:
>>message = 'Passwords dont match'
>>pForm = PasswordForm()
>>
>>return render_to_response('employee/change_password.html', {
>>  'pForm': pForm,
>>  'message': message })
>>
>> The Template:
>> {% extends "base_template.html" %}
>> {% block title %} Update Alert {% endblock %}
>> {% block top_menu %}
>> Home
>> {% endblock %}
>> {% block content %}
>> 
>> {{message}}
>> 
>> {{ pForm }}
>> 
>> 
>> 
>> {% endblock %}
>>   
>> 
>
> Regards,
>
> Roland van Laar
>
>
> >
>
>   


--~--~-~--~~~---~--~~
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 template language + greater than? does it exist?

2009-01-13 Thread Mengsong Chen
FYI,

http://www.djangosnippets.org/snippets/12/

On Tue, Jan 13, 2009 at 11:03 AM, Matías Costa wrote:

>
> Fast answer: No
>
> Better awswer: No, but you can get one on djangosnippets.org
>
> On Mon, Jan 12, 2009 at 2:44 PM, rabbi  wrote:
> >
> > is there a greater than method in the template language?
> > >
> >
>
> >
>

--~--~-~--~~~---~--~~
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: Change password form

2009-01-13 Thread Roland van Laar

Leslie Maclachlan wrote:
> Hello everyone,
>
> I have written a template and view to allow users to change their password.
> As soon as it hits the if pForm.is_valid, I get an error that there is a 
> required field (username) missing - I don't understand why it is asking 
> for this field, as I have not created it, but am assigning the username 
> in the view.  Could someone please explain what I am missing.
>   

Look in the code at: /django/contrib/auth/forms.py and other files in 
that directory
for information about how django handles it.

> Regards,
> Leslie
>
> The View:
> class PasswordForm(forms.Form):
>password = forms.CharField(max_length=20, widget=forms.PasswordInput())
>password2 = forms.CharField(max_length=20, widget=forms.PasswordInput())
>
> @login_required
> def Change_Password(request, next='/'):
>message = 'Change Password'
>pForm = PasswordForm()
>
>if request.method == 'POST':
>if request.POST['submit'] == 'Change':
>postDict = request.POST.copy()
>   
You are using LoginForm and not PasswordForm here.
>pForm = LoginForm(postDict)
>if pForm.is_valid():
>   
No indent after the if statement.  This should raise an error.
>uPass1 = request.POST['password']
>uPass2 = request.POST['password1']
>if uPass1 == uPass2:
>user = get_object_or_404(Employee.objects.get(name__exact 
> = request.session['uid']))
>#user = request.session['uid']
>print 'User: ' + user
>user.set_password(uPass1)
>user.save()
>return HttpResponseRedirect(next)
>else:
>message = 'Passwords dont match'
>pForm = PasswordForm()
>
>return render_to_response('employee/change_password.html', {
>  'pForm': pForm,
>  'message': message })
>
> The Template:
> {% extends "base_template.html" %}
> {% block title %} Update Alert {% endblock %}
> {% block top_menu %}
> Home
> {% endblock %}
> {% block content %}
> 
> {{message}}
> 
> {{ pForm }}
> 
> 
> 
> {% endblock %}
>   

Regards,

Roland van Laar


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



Change password form

2009-01-13 Thread Leslie Maclachlan

Hello everyone,

I have written a template and view to allow users to change their password.
As soon as it hits the if pForm.is_valid, I get an error that there is a 
required field (username) missing - I don't understand why it is asking 
for this field, as I have not created it, but am assigning the username 
in the view.  Could someone please explain what I am missing.

Regards,
Leslie

The View:
class PasswordForm(forms.Form):
   password = forms.CharField(max_length=20, widget=forms.PasswordInput())
   password2 = forms.CharField(max_length=20, widget=forms.PasswordInput())

@login_required
def Change_Password(request, next='/'):
   message = 'Change Password'
   pForm = PasswordForm()

   if request.method == 'POST':
   if request.POST['submit'] == 'Change':
   postDict = request.POST.copy()
   pForm = LoginForm(postDict)
   if pForm.is_valid():
   uPass1 = request.POST['password']
   uPass2 = request.POST['password1']
   if uPass1 == uPass2:
   user = get_object_or_404(Employee.objects.get(name__exact 
= request.session['uid']))
   #user = request.session['uid']
   print 'User: ' + user
   user.set_password(uPass1)
   user.save()
   return HttpResponseRedirect(next)
   else:
   message = 'Passwords dont match'
   pForm = PasswordForm()

   return render_to_response('employee/change_password.html', {
 'pForm': pForm,
 'message': message })

The Template:
{% extends "base_template.html" %}
{% block title %} Update Alert {% endblock %}
{% block top_menu %}
Home
{% endblock %}
{% block content %}

{{message}}

{{ pForm }}



{% endblock %}

--~--~-~--~~~---~--~~
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: Overloading ModelFormMetaclass, to implement a custom __init__() method and use ModelForm in a factory

2009-01-13 Thread James PIC

On Tue, Jan 13, 2009 at 11:57 AM, James PIC  wrote:
> That's what i'm actually trying to do:
>
> # todo : get a more descriptive FC prefix than "jpic"
> class JpicModelFormMetaclass(ModelFormMetaclass):
>"""
>Inherit from this, then use this new keyword argument
>'jpic_field_options' with a dict of dicts such as:
>{
>'field_name_that_is_m2m': {
>'queryset': aqueryset,
>},
>'field_name_that_is_fk': {
>'queryset': anotherqueryset,
>},
>}
>
>This solves the problem of using a queryset made in the view
>as choices for a M2M/FK field ...
>"""
>def __init__(self, *args, **kwargs):
>jpic_field_options = False
>if 'jpic_field_options' in kwargs.keys():
>jpic_field_options = kwargs.pop('jpic_field_options')
>super(JpicModelFormMetaclass, self).__init__(*args, **kwargs)
>if not jpic_field_options:
>return
>for field, args in jpic_field_options.items():
>if field not in self.fields:
>continue
>for arg, value in args.items():
>setattr(self.fields[field], arg, value)
>
> class JpicModelForm(ModelForm):
>__metaclass__ = JpicModelFormMetaclass
>
> This is how i tryed to copy the factory method to use my metaclass:
>
>def get_form_class(self):
># HACK: we should be able to construct a ModelForm without creating
># and passing in a temporary inner class
>class Meta:
>pass
>setattr(Meta, 'model', self.model_class)
>setattr(Meta, 'fields', self.get_fields())
>if Group.objects.get(name='Consultants') in
> self.request.user.groups.all():
>class_name = self.model_class_name + 'ConsultantForm'
>else:
>class_name = self.model_class_name + 'ClientForm'
>return JpicModelFormMetaclass(class_name.encode(),
> (JpicModelForm,), {'Meta': Meta,
>'formfield_callback': lambda
> f: f.formfield()})
>
> This error is thrown:
>
> Traceback:
> File "/home/python/libs/django/core/handlers/base.py" in get_response
>  86. response = callback(request, *callback_args,
> **callback_kwargs)
> File "/home/jpic/sites/devangels/django_tickets/views.py" in root
>  54. return view_class().root(request, url, action, dest_class)
> File "/home/jpic/sites/devangels/django_tickets/views.py" in root
>  210. self.formobj = self.get_form()
> File "/home/jpic/sites/devangels/django_tickets/views.py" in get_form
>  97. form = form_class(instance=self.model,
> jpic_field_options=options)
>
> Exception Type: TypeError at /component/1/ticket/create/
> Exception Value: __init__() got an unexpected keyword argument
> 'jpic_field_options'
>
> Please don't mind the possible problems of my 'formfield_callback'
> argument, i'll fix that ...

Apparently, i should have used the snippet directly (no
JpicModelFormMetaclass) and this factory code:
return ModelFormMetaclass(class_name.encode(), (JpicModelForm,), {'Meta': Meta,
 'formfield_callback': lambda f: f.formfield()})

As simple as that ... Case closed, sorry for posting before reading:
http://www.ibm.com/developerworks/linux/library/l-pymeta.html

Regards, James.

--~--~-~--~~~---~--~~
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: dependency between forms

2009-01-13 Thread uber.ubiwanken...@gmail.com

Thank you Malcolm,
it's not a problem to write customized extensions but I wanted to be
sure that it's the only way to do it.

Regards,
Giorgio

On Jan 13, 1:58 am, Malcolm Tredinnick 
wrote:
> On Mon, 2009-01-12 at 02:48 -0800, uber.ubiwanken...@gmail.com wrote:
> > Hi all,
> > I have 3 models: model1, model2, model3.
>
> > model2 depends on model1 and model3 depends on model2 (depend means
> > that have a foreignkey)
>
> > In the admin interface I don't want to include model3 in the same page
> > of model1 and I don't want to see model2 or model3 links to the change
> > list in my index page.
> > I'd like to manage model2 in the same page of model1 and model3 in
> > another page.
> > How can I do it?
>
> The admin interface doesn't provide multi-page editing or change forms.
> It provides a simple link to a single page for editing a model (possibly
> with inline to other models).
>
> You could write customised extensions to the admin class and its views
> to handle this, but it's going to require looking at the admin code and
> doing a bit of thinking. It's purely extension territory, not part of
> the built-in use-case.
>
> 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django template language + greater than? does it exist?

2009-01-13 Thread Matías Costa

Fast answer: No

Better awswer: No, but you can get one on djangosnippets.org

On Mon, Jan 12, 2009 at 2:44 PM, rabbi  wrote:
>
> is there a greater than method in the template language?
> >
>

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



Overloading ModelFormMetaclass, to implement a custom __init__() method and use ModelForm in a factory

2009-01-13 Thread James PIC

Hello everybody,

This snippet is working fine, i used this instead of adding custom
arguments when overloading each of my ModelForm's constructore to keep
the same __init__() signature.
http://www.djangosnippets.org/snippets/1272/

Currently refactoring, it makes sense to use a factory in my case.
I tryed to copy the pattern of forms.model.modelform_factory, but now
it seems that my __init__() method is not overloading ModelForm
anymore

Recall the code of forms.model.modelform_factory:

/trunk/django/forms/models.py
326 def modelform_factory(model, form=ModelForm, fields=None, exclude=None,
327formfield_callback=lambda f: f.formfield()):
328 # HACK: we should be able to construct a ModelForm without creating
329 # and passing in a temporary inner class
330 class Meta:
331 pass
332 setattr(Meta, 'model', model)
333 setattr(Meta, 'fields', fields)
334 setattr(Meta, 'exclude', exclude)
335 class_name = model.__name__ + 'Form'
336 return ModelFormMetaclass(class_name, (form,), {'Meta': Meta,
337   'formfield_callback': formfield_callback})

That's what i'm actually trying to do:

# todo : get a more descriptive FC prefix than "jpic"
class JpicModelFormMetaclass(ModelFormMetaclass):
"""
Inherit from this, then use this new keyword argument
'jpic_field_options' with a dict of dicts such as:
{
'field_name_that_is_m2m': {
'queryset': aqueryset,
},
'field_name_that_is_fk': {
'queryset': anotherqueryset,
},
}

This solves the problem of using a queryset made in the view
as choices for a M2M/FK field ...
"""
def __init__(self, *args, **kwargs):
jpic_field_options = False
if 'jpic_field_options' in kwargs.keys():
jpic_field_options = kwargs.pop('jpic_field_options')
super(JpicModelFormMetaclass, self).__init__(*args, **kwargs)
if not jpic_field_options:
return
for field, args in jpic_field_options.items():
if field not in self.fields:
continue
for arg, value in args.items():
setattr(self.fields[field], arg, value)

class JpicModelForm(ModelForm):
__metaclass__ = JpicModelFormMetaclass

This is how i tryed to copy the factory method to use my metaclass:

def get_form_class(self):
# HACK: we should be able to construct a ModelForm without creating
# and passing in a temporary inner class
class Meta:
pass
setattr(Meta, 'model', self.model_class)
setattr(Meta, 'fields', self.get_fields())
if Group.objects.get(name='Consultants') in
self.request.user.groups.all():
class_name = self.model_class_name + 'ConsultantForm'
else:
class_name = self.model_class_name + 'ClientForm'
return JpicModelFormMetaclass(class_name.encode(),
(JpicModelForm,), {'Meta': Meta,
'formfield_callback': lambda
f: f.formfield()})

This error is thrown:

Traceback:
File "/home/python/libs/django/core/handlers/base.py" in get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "/home/jpic/sites/devangels/django_tickets/views.py" in root
  54. return view_class().root(request, url, action, dest_class)
File "/home/jpic/sites/devangels/django_tickets/views.py" in root
  210. self.formobj = self.get_form()
File "/home/jpic/sites/devangels/django_tickets/views.py" in get_form
  97. form = form_class(instance=self.model,
jpic_field_options=options)

Exception Type: TypeError at /component/1/ticket/create/
Exception Value: __init__() got an unexpected keyword argument
'jpic_field_options'

Please don't mind the possible problems of my 'formfield_callback'
argument, i'll fix that ...

I asked on IRC and failed to fix it. Any tip will be appreciated, note
that my understanding of metaclasses is currently limited so that's
why i tryed to "just copy and hack".
There might be a better way.

Regards, James.

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



MultipleChoiceField initial data

2009-01-13 Thread Thierry

This doesn't seem to work:
auto_open_choices = forms.MultipleChoiceField(choices=( ('google',
'Google'), ('msn', 'MSN'), ('yahoo', 'Yahoo')), required=False,
initial=['google'])

>From what i read in the discussions here it should...
What am i doing wrong?
--~--~-~--~~~---~--~~
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: Slow view causing timeout errors

2009-01-13 Thread Daniel Roseman

On Jan 13, 2:53 am, Adam Tucker  wrote:
> I am working on a site where a page is loaded which replaces part of itself
> with another view using a simple ajax replacement (the load funciton in
> jQuery.) The view that is called iterates a loop anywhere from 3 to 10 times
> before getting to a render_to_response.  Unfortunately, the view pulls data
> from a very slow source which I can't control, so a single interation can
> take up to 30 seconds to complete, and after 60 seconds it times out.  I am
> looking for some pointers on ways that I could work around this, either by
> returning partial data at each iteration or some other method. Thanks!

The basic jQuery.ajax() method has an optional timeout parameter which
allows you to increase the default timeout on a per-request basis:
http://docs.jquery.com/Ajax/jQuery.ajax#options
Does that help?
--
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: ModelMultipleChoiceField in admin interface

2009-01-13 Thread Daniel Roseman

On Jan 13, 8:26 am, Matias Surdi  wrote:
> hmm... Not really... from your point of view, think about this:  I want
> to edit the children from the parent admin view, and *not* assign
> parents to children from children's admin view
>
> Do you see? the relation is the same, but from the other side.
>
> I think I'm going to need a custom field/widget for this.
>
> Thanks for your help.

Yes, that's why I say you have the relationship the wrong way round.
With it the right way round, and with inlines enabled, 'editing the
children from the parent admin' is exactly what you do. The way you
have it, you *can't* have multiple children to one parent, custom
widget or not - the underlying database models don't let you.
--
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: Path problem with jsi18n - internationalization

2009-01-13 Thread Tipan

>
> That's strange, are you succesfully using another component of Django
> i18n infrastructure in the same application?. De you have USE_I18N set to
> True in the settings file you are using?
>

Yes. The use_i18n is set to true and I've successfully translated most
of my pages, created the .po files with makemessages etc. It's just
the Javascript library element I can't seem to get working.

I just assumed I'd got the wrong path in the template to access the
jsi18n javascript.

Tim
--~--~-~--~~~---~--~~
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: Validating imported data

2009-01-13 Thread Eugene Mirotin

My favourite solution for this task is the following:
1) you create the "simple" form with the file upload and submit it
2) in submit handler you parse the file and create the "preview"
formset (is inline formset, form example) filling it with the parsed
data. If the file cannot be parsed, you can return to the user with
the same simple form and the error message
3) otherwise, you show the preview form to the user allowing him (if
necessary) to fix some data (of course, it's optional)
4) when the user confirms the data (submits this preview form), you
can process the plain formset with the regular handler and make custom
"cleaning" with all neccessary validations

All of these can be done on the same URL by adding some hidden field
that indicates the type of the form being submitted, or with other
similar trick.

Gene

On Jan 13, 5:42 am, Peter  wrote:
> Hello,
>
> I'm trying to build an application with django that supports data
> import from a CSV. The problem that I'm having is validating the data.
> I know how to validate data that comes from a form.
>
> However, in my case the user is using a CSV file for imput instead a
> form. Is there a way that I can validate the data without using a
> form? Or is there I can interface with the form validation with using
> a form?
>
> Thanks,
>
> ~Peter
--~--~-~--~~~---~--~~
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: ModelMultipleChoiceField in admin interface

2009-01-13 Thread Matias Surdi

Daniel Roseman escribió:
> On Jan 12, 5:38 pm, Matias Surdi  wrote:
>> Hi,
>>
>> I've two models related by a ForeignKey field.
>>
>> I'd like to have the possibility of adding child objects (side "One" of
>> the relation) from the admin interface of the parent ("Many" side of the
>> relation).
>>
>> Example:
>>
>> class Child(models.Model):
>> name = models.CharField(max_length=10)
>>
>> class Parent(models.Model):
>>name = models.CharField(max_length=10)
>>childs = models.ForeignKey(Child)
>>
>> In this example, a dropdown is shown on the admin that let's me choose
>> just one child or create another if the one I need doesn't exist.
>>
>> The point is, how can I have a list that lets me choose more than one
>> child and create them as needed?
>>
>> This is not a Many to Many relation, because every child belongs just to
>> one parent, but the widget I need is like the one from that kind of
>> relation in the admin interface (ie: Groups selection in the User edit
>> admin view).
>>
>> Thanks you very much.
> 
> You have the relationship the wrong way round. The ForeignKey belongs
> on the child, since presumably a child can only have one parent but a
> parent can have multiple children.
> 
> Once you've sorted that out, you can then use inline forms on the
> Parent admin to add multiple children to a single parent. See:
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects
> 
> --
> DR.
> > 
> 

hmm... Not really... from your point of view, think about this:  I want 
to edit the children from the parent admin view, and *not* assign 
parents to children from children's admin view

Do you see? the relation is the same, but from the other side.

I think I'm going to need a custom field/widget for this.

Thanks for your help.

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