Re: Tables with same schema

2009-04-30 Thread Ramashish Baranwal

>
> > I want to create several tables with same schema. This is to partition
> > the data into different tables. Apart from having model classes with
> > same definition, is there another way to do it?
>
> > Here is a trivial example that duplicates the class definition-
>
> > class Person(models.Model):
> >    first = models.CharField(max_length=16)
> >    last = models.CharField(max_length=16)
>
> > class Person2(models.Model):
> >    first = models.CharField(max_length=16)
> >    last = models.CharField(max_length=16)
>
> > Apart from the code duplication, the above doesn't capture the intent
> > that the two models represent tables with same schema. I'm looking for
> > something like-
>
> > class Person2(Person):
> >    pass
>
> > The above however doesn't work.
> > Any idea?
>
> > Thanks,
> > Ram
>
> I'd do it with one class that has all the common fields that is an abstract
> class(check the docs for this).  And then just 2 classes that subclass it.
> This should do just what you want.
>
Hi Alex,

Thanks for the quick reply. Abstract class fits the need perfectly.
However, I am using Django 0.96 where abstract class functionality is
not available. I can't upgrade  Django currently.
Any other way?

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



Re: help needed: apache httpd.conf and urls

2009-04-30 Thread zayatzz

Thanks!

Its working just fine now :)

Alan.

On Apr 30, 10:37 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-04-30 at 12:27 -0700, zayatzz wrote:
> > Hello
>
> > I have this in my template :
> > 
>
> > settings file is following:
> > MEDIA_ROOT = '/var/www/media/'
> > MEDIA_URL = "http://localhost/media/;
>
> > when i go to the webpage then the stuff that i get from server says
> > 
>
> > Even when i replace {{ MEDIA_URL }} with anything else i still get
> > this in browser:
> > 
>
> > Why?
>
> The MEDIA_URL variable will only be populated in your template if the
> template is passed a RequestContext instance as the context (not just a
> Context, because you want the context processors to be executed) *and*
> is you have the "media" context processor in your
> TEMPLATE_CONTEXT_PROCESSORS list (which it will be by default).
>
> I would suspect you've forgotten to pass a RequestContext to
> render_to_response() or whatever call you're using in your view.
>
> 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
-~--~~~~--~~--~--~---



Choices validation on model fields

2009-04-30 Thread Jeremy Epstein

Hi,

I have a model with a number of fields that use Django's 'choices'
attribute, to limit the allowed values of those fields to a
pre-defined list. I assumed that the Model system would validate my
fields when I create or update them, to ensure that invalid choices
weren't being assigned to fields. However, it seems that this doesn't
happen. I'm aware that such validation occurs at the form layer, but
I'd really like it to occur at the model layer as well.

I'm very new to Django (and Python) - I only really started using it
about two weeks ago. I haven't even started working with templates
yet, as I want to understand the model system and to get my models
stable before moving into the front-end.

I found http://code.djangoproject.com/ticket/6845 (Model validation
and its propagation to ModelForms), so I know that people are working
on this for future versions of Django. It will be great when model
validation is built-in for future versions of Django. However, I
really wanted to see if it was possible to add such validation
manually for Django 1.0.x.

I wrote a custom __setattr__ handler and exception class, to implement
choice validation for my model. I'm putting my code here to get
feedback about whether I've taken the right approach here, and whether
I've followed the Django conventions (as this is my first piece of
Django code), and also for the benefit of anyone else who would like
to implement this in their models. Feel free to copy and use this in
your own apps:

file 'bar/foo/models.py':

-

from django.db import models

FOO_CHOICES = (
('this', 'This'),
('that', 'That'),
('the other', 'The other'),
)

class Foo(models.Model):
"""
Foo is a fuuber model.
"""
name = models.CharField(max_length=255)
foo_type = models.CharField(max_length=255, choices=FOO_CHOICES)

def __unicode__(self):
return self.name

def __setattr__(self, name, value):
"""
Whenever foo_type is set, it is validated to ensure that it is
one of the allowed pre-defined choices. This method fires when a foo
object is instantiated (hence no need to duplicate it in __init__),
and also whenever foo_type is modified.
"""
choice_validator = ChoiceValidator()

if name == 'foo_type':
choice_validator.validate_choice(value, FOO_CHOICES, name)

models.Model.__setattr__(self, name, value)

class ChoiceValidator:
"""
Validation that a model's fields match that field's allowed choices.
"""

def validate_choice(self, choice_provided, choices_available, choice_type):
"""
Checks that the provided choice matches one of the choices
available. If not, an InvalidChoiceError exception is raised.
"""
is_valid_choice = False
valid_choices = []

# choices_available is a tuple of tuples. We convert it into a
list, for easy printing in the exception message.
for choice in choices_available:
valid_choices.append(choice[0])

# And while we're in the loop, we perform the actual
matching check. Don't break inside this condition, because we always
want all the choices appended to valid_choices.
if choice[0] == choice_provided:
is_valid_choice = True

if not is_valid_choice:
raise InvalidChoiceError(choice_provided, valid_choices,
choice_type)

class InvalidChoiceError(Exception):
"""
Raised when an attempt is made to set an invalid choice, when
setting a model field that has a list of allowed choices.
"""

def __init__(self, choice_provided, valid_choices, choice_type):
self.choice_provided = choice_provided
self.valid_choices = valid_choices
self.choice_type = choice_type

def __str__(self):
return 'invalid %s \'%s\', must be one of: \'%s\'' %
(self.choice_type, self.choice_provided, '\',
\''.join(self.valid_choices))

-

How to test it:

$ python manage.py shell

>>> from bar.foo.models import Foo
>>> foo1 = Foo(name='Foo Hoo', foo_type='that')

(works fine, 'that' is a valid choice)

>>> foo2 = Foo(name='Foo Too', foo_type='not this')

(prints a traceback, and this message:)

InvalidChoiceError: invalid foo_type 'not this', must be one of:
'this', 'that', 'the other'

Cheers,

Jeremy Epstein
http://www.greenash.net.au/

--~--~-~--~~~---~--~~
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: Tables with same schema

2009-04-30 Thread Alex Gaynor
On Fri, May 1, 2009 at 1:21 AM, Ramashish Baranwal <
ramashish.li...@gmail.com> wrote:

>
> Hi,
>
> I want to create several tables with same schema. This is to partition
> the data into different tables. Apart from having model classes with
> same definition, is there another way to do it?
>
> Here is a trivial example that duplicates the class definition-
>
> class Person(models.Model):
>first = models.CharField(max_length=16)
>last = models.CharField(max_length=16)
>
> class Person2(models.Model):
>first = models.CharField(max_length=16)
>last = models.CharField(max_length=16)
>
> Apart from the code duplication, the above doesn't capture the intent
> that the two models represent tables with same schema. I'm looking for
> something like-
>
> class Person2(Person):
>pass
>
> The above however doesn't work.
> Any idea?
>
> Thanks,
> Ram
>
> >
>
I'd do it with one class that has all the common fields that is an abstract
class(check the docs for this).  And then just 2 classes that subclass it.
This should do just what you want.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Tables with same schema

2009-04-30 Thread Ramashish Baranwal

Hi,

I want to create several tables with same schema. This is to partition
the data into different tables. Apart from having model classes with
same definition, is there another way to do it?

Here is a trivial example that duplicates the class definition-

class Person(models.Model):
first = models.CharField(max_length=16)
last = models.CharField(max_length=16)

class Person2(models.Model):
first = models.CharField(max_length=16)
last = models.CharField(max_length=16)

Apart from the code duplication, the above doesn't capture the intent
that the two models represent tables with same schema. I'm looking for
something like-

class Person2(Person):
pass

The above however doesn't work.
Any idea?

Thanks,
Ram

--~--~-~--~~~---~--~~
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: slug field not populated on form save

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 23:46 -0300, Gabriel wrote:
> I have a model with a custom field:

[...]
> class AutoSlugField(fields.SlugField):
> def __init__(self, prepopulate_from, force_update = False, *args,
> **kwargs):
> self.prepopulate_from = prepopulate_from
> self.force_update = force_update
> super(AutoSlugField, self).__init__(*args, **kwargs)
> 
> def pre_save(self, model_instance, add):
> if self.prepopulate_from:
> return slugify(model_instance, self, getattr(model_instance,
> self.prepopulate_from), self.force_update)
> else:
> return super(AutoSlugField, self).pre_save(model_instance, add)

[...]
> when I call form.save() it returns a Project instance without the slug
> value, although the field is correctly saved into the database.
> 
> Any idea why this is happening ?

The Model class calls pre_save() to work out the value to save into the
database. That's working correctly for you, as you've noticed: the right
value is being saved.

Some Field subclasses in Django also use pre_save() as a way to
normalise the value in the Model attribute. It sounds like you want that
to happen -- you would be normalising it from "nothing at all" to the
correct value. In that case, you need to call setattr() to set the
attribute value. That's why model_instance is passed as a parameter to
pre_save(). You could write something like this:

def pre_save(self, model_instance, add):
   if self.prepopulate_from:
  value = slugify(model_instance, self,
getattr(model_instance, self.prepopulate_from),
self.force_update)
   else:
  value = super(AutoSlugField,
self).pre_save(model_instance,
 add)
   setattr(model_instance, self.attname, value)
   return value

Does that clear things up?

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: ManyToMany query on all()?

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 19:26 -0700, jeff wrote:
> This seems like it should be easy, but it's got me stumped.
> 
> Here's a model from the Django examples:
> 
> class Entry(models.Model):
> blog = models.ForeignKey(Blog)
> headline = models.CharField(max_length=255)
> body_text = models.TextField()
> pub_date = models.DateTimeField()
> authors = models.ManyToManyField(Author)
> n_comments = models.IntegerField()
> n_pingbacks = models.IntegerField()
> rating = models.IntegerField()
> 
> Is there a single query to get all distinct authors for all entries in
> a certain blog?  All the examples demonstrate how to get all authors
> for a single entry.

Assuming "b" is the blog object you're trying to match, you can do this:

Authors.objects.filter(entry__blog=b)

I'm not completely sure how to explain how to arrive at that solution,
I'm afraid. Presumably you had seen something that looked like
Author.objects.filter(entry=e) for some particular entry "e". This
version is the same thing, but with one extra traversal of a relation
between models. If you knew the blog name, "n", and didn't happen to
have the Blog object, "b", you could write:

Author.objects.filter(entry__blog__name=n)

Every field connection adds another double-underscore piece to the
filter.

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



slug field not populated on form save

2009-04-30 Thread Gabriel

I have a model with a custom field:

class Project(models.Model):
slug = fields.AutoSlugField(max_length=50, unique=True,
editable=False, prepopulate_from="name", force_update=False)
name = models.CharField(unique=True, verbose_name=_('Name'),
max_length=50, help_text=_('The project name to show to the users'))


class AutoSlugField(fields.SlugField):
def __init__(self, prepopulate_from, force_update = False, *args,
**kwargs):
self.prepopulate_from = prepopulate_from
self.force_update = force_update
super(AutoSlugField, self).__init__(*args, **kwargs)

def pre_save(self, model_instance, add):
if self.prepopulate_from:
return slugify(model_instance, self, getattr(model_instance,
self.prepopulate_from), self.force_update)
else:
return super(AutoSlugField, self).pre_save(model_instance, add)


and a bounded form:

class ProjectForm(forms.ModelForm):
class Meta:
model = Project

when I call form.save() it returns a Project instance without the slug
value, although the field is correctly saved into the database.

Any idea why this is happening ?

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



ManyToMany query on all()?

2009-04-30 Thread jeff

This seems like it should be easy, but it's got me stumped.

Here's a model from the Django examples:

class Entry(models.Model):
blog = models.ForeignKey(Blog)
headline = models.CharField(max_length=255)
body_text = models.TextField()
pub_date = models.DateTimeField()
authors = models.ManyToManyField(Author)
n_comments = models.IntegerField()
n_pingbacks = models.IntegerField()
rating = models.IntegerField()

Is there a single query to get all distinct authors for all entries in
a certain blog?  All the examples demonstrate how to get all authors
for a single entry.

Thanks
Jeff
--~--~-~--~~~---~--~~
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: Template help

2009-04-30 Thread AlexK

On May 1, 9:47 am, Alex Gaynor  wrote:
> On Thu, Apr 30, 2009 at 7:45 PM, AlexK  wrote:
>
> > Hi all,
>
> > I would just like some comments about something particular in my
> > template. I'm concerned there may be a better way of doing what I am
> > doing. You will see why when you look at my code.
>
> >http://dpaste.com/39858/
>
> > I am mainly concerned with lines 3 to 7. Ignore that I should use a
> > variable for "Submit Query". These lines are being repeated in every
> > template that I have. Especially the user/profile bit.
>
> > Advice is welcome, thank you.
> > -Alex
>
> If the text is in every single page I might use a context processor(or just
> include a different template with that text) just because I'm lazy and that
> makes my job easier if I ever need to change the text, but theres nothing
> wrong with having the same text more than once.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero- Hide quoted text -
>
> - Show quoted text -

Thanks for your prompt reply Alex :)

I read up a bit on context processors here:
http://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-context-processors
and here
http://www.djangobook.com/en/2.0/chapter09/

The djangobook spelled it out very nicely for me :)

"Each view passes the same three variables — app, user and ip_address
— to its template. Wouldn’t it be nice if we could remove that
redundancy?
RequestContext and context processors were created to solve this
problem. Context processors let you specify a number of variables that
get set in each context automatically — without you having to specify
the variables in each render_to_response() call. The catch is that you
have to use RequestContext instead of Context when you render a
template."

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



Re: url template tag help

2009-04-30 Thread Margie

Oh, and one other thing I will add is that if you do find an import
error, you sometimes (maybe always?)  need to then restart the
server.

I can't explain any of this, but I've been thinking about your
question since you posted it beause I know this type of error happens
to me a lot (and indeed has been hard to debug), but I couldn't put my
finger on remembering what my solution was.  It just happened, I fixed
my syntax error, but still got reverseMatch error message.  Restarted
the server, and it was gone.

Margie

On Apr 30, 4:56 pm, Margie  wrote:
> Have you confirmed that you don't have any python syntax errors in any
> of your .py files, including urls.py?
>
> I thinkt that when reverse gets evaluated, it may be importing files
> at that time.  If one of the imports encounters a syntax error, i
> think that you will in some cases just get an error that indicates the
> reverse failed.  I got this just now, in fact.  I would recommend
> importing all of your files from within manage.py shell, ie:
>
> manage.py shell
> from app.urls import *
> from app.models import *
>
> I have encountered many errors  that were hard to debug based on the
> error message in the browser, but it becomes obvious when you import
> the files at the prompt.
>
> Margie
>
> On Apr 30, 8:52 am, Julián C. Pérez  wrote:
>
> > anyone??
> > i can't get around this...
> > and i don't want to hard-code the urls in templates either
> > :(
>
> > On 30 abr, 09:20, Julián C. Pérez  wrote:
>
> > > by now, i'll try to found some other way to create dynamic urls based
> > > on the views...
> > > maybe using a custom template tag
>
> > > On 29 abr, 21:52, Julián C. Pérez  wrote:
>
> > > > uhhh
> > > > i tried but nooo... your suggestion doesn't work...
> > > > let me show you 2 versions of error...
>
> > > > 1. "Reverse for 'proyName.view_aboutPage' with arguments '()' and
> > > > keyword arguments '{}' not found."
> > > > settings:
> > > > # in proyName.packages.appName.urls.py:
> > > >  ... url(r'^about/$', 'view_aboutPage',
> > > > name='proyName.link_aboutPage'), ...
> > > > # in the template (about.html):
> > > > ... show 'about' ...
>
> > > > 2. "Reverse for '' with
> > > > arguments '()' and keyword arguments '{}' not found."
> > > > settings:
> > > > # in proyName.packages.appName.urls.py:
> > > >  ... url(r'^about/$', 'view_aboutPage', name='link_aboutPage'), ... #
> > > > also fails with "name='proyName.link_aboutPage'"
> > > > # in the template (about.html):
> > > > ... show
> > > > 'about' ...
>
> > > > by the way, the view loks like:
> > > > # in proyName.packages.appName.views.py:
> > > > ...
> > > > def view_aboutPage(request):
> > > >         return render_to_response('pages/about.html',
> > > > context_instance=RequestContext(request))
> > > > ...
>
> > > > what can i do?? honestly, i do not know...
> > > > thanks!
>
> > > > On Apr 29, 12:37 pm, Kevin Audleman  wrote:
>
> > > > > You might be able to solve your problem by changing the name attribute
> > > > > of your URL to include  "proyName":
>
> > > > > url(r'^about/$', 'view_aboutPage', name='proyName.view_aboutPage'),
>
> > > > > ---
>
> > > > > The error message is telling you exactly what it's looking for, after
> > > > > all:
>
> > > > > the error:
> > > > > "Reverse for 'proyName.view_aboutPage' with arguments '()' and keyword
> > > > > arguments '{}' not found."
>
> > > > > I have solved most of my URL problems this way.
>
> > > > > Cheers,
> > > > > Kevin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: url template tag help

2009-04-30 Thread Margie

Have you confirmed that you don't have any python syntax errors in any
of your .py files, including urls.py?

I thinkt that when reverse gets evaluated, it may be importing files
at that time.  If one of the imports encounters a syntax error, i
think that you will in some cases just get an error that indicates the
reverse failed.  I got this just now, in fact.  I would recommend
importing all of your files from within manage.py shell, ie:

manage.py shell
from app.urls import *
from app.models import *

I have encountered many errors  that were hard to debug based on the
error message in the browser, but it becomes obvious when you import
the files at the prompt.

Margie

On Apr 30, 8:52 am, Julián C. Pérez  wrote:
> anyone??
> i can't get around this...
> and i don't want to hard-code the urls in templates either
> :(
>
> On 30 abr, 09:20, Julián C. Pérez  wrote:
>
> > by now, i'll try to found some other way to create dynamic urls based
> > on the views...
> > maybe using a custom template tag
>
> > On 29 abr, 21:52, Julián C. Pérez  wrote:
>
> > > uhhh
> > > i tried but nooo... your suggestion doesn't work...
> > > let me show you 2 versions of error...
>
> > > 1. "Reverse for 'proyName.view_aboutPage' with arguments '()' and
> > > keyword arguments '{}' not found."
> > > settings:
> > > # in proyName.packages.appName.urls.py:
> > >  ... url(r'^about/$', 'view_aboutPage',
> > > name='proyName.link_aboutPage'), ...
> > > # in the template (about.html):
> > > ... show 'about' ...
>
> > > 2. "Reverse for '' with
> > > arguments '()' and keyword arguments '{}' not found."
> > > settings:
> > > # in proyName.packages.appName.urls.py:
> > >  ... url(r'^about/$', 'view_aboutPage', name='link_aboutPage'), ... #
> > > also fails with "name='proyName.link_aboutPage'"
> > > # in the template (about.html):
> > > ... show
> > > 'about' ...
>
> > > by the way, the view loks like:
> > > # in proyName.packages.appName.views.py:
> > > ...
> > > def view_aboutPage(request):
> > >         return render_to_response('pages/about.html',
> > > context_instance=RequestContext(request))
> > > ...
>
> > > what can i do?? honestly, i do not know...
> > > thanks!
>
> > > On Apr 29, 12:37 pm, Kevin Audleman  wrote:
>
> > > > You might be able to solve your problem by changing the name attribute
> > > > of your URL to include  "proyName":
>
> > > > url(r'^about/$', 'view_aboutPage', name='proyName.view_aboutPage'),
>
> > > > ---
>
> > > > The error message is telling you exactly what it's looking for, after
> > > > all:
>
> > > > the error:
> > > > "Reverse for 'proyName.view_aboutPage' with arguments '()' and keyword
> > > > arguments '{}' not found."
>
> > > > I have solved most of my URL problems this way.
>
> > > > Cheers,
> > > > Kevin
--~--~-~--~~~---~--~~
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: Template help

2009-04-30 Thread Alex Gaynor
On Thu, Apr 30, 2009 at 7:45 PM, AlexK  wrote:

>
> Hi all,
>
> I would just like some comments about something particular in my
> template. I'm concerned there may be a better way of doing what I am
> doing. You will see why when you look at my code.
>
> http://dpaste.com/39858/
>
> I am mainly concerned with lines 3 to 7. Ignore that I should use a
> variable for "Submit Query". These lines are being repeated in every
> template that I have. Especially the user/profile bit.
>
> Advice is welcome, thank you.
> -Alex
> >
>
If the text is in every single page I might use a context processor(or just
include a different template with that text) just because I'm lazy and that
makes my job easier if I ever need to change the text, but theres nothing
wrong with having the same text more than once.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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

2009-04-30 Thread AlexK

Hi all,

I would just like some comments about something particular in my
template. I'm concerned there may be a better way of doing what I am
doing. You will see why when you look at my code.

http://dpaste.com/39858/

I am mainly concerned with lines 3 to 7. Ignore that I should use a
variable for "Submit Query". These lines are being repeated in every
template that I have. Especially the user/profile bit.

Advice is welcome, thank you.
-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
-~--~~~~--~~--~--~---



Re: Allow only specified HTML tags.

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 15:35 -0700, Brandon wrote:
> I want to have a message board type program which will only allow html
> tags which are in a specified list. How can I accomplish such a feat
> with the django template system? I want to find a way before trying to
> write my own template tags.

There's no default tag to do anything like that. There might be a
third-party tag -- search for words like "HTML whitelisting" along with
words like "Django" to find an overlap.

I wouldn't be too surprised if you had to write your own tag for this (I
personally wouldn't use a tag, but just do it in a Pythong function
before storing the data). Whichever way you do it, the module you'll
want to use is html5lib, which has the best support for HTML
whitelisting of pretty much anything out there.

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: managing templates(html pages)

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 15:14 -0700, Frutoso wrote:
> Hello all - I am new to Django development and I have a question about
> templates.
> 
> I have many templates(html pages) and want to know the best way to
> manage them all. For example:
> I have business_form.html: to get data
> I have business.html: to display data
> and so on.
> 
> Now, if I change a link in the navigation portion of my page I will
> have to change them in all my html pages if I want the pages to all
> look alike. There has got to be a way to manage this better. Please
> help.
> 
> I have used asp.net in the past and it uses a feature call
> master.pages which manages this for all pages. Is there something like
> that for Django?

There's a similar hierarchy structure in Django, although the main
method is based on extension, rather than inclusion. Read about the
"extends" template tag. You would typically put the navigation portion
into a base template and also have blocks (probably empty) that are
placeholders for the main content. Then you "extend" the base template
in a child and override the content blocks, putting the final content
into them. That's very normal Django practice and very simple to use.

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: I'm having some trouble with signals.

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 15:03 -0700, Brian McKeever wrote:
> I'm sure I made some dumb mistake, but I just can't see it.
> Basically, I'm having difficulty connecting to the signal with my
> model.

Don't have time to look into this deeply at the moment, but I suspect I
know the problem. The signal implementation uses weakrefs in a lot of
places. And weakrefs to things like instance methods and, particularly,
temporary objects, lead to unexpected behaviour because the temporary
object is cleaned up.

Try creating your signal method as a module-level object. Alternatively,
don't both testing the internals of the signal framework (which is
really what you're doing there), since that's already tested en passant
(particularly registration and activation) as part of Django's core
tests. So you can avoid the hassle with some confidence, if you like.

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: managing templates(html pages)

2009-04-30 Thread Laszlo Antal


On Thu, 30 Apr 2009 3:14 pm, Frutoso wrote:
>
> Hello all - I am new to Django development and I have a question about
> templates.
>
> I have many templates(html pages) and want to know the best way to
> manage them all. For example:
> I have business_form.html: to get data
> I have business.html: to display data
> and so on.
>
> Now, if I change a link in the navigation portion of my page I will
> have to change them in all my html pages if I want the pages to all
> look alike. There has got to be a way to manage this better. Please
> help.
>
> I have used asp.net in the past and it uses a feature call
> master.pages which manages this for all pages. Is there something like
> that for Django?
>
> Thanks,
> Frutoso
>
Hi,

Not sure.
Do you have the navigation portion in all of your files?
If so create a file called base_business.html
Put all your navigation in there and extend this file in your other 
files.

Hope that helps

lzantal


> Laszlo Antal

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



Chaining Managers

2009-04-30 Thread adam

I was wondering if it was possible (and, if so, how) to chain together
multiple managers to produce a query set that is affected by both of
the individual managers. I'll explain the specific example that I'm
working on:

I have multiple abstract model classes that I use to provide small,
specific functionality to other models. Two of these models are a
DeleteMixin and a GlobalMixin.

The DeleteMixin is defined as such:

class DeleteMixin(models.Model):
deleted = models.BooleanField(default=False)
objects = DeleteManager()

class Meta:
abstract = True

def delete(self):
self.deleted = True
self.save()

Basically it provides a pseudo-delete (the deleted flag) instead of
actually deleting the object.

The GlobalMixin is defined as such:

class GlobalMixin(models.Model):
is_global = models.BooleanField(default=True)

objects = GlobalManager()

class Meta:
abstract = True

It allows any object to be defined as either a global object or a
private object (such as a public/private blog post).

Both of these have their own managers that affect the queryset that is
returned. My DeleteManager filters the queryset to only return results
that have the deleted flag set to False, while the GlobalManager
filters the queryset to only return results that are marked as global.
Here is the declaration for both:

class DeleteManager(models.Manager):
def get_query_set(self):
return super(DeleteManager, self).get_query_set().filter
(deleted=False)

class GlobalManager(models.Manager):
def globals(self):
return self.get_query_set().filter(is_global=1)

The desired functionality would be to have a model extend both of
these abstract models and grant the ability to only return the results
that are both non-deleted and global. I ran a test case on a model
with 4 instances: one was global and non-deleted, one was global and
deleted, one was non-global and non-deleted, and one was non-global
and deleted. If I try to get result sets as such: SomeModel.objects.all
(), I get instance 1 and 3 (the two non-deleted ones - great!). If I
try SomeModel.objects.globals(), I get an error that DeleteManager
doesn't have a globals (this is assuming my model declaration is as
such: SomeModel(DeleteMixin, GlobalMixin). If I reverse the order, I
don't get the error, but it doesn't filter out the deleted ones). If I
change GlobalMixin to attach GlobalManager to globals instead of
objects (so the new command would be SomeModel.globals.globals()), I
get instances 1 and 2 (the two globals), while my intended result
would be to only get instance 1 (the global, non-deleted one).

I wasn't sure if anyone had run into any situation similar to this and
had come to a result. Either a way to make it work in my current
thinking or a re-work that provides the functionality I'm after would
be very much appreciated. I know this post has been a little long-
winded. If any more explanation is needed, I would be glad to provide
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
-~--~~~~--~~--~--~---



Allow only specified HTML tags.

2009-04-30 Thread Brandon

I want to have a message board type program which will only allow html
tags which are in a specified list. How can I accomplish such a feat
with the django template system? I want to find a way before trying to
write my own template tags.

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



managing templates(html pages)

2009-04-30 Thread Frutoso

Hello all - I am new to Django development and I have a question about
templates.

I have many templates(html pages) and want to know the best way to
manage them all. For example:
I have business_form.html: to get data
I have business.html: to display data
and so on.

Now, if I change a link in the navigation portion of my page I will
have to change them in all my html pages if I want the pages to all
look alike. There has got to be a way to manage this better. Please
help.

I have used asp.net in the past and it uses a feature call
master.pages which manages this for all pages. Is there something like
that for Django?

Thanks,
Frutoso

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



I'm having some trouble with signals.

2009-04-30 Thread Brian McKeever

I'm sure I made some dumb mistake, but I just can't see it.
Basically, I'm having difficulty connecting to the signal with my
model.

#my test
def test_set_trigger_bug(self):
self.assertEqual(len(game_reset.receivers), 0)
def trigger(): pass
game_reset.connect(trigger)
self.assertEqual(len(game_reset.receivers), 1)
game_reset.disconnect(trigger)
self.assertEqual(len(game_reset.receivers), 0)

game_reset_event = GameResetEvent(game = self.game)
game_reset_event.save()
game_reset_event.set_trigger(trigger)
self.assertEqual(len(game_reset.receivers), 1) #this fails 
saying
the number of receivers is still 0

#if you comment out the previous assertion, the rest
of this works:
def set_trigger(trigger):
game_reset.connect(trigger)

set_trigger(trigger)
self.assertEqual(len(game_reset.receivers), 1)

#my model
class GameResetEvent( EventStrategy, models.Model):
game = models.ForeignKey("Game")
def set_trigger( self, trigger):
game_reset.connect(trigger)
def passes_filter( self, signal, sender, **kwargs):
return sender.id == self.game.id
class EventStrategy:
def set_trigger( self, trigger): pass
def passes_filter(signal, sender, **kwargs): pass

#my signal definition
game_reset =django.dispatch.Signal()

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



Re: how to change database within Django.

2009-04-30 Thread peter

Hi,
  We have a database for each product that we have.  Within the
database, there are product specific tables.  The current setup uses
PHP/MySQL and the front end is a simple form that a user can use to
select which product they want to do a search on, follow by a serial
number.  I'm _very_ surprised that Django can't switch databases to do
simple queries.  I have gone and digged around this group and found
this thread.

http://groups.google.com/group/django-developers/browse_thread/thread/9f0353fe0682b73

Frankly, this is a little to much hassle for my taste...if there isn't
an easier way to do this, then I will have to think of another
framework alternative...perhaps RoR.

-peter

On Apr 30, 12:54 pm, Daniel Roseman 
wrote:
> On Apr 30, 6:45 pm, peter  wrote:
>
> > Hello,
> >   I'm an newbie so please bear with me.
>
> >   I have a simple form that a user can select the from different
> > product line (databases) and search based on serial number.  From what
> > I have read, the database name needs to be specified within Django,
> > which in this case is a dynamic variable.  How can I get around this
> > dealing with multiple database search problem?
>
> > Thanks,
> > -Peter
>
> Django can't currently switch between databases - there is a Summer of
> Code project this year to make it possible - but I wonder if you
> really need it.
>
> I suspect you are confused about what a database consists of. A
> database is a collection of tables, and individual databases are
> usually quite separate from one another. While I don't know the
> details of your setup, it seems unlikely that you would have multiple
> databases for different product lines - in fact I wouldn't even have
> separate sets of tables, the best way would be to have one table
> containing the product line codes and one with the individual
> products, with a foreign key to the product lines table.
>
> Can you give more details of your setup - is this a legacy database?
> --
> 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: how to change database within Django.

2009-04-30 Thread Daniel Roseman

On Apr 30, 6:45 pm, peter  wrote:
> Hello,
>   I'm an newbie so please bear with me.
>
>   I have a simple form that a user can select the from different
> product line (databases) and search based on serial number.  From what
> I have read, the database name needs to be specified within Django,
> which in this case is a dynamic variable.  How can I get around this
> dealing with multiple database search problem?
>
> Thanks,
> -Peter


Django can't currently switch between databases - there is a Summer of
Code project this year to make it possible - but I wonder if you
really need it.

I suspect you are confused about what a database consists of. A
database is a collection of tables, and individual databases are
usually quite separate from one another. While I don't know the
details of your setup, it seems unlikely that you would have multiple
databases for different product lines - in fact I wouldn't even have
separate sets of tables, the best way would be to have one table
containing the product line codes and one with the individual
products, with a foreign key to the product lines table.

Can you give more details of your setup - is this a legacy database?
--
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: Template tags and variables overlapping

2009-04-30 Thread Sean Brant

If the tag excepts more than one argument you should be able to do
something like this.

{% sayHello "Robert and" currentname %}

You would just need to figure out how best to break the bits up (a
regex probably would work) and iterate over those bits resolving the
variables to strings, keeping the strings normal strings.
--~--~-~--~~~---~--~~
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: Caught an exception while rendering: coercing to Unicode: need string or buffer, SentenceText found

2009-04-30 Thread Bro

I love you all :) 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: Caught an exception while rendering: coercing to Unicode: need string or buffer, SentenceText found

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 12:42 -0700, Bro wrote:
> class SentenceText(models.Model):
> language = models.ForeignKey(Language)
> text_id = models.IntegerField()
> text = models.TextField()
> def __unicode__(self):
> return self.id + ' ' + self.text
> 
> class Box(models.Model):
> label = models.ForeignKey(SentenceText, to_field='text_id',
> related_name='%(class)s_related_label')
> description = models.ForeignKey(SentenceText, to_field='text_id',
> related_name='%(class)s_related_description')
> def __unicode__(self):
> return self.label
> 
> 
> 
> I've got a strange error and in many hour, I haven't manage to fix it.
> 
> In the Box class, I have 2 ForeignKey to SentenceText because I want
> for example the same label (or description) in french or in english.
> 
> But when I try to show a Box list (in admin panel) or a Box detail,
> I've got this error :
> 
> "Caught an exception while rendering: coercing to Unicode: need string
> or buffer, SentenceText found"

A  __unicode__ method *must* return a unicode string. You're returning
self.label which is a SentenceText object -- as the exception notes.
It's certainly no doubt possible to convert a SentenceText into a string
by some means, but Python will not do that for you as part of the
__unicode__ (or __str__) method return process. You must make sure you
are converting to a string.

The simplest and normally completely correct solution here is to write

def __unicode__(self):
   return unicode(self.label)

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: Template tags and variables overlapping

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 12:22 -0700, Julián C. Pérez wrote:
> jajaja i know
> that what just a stupid example to make my point...

Well, the details are important for something like this, since the
complexity of what you're after dictates which solution approach might
be most appropriate.

> i plan to make more complex custom tags

A template tag has no way of knowing what is intended to be literal and
what you want to replace with dynamic content, by default. All the
arguments are simply passed in as a big string to the template tag. So
if you want to treat something as a variable, it's up to you to work out
which parts are the variable parts and look them up (via a resolve()
call) appropriately in your template tag class's render() method.

You might want to consider if using Django's variable substitution
syntax is really what you want to use there, as it's likely to lead to
confusion (because normally that syntax is not appropriate inside
template tags). Also, consider if a template tag that takes all that
information as an argument is the right approach (which is what you're
doing now), or if it might be better to use a block tag of some kind.
For example, Django's localisation support needs to able to replace
content with variables in places, so it uses a block tag structure:

{% blocktrans foo|bar as baz %}
Here is some content containing {{ baz }}.
{% endblocktrans %}

You could have a look at the blocktrans tag for some sample
implementation code.

In short, though, you -- as the template tag author -- have to
explicitly write your tag argument processing to understand the context
in which the arguments should be treated, whether as literals or
variables or function calls or... . There's no default syntax for
variables in template tags, because the possibilities are a bit too
broad (and, ideally, a template tag is still relatively simple and won't
need complex variable substitution 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: Caught an exception while rendering: coercing to Unicode: need string or buffer, SentenceText found

2009-04-30 Thread Alex Gaynor
On Thu, Apr 30, 2009 at 3:42 PM, Bro  wrote:

>
> class SentenceText(models.Model):
>language = models.ForeignKey(Language)
>text_id = models.IntegerField()
>text = models.TextField()
>def __unicode__(self):
>return self.id + ' ' + self.text
>
> class Box(models.Model):
>label = models.ForeignKey(SentenceText, to_field='text_id',
> related_name='%(class)s_related_label')
>description = models.ForeignKey(SentenceText, to_field='text_id',
> related_name='%(class)s_related_description')
>def __unicode__(self):
>return self.label
>
> 
>
> I've got a strange error and in many hour, I haven't manage to fix it.
>
> In the Box class, I have 2 ForeignKey to SentenceText because I want
> for example the same label (or description) in french or in english.
>
> But when I try to show a Box list (in admin panel) or a Box detail,
> I've got this error :
>
> "Caught an exception while rendering: coercing to Unicode: need string
> or buffer, SentenceText found"
>
> I need help
> >
>
You need to return unicode(self.label) since you're return a different
object and __unicode__ *needs* to return a unicode string.  Also your
SenteceText.__unicoed__ will fail since it adds a string to an int.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Caught an exception while rendering: coercing to Unicode: need string or buffer, SentenceText found

2009-04-30 Thread Bro

class SentenceText(models.Model):
language = models.ForeignKey(Language)
text_id = models.IntegerField()
text = models.TextField()
def __unicode__(self):
return self.id + ' ' + self.text

class Box(models.Model):
label = models.ForeignKey(SentenceText, to_field='text_id',
related_name='%(class)s_related_label')
description = models.ForeignKey(SentenceText, to_field='text_id',
related_name='%(class)s_related_description')
def __unicode__(self):
return self.label



I've got a strange error and in many hour, I haven't manage to fix it.

In the Box class, I have 2 ForeignKey to SentenceText because I want
for example the same label (or description) in french or in english.

But when I try to show a Box list (in admin panel) or a Box detail,
I've got this error :

"Caught an exception while rendering: coercing to Unicode: need string
or buffer, SentenceText found"

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



Re: database user vs schema owner

2009-04-30 Thread Jason

I'm running 1.0.2 unfortunately. I'll run the idea of synonyms by our
DBAs.

Thanks!
Jason

On Apr 30, 11:53 am, Ian Kelly  wrote:
> On Apr 30, 12:30 pm, Jason Geiger  wrote:
>
> > Hello. I'm using Oracle and I would like to have a restricted user for
> > Django that can only do DML. Is there a way to specify a schema that
> > would prefix all "naked" table references so that this user can find
> > the tables as it isn't the schema owner?
>
> > If there isn't something like that, I think an alter session should do
> > the trick:
> > alter session set current_schema=my_schema
> > But I'm not sure where I should put something like that.
>
> > Thanks,
> > Jason
>
> Jason,
>
> If you're using Django trunk or the 1.1 beta version, you can use the
> connection_created signal to run your alter session statement at
> connection time.
>
> Otherwise, you could do what we do: create synonyms for the tables
> inside the Django user's schema.
>
> Regards,
> Ian
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: help needed: apache httpd.conf and urls

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 12:27 -0700, zayatzz wrote:
> Hello
> 
> I have this in my template :
> 
> 
> settings file is following:
> MEDIA_ROOT = '/var/www/media/'
> MEDIA_URL = "http://localhost/media/;
> 
> when i go to the webpage then the stuff that i get from server says
> 
> 
> Even when i replace {{ MEDIA_URL }} with anything else i still get
> this in browser:
> 
> 
> Why?

The MEDIA_URL variable will only be populated in your template if the
template is passed a RequestContext instance as the context (not just a
Context, because you want the context processors to be executed) *and*
is you have the "media" context processor in your
TEMPLATE_CONTEXT_PROCESSORS list (which it will be by default).

I would suspect you've forgotten to pass a RequestContext to
render_to_response() or whatever call you're using in your view.

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



help needed: apache httpd.conf and urls

2009-04-30 Thread zayatzz

Hello

I have this in my template :


settings file is following:
MEDIA_ROOT = '/var/www/media/'
MEDIA_URL = "http://localhost/media/;

when i go to the webpage then the stuff that i get from server says


Even when i replace {{ MEDIA_URL }} with anything else i still get
this in browser:


Why?

Just in case you need my httpd.conf:


SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mce.settings
PythonOption django.root /mce
PythonDebug On
PythonPath "['/home/projects', '/home/zay2/Django/Django-1.0.2-
final'] + sys.path"

Alias /media/admin "/home/zay2/Django/Django-1.0.2-final/django/
contrib/admin/media"
Alias /media "/var/www/media"

Order allow,deny
Allow from all


SetHandler None


SetHandler None


SetHandler None


There probably is something unnecessary or confusing here, but this is
first time i've installed apache, mod_python, mysql and phpmyadmin so
if you spot room for improvement, let me know.

Alan
--~--~-~--~~~---~--~~
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: Template tags and variables overlapping

2009-04-30 Thread Julián C . Pérez

jajaja i know
that what just a stupid example to make my point...
i plan to make more complex custom tags

On Apr 30, 12:11 pm, Lakshman Prasad  wrote:
> Why cant you just do something like
>
> {% sayHello " Hello Robert and " %} {{ currentname }}
>
> 2009/4/30 Julián C. Pérez 
>
>
>
>
>
> > hi u all... again
> > this has become my first resource on getting help
> > a new doubt i have...
> > in templates...
> > i have a variable, let's say varOne -suposse it's equal to "Kathleen"
> > ... {{ currentName }} ...
> > and i have created a custom tag which takes an argument, called
> > sayHello
> > ... {% sayHello "Robert and Mary" %} ... > this would output 'Hello
> > Robert and Mary'
> > but if i do something like:
> > ... {% sayHello "Robert and {{ currentName }}" %} ... > this would
> > output 'Hello Robert and {{ currentName }}'
> > needless to say i want some output like 'Hello Robert and Kathleen'
>
> > how can i get this to work??
> > thank u all!
>
> --
> Regards,
> Lakshman
> becomingguru.com
> lakshmanprasad.com
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Rename and Regroup apps in admin dashboard

2009-04-30 Thread lzantal

Hi,

I have a very unusual need. (long post)
I am developing an e-store with satchmo.
It fits all my needs but I need to rename and regroup the apps in
admin view.
Eg: It keeps customer/supplier info in Contact App, I would like to
rename it to Customer and Supplier and move them into there own main
Group.

Since the default install does everything with the data the way I want
it I would rather not touch
the core files for this.

I was thinking to do it 2 ways:
1: Create a Customer App and inherit the needed classes from satchmo's
Contact models
2: Create the layout the way I want it and hardcode the calls for
Contact view

I am not to happy with eider of them.
Does anyone done something similar?
Would you mind sharing how you would go about to accomplish this?

Sincerely

Laszlo Antal

--~--~-~--~~~---~--~~
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: database user vs schema owner

2009-04-30 Thread Ian Kelly

On Apr 30, 12:30 pm, Jason Geiger  wrote:
> Hello. I'm using Oracle and I would like to have a restricted user for
> Django that can only do DML. Is there a way to specify a schema that
> would prefix all "naked" table references so that this user can find
> the tables as it isn't the schema owner?
>
> If there isn't something like that, I think an alter session should do
> the trick:
> alter session set current_schema=my_schema
> But I'm not sure where I should put something like that.
>
> Thanks,
> Jason

Jason,

If you're using Django trunk or the 1.1 beta version, you can use the
connection_created signal to run your alter session statement at
connection time.

Otherwise, you could do what we do: create synonyms for the tables
inside the Django user's schema.

Regards,
Ian
--~--~-~--~~~---~--~~
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 change database within Django.

2009-04-30 Thread peter

Hello,
  I'm an newbie so please bear with me.

  I have a simple form that a user can select the from different
product line (databases) and search based on serial number.  From what
I have read, the database name needs to be specified within Django,
which in this case is a dynamic variable.  How can I get around this
dealing with multiple database search problem?

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: Saving Multiple forms? or fields... confused.

2009-04-30 Thread Karen Tracey
On Thu, Apr 30, 2009 at 10:09 AM, tdelam  wrote:

>
> Hi Karen,
>
> Thanks for responding.
>
> Okay so, here is the new forms code:
>
> class TrueFalseForm(forms.Form):
>def __init__(self, q, *args, **kwargs):
>super(TrueFalseForm, self).__init__(*args, **kwargs)
>self.fields[q.title] = forms.ModelChoiceField(
>queryset=q.answer_set.all(),
>widget=forms.RadioSelect,
>empty_label=None,
>)
>


So you have a form, with a single field in it that is a ModelChoiceField.
The form is associated with a Question, the name of the form field is the
value of the title field of the Question, and the choices are the Answers
associated with that question.  So when this form is POSTed what you will be
able to get from it is the instance of the selected Answer.

(Note there is nothing about this form that restricts it to True/False
questions so its name is a bit confusing. Also I'm uneasy about the form
field name being the title field value from the question.  I think you will
run into problem here if you ever put non-ASCII characters in your question
tittles.)


>
>def save(self):
>choice = Answer(
>choice_answer = # selected answer,
>question = # Need Question instance
>)
>choice.save()
>

At the point where you want to save the submitted data, what you have in the
cleaned_data of the form is the selected Answer.  Previously you were
passing q into the save(),so you could have retrieved the selected Answer
via:

selected_answer = self.cleaned_data[q.title]

Previously you were also creating in save() a different model, a
QuestionResponse, not an Answer.  I am not sure why you have changed it to
creating a new Answer here?  I don't believe you want to create a new Answer
when you save the form, as that would mean your answer_set for the Question
keeps growing and the next time you create a form for it you will have
multiple (identical) Answers listed.  Perhaps you were moving towards adding
a field to Answer to track how many times it had been selected, so you could
do something like this in save?

selected_answer.times_selected += 1
selected_answer.save()

That code is vulnerable to missing increments resulting from multiple
threads/processes in the web server simultaneously attempting to save an
increment for the same Answer, so if you were headed down this path and need
to ensure that all 'votes' are counted you'd have to worry about that.

Alternatively you could go back to your original approach, where you created
a new instance of a different model (QuestionResponse) when saving.  Only
what I think you want in a QuestionResponse is a ForeignKey to Answer, not a
CharField and a ForeignKey to Question as you had originally.  Answer has
both those things already so I don't know why you would want to duplicate
them.  Assuming your QuestionResponse has a field answer that is a
ForeignKey to Answer, then you could create a new QuestionResponse in save:

QuestionResponse.objects.create(answer=self.cleaned_data[q.title])

But I think what you may want to do first is take a step back and rethink
your models.  You've got some stuff in there that is half-implemented (the
question_type Question field) and it isn't clear to me that the models as
you've started laying them out are going to really support all the different
kinds of Questions you have in mind.

Even for the simple select-one-from-a-list-of-choices your current Answer
model is cumbersome.  If you've got multiple questions with the same Answers
(say for the True/False case), as you have it set up now you have to create
Answer True for Q1, Answer True for Q2, Answer False for Q1, Answer False
for Q2, etc.  Getting rid of the ForeingKey to Question in Answer and
instead having a ManyToManyField of Answers in Question would make that
easier, but I'm not sure how well that will work for the other kinds of
questions you have in mind.

You seem to have jumped into coding the full survey solution (show a bunch
of questions in a list and save all the answers on POST) before nailing down
some of the more basic issues: what all the question types will look like
and how they will be linked to answers and how the responses will be
recorded.  Figure out the answers to those issues, and get things working
for a single question of each type you are interested in.  Expanding that to
deal with a whole list of questions should then be straightforward.

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 

Re: Configuration help. Multiple projects.

2009-04-30 Thread Margie

I have a similar situation, in that I have been implementing a website
for my company which is trying to move data from excel spreadsheets
into a web app that manages the "stuff" we track.   agree with Kevin
that I think you want one project (I'm assuming by project you mean
settings.py file), and that project contains multiple apps.  In my
situation I have a chipmanager app, a taskmanager app, and a
forummanager app.  I am in a big company, let's say it's called
foocorp, and the name of my webapp is called "myapp".  I have urls
like this:

myapp.foocorp.com/chipmanager/chip/add
myapp.foocorp.com/chipmanager/chip/edit/

myapp.foocorp.com/taskmanager/tasks
myapp.foocorp.com/taskmanager/tasks//edit

myapp.foocorp.com/forummanger/topic/
myapp.foocorp.com/forummanager/edit_post/

The various apps all talk to each other, but each has its own
urls.py.  For example, the taskmanager pages for tasks have a button
button in the task display to go to a forum for the task.  This takes
you to a page that is in the forummanager.  I use the {% url %}
template command heavily in my html, and this has also proven to be
very flexible, compared to html that has hardcoded html paths in it,
or even relative ones.  I worked with someone else's app that used
just html links in their templates, and moving that app into my
environment was a lot of unnecessary pain that could have been avoided
had they used {% url %} in their templates in place of links that
contained '..' and '/'. Hope this makes sense.  If not, start
exploring and it will ...

I will say that in the beginning, what was in what app was muddled in
my head.  To get going I used just a single urls.py file and basically
had a single app. But over time it became more clear how to make it
more modular and I refactored into the multiple apps.  This has proven
to be much more maintainable and understandable, so I definitely
recommend it.

We have just recently moved onto having a domain and using apache.
IE, this allowed me to serve the website from myapp.foocorp.com.  I
had some help on the apache/it side, so I can't give you a ton of
details, but basically we requested a dns alias 'myapp.foocorp.com'
from my  company's IT group and then created an apache configuration
file that allows me to serve up my app from myapp.foocorp.com.   We
used fcgi.

I believe that if I had some other app that I wanted to serve through
maypp.foocorp.com/wiki, that that could be done using some apache
magic that picks out the /wiki and then sends that to your wiki app.

Hope this helps!

Margie


On Apr 30, 10:58 am, "eric.frederich" 
wrote:
> Kevin,
>
> Yes...that is what I was thinking but I wasn't sure if it was the
> "correct" thing to do.  You saying that helps ease my mind.
>
> Also, one concern I had was that if I did this and the "1 project to
> rule them all" was hogging up the root directory "/", would I still be
> able to have other non-django apps on this server?  Would I be able to
> havehttp://someserver/wiki/and have it go to a MediaWiki or would it
> be going through my django app and matching my urlconf?
>
> Sorry...I know even less about Apache than I do django, python, or web
> stuff in general.
>
> Thanks,
> ~Eric
>
> On Apr 30, 1:42 pm, Kevin Audleman  wrote:
>
> > Your needs are a bit vague, but here's a thought:
>
> > I would think that you would want one project which would conceptually
> > encompass everything your company does. Within that project you would
> > create multiple apps: one for training and one for project XYZ (if I'm
> > reading your requirements correctly). This way the logic for each
> > "project" would be contained in its own directory complete with views,
> > models, etc. They will live in the same Django project and share a
> > settings.py file, urls.py file and can easily talk to each other.
>
> > Kevin
>
> > On Apr 30, 7:47 am, "eric.frederich"  wrote:
>
> > > So, I have been tasked with creating a new website within my company
> > > for a new project.  Lets call the project XYZ (because just calling it
> > > 'the project' is confusing since Django already has a concept of
> > > projects).
>
> > > The website will be your run of the mill project page with
> > > announcements, newsletters, presentations etc.
> > > One other thing they wanted was to be able to manage and track
> > > training for XYZ.
>
> > > We have been looking to change the way we track other training
> > > (currently in a spreadsheet) for a while now.  I took the opportunity
> > > and created a Django application for all training, not just for XYZ.
> > > I'd like it to live athttp://someserver/training/.  From there they
> > > could find training on AutoCad, Visio, MathCad, as well as XYZ.
>
> > > For the XYZ project page, I'd like it to live athttp://someserver/XYZ/.
>
> > > So now here's the question.  Should the training site and the XYZ site
> > > both be projects?  If they're both projects, how 

Re: Configuration help. Multiple projects.

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 11:33 -0700, eric.frederich wrote:
> Malcom,
> 
> That helped.
> 
> I think I understand what you're saying.
> 
> I could have two projects, projectA that has appA1 and appA2 installed
> and projectB that has appB1 and appB2 installed.
> If projectA and projectB's settings.py file shares the same DB
> info...then projectB would be able to use data from appA1 just by
> importing the models from appA1.
> Would projectB need to list appA1 in INSTALLED_APPS or in a projectB
> view could I just do "from appA1.models import SomeModel"?

You should definitely put appA1 in the INSTALLED_APPS list for projectB.
There are some very limited cases where you could get away without doing
that, but it would be very fiddly to debug when things go wrong and
there's pretty much no gain at all in not doing so.

> So it seems pretty easy and straightforward if the apps either exist
> in the same Django project or utilize the same database.  Of course,
> the former would imply the latter.

Right. The data isn't tied to projects, it's tied to the database and
the (reusable) apps are used to access the data (and provide the model
definitions) in more than one installation at the same time.

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: Configuration help. Multiple projects.

2009-04-30 Thread eric.frederich

Malcom,

That helped.

I think I understand what you're saying.

I could have two projects, projectA that has appA1 and appA2 installed
and projectB that has appB1 and appB2 installed.
If projectA and projectB's settings.py file shares the same DB
info...then projectB would be able to use data from appA1 just by
importing the models from appA1.
Would projectB need to list appA1 in INSTALLED_APPS or in a projectB
view could I just do "from appA1.models import SomeModel"?

So it seems pretty easy and straightforward if the apps either exist
in the same Django project or utilize the same database.  Of course,
the former would imply the latter.

~Eric


On Apr 30, 2:04 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-04-30 at 10:53 -0700, eric.frederich wrote:
> > Malcom,
>
> > Thanks for replying.
>
> > Let me try to explain a little more.
>
> > When I said "get a list of XYZ training courses" I did mean getting
> > the Course objects back and doing a little logic with them.
> > Something I'd want on the XYZ main page would be a listing of upcoming
> > training courses for XYZ by location.
>
> > Other than that the XYZ site would be completely separate from the
> > training site.
>
> > I'd have urls like...
>
> >http://someserver/XYZ/announements/
> >http://someserver/XYZ/presentations/
> >http://someserver/XYZ/newsletters/
> >http://someserver/XYZ/contact/
> >http://someserver/XYZ/about/
>
> > For training I'd have
>
> >http://someserver/training/courses/
> >http://someserver/training/categories/
> >http://someserver/training/categories/mathcad/
> >http://someserver/training/categories/xyz/
> >http://someserver/training/offerings/
> >http://someserver/training/categories/
>
> > Again, I know this is dead simple if I have my training application
> > and my XYZ application in the same Django project.  Because it is so
> > dead simple I am wondering if it is the wrong thing to do.
>
> > What I'm asking is if this can this be done if they are in two
> > different Django projects using only Django (no web services / soap /
> > RCP)?
>
> Okay, I think I understand where you're going. Thinking about "projects"
> here may be confusing things, so I'll try to avoid that word and phrase
> things a little differently.
>
> Presumably you have some (Django) application -- something you can put
> in an INSTALLED_APPS list -- which knows how to retrieve the XYZ
> objects. If the main training application is using the same database as
> XYZ, then your problem is easy because you can also include the
> application that knows how to retrieve XYZ objects in the main training
> project's settings file and use it to retrieve the objects from the
> database.
>
> If things are in multiple databases -- the XYZ objects in one database
> and the main training app primarily using another database -- then
> things are a little harder. Two solutions jump to mind then:
>
> One is to create a little HTTP-based API that doesn't necessarily go
> through the external site -- it could be as simple as a lighttpd or
> Apache server on the internal network with the right settings.py file.
> You talk to that API to get back XYZ objects in a form that your code
> could read: a simple view that knows how to understand parameters and
> returns things in, say, a JSON or XML format, for example (or even send
> pickled Python strings over the network, since it's all internal
> anyway).
>
> Another option is to do Poor Man's Multi-database support, which isn't
> too painful. Here's a good explanation of how that 
> works:http://www.mechanicalgirl.com/view/multiple-database-connection-a-sim...
>
> Your "put everything in one project" option certainly is a solution,
> too. It's essentially the same as my "everything in the same database"
> version. The difference is that I'm trying to get you thinking in terms
> of applications which fetch data from the database and using the same
> application (the one that handles XYZ objects) in multiple projects --
> where a project is a settings file, a root URL config file and a bunch
> of applications.
>
> Does that help you at all, or just confuse the issue even further?
>
> 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
-~--~~~~--~~--~--~---



database user vs schema owner

2009-04-30 Thread Jason Geiger

Hello. I'm using Oracle and I would like to have a restricted user for
Django that can only do DML. Is there a way to specify a schema that
would prefix all "naked" table references so that this user can find
the tables as it isn't the schema owner?

If there isn't something like that, I think an alter session should do
the trick:
alter session set current_schema=my_schema
But I'm not sure where I should put something like that.

Thanks,
Jason
--~--~-~--~~~---~--~~
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 on Amazon EC2

2009-04-30 Thread creecode

Hello Joshua,

On Apr 30, 2:34 am, Joshua Partogi  wrote:

> it seems that EC2 is not reliable though
> scalable.

I don't think this is the case.  I've been running an instance for
months with no more issues than if I'd been running on my own
hardware.  If you take sensible backup and other precautions you
should be able to recover from a problem when it does occur with
little problem.  I say when because no matter how you set up, the
underlying hardware ( yours or hosting providers ) will eventually
fail.

Toodle-lo...
creecode
--~--~-~--~~~---~--~~
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 form validation doesn't work.

2009-04-30 Thread Lacrima

Thank you very much, Daniel!!!

Max.

On Apr 30, 8:41 pm, Daniel Roseman 
wrote:
> On Apr 30, 5:43 pm, Lacrima  wrote:
>
>
>
> > Hello!
>
> > For example I have:
> > class ContactForm(forms.Form):
> >     def __init__(self, foo, *args, **kwargs):
> >         super(ContactForm, self).__init__(*args, **kwargs)
> >         self.fields['subject'] = forms.CharField()
> >         self.fields['message'] = forms.CharField()
> >         self.fields['sender'] = forms.EmailField()
> >         if foo == 'boo':
> >             self.fields['cc_myself'] = forms.BooleanField()
>
> > In a view I have standard Django form processing like this:
> > def contact(request):
> >     if request.method == 'POST':
> >         form = ContactForm(request.POST)
> >         if form.is_valid():
> >         #processing the form here
> >     else:
> >         form = ContactForm('boo')
> >     return render_to_response('base_contact.html', {
> >         'form': form,
> >     })
>
> > But It seems that binding and validation doesn't work if I have custom
> > __init__ method with an additional parameter.
> > The form never is bound.
> > After submitting the form I try the next in my debug probe:>>> print 
> > request.method
> > POST
> > >>> print request.POST
>
> >  > u'sender': [u...@me.com'], u'subject': [u'Hello']}>
>
> > >>> form = ContactForm(request.POST)  #I am trying to bind data to form
> > >>> print form.is_bound  #but it doesn't work
> > False
> > >>> print form.is_valid() #so form isn't valid
> > False
>
> > So my question: what I am doing wrong when trying to override __init__
> > method?
>
> > And one more... If I delete additional parameter in __init__
> > definition then everything is ok:
> > class ContactForm(forms.Form):
> >     def __init__(self, *args, **kwargs):
> >         super(ContactForm, self).__init__(*args, **kwargs)
> >         self.fields['subject'] = forms.CharField()
> >         self.fields['message'] = forms.CharField()
> >         self.fields['sender'] = forms.EmailField()
> >         self.fields['cc_myself'] = forms.BooleanField()
>
> > >>> print request.method
> > POST
> > >>> print request.POST
>
> >  > u'sender': [u...@me.com'], u'subject': [u'Hi again']} form = 
> > ContactForm(request.POST)
> > >>> print form.is_bound
> > True
> > >>> print form.is_valid()
>
> > True
>
> > So, please, help me resolve this problem!
>
> > With regards,
> > Max.
>
> > (sorry if my English isn't very proper)
>
> This is because your 'foo' variable is stealing the value of
> request.POST you're passing into the form instantiation.
>
> You could do this:
> form = ContactForm(foo, data=request.POST)
> because you'll need to pass foo in.
>
> Or, define the _init__ like this:
>     def __init__(self, *args, **kwargs):
>         foo = kwargs.pop('foo', None)
>         ...etc...
>         if foo = 'boo'
> --
> 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: Configuration help. Multiple projects.

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 10:53 -0700, eric.frederich wrote:
> Malcom,
> 
> Thanks for replying.
> 
> Let me try to explain a little more.
> 
> When I said "get a list of XYZ training courses" I did mean getting
> the Course objects back and doing a little logic with them.
> Something I'd want on the XYZ main page would be a listing of upcoming
> training courses for XYZ by location.
> 
> Other than that the XYZ site would be completely separate from the
> training site.
> 
> I'd have urls like...
> 
> http://someserver/XYZ/announements/
> http://someserver/XYZ/presentations/
> http://someserver/XYZ/newsletters/
> http://someserver/XYZ/contact/
> http://someserver/XYZ/about/
> 
> For training I'd have
> 
> http://someserver/training/courses/
> http://someserver/training/categories/
> http://someserver/training/categories/mathcad/
> http://someserver/training/categories/xyz/
> http://someserver/training/offerings/
> http://someserver/training/categories/
> 
> Again, I know this is dead simple if I have my training application
> and my XYZ application in the same Django project.  Because it is so
> dead simple I am wondering if it is the wrong thing to do.
> 
> What I'm asking is if this can this be done if they are in two
> different Django projects using only Django (no web services / soap /
> RCP)?

Okay, I think I understand where you're going. Thinking about "projects"
here may be confusing things, so I'll try to avoid that word and phrase
things a little differently.

Presumably you have some (Django) application -- something you can put
in an INSTALLED_APPS list -- which knows how to retrieve the XYZ
objects. If the main training application is using the same database as
XYZ, then your problem is easy because you can also include the
application that knows how to retrieve XYZ objects in the main training
project's settings file and use it to retrieve the objects from the
database.

If things are in multiple databases -- the XYZ objects in one database
and the main training app primarily using another database -- then
things are a little harder. Two solutions jump to mind then:

One is to create a little HTTP-based API that doesn't necessarily go
through the external site -- it could be as simple as a lighttpd or
Apache server on the internal network with the right settings.py file.
You talk to that API to get back XYZ objects in a form that your code
could read: a simple view that knows how to understand parameters and
returns things in, say, a JSON or XML format, for example (or even send
pickled Python strings over the network, since it's all internal
anyway).

Another option is to do Poor Man's Multi-database support, which isn't
too painful. Here's a good explanation of how that works:
http://www.mechanicalgirl.com/view/multiple-database-connection-a-simple-use-case/

Your "put everything in one project" option certainly is a solution,
too. It's essentially the same as my "everything in the same database"
version. The difference is that I'm trying to get you thinking in terms
of applications which fetch data from the database and using the same
application (the one that handles XYZ objects) in multiple projects --
where a project is a settings file, a root URL config file and a bunch
of applications.

Does that help you at all, or just confuse the issue even further?

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: Configuration help. Multiple projects.

2009-04-30 Thread eric.frederich

Kevin,

Yes...that is what I was thinking but I wasn't sure if it was the
"correct" thing to do.  You saying that helps ease my mind.

Also, one concern I had was that if I did this and the "1 project to
rule them all" was hogging up the root directory "/", would I still be
able to have other non-django apps on this server?  Would I be able to
have http://someserver/wiki/ and have it go to a MediaWiki or would it
be going through my django app and matching my urlconf?

Sorry...I know even less about Apache than I do django, python, or web
stuff in general.

Thanks,
~Eric

On Apr 30, 1:42 pm, Kevin Audleman  wrote:
> Your needs are a bit vague, but here's a thought:
>
> I would think that you would want one project which would conceptually
> encompass everything your company does. Within that project you would
> create multiple apps: one for training and one for project XYZ (if I'm
> reading your requirements correctly). This way the logic for each
> "project" would be contained in its own directory complete with views,
> models, etc. They will live in the same Django project and share a
> settings.py file, urls.py file and can easily talk to each other.
>
> Kevin
>
> On Apr 30, 7:47 am, "eric.frederich"  wrote:
>
> > So, I have been tasked with creating a new website within my company
> > for a new project.  Lets call the project XYZ (because just calling it
> > 'the project' is confusing since Django already has a concept of
> > projects).
>
> > The website will be your run of the mill project page with
> > announcements, newsletters, presentations etc.
> > One other thing they wanted was to be able to manage and track
> > training for XYZ.
>
> > We have been looking to change the way we track other training
> > (currently in a spreadsheet) for a while now.  I took the opportunity
> > and created a Django application for all training, not just for XYZ.
> > I'd like it to live athttp://someserver/training/.  From there they
> > could find training on AutoCad, Visio, MathCad, as well as XYZ.
>
> > For the XYZ project page, I'd like it to live athttp://someserver/XYZ/.
>
> > So now here's the question.  Should the training site and the XYZ site
> > both be projects?  If they're both projects, how could I get a list of
> > all XYZ training courses from the XYZ project page?  That would
> > involve 1 project pulling data from the other.
>
> > I could just have one Django project at '/' instead of one at '/
> > training' and one at '/XYZ'.  Doing that, getting a list of XYZ
> > training courses up on the XYZ project page would be easy.  Now is
> > having a single Django project hogging up '/' going to prevent me from
> > running other things like a MediaWiki or BugZilla?  Do I need to use
> > "http://someserver/django/training; and "http://someserver/django/
> > XYZ"?
>
> > So I need some help deciding what to do.  Multiple projects or a
> > single project?  If I do multiple, how can I access models across
> > projects.  If I do a single project how do I configure Apache in a way
> > that won't mess things up down the road?
>
> > What would you do?
>
> > Thanks in advance.
> > ~Eric
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Configuration help. Multiple projects.

2009-04-30 Thread eric.frederich

Malcom,

Thanks for replying.

Let me try to explain a little more.

When I said "get a list of XYZ training courses" I did mean getting
the Course objects back and doing a little logic with them.
Something I'd want on the XYZ main page would be a listing of upcoming
training courses for XYZ by location.

Other than that the XYZ site would be completely separate from the
training site.

I'd have urls like...

http://someserver/XYZ/announements/
http://someserver/XYZ/presentations/
http://someserver/XYZ/newsletters/
http://someserver/XYZ/contact/
http://someserver/XYZ/about/

For training I'd have

http://someserver/training/courses/
http://someserver/training/categories/
http://someserver/training/categories/mathcad/
http://someserver/training/categories/xyz/
http://someserver/training/offerings/
http://someserver/training/categories/

Again, I know this is dead simple if I have my training application
and my XYZ application in the same Django project.  Because it is so
dead simple I am wondering if it is the wrong thing to do.

What I'm asking is if this can this be done if they are in two
different Django projects using only Django (no web services / soap /
RCP)?


On Apr 30, 12:49 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-04-30 at 07:47 -0700, eric.frederich wrote:
> > So, I have been tasked with creating a new website within my company
> > for a new project.  Lets call the project XYZ (because just calling it
> > 'the project' is confusing since Django already has a concept of
> > projects).
>
> > The website will be your run of the mill project page with
> > announcements, newsletters, presentations etc.
> > One other thing they wanted was to be able to manage and track
> > training for XYZ.
>
> > We have been looking to change the way we track other training
> > (currently in a spreadsheet) for a while now.  I took the opportunity
> > and created a Django application for all training, not just for XYZ.
> > I'd like it to live athttp://someserver/training/.  From there they
> > could find training on AutoCad, Visio, MathCad, as well as XYZ.
>
> > For the XYZ project page, I'd like it to live athttp://someserver/XYZ/.
>
> > So now here's the question.  Should the training site and the XYZ site
> > both be projects?  If they're both projects, how could I get a list of
> > all XYZ training courses from the XYZ project page?  That would
> > involve 1 project pulling data from the other.
>
> > I could just have one Django project at '/' instead of one at '/
> > training' and one at '/XYZ'.  Doing that, getting a list of XYZ
> > training courses up on the XYZ project page would be easy.  Now is
> > having a single Django project hogging up '/' going to prevent me from
> > running other things like a MediaWiki or BugZilla?  Do I need to use
> > "http://someserver/django/training; and "http://someserver/django/
> > XYZ"?
>
> You're asking (yourself) some good questions here. However, either I'm
> misunderstanding your explanation (and the word "projects" has become
> ambiguous, despite your efforts) or you're looking at possibly the wrong
> layer.
>
> The issue I'm having is with the simple statement "get a list of XYZ
> training courses". What does this really involve? Is it retrieving a
> list of objects from the database? Or is it a matter of constructing a
> bunch of links correctly?
>
> In short, I'm not quite sure what the difficult part of this process
> potentially would be. I don't mean that I cannot imagine anything would
> be difficult. Rather, I'm wondering which part of it is the particular
> obstacle you're trying to overcome; I don't have enough information to
> understand what the hard part is, because I don't understand the
> requirements.
>
> 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: Configuration help. Multiple projects.

2009-04-30 Thread Kevin Audleman

Your needs are a bit vague, but here's a thought:

I would think that you would want one project which would conceptually
encompass everything your company does. Within that project you would
create multiple apps: one for training and one for project XYZ (if I'm
reading your requirements correctly). This way the logic for each
"project" would be contained in its own directory complete with views,
models, etc. They will live in the same Django project and share a
settings.py file, urls.py file and can easily talk to each other.

Kevin

On Apr 30, 7:47 am, "eric.frederich"  wrote:
> So, I have been tasked with creating a new website within my company
> for a new project.  Lets call the project XYZ (because just calling it
> 'the project' is confusing since Django already has a concept of
> projects).
>
> The website will be your run of the mill project page with
> announcements, newsletters, presentations etc.
> One other thing they wanted was to be able to manage and track
> training for XYZ.
>
> We have been looking to change the way we track other training
> (currently in a spreadsheet) for a while now.  I took the opportunity
> and created a Django application for all training, not just for XYZ.
> I'd like it to live athttp://someserver/training/.  From there they
> could find training on AutoCad, Visio, MathCad, as well as XYZ.
>
> For the XYZ project page, I'd like it to live athttp://someserver/XYZ/.
>
> So now here's the question.  Should the training site and the XYZ site
> both be projects?  If they're both projects, how could I get a list of
> all XYZ training courses from the XYZ project page?  That would
> involve 1 project pulling data from the other.
>
> I could just have one Django project at '/' instead of one at '/
> training' and one at '/XYZ'.  Doing that, getting a list of XYZ
> training courses up on the XYZ project page would be easy.  Now is
> having a single Django project hogging up '/' going to prevent me from
> running other things like a MediaWiki or BugZilla?  Do I need to use
> "http://someserver/django/training; and "http://someserver/django/
> XYZ"?
>
> So I need some help deciding what to do.  Multiple projects or a
> single project?  If I do multiple, how can I access models across
> projects.  If I do a single project how do I configure Apache in a way
> that won't mess things up down the road?
>
> What would you do?
>
> Thanks in advance.
> ~Eric
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic form validation doesn't work.

2009-04-30 Thread Daniel Roseman

On Apr 30, 5:43 pm, Lacrima  wrote:
> Hello!
>
> For example I have:
> class ContactForm(forms.Form):
>     def __init__(self, foo, *args, **kwargs):
>         super(ContactForm, self).__init__(*args, **kwargs)
>         self.fields['subject'] = forms.CharField()
>         self.fields['message'] = forms.CharField()
>         self.fields['sender'] = forms.EmailField()
>         if foo == 'boo':
>             self.fields['cc_myself'] = forms.BooleanField()
>
> In a view I have standard Django form processing like this:
> def contact(request):
>     if request.method == 'POST':
>         form = ContactForm(request.POST)
>         if form.is_valid():
>         #processing the form here
>     else:
>         form = ContactForm('boo')
>     return render_to_response('base_contact.html', {
>         'form': form,
>     })
>
> But It seems that binding and validation doesn't work if I have custom
> __init__ method with an additional parameter.
> The form never is bound.
> After submitting the form I try the next in my debug probe:>>> print 
> request.method
> POST
> >>> print request.POST
>
>  u'sender': [u...@me.com'], u'subject': [u'Hello']}>
>
> >>> form = ContactForm(request.POST)  #I am trying to bind data to form
> >>> print form.is_bound  #but it doesn't work
> False
> >>> print form.is_valid() #so form isn't valid
> False
>
> So my question: what I am doing wrong when trying to override __init__
> method?
>
> And one more... If I delete additional parameter in __init__
> definition then everything is ok:
> class ContactForm(forms.Form):
>     def __init__(self, *args, **kwargs):
>         super(ContactForm, self).__init__(*args, **kwargs)
>         self.fields['subject'] = forms.CharField()
>         self.fields['message'] = forms.CharField()
>         self.fields['sender'] = forms.EmailField()
>         self.fields['cc_myself'] = forms.BooleanField()
>
> >>> print request.method
> POST
> >>> print request.POST
>
>  u'sender': [u...@me.com'], u'subject': [u'Hi again']} form = 
> ContactForm(request.POST)
> >>> print form.is_bound
> True
> >>> print form.is_valid()
>
> True
>
> So, please, help me resolve this problem!
>
> With regards,
> Max.
>
> (sorry if my English isn't very proper)

This is because your 'foo' variable is stealing the value of
request.POST you're passing into the form instantiation.

You could do this:
form = ContactForm(foo, data=request.POST)
because you'll need to pass foo in.

Or, define the _init__ like this:
def __init__(self, *args, **kwargs):
foo = kwargs.pop('foo', None)
...etc...
if foo = 'boo'
--
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: url template tag help

2009-04-30 Thread Kevin Audleman

The other thing is that if there is anything else wrong with your
views.py file it can cause Django to throw up this error. See if the
error is occurring on the first occurence of {% url %} that gets
called for the page you are requesting. That would be a good
indication that your error is somewhere else.

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



Re: How do you manage the depenedencies between your project and other open source?

2009-04-30 Thread Matías Iturburu
On Wed, Apr 29, 2009 at 10:44 PM, meppum  wrote:

>
> Just wanted to get an idea of what tools others were using to manage
> the dependencies between their code and other projects. For instance,
> if I have a project that uses django registration, voting, and tags
> I'd like to have an automated way of downloading this source code when
> i deploy to new locations. I guess sort of like Maven for Java. What
> are my options?



Coming from the zope world I found buildout the way to deal with this kind
of things, there are two nice post from dan fairs which are fairly
introductory[1][2], which even points to some nice paster templates for
making all the boilerplate for you (even setting up everything for serving
static files and that kind of mess you do when in dev mode).

I use that method for all my django projects, although it's a little "slow"
to run, the amount of time and mess when dealing with bureaucratic project
stuff is cut dramatically.





[1]
http://www.stereoplex.com/two-voices/a-django-development-environment-with-zc-buildout[2]
http://www.stereoplex.com/two-voices/fez-djangoskel-django-projects-and-apps-as-eggs


-- 
Matías Iturburu
Revoluciones Informáticas
www.revolucionesweb.com.ar
http://www.linkedin.com/in/miturburu

--~--~-~--~~~---~--~~
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: Template tags and variables overlapping

2009-04-30 Thread Lakshman Prasad
Why cant you just do something like

{% sayHello " Hello Robert and " %} {{ currentname }}

2009/4/30 Julián C. Pérez 

>
> hi u all... again
> this has become my first resource on getting help
> a new doubt i have...
> in templates...
> i have a variable, let's say varOne -suposse it's equal to "Kathleen"
> ... {{ currentName }} ...
> and i have created a custom tag which takes an argument, called
> sayHello
> ... {% sayHello "Robert and Mary" %} ... > this would output 'Hello
> Robert and Mary'
> but if i do something like:
> ... {% sayHello "Robert and {{ currentName }}" %} ... > this would
> output 'Hello Robert and {{ currentName }}'
> needless to say i want some output like 'Hello Robert and Kathleen'
>
> how can i get this to work??
> thank u all!
> >
>


-- 
Regards,
Lakshman
becomingguru.com
lakshmanprasad.com

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



Re: How to include session data in traceback

2009-04-30 Thread Brian Morton

D'oh.  Thanks.  I was confusing load and loads.  I thought they were
the same thing.

On Apr 30, 12:55 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-04-30 at 09:47 -0700, Brian Morton wrote:
> > Thanks.  That makes perfect sense.  Since my session data is persisted
> > in the db (and I don't have a cleanup script active at the moment), I
> > can retrieve the pickled session data based on the session id in the
> > cookie (that is in the traceback).  The problem is decoding that
> > session data.  Can the pickle module accept a string as input and
> > output the unpickled data?  I know it does it with file objects via
> > load, but I can't find any reference on how to do this with a string.
>
> The documentation for the pickle module tells all. :-)
>
> http://docs.python.org/library/pickle.html#pickle.loads
>
> 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: How to include session data in traceback

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 09:47 -0700, Brian Morton wrote:
> Thanks.  That makes perfect sense.  Since my session data is persisted
> in the db (and I don't have a cleanup script active at the moment), I
> can retrieve the pickled session data based on the session id in the
> cookie (that is in the traceback).  The problem is decoding that
> session data.  Can the pickle module accept a string as input and
> output the unpickled data?  I know it does it with file objects via
> load, but I can't find any reference on how to do this with a string.

The documentation for the pickle module tells all. :-)

http://docs.python.org/library/pickle.html#pickle.loads

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



Template tags and variables overlapping

2009-04-30 Thread Julián C . Pérez

hi u all... again
this has become my first resource on getting help
a new doubt i have...
in templates...
i have a variable, let's say varOne -suposse it's equal to "Kathleen"
... {{ currentName }} ...
and i have created a custom tag which takes an argument, called
sayHello
... {% sayHello "Robert and Mary" %} ... > this would output 'Hello
Robert and Mary'
but if i do something like:
... {% sayHello "Robert and {{ currentName }}" %} ... > this would
output 'Hello Robert and {{ currentName }}'
needless to say i want some output like 'Hello Robert and Kathleen'

how can i get this to work??
thank u all!
--~--~-~--~~~---~--~~
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: Configuration help. Multiple projects.

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 07:47 -0700, eric.frederich wrote:
> So, I have been tasked with creating a new website within my company
> for a new project.  Lets call the project XYZ (because just calling it
> 'the project' is confusing since Django already has a concept of
> projects).
> 
> The website will be your run of the mill project page with
> announcements, newsletters, presentations etc.
> One other thing they wanted was to be able to manage and track
> training for XYZ.
> 
> We have been looking to change the way we track other training
> (currently in a spreadsheet) for a while now.  I took the opportunity
> and created a Django application for all training, not just for XYZ.
> I'd like it to live at http://someserver/training/.  From there they
> could find training on AutoCad, Visio, MathCad, as well as XYZ.
> 
> For the XYZ project page, I'd like it to live at http://someserver/XYZ/.
> 
> So now here's the question.  Should the training site and the XYZ site
> both be projects?  If they're both projects, how could I get a list of
> all XYZ training courses from the XYZ project page?  That would
> involve 1 project pulling data from the other.
> 
> I could just have one Django project at '/' instead of one at '/
> training' and one at '/XYZ'.  Doing that, getting a list of XYZ
> training courses up on the XYZ project page would be easy.  Now is
> having a single Django project hogging up '/' going to prevent me from
> running other things like a MediaWiki or BugZilla?  Do I need to use
> "http://someserver/django/training; and "http://someserver/django/
> XYZ"?

You're asking (yourself) some good questions here. However, either I'm
misunderstanding your explanation (and the word "projects" has become
ambiguous, despite your efforts) or you're looking at possibly the wrong
layer.

The issue I'm having is with the simple statement "get a list of XYZ
training courses". What does this really involve? Is it retrieving a
list of objects from the database? Or is it a matter of constructing a
bunch of links correctly?

In short, I'm not quite sure what the difficult part of this process
potentially would be. I don't mean that I cannot imagine anything would
be difficult. Rather, I'm wondering which part of it is the particular
obstacle you're trying to overcome; I don't have enough information to
understand what the hard part is, because I don't understand the
requirements.

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



Dynamic form validation doesn't work.

2009-04-30 Thread Lacrima

Hello!

For example I have:
class ContactForm(forms.Form):
def __init__(self, foo, *args, **kwargs):
super(ContactForm, self).__init__(*args, **kwargs)
self.fields['subject'] = forms.CharField()
self.fields['message'] = forms.CharField()
self.fields['sender'] = forms.EmailField()
if foo == 'boo':
self.fields['cc_myself'] = forms.BooleanField()

In a view I have standard Django form processing like this:
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
#processing the form here
else:
form = ContactForm('boo')
return render_to_response('base_contact.html', {
'form': form,
})

But It seems that binding and validation doesn't work if I have custom
__init__ method with an additional parameter.
The form never is bound.
After submitting the form I try the next in my debug probe:
>>> print request.method
POST
>>> print request.POST

>>> form = ContactForm(request.POST)  #I am trying to bind data to form
>>> print form.is_bound  #but it doesn't work
False
>>> print form.is_valid() #so form isn't valid
False
>>>

So my question: what I am doing wrong when trying to override __init__
method?

And one more... If I delete additional parameter in __init__
definition then everything is ok:
class ContactForm(forms.Form):
def __init__(self, *args, **kwargs):
super(ContactForm, self).__init__(*args, **kwargs)
self.fields['subject'] = forms.CharField()
self.fields['message'] = forms.CharField()
self.fields['sender'] = forms.EmailField()
self.fields['cc_myself'] = forms.BooleanField()

>>> print request.method
POST
>>> print request.POST

>>> form = ContactForm(request.POST)
>>> print form.is_bound
True
>>> print form.is_valid()
True

So, please, help me resolve this problem!

With regards,
Max.

(sorry if my English isn't very proper)

--~--~-~--~~~---~--~~
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: export the html data in table format to CSV or excel file format using javascript

2009-04-30 Thread Phil Mocek

On Thu, Apr 30, 2009 at 01:41:01AM -0700, Nalini wrote:
> Does any one give me the source to export the html data in table
> format to CSV or excel file format using javascript.

Your question does not seem to be related to Django, which is the topic
of this mailing list.

You'd be more likely to find help if you posed your question somewhere
that people discuss javascript programming, such as the
comp.lang.javascript newsgroup [1].  Prior to doing that, you'd be well
off to search for prior discussion of the topic in that group [2] and
elsewhere on the Web so that you can show in your message that you have
done so and thus are able to think for yourself and not simply being
lazy [3].


References:

[1]: 
[2]: 
[3]: 

-- 
Phil Mocek

--~--~-~--~~~---~--~~
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 include session data in traceback

2009-04-30 Thread Brian Morton

Thanks.  That makes perfect sense.  Since my session data is persisted
in the db (and I don't have a cleanup script active at the moment), I
can retrieve the pickled session data based on the session id in the
cookie (that is in the traceback).  The problem is decoding that
session data.  Can the pickle module accept a string as input and
output the unpickled data?  I know it does it with file objects via
load, but I can't find any reference on how to do this with a string.

On Apr 30, 12:43 pm, Malcolm Tredinnick 
wrote:
> On Thu, 2009-04-30 at 04:58 -0700, Brian Morton wrote:
> > I am considering filing an enhancement request but I want to check
> > first to make sure this functionality doesn't already exist.
>
> > Is there some way to make Django include the contents of session in
> > the traceback email received from a 500 error?
>
> It's not possible to guarantee that that information will be available
> or that trying to get that information won't cause further errors. A 500
> error is because of an entirely unexpected problem and could potentially
> be caused by anything, so Django should do the absolute minimum to get
> out of there at that point -- talking to the database for session data
> (which is still the common case for storing sessions) is not the
> minimum.
>
> However, if you want to write your handling for those unexpected errors,
> you can subclass the django.core.handlers.* class that you're using and
> override the handle_unexpected_exception() method to do whatever you
> would like. That's why that method is separated out.
>
> 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: How to include session data in traceback

2009-04-30 Thread Malcolm Tredinnick

On Thu, 2009-04-30 at 04:58 -0700, Brian Morton wrote:
> I am considering filing an enhancement request but I want to check
> first to make sure this functionality doesn't already exist.
> 
> Is there some way to make Django include the contents of session in
> the traceback email received from a 500 error?

It's not possible to guarantee that that information will be available
or that trying to get that information won't cause further errors. A 500
error is because of an entirely unexpected problem and could potentially
be caused by anything, so Django should do the absolute minimum to get
out of there at that point -- talking to the database for session data
(which is still the common case for storing sessions) is not the
minimum.

However, if you want to write your handling for those unexpected errors,
you can subclass the django.core.handlers.* class that you're using and
override the handle_unexpected_exception() method to do whatever you
would like. That's why that method is separated out.

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



Getting user info into an attribute while still using generic views?

2009-04-30 Thread Lior

Hello,
I'm using generic views to manage a model. In that model, when I
create an instance (and not when I update it), I need to set one
of its attribute (owner) to the currently logged in user value. I'd
like to continue using generic views, so can I do this without
creating a view. Is that possible?
The only solution, so far would be to create a new view (and in that
view do all what the generic view do, that is testing form fields,
etc.), and set my attribute from the request.user variable. But I
don't see how to keep the generic view usage in url.py.

Any other way ?

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



Re: url template tag help

2009-04-30 Thread Karen Tracey
2009/4/30 Julián C. Pérez 

>
> anyone??
> i can't get around this...
> and i don't want to hard-code the urls in templates either
> :(
>

Truly, the url template tag is not fundamentally broken, so there is
something you are doing that is causing a problem.  There may be a bug, but
it is very difficult to tell with the bits of results you have posted
without showing what you were trying at the time.

If I were in your situation I'd start with an extremely simplified setup --
maybe a fresh project or app, and experiment.  Start with a very simply
named URL pattern, in the main urls.py, and verify that that works.  Then
change things one step at a time, moving the url pattern into an included
urls.py, changing the name to be more like what you were trying first, etc.
and verifying at each step that it still works.  If and when it stops
working you've got a clue as to what might be causing the problem because
you will have changed only one thing.

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: url template tag help

2009-04-30 Thread Julián C . Pérez

anyone??
i can't get around this...
and i don't want to hard-code the urls in templates either
:(

On 30 abr, 09:20, Julián C. Pérez  wrote:
> by now, i'll try to found some other way to create dynamic urls based
> on the views...
> maybe using a custom template tag
>
> On 29 abr, 21:52, Julián C. Pérez  wrote:
>
> > uhhh
> > i tried but nooo... your suggestion doesn't work...
> > let me show you 2 versions of error...
>
> > 1. "Reverse for 'proyName.view_aboutPage' with arguments '()' and
> > keyword arguments '{}' not found."
> > settings:
> > # in proyName.packages.appName.urls.py:
> >  ... url(r'^about/$', 'view_aboutPage',
> > name='proyName.link_aboutPage'), ...
> > # in the template (about.html):
> > ... show 'about' ...
>
> > 2. "Reverse for '' with
> > arguments '()' and keyword arguments '{}' not found."
> > settings:
> > # in proyName.packages.appName.urls.py:
> >  ... url(r'^about/$', 'view_aboutPage', name='link_aboutPage'), ... #
> > also fails with "name='proyName.link_aboutPage'"
> > # in the template (about.html):
> > ... show
> > 'about' ...
>
> > by the way, the view loks like:
> > # in proyName.packages.appName.views.py:
> > ...
> > def view_aboutPage(request):
> >         return render_to_response('pages/about.html',
> > context_instance=RequestContext(request))
> > ...
>
> > what can i do?? honestly, i do not know...
> > thanks!
>
> > On Apr 29, 12:37 pm, Kevin Audleman  wrote:
>
> > > You might be able to solve your problem by changing the name attribute
> > > of your URL to include  "proyName":
>
> > > url(r'^about/$', 'view_aboutPage', name='proyName.view_aboutPage'),
>
> > > ---
>
> > > The error message is telling you exactly what it's looking for, after
> > > all:
>
> > > the error:
> > > "Reverse for 'proyName.view_aboutPage' with arguments '()' and keyword
> > > arguments '{}' not found."
>
> > > I have solved most of my URL problems this way.
>
> > > Cheers,
> > > Kevin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Help: django.contrib.admin

2009-04-30 Thread David

fixed... thanks!

david


On Apr 30, 8:42 am, Karen Tracey  wrote:
> On Thu, Apr 30, 2009 at 11:36 AM, David  wrote:
>
> > Hello,
>
> > I followed Django tutorial 2 to activate the admin site, however I got
>
> > da...@django:~/mysite$ python manage.py syncdb
> > Error: No module named admindjango.contrib
>
> > after I added "django.contrib.admin" to your INSTALLED_APPS setting.
> > This is how it looks like.
>
> > INSTALLED_APPS = (
> >    'django.contrib.admin'
> >    'django.contrib.auth',
> >    'django.contrib.contenttypes',
> >    'django.contrib.sessions',
> >    'django.contrib.sites',
> >    'mysite.polls'
> > )
>
> > anybody knows how to fix it?
>
> Put a comma on the end of the 'django.contrib.admin' line.  Lacking the
> comma, it's being combined with the next line.
>
> 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: Help: django.contrib.admin

2009-04-30 Thread Karen Tracey
On Thu, Apr 30, 2009 at 11:36 AM, David  wrote:

>
> Hello,
>
> I followed Django tutorial 2 to activate the admin site, however I got
>
> da...@django:~/mysite$ python manage.py syncdb
> Error: No module named admindjango.contrib
>
> after I added "django.contrib.admin" to your INSTALLED_APPS setting.
> This is how it looks like.
>
> INSTALLED_APPS = (
>'django.contrib.admin'
>'django.contrib.auth',
>'django.contrib.contenttypes',
>'django.contrib.sessions',
>'django.contrib.sites',
>'mysite.polls'
> )
>
>
> anybody knows how to fix it?


Put a comma on the end of the 'django.contrib.admin' line.  Lacking the
comma, it's being combined with the next line.

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



Help: django.contrib.admin

2009-04-30 Thread David

Hello,

I followed Django tutorial 2 to activate the admin site, however I got

da...@django:~/mysite$ python manage.py syncdb
Error: No module named admindjango.contrib

after I added "django.contrib.admin" to your INSTALLED_APPS setting.
This is how it looks like.

INSTALLED_APPS = (
'django.contrib.admin'
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mysite.polls'
)


anybody knows how to fix it?

Thanks so much.

--~--~-~--~~~---~--~~
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: Is there a bug in queryset distinct() filtration in Postgre SQL?

2009-04-30 Thread Tyler Erickson

Malcolm,

As you guessed, it was the default ordering that was causing the
problem for me.  After removing the default ordering from the model,
distinct() works as expected.

I still find it strange that distinct().count() was not affected by
the model's default ordering, while the actual list of records was
affected.

Thanks for your help,
Tyler


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



Configuration help. Multiple projects.

2009-04-30 Thread eric.frederich

So, I have been tasked with creating a new website within my company
for a new project.  Lets call the project XYZ (because just calling it
'the project' is confusing since Django already has a concept of
projects).

The website will be your run of the mill project page with
announcements, newsletters, presentations etc.
One other thing they wanted was to be able to manage and track
training for XYZ.

We have been looking to change the way we track other training
(currently in a spreadsheet) for a while now.  I took the opportunity
and created a Django application for all training, not just for XYZ.
I'd like it to live at http://someserver/training/.  From there they
could find training on AutoCad, Visio, MathCad, as well as XYZ.

For the XYZ project page, I'd like it to live at http://someserver/XYZ/.

So now here's the question.  Should the training site and the XYZ site
both be projects?  If they're both projects, how could I get a list of
all XYZ training courses from the XYZ project page?  That would
involve 1 project pulling data from the other.

I could just have one Django project at '/' instead of one at '/
training' and one at '/XYZ'.  Doing that, getting a list of XYZ
training courses up on the XYZ project page would be easy.  Now is
having a single Django project hogging up '/' going to prevent me from
running other things like a MediaWiki or BugZilla?  Do I need to use
"http://someserver/django/training; and "http://someserver/django/
XYZ"?

So I need some help deciding what to do.  Multiple projects or a
single project?  If I do multiple, how can I access models across
projects.  If I do a single project how do I configure Apache in a way
that won't mess things up down the road?

What would you do?

Thanks in advance.
~Eric

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



Re: url template tag help

2009-04-30 Thread Julián C . Pérez

by now, i'll try to found some other way to create dynamic urls based
on the views...
maybe using a custom template tag

On 29 abr, 21:52, Julián C. Pérez  wrote:
> uhhh
> i tried but nooo... your suggestion doesn't work...
> let me show you 2 versions of error...
>
> 1. "Reverse for 'proyName.view_aboutPage' with arguments '()' and
> keyword arguments '{}' not found."
> settings:
> # in proyName.packages.appName.urls.py:
>  ... url(r'^about/$', 'view_aboutPage',
> name='proyName.link_aboutPage'), ...
> # in the template (about.html):
> ... show 'about' ...
>
> 2. "Reverse for '' with
> arguments '()' and keyword arguments '{}' not found."
> settings:
> # in proyName.packages.appName.urls.py:
>  ... url(r'^about/$', 'view_aboutPage', name='link_aboutPage'), ... #
> also fails with "name='proyName.link_aboutPage'"
> # in the template (about.html):
> ... show
> 'about' ...
>
> by the way, the view loks like:
> # in proyName.packages.appName.views.py:
> ...
> def view_aboutPage(request):
>         return render_to_response('pages/about.html',
> context_instance=RequestContext(request))
> ...
>
> what can i do?? honestly, i do not know...
> thanks!
>
> On Apr 29, 12:37 pm, Kevin Audleman  wrote:
>
> > You might be able to solve your problem by changing the name attribute
> > of your URL to include  "proyName":
>
> > url(r'^about/$', 'view_aboutPage', name='proyName.view_aboutPage'),
>
> > ---
>
> > The error message is telling you exactly what it's looking for, after
> > all:
>
> > the error:
> > "Reverse for 'proyName.view_aboutPage' with arguments '()' and keyword
> > arguments '{}' not found."
>
> > I have solved most of my URL problems this way.
>
> > Cheers,
> > Kevin
--~--~-~--~~~---~--~~
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: Saving Multiple forms? or fields... confused.

2009-04-30 Thread tdelam

Hi Karen,

Thanks for responding.

Okay so, here is the new forms code:

class TrueFalseForm(forms.Form):
def __init__(self, q, *args, **kwargs):
super(TrueFalseForm, self).__init__(*args, **kwargs)
self.fields[q.title] = forms.ModelChoiceField(
queryset=q.answer_set.all(),
widget=forms.RadioSelect,
empty_label=None,
)

def save(self):
choice = Answer(
choice_answer = # selected answer,
question = # Need Question instance
)
choice.save()

How can I actually save the data submitted to the form here in this
code? I put 2 comments where I know I should be saving the data but I
am not sure how given the nature of this form.

Here is my view if it helps:

def survey(request):
surveys = Survey.objects.all()
if request.method == 'POST':
questions = get_list_or_404(Question)
for q in questions:
form = TrueFalseForm(q, request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect("/thanks/")
else:
question_list = get_list_or_404(Question)
forms = []
for questions in question_list:
if questions.question_type == 1:
form = TrueFalseForm(questions)
forms.append(form)
return render_to_response('survey.html', {
'surveys': surveys,
'forms': forms
})

On Apr 29, 10:22 pm, Karen Tracey  wrote:
> On Wed, Apr 29, 2009 at 4:00 PM, tdelam  wrote:
>
> > Hi,
>
> > I am building a small survey app, questions are added to a survey
> > through django-admin, I am building the form dynamically, when the
> > form is submitted I only get the first form saving, here is the code:
> >http://dpaste.com/hold/39401/Does anyone have any tips on how I can
> > get the other ones to save when the submit is clicked? Do I need to
> > loop somewhere prior to saving?
>
> You already have a loop, the problem is you are returning after the first
> save:
>
>         if request.method == 'POST':
>                 questions = get_list_or_404(Question)
>                 for q in questions:
>                         form = TrueFalseForm(q, data=request.POST)
>                         if form.is_valid():
>                                 form.save(q)
>                                 return HttpResponseRedirect("/thanks/")
>
> Thus immediately after you find the first valid form, you save it (though I
> don't see, actually, where you use the form's data during save, but I could
> just be missing what you're doing there) and return a response, terminating
> the loop you are in.  If you want to save all the valid forms, you'll need
> to move that return statement to outside the loop.  (Also note you'll just
> ignore invalid forms, as opposed to re-displaying the page with errors.
> Also if all forms are invalid, you'll fall through to the render_to_response
> without having set the forms variable used by it to a value, which will
> likely cause a server error.)
>
> 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: Ajax and https

2009-04-30 Thread Rishabh Manocha
On Thu, Apr 30, 2009 at 4:10 PM, ruben.django wrote:

>
> Hi,
>
> i've got a template with a jquey ajax call. Before, the web service
> (Apache) always redirects to a http direction and the ajax call worked
> perfectly, but from now, it redirects to a secure https direction and
> the ajax call has stopped working. The browser shows me the next
> message:
>
> Security error: the content in https://mysite/foo/34 can't load data
> from http://mysite/foo/34.
>
> Can anybody help me?
>
> Thanks.
>
> >
>
I don't think this has anything to do with Django. Your problem is that
you're making an Ajax call from a https connection to a http connection (
https://mysite/foo/34 to http://mysite/foo/34). Fix this and your problems
should go away.

-- 

Best,

R

--~--~-~--~~~---~--~~
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: Ajax and https

2009-04-30 Thread shi shaozhong

Hi, there.  I will be interested as well.

Regards,

David

2009/4/30 ruben.django :
>
> Hi,
>
> i've got a template with a jquey ajax call. Before, the web service
> (Apache) always redirects to a http direction and the ajax call worked
> perfectly, but from now, it redirects to a secure https direction and
> the ajax call has stopped working. The browser shows me the next
> message:
>
> Security error: the content in https://mysite/foo/34 can't load data
> from http://mysite/foo/34.
>
> Can anybody help me?
>
> 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
-~--~~~~--~~--~--~---



Ajax and https

2009-04-30 Thread ruben.django

Hi,

i've got a template with a jquey ajax call. Before, the web service
(Apache) always redirects to a http direction and the ajax call worked
perfectly, but from now, it redirects to a secure https direction and
the ajax call has stopped working. The browser shows me the next
message:

Security error: the content in https://mysite/foo/34 can't load data
from http://mysite/foo/34.

Can anybody help me?

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 on Amazon EC2

2009-04-30 Thread Jörn Paessler

Hi Joshua,

we do not have public AMIs to offer, but if you logon to Amazon's  
Management Console and search for "django" under AMIs you find at  
least three public images:


I reckon this should be a good start.

Best
Joern



---
beyond content GmbH
Dipl.-Ing. Jörn Paessler
Geschäftsführer
Burgschmietstr. 10
90419 Nürnberg, Germany
E-Mail: joern.paess...@beyond-content.de
Web: www.beyond-content.de
Fon: +49 (0)911 977 98162
Fax:  +49-(0)911 787 2525
Geschäftsführer: Dipl.-Ing. Jörn Paessler
Sitz der Gesellschaft: Nürnberg
Handelsregister: Amtsgericht Nürnberg HRB 23740
USt-IdNr.: DE247571538

Am 30.04.2009 um 11:34 schrieb Joshua Partogi:

>
> Hi Jörn,
>
> Thank you very much for sharing your experience. We were going to use
> it for a community site, but it seems that EC2 is not reliable though
> scalable. This is a tough choice. :-( Any chance that you already
> created an AMI for this that perhaps you can share with the
> community?
>
>
> Best regards,
>
> On Apr 29, 9:09 pm, Jörn Paessler 
> wrote:
>> Hi Joshua,
>>
>> we have been hosting our django sites on EC2 for about 9 months now.
>>
>> We are quite happy with it but there are some things you have to take
>> care of:
>> - we recently had a downtime, because the host system crashed. We had
>> a new instance up and running pretty fast but you have to keep in
>> mind: there is no self-healing mechanism to e.g. broken HDD on EC2.
>> You need to have a backup plan. An Amazon support employeee send me
>> this reply afterwards:
>> "Instances depend on the health of the underlying host. The component
>> that breaks most often are hard disks, so if the instance had any  
>> data
>> stored on the disk, it may not be recoverable if there was a fatal
>> failure, so moving an instance is not easily possible. In general, we
>> recommend that you architect your system in a way so that a single
>> instance failure does not disrupt the overall operation of your
>> system. We also recommend keeping current backups."
>> - For planning your infrastructure this blogentry might be quite
>> helpful:
>>"Experiences deploying a large-scale infrastructure in Amazon  
>> EC2 "
>>> ...
>>  >
>> - we do manage every ressource with SVN. Even the SQL-dumps are
>> periodically persisted via SVN. For our sites (90% corporate  
>> websites)
>> this is a possible solution. I wouldn't recommend this for community
>> websites.
>> - On the high traffic sites we serve the media with Cloudfront. Runs
>> very smooth.
>> - Site data, logs and config-files are located on a mounted EBS.
>> - The best deal for the buck is a medium instance, find more
>> information here:
>> > ...
>>  >
>> "Our conclusion of these tests is that we will mostly use the
>> “c1.medium” instances (”High CPU Medium Instance”) for webhosting and
>> other performance-relevant uses because it offers 150-300% more
>> performance (for CPU, disk and memory) than “m1.small” instances  
>> while
>> only costing 100% more."
>>
>> Hope that information helps!
>>
>
> >


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



Form using widget built by filter_horizontal

2009-04-30 Thread Filip Gruszczyński

In admin definition attribute filter_horirozntal can be specified,
that creates cool javascript using widget for ManyToMany field. I
would like to use such widget in my form. How can I specify this? I
looked into django.forms.widgets, but none looks like this one.

-- 
Filip Gruszczyński

--~--~-~--~~~---~--~~
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 include session data in traceback

2009-04-30 Thread Brian Morton

I am considering filing an enhancement request but I want to check
first to make sure this functionality doesn't already exist.

Is there some way to make Django include the contents of session in
the traceback email received from a 500 error?  It is very useful in
the case of debugging an error with the session (say, a missing key).
I cannot find any reference to this in the docs.
--~--~-~--~~~---~--~~
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: count the number of times an object / class has been instantiated

2009-04-30 Thread Bastien

Sorry if my question is a bit off topic, sometimes my mind tends to
forget that python has not been created just for django... and thanks
for the answer Andy.

Bastien

On Apr 30, 1:40 pm, Andy Mikhailenko  wrote:
> Hi, your question does not seem to be related to Django. Anyway:
>
> class A:
>     cnt = 0
>     def __init__(self):
>         A.cnt += 1
>
> If you want to count saved instances of a Django model, use
> MyModel.objects.count().
>
> Cheers,
> 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: count the number of times an object / class has been instantiated

2009-04-30 Thread Andy Mikhailenko

Hi, your question does not seem to be related to Django. Anyway:

class A:
cnt = 0
def __init__(self):
A.cnt += 1

If you want to count saved instances of a Django model, use
MyModel.objects.count().

Cheers,
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: how to require/validate minimum number of forms in formset?

2009-04-30 Thread patrickk

I know that it´s not allowed to ask things twice on this list ...

unfortunately this bug makes formsets unusable (at least for me) and I
´m wondering why nobody else seems to have problems with this issue.
so maybe I´m just doing something wrong and I don´t see it.

thanks,
patrick


On 15 Apr., 22:34, patrickk  wrote:
> this is strange (at least to me), but the clean-method doesn´t seem to
> be called when _all_ forms are marked for deletion.
>
> patrick
>
> On 15 Apr., 22:05, patrickk  wrote:
>
> > to be more precise:
>
> > class AmountBaseFormset(formsets.BaseFormSet):
>
> >     def clean(self):
> >         (pseudo-code) if number of forms equal number of deleted
> > forms:
> >         raise forms.ValidationError(u'At least one Item is required.')
>
> > question is: how do I figure out the number of forms resp. the number
> > of delete forms here.
> > or is this approach the wrong way?
>
> > thanks,
> > patrick
>
> > On 15 Apr., 21:03, patrickk  wrote:
>
> > > I´m allowing the forms within a formset to be deleted. but I need at
> > > least one form to save the formset. is it possible to require at least
> > > one form? if yes, how do I achieve this?
>
> > > thanks,
> > > patrick
>
>
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



count the number of times an object / class has been instantiated

2009-04-30 Thread Bastien

Hi,

Just for curiosity, anyone knows about a way to count how many times
an object or a class has been instantiated? I could add a simple
counter as a method of the class but what would trigger it?

thanks,
Bastien
--~--~-~--~~~---~--~~
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: Do you know about Django 1.1 current status

2009-04-30 Thread Russell Keith-Magee

On Thu, Apr 30, 2009 at 2:29 PM, Alex Gaynor  wrote:
>
>
> On Thu, Apr 30, 2009 at 2:27 AM, chefsmart  wrote:
>>
>> Hi,
>>
>> Am not sure whether Django-users or Django-developers is the better
>> mailing list for this topic? However,...
>>
>> The Django roadmap for 1.1 estimated the release to be around mid-
>> April 2009.
>>
>> That hasn't happened and of course this is because the developers and
>> contributors feel it's not ready yet.
>>
>> However, it would be of immense help to many users, including myself,
>> if an updated roadmap was published.
>>
>> Regards,
>> CM.
>>
>
> There isn't a real roadmap from here on out, other than it will be
> released(following a release candidate) once we are reasonably sure we have
> most of the bugs out.  The roadmap page on trac shows a little more than 100
> more bugs to be fixed.  So it isn't really a matter of having a roadmap,
> just of hunkering down and fixing the last of the bugs.

We _do_ have a roadmap [1] - while it doesn't have a firm release date
on it, it does list what needs to be done before a release will
happen.

[1] http://code.djangoproject.com/wiki/Version1.1Roadmap

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: Django, FCGI, Cherokee. Spawning PHP Processes and detaching?

2009-04-30 Thread Oli Warner
You're a fair way down this route already but I'll tell you what I would do
faced with a similar situation:

   1. Set up a local-only site inside Cherokee with my PHP and have it
   output the results in a nice format (I'd use JSON)
   2. Use urllib2 and simplejson to pull the data back into Djangoland.

They're both going to be a pain in the rear to maintain but I think my route
looks simpler, even if it does eat more resources (which it probably would).

On Thu, Apr 30, 2009 at 4:12 AM, aaron smith <
beingthexemplaryli...@gmail.com> wrote:

>
> Hey All,
>
> Sorry If I don't have some of this terminology correct. Here's my
> problem. I have a django app, which I'm serving with Cherokee and
> FCGI. My django app manages a bunch of stuff, and has to make a couple
> calls to an external soap service, to record some customer data.
>
> Unfortunately, I can't get the soap service working with Python. And
> the people who write the service only provide php as an "official"
> language. So what I'm doing is running PHP as a cli, reading
> parameters, kick of to soap etc.
>
> The problem I'm hitting is that in Python, when I send out the php
> call. It's blocking. So the request to the user on the site sits there
> and waits because the soap service is jank slow. So, what I'm trying
> to figure out is how to launch the PHP script from Python, but have it
> detach from the current process so it finishes by itself. The php
> script does all the work, I don't care about the exit code or any
> STDOUT data.
>
> I've tried a number of methods. subprocess.Popen, os.system, etc. When
> those don't work, I've even tried having python call a shell script,
> which does the actual PHP call for me so I can add on the & at the end
> to daemonize it. Bleh, I just can't figure out why this is not
> working. To give some context into things i've tried:
>
> #directly calling the php script
> cmd = "/usr/bin/php "
> cmd += settings.CODEIGNITER_CRON_SCRIPTS_PATH+settings.INSERT_VN
> cmd += " "+str(customer.id)+" "+ph+" "+fn+" "+ln+" "+amount+" &"
> os.system(cmd)
>
> #this is the shell script which takes the args, and adds &, in the
> call to the php script
> cmd = settings.CODEIGNITER_CRON_SCRIPTS_PATH+"insert_virtual_number.sh"
> cmd += " "+str(customer.id)+" "+ph+" "+fn+" "+ln+" "+amount
> os.system(cmd)
>
> #using Popen to call the php script
>
> pid=subprocess.Popen(["/usr/bin/php",settings.CODEIGNITER_CRON_SCRIPTS_PATH+settings.INSERT_VN,str(
> customer.id),ph,fn,ln,amount]).pid
>
> #using Popen to call the shell script version
>
> pid=subprocess.Popen(["/bin/bash",settings.CODEIGNITER_CRON_SCRIPTS_PATH+"insert_virtual_number.sh",str(
> customer.id),ph,fn,ln,amount]).pid
>
> Does anyone have any pointers, or tips in the right direction? I'm so
> close, arg!
>
> Thanks much.
> A
>
> >
>

--~--~-~--~~~---~--~~
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 on Amazon EC2

2009-04-30 Thread Joshua Partogi

Hi Jörn,

Thank you very much for sharing your experience. We were going to use
it for a community site, but it seems that EC2 is not reliable though
scalable. This is a tough choice. :-( Any chance that you already
created an AMI for this that perhaps you can share with the
community?


Best regards,

On Apr 29, 9:09 pm, Jörn Paessler 
wrote:
> Hi Joshua,
>
> we have been hosting our django sites on EC2 for about 9 months now.
>
> We are quite happy with it but there are some things you have to take  
> care of:
> - we recently had a downtime, because the host system crashed. We had  
> a new instance up and running pretty fast but you have to keep in  
> mind: there is no self-healing mechanism to e.g. broken HDD on EC2.  
> You need to have a backup plan. An Amazon support employeee send me  
> this reply afterwards:
> "Instances depend on the health of the underlying host. The component  
> that breaks most often are hard disks, so if the instance had any data  
> stored on the disk, it may not be recoverable if there was a fatal  
> failure, so moving an instance is not easily possible. In general, we  
> recommend that you architect your system in a way so that a single  
> instance failure does not disrupt the overall operation of your  
> system. We also recommend keeping current backups."
> - For planning your infrastructure this blogentry might be quite  
> helpful:
>    "Experiences deploying a large-scale infrastructure in Amazon EC2 "
>      >
> - we do manage every ressource with SVN. Even the SQL-dumps are  
> periodically persisted via SVN. For our sites (90% corporate websites)  
> this is a possible solution. I wouldn't recommend this for community  
> websites.
> - On the high traffic sites we serve the media with Cloudfront. Runs  
> very smooth.
> - Site data, logs and config-files are located on a mounted EBS.
> - The best deal for the buck is a medium instance, find more  
> information here:
>   >
> "Our conclusion of these tests is that we will mostly use the  
> “c1.medium” instances (”High CPU Medium Instance”) for webhosting and  
> other performance-relevant uses because it offers 150-300% more  
> performance (for CPU, disk and memory) than “m1.small” instances while  
> only costing 100% more."
>
> Hope that information helps!
>

--~--~-~--~~~---~--~~
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 on Amazon EC2

2009-04-30 Thread Joshua Partogi

Hi creecode,

Thanks very much for sharing your experience with django on EC2. We
really appreciate it. :-) It made us more confident that it is more
suitable than AppEngine.

Best regards,

On Apr 29, 5:28 pm, creecode  wrote:
> Hello Joshua,
>
> I don't have any detail or tips.  You just need to get to grips with
> using EC2 and then install Django on your instance.  I've been using
> Django on an EC2 instance since late last year and they work fine
> together.  I use S3 as my main media server via S3Storage.
>
> On Apr 28, 8:41 pm, Joshua Partogi  wrote:
>
> > Has anyone here had any experience on
> > deploying django apps on Amazon EC2 that would like to share their
> > experience?

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



export the html data in table format to CSV or excel file format using javascript

2009-04-30 Thread Nalini

Hi,

Does any one give me the source to export the html data in table
format to CSV or excel file format using javascript.

Regards,
Nalini
--~--~-~--~~~---~--~~
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 the admin site link foreign keys?

2009-04-30 Thread Daniel Roseman

On Apr 30, 6:11 am, Rex  wrote:
> Let's say I've got two models: User, and Country. Each user is from
> one country, and each country has multiple users. so the User model
> contains a ForeignKey for a Country object.
>
> Can I do either of the following through the Django admin web
> interface?
>
> (1) When I'm looking at the list of Users, have the "country" column
> contain a hyperlink that takes me to that particular Country object.

Not automatically, but you can define a method that returns HTML
containing the link for each country, and use that in the changelist
for Users. See list_display on this page:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/

> (2) When I'm looking at a Country object, show the set of all users
> that have a ForeignKey to this Country, along with a hyperlink to
> those User objects.

You can use inline editing of foreign key items, which is far more
powerful. See
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects

> Any tips would be appreciated.
>
> Thanks,
>
> Rex
--
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: Do you know about Django 1.1 current status

2009-04-30 Thread Alex Gaynor
On Thu, Apr 30, 2009 at 2:27 AM, chefsmart  wrote:

>
> Hi,
>
> Am not sure whether Django-users or Django-developers is the better
> mailing list for this topic? However,...
>
> The Django roadmap for 1.1 estimated the release to be around mid-
> April 2009.
>
> That hasn't happened and of course this is because the developers and
> contributors feel it's not ready yet.
>
> However, it would be of immense help to many users, including myself,
> if an updated roadmap was published.
>
> Regards,
> CM.
> >
>
There isn't a real roadmap from here on out, other than it will be
released(following a release candidate) once we are reasonably sure we have
most of the bugs out.  The roadmap page on trac shows a little more than 100
more bugs to be fixed.  So it isn't really a matter of having a roadmap,
just of hunkering down and fixing the last of the bugs.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Do you know about Django 1.1 current status

2009-04-30 Thread chefsmart

Hi,

Am not sure whether Django-users or Django-developers is the better
mailing list for this topic? However,...

The Django roadmap for 1.1 estimated the release to be around mid-
April 2009.

That hasn't happened and of course this is because the developers and
contributors feel it's not ready yet.

However, it would be of immense help to many users, including myself,
if an updated roadmap was published.

Regards,
CM.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---