Re: User Auth... is_group in a template?

2009-02-09 Thread Nathaniel Whiteinge

On Feb 9, 9:01 am, Alfonso  wrote:
> but is there a similar syntax for displaying HTML blocks depending on
> the user group?

Not builtin, no. But easy to add with a filter:

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



Re: Getting Logged in User with Test Client

2009-01-24 Thread Nathaniel Whiteinge

On Jan 23, 10:22 pm, Vbabiy  wrote:
> How can I get the user model when I use the client to login in to the
> application?

This method is a little ugly, but it works::

from django.contrib.auth.models import User
def test_showAccountWithZeroTrackers(self):
self.client.login(username='user', password='test123')
user = User.objects.get(id=self.client.session
['_auth_user_id'])
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, 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: API mismatch bug with CursorDebugWrapper?

2009-01-24 Thread Nathaniel Whiteinge

On Jan 23, 7:14 pm, Karen Tracey  wrote:
> Take a look at the implementation of CursorDebugWrapper
> __getattr__ in django/db/backends/util.py -- CursorDebugWrapper defers to
> the wrapped cursor for anything it itself doesn't implement.

Thanks, Karen. You're exactly right. I was coming at it from the other
direction and relying too much on the shell. Quandary solved.
- whiteinge
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



API mismatch bug with CursorDebugWrapper?

2009-01-23 Thread Nathaniel Whiteinge

Requesting a sanity check before I file a ticket.

The API for directly accessing a database cursor() changes depending
on if DEBUG is True or False. (Excepting execute() and executemany().)

This shell session spells it out more clearly:
http://dpaste.com/hold/112331/

Is this intentional?

Thanks.
- whiteinge
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, 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: The First Page

2009-01-12 Thread Nathaniel Whiteinge

On Jan 11, 9:53 pm, "pyramid...@gmail.com" 
wrote:
> I am slightly confused with starting out
> I just want to start with the initial index page

You just need a line in your main urlconf (the one specified in your
settings.py file) that maps directly to an HTML file in your templates
directory. Here is a perfect example (line 35):

http://code.djangoproject.com/browser/djangoproject.com/django_website/urls.py#L35

You may find downloading the source code for the official Django site
helpful as an example of a working Django site as you're learning. You
get a local copy if you're using Subversion with the following
command:

svn co http://code.djangoproject.com/svn/djangoproject.com/django_website

Or you can also just browse it directly online with your browser:
http://code.djangoproject.com/browser/djangoproject.com/django_website

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



Re: User in form wizard

2008-12-08 Thread Nathaniel Whiteinge

On Dec 8, 8:00Â am, chewynougat <[EMAIL PROTECTED]>
wrote:
> Could anyone tell me if I can pass the current user to a form wizard
> step so I can prepopulate their object details in the form? If so,
> how?

It depends on where exactly you need to access the current user. If
you can do it *after* form validation has been completed and just use
``commit=False`` [1] when saving the form to fill in the extra data,
that's easily accomplished in the ``done()`` method of the form [2].

However, if you need the current user right when the form is
instantiated (if you need a pre-populated form to edit an existing
object, for example) you're in for a bit of extra work. Here's a
FormWizard class that I use to pass the ``instance`` [1] keyword to
all the ModelForms in a Wizard. (Obviously you'll need to do a bit of
extra leg-work if all of your forms don't derive from the same model,
or aren't ModelForms at all.)::

class YourFormWizard(FormWizard):
def __call__(self, request, *args, **kwargs):
"""Override for getting instance to get_form."""
self.instance = kwargs.pop('instance', None)
return super(YourFormWizard, self).__call__(
request, *args, **kwargs)

def get_form(self, step, data=None):
"""Override for passing the instance keyword argument."""
# If all your ModelForms aren't of the same model you'll
# need to do an isinstance() check, or something similar
to
# only pass the instance keyword to the right form.
return self.form_list[step](
data,
prefix=self.prefix_for_step(step),
initial=self.initial.get(step, None),
instance=self.instance)

Use like so::

def some_edit_view(request, some_id):
instance = get_object_or_4o4(
YourModel, user=request.user, id=some_id)
return YourFormWizard([YourForm1, YourForm2])(
request, instance=instance)

If that's more confusing than helpful, post your code and I'll give
you a more specific example. :)

- whiteinge


.. [1] 
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method
.. [2] 
http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/#creating-a-formwizard-class
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to delete template fragment cache?

2008-12-03 Thread Nathaniel Whiteinge

On Dec 3, 12:37 am, Bartek SQ9MEV <[EMAIL PROTECTED]> wrote:
> I know I should use cache.delete('a'), but how can I get key for
> particular fragment?

The key is 'fragment_name:additional:arguments:seperated:by:colons'.

> What is better idea? Use signals (I do not know too mouch about them
> yet)or just overwrite model_save method?

It doesn't really matter. Signals are most useful, IMO, for tying
behavior to events that happen in apps you don't control (3rd-party,
contrib, etc.).
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to get RadioSelect items one by one in a template

2008-10-20 Thread Nathaniel Whiteinge

On Oct 18, 3:40 am, Torsten Bronger <[EMAIL PROTECTED]>
wrote:
> I try to achieve the following HTML table layout:
>
> .+--+---+
> .|  1   |   |
> .+--+---+
> .|  2   |   |
> .+--+---+
> .|  3   |   |
> .+--+---+
>
> In the cells 1, 2, 3, I'd like to have the choices of a RadioSelect
> widget.  However, I don't know how to access one item of a
> RadioSelect in the template.


AFAIK this is still not possible with an unpatched Django. See the
following tickets:

.. [1] http://code.djangoproject.com/ticket/4785
.. [2] http://code.djangoproject.com/ticket/4592
.. [3] http://code.djangoproject.com/ticket/6458

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



Re: Highlight current active page

2008-10-17 Thread Nathaniel Whiteinge

A slight variation that doesn't require repeating the whole navigation
div in each base_SECTION.html template:

# base.html
{% block content %}...{% endblock %}
{% block navigation %}

Section
1
Section
2

{% endblock %}

# base_section1.html
{% extends "base.html" %}
{% block active_section_1 %} class="active"{% endblock %}

# base_section2.html
{% extends "base.html" %}
{% block active_section_2 %} class="active"{% endblock %}

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



Re: Blank choice for USStateField?

2008-06-26 Thread Nathaniel Whiteinge

On Jun 26, 12:00 pm, Huuuze <[EMAIL PROTECTED]> wrote:
> Just out of curiosity, are the Django devs working on a patch?  I
> wasn't able to find a ticket for this issue.

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



Re: Blank choice for USStateField?

2008-06-26 Thread Nathaniel Whiteinge

On Jun 26, 8:29 am, Huuuze <[EMAIL PROTECTED]> wrote:
> How can I add an empty value as the initial value?

At the moment you have do a bit of leg-work for this. Something like
the following should work (untested)::

from django.contrib.localflavor.us.us_states import STATE_CHOICES
from django.contrib.localflavor.us.forms import USStateField

class YourModelForm(forms.ModelForm):
class Meta:
...

YOUR_STATE_CHOICES = list(STATE_CHOICES)
YOUR_STATE_CHOICES.insert(0, ('', '-'))
state = USStateField(widget=forms.Select(
choices=YOUR_STATE_CHOICES))
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to use dynamic choice in a ChoiceField

2008-06-26 Thread Nathaniel Whiteinge

On Jun 26, 7:53 am, mwebs <[EMAIL PROTECTED]> wrote:
> gallery = forms.ChoiceField(Gallery.objects.filter( ...))

You want to use a ModelChoiceField [1] instead of a ChoiceField. It
takes a QuerySet as an argument::

class PictureForm(forms.Form):
...
gallery = forms.ModelChoiceField(
Gallery.objects.filter(...))

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



Re: wizard authentication

2008-06-26 Thread Nathaniel Whiteinge

On Jun 25, 12:13 pm, twenger26 <[EMAIL PROTECTED]> wrote:

> def wrapper_for_wizard(request):
>     return AddOrderWizard([OrderForm1, OrderForm2Quote, OrderForm3])

You're on the right track! You need to pass your list of forms to the
wizard constructor, as you're doing, as well as pass the request
object when instantiating the form. Try this::

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



Re: Choosing between User.first_name/last_name & username

2008-06-22 Thread Nathaniel Whiteinge

Stuart Grimshaw wrote:
> but it was throwing syntax errors on "player.player.first_name == '' ?
> player.player.username : player.player.first_name)"

It looks like you're trying to use a ternary operator here, but only
Python 2.5 and later has one (and the syntax is different [2]). The
good news is that you can accomplish what you want without using a
ternary operator since Python boolean operators return values instead
of just true or false [1]. Try the following instead::

swap_players_form.fields['side_a'].choices = [(
player.player.id,
player.player.first_name or player.player.username
) for player in side_a]

I similar idiom that I make frequent use of if I don't require that a
user enter a first or last name and therefore need to use the username
as a fallback is the following. (Note the built-in Django method
``get_full_name`` always returns a string, but the first name or the
last name can be empty.)::

user.get_full_name() or user.username

.. [1] http://www.diveintopython.org/power_of_introspection/and_or.html
.. [2]

The Python 2.5 ternary operator syntax::

value_when_true if condition else value_when_false

is equivalent to::

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



Re: Initializing a form.

2008-06-19 Thread Nathaniel Whiteinge

On Jun 19, 4:36 pm, Adi <[EMAIL PROTECTED]> wrote:
> In order to set up the initial values on a couple of fields of my
> form, I need to pass in a couple of model objects to my ModelForm's
> init method.

Try this::

class YourForm(forms.ModelForm):
class Meta:
...

def __init__(self, *args, **kwargs):
# pop() your custom keyword args before calling super()
self.modelobj1 = kwargs.pop('modelobj1', None)
self.modelobj2 = kwargs.pop('modelobj2', None)
super(YourForm, self).__init__(*args, **kwargs)

# Call like this:
modelobj1 = SomeModel.objects.get(id=1)
modelobj2 = SomeModel.objects.get(id=2)
form = YourForm(modelobj1=modelobj1, modelobj2=modelobj2)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-19 Thread Nathaniel Whiteinge

On Jun 19, 3:45 pm, Nathaniel Whiteinge <[EMAIL PROTECTED]> wrote:
>                 if self.instance.state == 'processing':
>                     queryset = queryset.exclude(state='new')

The above lines aren't quite right ``self.instance`` is an instance of
your ``SomeModel`` and presuming there is a foreign key to
``YourStateModel`` it should look something like this instead::

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



Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-19 Thread Nathaniel Whiteinge

On Jun 19, 3:23 pm, Huuuze <[EMAIL PROTECTED]> wrote:
> In this example, what if you wanted to selectively remove a value from
> the choice list.

For that you'll have to move the field declaration into the form's
__init__ method::

class SomeForm(forms.ModelForm):
class Meta:
model = SomeModel

def __init__(self, *args, **kwargs):
super(SomeForm, self).__init__(*args, **kwargs)

# Get the base queryset
queryset = YourStateModel.objects.all()

# Don't forget to pass the instance keyword
# when instantiating your form
if self.instance:
# selectively modify or filter the queryset as needed
if self.instance.state == 'processing':
queryset = queryset.exclude(state='new')

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



Re: Form Validation

2008-06-11 Thread Nathaniel Whiteinge

On Jun 10, 9:42 pm, Adi <[EMAIL PROTECTED]> wrote:
> The application flow works like this: You create a Relation object
> within the context of an Owner Object. There is a rule that says that
> a owner cannot have two Relation with the same pet value. How can I
> create a validation on the form that can check this rule. Basically,
> How can i pass owner object that I have in the view when I call
> RelationForm.is_valid()

A trick I use quite frequently with ModelForms is to require that an
instance is passed to the form on creation::

class RelationForm(ModelForm):
class Meta:
model = Relation
fields  = ('pet')

class NoInstance(Exception):
"""Raise this error when an instance
   was not passed to the form.

"""
pass

def __init__(self, *args, **kwargs):
super(RelationForm, self).__init__(*args, **kwargs)

# this isn't necessary, but helps remind you that this
# form will expect self.instance.user to exist
if not self.instance or not self.instance.owner:
raise self.NoInstance("You must pass an"\
" instance to this form.")

def clean(self):
try:
Relation.objects.get(
owner=self.instance.owner,
pet=self.cleaned_data.get('pet'))
except Relation.DoesNotExist:
return self.cleaned_data

raise forms.ValidationError(
'You cannot have two of the same pet')

Then in your view, you have to do one of the following::

def my_view(request):
# for a new Relation model:
instance = Relation(user=request.user)
# or for an existing Relation model:
instance = Relation.objects.get(user=request.user)

if request.method == 'POST':
form = RelationForm(request.POST, instance=instance)
if form.is_valid():
...
else:
form = RelationForm(instance=instance)

return render_to_response(...)

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



Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-07 Thread Nathaniel Whiteinge

On Jun 7, 4:18 pm, Berco Beute <[EMAIL PROTECTED]> wrote:
> Quite a lot of work for something so simple

I agree that overriding default widgets is currently too much work.
But here's a slightly shorter version that works in exactly the same
way as your example::

class SomeForm(forms.ModelForm):
class Meta:
model = SomeModel

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



Re: Remove empty value ('---------') from HTML SELECT choices

2008-06-05 Thread Nathaniel Whiteinge

On Jun 5, 7:36 am, Berco Beute <[EMAIL PROTECTED]> wrote:
> My model has a ForeignKey that renders as a SELECT field in HTML. The
> problem is that there's an empty value ('-') that I would like
> to hide.

Presuming you are using newforms (i.e. not the Admin), then override
the ModelChoiceField [1] for that ForeignKey in your form and pass the
argument ``empty_label=None`` [2].

.. [1] http://www.djangoproject.com/documentation/newforms/#modelchoicefield
.. [2] 
http://code.djangoproject.com/browser/django/trunk/django/newforms/models.py?rev=7326#L303
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Getting 'instance' in ModelForms

2008-05-16 Thread Nathaniel Whiteinge

On May 16, 6:27 am, Greg Taylor <[EMAIL PROTECTED]> wrote:
> class Form_SKU(ModelForm):
> """
> The form for updating SKUs.
> """
> selected = self.instance.colors

``self`` isn't in scope here, try the code below (and it wouldn't hurt
to read-up on Python OOP).

class Form_SKU(ModelForm):
def __init__(self, *args, **kwargs):
super(Form_SKU, self).__init__(*args, **kwargs)
if self.instance:
selected = self.instance.colors
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: urls() and request.user

2008-05-04 Thread Nathaniel Whiteinge

On May 4, 5:42 am, "Guillaume Lederrey" <[EMAIL PROTECTED]>
wrote:
> I havent done any functional programming in a long time , but ... isnt
> there a way to use an anonymous function (if that's what it is called)
> and do the wrapper "inline" ? Something like :

Yeah, something like that would work, although tying it into your
example above would look pretty ugly, I'm guessing::

(r'^test/$', lambda request: HttpResponse('Hello, %s' %
request.user)),

If you're only trying to get the currently logged in user into the
template context, it's already there as ``{{ user }}`` if you're using
generic views [1]. Sorry I didn't mention that in my first reply.

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



Re: urls() and request.user

2008-05-01 Thread Nathaniel Whiteinge

On May 1, 10:04 am, "Guillaume Lederrey"
<[EMAIL PROTECTED]> wrote:
> This of course doesnt work because the request isnt in the scope. I
> could redefine a view in my views.py and do the work on the request
> manually, but i have a feeling there is a solution to do that directly
> in my urls.py.

Sorry, there isn't a way to get at the request object in your urlconf.
You'll have to make a wrapper around the generic view -- when the
wrapper is small, I often just put it in my ``urls.py``::

from django.conf.urls.defaults import *
from whereever.youput.create_update import update_object

urlpatterns = patterns('',
('^pattern/$', 'path.to.this.urlconf.mywrapper'),
)

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



Re: Django Registration URLs

2008-04-29 Thread Nathaniel Whiteinge

On Apr 28, 6:30 pm, Szaijan <[EMAIL PROTECTED]> wrote:
> The base urls function properly, i.e. /visionary/accounts/register
> goes where it is supposed to, but when resulting URLs are called, they
> all get called as /accounts/register/complete instead of /visionary/
> accounts/register/complete.

Look at the view [1] in django-registration where that is happening.
That particular url can be overridden by passing a new value to the
``success_url`` parameter. If you don't want to modify your checkout
of django-registration (which you shouldn't!), remember that Django
stops at the first matching url, so before the line in your urlconf
where you include ``registration.urls``, put something like the
following::

url(r'^visionary/accounts/register/$', register, {'success_url': '/
visionary/accounts/register/complete'}, name='registration_register'),


.. [1] 
http://code.google.com/p/django-registration/source/browse/trunk/registration/views.py?r=142#49
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Overriding model __init__() method

2008-04-28 Thread Nathaniel Whiteinge

I'm using the __init__() method in a few models to save state for
later use in save(), e.g.::

class MyModel(models.Model):
...
def __init__(self, *args, **kwargs):
super(MyModel, self).__init__(*args, **kwargs)
self.old_value = self.value
def save(self):
if self.old_value != self.value:
...
super(MyModel, self).save()

But that functionality seems to have broken in the last week. It
appears that __init__() isn't be called (as often?) as it used to. I'm
on the GIS branch and it seems to have broken on r7482 (qs-rf merge).

I'm on deadline this week, and don't have much time to play with a
small test app on trunk, but I use this technique in other projects,
so I was wondering if this method an ok way to check for changes
between model saves and there's a bug somewhere, or am I doing
something fragile that should be done another way?

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



Re: GeoDjango: distance between PointFields problem

2008-04-24 Thread Nathaniel Whiteinge

On Apr 23, 9:23 am, Justin Bronn <[EMAIL PROTECTED]> wrote:
> > A PointField from that same model containing lat/long pairs obtained
> > from the Google geocoder.

Quick follow-up in case anyone else has a similar problem. The Google
geocoder annoyingly returns latitude and longitude as y/x instead of x/
y.
Not so obvious if you don't know lat/long very well.

Thanks, Justin, for pointing this out on IRC, and for all the other
helpful links.

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



Re: Getting the user object into a newform

2008-04-24 Thread Nathaniel Whiteinge

On Apr 24, 4:44 am, nickloman <[EMAIL PROTECTED]> wrote:
> class MyForm(forms.Form):
> def __init__(self, user, data=None):
> forms.Form.__init__(self, data)
>
> self.fields['my_options'] =
> ModelChoiceField(queryset=SomeModel.objects.get_users_objects(user))

You're on the right track. I have two suggestions. Since you're
subclassing, make a call to super() and remove the non-standard
arguments before passing them along to super()::

class MyForm(forms.Form):
def __init__(self, *args, **kwargs):
user = kwargs.pop('user', '')
super(MyForm, self).__init__(*args, **kwargs)
if user:
self.fields['my_options'] = ModelChoieField...

Now that ModelForms exist and they can have access to things like
``self.instance.user`` I don't use the above quite as much, but it's
still very useful for non-ModelForms.

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



Re: GeoDjango: distance between PointFields problem

2008-04-22 Thread Nathaniel Whiteinge

On Apr 22, 11:54 am, Justin Bronn <[EMAIL PROTECTED]> wrote:
> (1) What geographic fields are in your model, what type are they
> (e.g., PointField, etc.), and their SRID.

A plain PointField, e.g.: ``location = PointField()``. I believe
GeoDjango defaults to WGS84 for the SRID.

> (2) The geometry type of the parameter you're passing to `distance`,
> and its SRID.

A PointField from that same model containing lat/long pairs obtained
from the Google geocoder.

> My guess is that you're trying to calculate distances from a projected
> coordinate system to a geodetic point that is outside the valid range
> of your projection.

That sounds likely. I've done a bit of Googling for explanations for
the concepts and terms in use with GeoDjango, but I have a shaky
understanding, at best. Do you know of any simple-language
introductions to working with GIS? The best I've seen so far is the
link below.

So now that you know more about my setup, how would I find the
distance between two users in a model?

Thanks for your help so far, Justin.
- whiteinge


.. __:
http://www.sharpgis.net/post/2007/05/Spatial-references2c-coordinate-systems2c-projections2c-datums2c-ellipsoids-e28093-confusing.aspx
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



GeoDjango: distance between PointFields problem

2008-04-22 Thread Nathaniel Whiteinge

I'm calculating the distance between two plain PointFields in the GIS
branch using the distance GeoQuerySet method [1] and I'm coming up
with some confusing results.

The distance between nearby things is often about right, maybe off by
a mile or two. But the distance between farther locations is off by
quite a bit. The distance between Salt Lake City and Chicago is
reported as just over 10,000 miles, for example.

I'm not sure how to go about troubleshooting this. Any advice would be
very much appreciated.
- whiteinge


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



Re: GeoDjango: Completely Overwhelmed

2008-04-15 Thread Nathaniel Whiteinge

I'm really new to GeoDjango myself, and I agree that jumping right in
is a bit of a shock. Hopefully someone more knowledgeable will also
pipe-up, but I think I can start you off in the right direction.

On Apr 14, 9:43 pm, Alex Ezell <[EMAIL PROTECTED]> wrote:
> The system would then show them trips which have start, end, or both
> points in common with the locations they have entered in the search.
> "In common" being defined as within a radius of say 100 miles or so.

If I understand your question correctly, you're only interested in the
start and end points and not the points along that line between the
two. So define a regular model with a ``PointField`` [1] to hold the
lat/long for a location and make sure to use a ``GeoManager`` [2] for
that model. I've been using GeoPy [3] to obtain lat/long from
addresses and zipcodes. If you need to do complex lookups that you
would normally use a ``Q`` object for, make sure to use a ``GeoQ``
object [4] instead.

Once you've done that and have a few items in your database you can
query proximity pretty easily [5]. You can search for other points in
the database that are within a certain radius using a regular queryset
filter like
``yourmodel.objects.filter(point__distance_lte=(STARTINGPOINT,
D(mi=100))``. If you want to return the distance between your starting
point and a bunch of objects use the ``distance()`` manager method
[6]. Also, I've found the built-in Distance measure functions [7]
really helpful for doing conversions.

.. [1] http://code.djangoproject.com/wiki/GeoDjangoModelAPI#FieldTypes
.. [2] http://code.djangoproject.com/wiki/GeoDjangoModelAPI#GeoManager
.. [3] http://exogen.case.edu/projects/geopy/
.. [4] from django.contrib.gis.db.models import GeoQ
.. [5] http://code.djangoproject.com/wiki/GeoDjangoDatabaseAPI#DistanceLookups
.. [6] http://code.djangoproject.com/wiki/GeoDjangoDatabaseAPI#distance
.. [7] http://code.djangoproject.com/wiki/GeoDjangoExtras#Measure

So I just mentioned three completely different parts of GeoDjango all
named "distance", hopefully I didn't confuse you even more!  :-P

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



Re: Printing only the radio input

2008-04-05 Thread Nathaniel Whiteinge

On Apr 5, 6:36 am, J. Pablo Fernández <[EMAIL PROTECTED]> wrote:
> and what I want to do is print the individuals  type="radio" ...> without any label, list or anything.


No, this isn't currently possible.

If you don't mind patching your Django installation, there's a ticket
[1] with a patch that talks about exactly this. There's been talk
recently on the django-dev list about changes to how forms are
rendered which will, hopefully, allow this flexibility, but that's a
long way off.

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



Re: add RequestContext automatically to each render_to_response call

2008-03-10 Thread Nathaniel Whiteinge

On Mar 10, 3:28 am, Julian <[EMAIL PROTECTED]> wrote:
> def render_to_response(*args, **kwargs):
> kwargs['context_instance'] = RequestContext(request)
> return _render_to_response(*args, **kwargs)

That's exactly how Snippet #3 [1] does it. I personally prefer using
the built-in direct_to_template() [2].

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



Re: How to return Admin to previous filters after save?

2008-02-20 Thread Nathaniel Whiteinge

On Feb 19, 7:08 pm, cyberjack <[EMAIL PROTECTED]> wrote:
> Thanks for the suggestion, but there has got to be a simple way to
> solve this problem. Does anyone else have an idea for solving this
> problem?

It's just a regular Django view that's doing the work here. Take a
look at the `change_stage` view [1] -- lines 355 to 369 in particular
-- you'll see the redirects are hard-coded. All the simple solutions
will be workarounds because of that.

.. [1] 
http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/views/main.py?rev=6991#L310

A complex solution would be to make a copy of that view somewhere,
modify it to suit your needs, and point at your version with an
URLconf that has higher precedence than your Admin URLconf (since
Django stops at the first matching pattern). I can't guess about many
potential pitfalls here, but it looks like it could be fairly
straightforward if you get all your imports right.


> Baring that, is there a way I can diff the the newforms-admin and see
> what's changed?
> Maybe I can figure out how the do the URL redirection if it's included
> in the new branch.

I misspoke by suggesting newforms-admin; I don't know for sure that
this is possible. It is far more flexible than the current Admin, so I
have high hopes, and other people also want this same functionality
[2].

.. [2] http://code.djangoproject.com/ticket/6002


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



Re: How to return Admin to previous filters after save?

2008-02-14 Thread Nathaniel Whiteinge

Another workaround: I used JavaScript to open links on the change_list
page in a pop-up window (helps to append `?_popup=1` to the URL). It's
not perfect (you have to refresh the change_list page to see your
changes), but it keeps all your filtering intact.

I believe redirecting to an URL of your choosing is (or will be)
possible with the newforms-admin branch.

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



Re: Help filter with Admin

2008-02-07 Thread Nathaniel Whiteinge

On Feb 7, 3:06 pm, [EMAIL PROTECTED] wrote:
> Can you please give an example of what the list_filter be
> in the model, to get the filterting to work?

Is it just not showing up after the existing list_filter options?

Assuming your current list_filter looks like:
list_filter = ('affiliation', 'publication', 'research',)

Then at the bottom of that JavaScript file, where the usage examples
are (before the very last closing brackets), add something like the
following:
customFilter('By affiliation', 'school__in=A,B', 'School A or B');

The first argument needs to be the exact text of the list_filter
heading (the H3 element) that you're trying to hook on to.

Email me off-list if that didn't get it working. I'm happy to help.
- whiteinge
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newwbie trying to get a variable name into a field name

2008-02-07 Thread Nathaniel Whiteinge

On Feb 7, 2:01 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I know I can't do what I am trying to do in the Media class, but how
> can I do this? How can I name that folder from the media_type
> fieldname?

You have to override the _save_FIELD_file method in your model. Marty
Alchin has a good write-up [1] of how to do it.

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



Re: Which markup language to choose?

2008-02-06 Thread Nathaniel Whiteinge

On Feb 6, 2:55 pm, Florian Lindner <[EMAIL PROTECTED]> wrote:
> For a) it's important for me to have the possibility to embed raw
> HTML. AFAIK markdown provides hat possiblity, is it also possible with
> textile and reST?

For a) you'll never be left wanting with RestructuredText. It is *by
far* the most flexible. All the Django docs are done using it (which
is also a good place to look at examples). I even use it for school
papers. You can produce a variety of slick-looking output, check out
rst2a.com [1] for examples and download-able style sheets. If you're
on a Mac, there's a pretty slick GUI program [2] for composing it too.

.. [1] http://www.rst2a.com/
.. [2] http://python.net/~gherman/ReSTedit.html
(not sure if the above link is the latest version...)

> For b) it's important the output is more or less pretty also if the
> writer is not aware of using a markup language. Or should I just stick
> with {{ comment.content | escape | urlizetrunc:40 | linebreaks }}?

For b) I'm pretty ambivalent. Textile seems to be on the way out
though.

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



Re: Help filter with Admin

2008-02-03 Thread Nathaniel Whiteinge

On Feb 3, 7:56 pm, [EMAIL PROTECTED] wrote:
> Is there a way to select both 'A' and 'B' under affiliation and get
> both Tom and Diane?

You can use non-standard filters in the Admin by manually typing the
in the URL. For example:
http://yoursite/admin/yourapp/student/?school__in=1,2

Unfortunately, getting that link to show up in the Admin list of
filters is difficult to impossible right now with vanilla Django. (The
newforms-admin branch makes this much easier, I believe.)

I've been using a JavaScript solution to accomplish the same effect
that you're after. Your question inspired me to clean it up a bit and
post it to Django Snippets. It might have a bug or two, but I tested
it with your use-case and it worked just fine.

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

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



Re: Managing the order of subordinate objects

2008-01-29 Thread Nathaniel Whiteinge

On Jan 28, 7:59 pm, Peter Rowell <[EMAIL PROTECTED]> wrote:
> You can also add an 'order' field to the subordinates, but you are
> only looking at one of them at a time in admin, so ... it requires the
> user to do a lot of remembering/note-taking.

I have an app with an order field, and I was thinking on this same
problem last week. I hacked up a quick solution using jQuery to make
Ajax calls from the Admin's list_display. It's nothing special (esp.
if you already are familiar with jQuery) -- but, hey, it does the job.

I just posted a snippet [1] with instructions. Hope it helps or gives
you a better idea.

.. [1] http://www.djangosnippets.org/snippets/568/

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



Re: How to use newforms ChoiceField to show dynamic choices

2008-01-24 Thread Nathaniel Whiteinge

ModelChoiceField. Currently not documented, but here's example code.
Use your browser's find for "ModelChoiceField".

http://www.djangoproject.com/documentation/models/model_forms/


On Jan 24, 9:47 pm, shabda <[EMAIL PROTECTED]> wrote:
> I want to use the ChoiceField to show choices depending on a query
> set. For exmple the ChoiceField must get all active Users and them
> show them in a drop down, something like what happens in Admin. How
> can I do that?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Accessing individual radio buttons from a template

2008-01-22 Thread Nathaniel Whiteinge

I'd like to be able access the individual radio buttons of a
ChoiceField using the RadioSelect widget directly from a template.
After quite a bit of searching, I don't think this is currently
possible with newforms but I was wondering if anyone knows of
something I missed.

An earlier workaround ([1], [2]) doesn't seem to work any longer since
as_widget() appears to return a string. (Based on the workaround I
presume as_widget() used to return an iterable object.)

Any advice would be very much appreciated.

Thanks.
- whiteinge

.. [1] 
http://groups.google.com/group/django-users/browse_thread/thread/df7e0410fc27f988/9ab6ead8395783bc
.. [2] 
http://groups.google.com/group/django-users/browse_thread/thread/c505f2b9e9c82881/6108563b8df4a4fb
.. [3] 
http://groups.google.com/group/django-developers/browse_thread/thread/d098b7b40a977ea3/566ab80fc286e053
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Post Save

2008-01-21 Thread Nathaniel Whiteinge

In the Django world (and the newspaper world), the canonical term for
what you're looking for is 'slug' and Django even has a built-in slug
model field [1].

If you're just using the built-in Admin, then it even has JavaScript
that will create the slug based on another model field.

However, if you need this functionality outside the Admin there are a
few options open to you:

The method defined in your model class that you were trying to recall
is documented at the bottom of the Model API docs [2]. This is an
excellent place to put this kind of functionality (you can even reuse
Django's built-in slugify functionality [3][4] that the Admin uses).
In fact, this is a fairly common use-case, you can browse how other
people have tried to solve this same problem by looking over the slug
tag on Django Snippets [5].

.. [1] http://www.djangoproject.com/documentation/model-api/#slugfield
.. [2] 
http://www.djangoproject.com/documentation/model-api/#overriding-default-model-methods
.. [3] http://www.djangoproject.com/documentation/templates/#slugify
.. [4] http://www.djangosnippets.org/snippets/43/
.. [5] http://www.djangosnippets.org/tags/slug/

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



Re: Foreign key drop down not updating in newforms

2008-01-02 Thread Nathaniel Whiteinge

On Dec 30 2007, 6:46 pm, makebelieve <[EMAIL PROTECTED]> wrote:
> Part of a form of mine has a drop down to choose a region which is a
> foreign key to the object I'm updating.  Further, I have a link to add
> a new region if the user does not see what they want.  If a user adds
> a new region it is successfully made in the database, but it will not
> show up in the drop down until I restart my web server.  Is there a
> way around this?

The problem you're having is usually referred to as import-time vs.
execution-time, and is definitely worth reading up on as you're
starting to learn Python. What is happening is the for-loop is only
being run one time as Python is starting up (which affects long-
running Python processes such as the one started by Apache, for
example). A simplified explanation is that your class is being defined
in memory as Python starts-up and the region_choices value is
essentially hard-coded for the duration. You can get around this by
putting your for-loop in a method, since it will be re-run every time
the method is called.

Fortunately, Django has an even better solution for what you're trying
to do: use a ModelChoiceField instead -- it'll handle all that
ForeignKey business for you automatically. It not currently
documented, but you can find example usage here [1] (use your
browser's find).

.. [1] http://www.djangoproject.com/documentation/models/model_forms/

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



Re: django.contrib.auth.views.password_change how to

2007-10-31 Thread Nathaniel Whiteinge

It's really as simple as including the view in your urlconf and
copying the relevant template parts from Django. Here are two stripped-
down examples.

http://dpaste.com/23815/
http://dpaste.com/23814/

You can use the built-in login in much the same way. Just copy the
relevant parts of the template:

http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/templates/admin/login.html

- whiteinge


On Oct 31, 10:26 am, Gigs_ <[EMAIL PROTECTED]> wrote:
> can anyoune give me simple example how to use:
> django.contrib.auth.views.password_change?
>
> thanks!


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



Re: admin customization for foreign key

2007-10-29 Thread Nathaniel Whiteinge

>   The Project and ProjectUnits are defined before the Crews are
> assigned, but when assigning a Crew to a ProjectUnit I'd like to know
> if the Crew is already scheduled to work that day.  That's allowed,
> but I'd like a confirmation alert when this happens, or ideally, have
> the droplist for crew in the admin show a * (or any indicator) next to
> everyone already on assignment that day.
>
>   Any suggestions for doing this would be appreciated.  If the above
> isn't possible, pointers to doing this type of thing outside the admin
> interface would be helpful.  Thanks,

Here are two offhand suggestions that won't require much effort,
although both are hackish.

1.  If you're not using the __str__() method in your Crew model for
anything important (and if you have small database) you could insert
an asterisk there and it will show up in your drop-down list::
def is_working_today(self):
# untested code...returns true if the crew
# has any other projectunits assigned today
return bool(
self.projectunit_set.filter(
day=datetime.date.today()))
def __str__(self):
return is_working_today() and '*'+ crew_name or crew_name

2.  Or, if you have a lot of crew entries in your database, you could
use raw_id_admin [1]_ to pop-up the list of crew members and put
is_working_today in your list_display [2]_ which will give you a quick
yes-or-no view.

.. [1] 
http://www.djangoproject.com/documentation/model-api/#many-to-one-relationships
.. [2] http://www.djangoproject.com/documentation/model-api/#list-display

Maybe someone else will have a suggestion that makes mine look silly.
Either way, good luck!
- whiteinge


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



Re: Example for update_object

2007-10-29 Thread Nathaniel Whiteinge

> What's is your opinion about how long it takes until these forms are
> implemented with newforms in SVN?

The devs work on Django in their spare time, so there isn't a strict
timetable for updates. My advice is not to wait -- forge ahead using
the afore-mentioned snippet or regular views.

Keep an eye on the newforms-admin branch [1]_ for an indicator of how
newforms development is progressing. Once it is merged into trunk, I
suspect newforms will be 'finalized' quickly afterward.

.. [1] http://code.djangoproject.com/wiki/NewformsAdminBranch


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



Re: First post thanks and question.

2007-10-29 Thread Nathaniel Whiteinge

Hello!

> It actually works!  In the admin interface it displays the 'contact'
> field as a combination of the 'first' and 'last' fields of the
> contact, which is exactly what I wanted.  But, my question is how did
> it know to do that?  What if I had wanted it to display the
> 'login_name' instead, for instance?

It is simply displaying the result of the __str__() method in your
Contact model.

> The second question is related to the same field.  In the create new
> 'Away' form, the contact field is shown as a select field, which is
> great, but the items in it are not sorted.  They are placed in the
> order in which they are created.  Is there a way to sort the items on
> that list?

You are nearly there. The ordering attribute of the Admin class in
your Contact model only applies to queries for the Admin's change-list
pages [1]_. If you add a Meta class to that model with that same
ordering field [2]_, it will apply to queries for everything site-wide
and fix the ordering in your select box. It's a little confusing at
first since they look exactly the same. :-)

class Meta:
ordering = ('first', 'last')

.. [1] http://www.djangoproject.com/documentation/model-api/#id7
.. [2] http://www.djangoproject.com/documentation/model-api/#ordering

Cheers!
- whiteinge


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



Re: Problem get_FOO_url in development server

2007-10-29 Thread Nathaniel Whiteinge

Did you include the port in your MEDIA_URL setting? [1]_

MEDIA_URL = 'http://localhost:8000/media/'

.. [1] http://www.djangoproject.com/documentation/settings/#media-url

- whiteinge


On Oct 29, 4:30 am, Przemek Gawronski <[EMAIL PROTECTED]>
wrote:
> Hi, the ImageField creates in a model get_FOO_url to use in the
> templates. But it isn't working correctly when used with djangos
> development server because the port number (by default :8000) isn't
> included. Is that a bug or am I missing something?
>
> Przemek
> --
> AIKIDO TANREN DOJO  -   Poland - Warsaw - Mokotow - Ursynow - Natolin
> info:  http://tanren.pl/  phone:+4850151   email:[EMAIL PROTECTED]


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



Re: Example for update_object

2007-10-24 Thread Nathaniel Whiteinge

On Oct 24, 5:21 am, Florian Lindner <[EMAIL PROTECTED]> wrote:
> I'm looking for an example on how to use the
> django.views.generic.create_update.update_object generic view.

The create and update generic views haven't been updated for newforms
yet. There's a Django Snippet [1]_ that might be helpful in the
meantime.

.. [1] http://www.djangosnippets.org/snippets/99/

> Is object.get_absolute_url() a function I need to implement in my model?

Yes. [2]_

.. [2] http://www.djangoproject.com/documentation/model-api/#get-absolute-url

> The documentation of the view links to the manipulator and formfield
> documentation. There is mentioned that learning the stuff isn't worth anymore
> cause it's being replaced. Is this true also for this generic view? Where can
> I find an example on how to use the view with the newforms (I think it's this
> it's being replaced with). I'm using the svn version of Django.

Oldforms isn't worth learning at this point -- newforms is "nearly
there". There are some examples ([3]_, [4]_) of how to use newforms in
a view on the newforms page in the docs.

.. [3] 
http://www.djangoproject.com/documentation/newforms/#using-forms-in-views-and-templates
.. [4] http://www.djangoproject.com/documentation/newforms/#form-for-instance

The only generic views that are currently not working are create and
update.

- whiteinge


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



Re: Downloadable HTML documentation?

2007-09-30 Thread Nathaniel Whiteinge

On Sep 30, 2:23 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Given the age of that ticket, however, is the procedure that "requires
> a bit of work" documented anywhere?

Or you could just use SmileyChris' implementation [1]_ for now (which
works well).

.. [1] http://smileychris.tactful.co.nz/ramblings/django-documentation/


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



Re: Using decoupled urls.py and generic views

2007-09-14 Thread Nathaniel Whiteinge

Whoops, mind the typo. Should be::

urlpatterns = patterns("xgm.AbbrDB.views",
(r"^$", "search"),
)
urlpatterns += patterns("django.views.generic.list_detail",
(r'^list/$', 'object_list', info_dict),
)


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



Re: Using decoupled urls.py and generic views

2007-09-14 Thread Nathaniel Whiteinge

If you're only doing one or two, use callables [1]_ which will ignore
your view prefix::

from django.conf.urls.defaults import *
from models import Abbreviation
import django.views.generic.list_detail.object_list as object_list

info_dict = { "queryset": Abbreviation.objects.all(), }

urlpatterns = patterns("xgm.AbbrDB.views",
(r"^$", "search"),
(r'^list/$', object_list, info_dict),
)

Otherwise I'd recommend this syntax to join multiple urlpatterns
together::

urlpatterns = patterns("xgm.AbbrDB.views",
(r"^$", "search"),
(r'^list/$', object_list, info_dict),
)
urlpatterns += patterns("django.views.generic.list_detail",
(r'^list/$', 'object_list', info_dict),
)

.. [1] 
http://www.djangoproject.com/documentation/url_dispatch/#passing-callable-objects-instead-of-strings

Cheers!
- whiteinge


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



Re: Form field value

2007-09-08 Thread Nathaniel Whiteinge

Your best bet is probably to use ``save(commit=False)`` [1]_ to get a
Profile instance, then set the user fk and call ``save()`` again. This
is the example from the newforms docs::

# Create a form instance with POST data.
>>> f = AuthorForm(request.POST)

# Create, but don't save the new author instance.
>>> new_author = f.save(commit=False)

# Modify the author in some way.
>>> new_author.some_field = 'some_value'

# Save the new instance.
>>> new_author.save()

.. [1] http://www.djangoproject.com/documentation/newforms/#the-save-method

Cheers.
- whiteinge


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



Re: Fixtures auto-incrementing primary keys?

2007-09-08 Thread Nathaniel Whiteinge

Thanks for the replies, both.

> This idea has occurred to me before, and I can see how it could be
> useful, but I got caught up on one significant detail: how do you
> handle references? When you specify the PK, you provide an identifier
> to use as a cross reference. If this identifier no longer exists, what
> do you use as a reference in its place?

I hadn't thought that far ahead. You're right. I'll give it some
thought.

> You shouldn't even need to write a PK counter - just save the objects
> without a primary key, and the database will allocate the next
> available key. The issue is how to cross reference.

Heh, whoops! It didn't occur to me to set the pk to None, I was just
omitting 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Fixtures auto-incrementing primary keys?

2007-09-06 Thread Nathaniel Whiteinge

Can fixtures have auto-incrementing primary keys or must you have
specific PKs in the the serialized json/xml/etc files? If not, is
there a reason for this?

I'm programmatically generating fixtures from Freebase.org queries for
a project. Although it's not a much extra work to add a pk counter, it
is the second time this has struck me as annoying. Would the devs be
open to a patch for this sort of thing?

Thanks,
- whiteinge


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



Re: A question about an interface via a Form

2007-09-04 Thread Nathaniel Whiteinge

On Sep 4, 4:24 am, Nader <[EMAIL PROTECTED]> wrote:
> I am a new in Django world. I have installed Django and have made a

Welcome! :-)

> The Model in this application looks like :
>
> class ContactInfo(models.Model):
>   contactId = models.IntegerField(primary_key=True)

Quick note: This isn't necessary. Django will add a pk for you [1]_.

To make an empty form a good place to start is form_for_model [2]_.

First create the form class::

ContactInfoForm = form_for_model(ContactInfo)

If you only want a few of the fields from your model in this form use
the fields [3]_ argument in the example above.

Then create an empty form::

   form = ContactInfoForm()

You're nearly there at this point. For an example of a view to process
this form, look at the bottom of the form_for_instance section [4]_
(this is also how to make an edit-form with data from the database).

The docs can be pretty daunting at first, but stick with 'em and feel
free to run any questions you have past this list!

Good luck,
- whiteinge

.. [1] 
http://www.djangoproject.com/documentation/model-api/#automatic-primary-key-fields
.. [2] 
http://www.djangoproject.com/documentation/newforms/#generating-forms-for-models
.. [3] 
http://www.djangoproject.com/documentation/newforms/#using-a-subset-of-fields-on-the-form
.. [4] http://www.djangoproject.com/documentation/newforms/#form-for-instance


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



Re: CRUD generic views and new forms

2007-08-26 Thread Nathaniel Whiteinge

The CRUD generic views haven't been updated for newforms yet. In the
meantime you can try using this snippet:

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

- whiteinge


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



Re: TyneMCE-like for math, You know one?

2007-08-26 Thread Nathaniel Whiteinge

Depending on your ultimate output needs, ASCIIMathML.js may be a good
solution:

http://www1.chapman.edu/~jipsen/mathml/asciimathdemo.html


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



Re: editable=False? visible=False?

2007-08-22 Thread Nathaniel Whiteinge

> is there a way to show the value of the field without making it
> editable?

This isn't possible by throwing an option into your field definition.

If you trust your Admin-site users, the easiest thing to do is
probably add the disabled [1]_ attribute to the element via custom
admin javascript [2]_.

.. [1] http://www.w3.org/TR/html401/interact/forms.html#disabled
.. [2] http://www.djangoproject.com/documentation/model-api/#js

- whiteinge


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



Re: List comprehension with unique, sorted values

2007-08-19 Thread Nathaniel Whiteinge

> It works like a charm, but I'm obviously getting duplicates, and the
> choices are not sorted.

Looks like set() may do the job (I've never used it, but I'm glad to
learn about those related functions).
Another option may be tacking distinct() onto your query.

.. _distinct: http://www.djangoproject.com/documentation/db-api/#distinct

- whiteinge


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



Re: create_or_update() shortcut

2007-08-02 Thread Nathaniel Whiteinge

On Aug 2, 3:01 am, Jens Diemer <[EMAIL PROTECTED]> wrote:
> We have the shortcut get_or_create() [1], but whats about a 
> create_or_update() ?

One exists as a patch_. I've been using it with the current svn for a
while without problems. I find that an update_or_create() shortcut is
particularly helpful working with newforms and use it in quite a few
places. The patch gets pinged every so often [1]_; it will likely make
it into trunk eventually.

.. patch: http://code.djangoproject.com/ticket/3182
.. [1] 
http://groups.google.com/group/django-developers/search?group=django-developers=3182

- whiteinge


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



Re: overiding the clean method on newforms

2007-07-30 Thread Nathaniel Whiteinge

I found the forms from James Bennett's Django Registation app helpful
when I was first learning newforms.

http://django-registration.googlecode.com/svn/trunk/registration/forms.py

- whiteinge

On Jul 30, 2:08 am, james_027 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> is there any sample on over riding the clean method of the newforms?
>
> Thanks
> james


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



Multiple URLconfs per app?

2007-07-18 Thread Nathaniel Whiteinge

I'm a little fuzzy on how Django imports additional app URLconfs. I've
got two parts of an app that are closely related to one another,
however I'd like to give them both root URLs.

myproject/urls.py::

urlpatterns = patterns('',
(r'^feature1/', include('myproject.apps.myapp.urls')),
(r'^feature2/', include('myproject.apps.myapp.urls')),
)

Is there a way to group the URLs in the app's urls.py so as to keep
them all in that one file? Or do I *have* to make seperate files (e.g.
feature1_urls.py, feature2_urls.py)?

myproject/urls.py::

urlpatterns = patterns('',
(r'^feature1/',
include('myproject.apps.myapp.urls.feature1')),
(r'^feature2/',
include('myproject.apps.myapp.urls.feature2')),
)

- whiteinge


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



Re: Two huge forms delema

2007-07-15 Thread Nathaniel Whiteinge

I don't have much experience with sub-classing forms, but I suspect
`del self.fields[a]` should do the trick. Let us know!

- whiteinge

On Jul 15, 7:04 am, Eratothene <[EMAIL PROTECTED]> wrote:
> Fixed examples mistakes:
>
> class A(forms.Form)
>   a = field
>   b = field
>
> class B(A)
>   del a # Is there  working equivalent for this?
>   c = field
>
> Hence, class B inherited only a field b, but not 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms: manually accessing initial value for field

2007-07-12 Thread Nathaniel Whiteinge

The form object has the initial values in a couple places in dicts.
Since it's a dict you can access it's fields with the dot-syntax. I
just successfully tried this on one of my forms::

{{ form.fields.FIELDNAME.initial }}

or::

{{ form.initial.FIELDNAME }}

Just watch that your view is passing the whole form object to the
template, not `form.as_p()` (or something).

- whiteinge


On Jul 11, 12:32 pm, Chris Hoeppner <[EMAIL PROTECTED]> wrote:
> Hi there!
>
> I was just wondering how to access the value I've set in the view with
> Form(initial={'val':somevar}) in the template. Maybe field.value? No.
> field.initial? No.
>
> Any clues? Thanks!


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



Re: Django + newforms + jQuery

2007-07-12 Thread Nathaniel Whiteinge

> Well, in general, I'm pretty new to web development including javascript
> (but with 7 years of python coding) so I just wanted to see what (and
> how) people do newforms and jQuery to get the idea.

This__ isn't interesting, but it *is* an example. :-)

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

I find the two frameworks to be a pretty solid match.

- whiteinge


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



threadlocals in Manager, import-time vs. execution-time problem?

2007-07-11 Thread Nathaniel Whiteinge

I'm having a problem with threadlocals in a custom manager making
queries for the wrong user. I've Googled around quite a bit, and
haven't found the answer -- except others *do* seem to be successfully
using threadlocals in Managers. Ostensibly this is a import-time vs.
execution-time problem, but I'm not sure. Can someone identify my
folly?

class PickManager(models.Manager):
def get_query_set(self):
return super(PickManager,
self).get_query_set().select_related()

def history(self):
return self.filter(user=threadlocals.get_current_user())


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



Re: Variables available to all templates

2007-06-29 Thread Nathaniel Whiteinge

A `related thing`__ came up on the Django Dev list this week.

I'm not that old-school. :-) I use that `{% if user.is_authenticated
%}` all over my site and it's a pain to import and call all the stuff
you need for render_to_response over and over. So this is what I
changed all my views to this week::

from django.views.generic.simple import direct_to_template

def my_view(self):
return direct_to_template(request, 'my_template.html', {
'extra-context': 'goes here',
})

.. __: 
http://groups.google.com/group/django-developers/browse_thread/thread/e0a59d1eaa84c7b4/#

- whiteinge



On Jun 29, 12:13 pm, "Jeremy Dunck" <[EMAIL PROTECTED]> wrote:
> On 6/29/07, Kirk Strauser <[EMAIL PROTECTED]> wrote:
> ...
>
> > return render_to_response('index.html', 
> > context_instance=RequestContext(request))
> ...
>
> > My only concern is that it would seem that I'll need to manually build and
> > pass in a RequestContext for every single view, since I want to have a login
> > or logout link at the top of each one.  Is that correct?
>
> render_to_response(template_name, context_instance=None, **kwargs) is
> a shortcut over this:
>
> t = get_template(template_name)
> c = context_instance or Context()
> c.update(kwargs)
> return HttpResponse(t.render(c))
>
> So passing in context_instance is still shorter.
>
> If you still don't like it, you could use
> django.views.generic.direct_to_template as the last line instead of
> render_to_response.
>
> I guess I'm old school-- I still generally use the longer form.  :)


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



Re: Method to find the admin url for an object

2007-06-27 Thread Nathaniel Whiteinge

Not sure if this is what you're looking for, or if there's an official
way to to this, but I'm using this::

def get_admin_url(self):
return "%s/%s/%s/%s/" % ("/admin", self._meta.app_label,
self._meta.object_name.lower(), self.id)

Stolen from wamber.net.

- whiteinge

On Jun 27, 11:10 am, "Chris Brand" <[EMAIL PROTECTED]> wrote:
> In going through cleaning up all the hard-coded urls in my templates, I'm
> making good use of the get_absolute_url methods that I've added to my
> models.
>
> Looking at the links I'm left with, they're almost all to the admin pages.
> How would I write a method to provide a get_admin_change_url method ?
>
> Thanks,
>
> Chris Brand


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



Re: Attrs in models

2007-06-24 Thread Nathaniel Whiteinge

Malcolm has a really `good write-up`__ about the reasoning behind
newforms (and oldforms) and why it's not just part of the model.

If you find yourself having to do this sort of thing a lot, I would
suggest putting those BaseForm class definitions right next to the
model class in models.py. I do a similar thing with Managers. You
could even put the list of elements that need custom CSS classes
directly in your model. Or, better yet, make it a dictionary like
{ 'element: 'classname' }. Or even better still, maybe you could do
something like this in your model::

@property
def custom_class_list(self):
# you might have to strip out 'id' from this list
return [i.name for i in self._meta.fields]

And then just have a generic BaseForm that you use with all your
form_for_* generated-forms.

.. __: http://groups.google.com/group/django-users/msg/74aaef38380f2c31

Cheers.
- whiteinge


On Jun 24, 4:49 pm, l5x <[EMAIL PROTECTED]> wrote:
> This is a great stuff and I'm really glad that you show me that, but I
> still wonder if it is possible to do sth like that in a model ;-)
> I mean:
>
> Model looks like that:
>
> class ShortNews(models.Model):
> url = models.URLField("URL")
> description = models.CharField("Desc", maxlength="200")
> author = models.ForeignKey(User, editable=False)
> date = models.DateTimeField("Date", auto_now_add=True)
> status = models.IntegerField("Status", editable=False, default="0")
>
> and I don't know why it is not possible to do sth like:
>
> class ShortNews(models.Model):
> url = models.URLField("URL", attr['class':'required'])
> description = models.CharField("Desc", maxlength="200",
> attr['class':'highlight'])
>  ..etc
>
> It's much faster than doing that at every form_for_* and you don't
> have to have it spread all over the code. But the point is, that I
> don't know if there is something which can allow to do that :)
>
> Thanks,
> l5x


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



Re: Attrs in models

2007-06-24 Thread Nathaniel Whiteinge

The name of the fields will be the same name you use in your model.

You can replace the loop with explicit calls for each field::

self.fields['name'].widget.attrs['class'] = yourClass1
self.fields['username'].widget.attrs['class'] = yourClass2

Or if you want to pass a list in as an argument just pop() it before
calling super()::

class BaseYourForm(forms.BaseForm):
def __init__(self, *args, **kwargs):
tmpVariable = kwargs.pop('yourListofFields', False)

super(BaseYourForm, self).__init__(*args, **kwargs)

for i in tmpVariable:
self.fields[i].widget.attrs['class'] =
'yourclassname'

You were close by passing your list of fields to the base form you
created, but you actually need to pass it when you instantiate your
form::

YourForm = form_for_model(YourModel, form=BaseYourForm)
list_of_required = ['name', 'username']
form = YourForm(yourlistoffields=list_of_required)

Cheers.
- whiteinge


On Jun 24, 2:46 pm, l5x <[EMAIL PROTECTED]> wrote:
> And what if I need a class only in selected fields ?:)
> Can I pass it somehow through a list of the fields ?
>
> Something like that should be nice:
>
> list_of_required = ['name', 'username']
> MyForm = form_for_model(MyModel, form=
> BaseYourForm(list_of_required))
>
> Hm. I guess that I only have to modify the loop:
>
> for i in self.fields:
> self.fields[i].widget.attrs['class'] =
> 'yourclassname'
>
> But what's the name of field ? i.name ? or what ?
>
> On Jun 24, 10:31 pm, l5x <[EMAIL PROTECTED]> wrote:
>
> > I think that it's a right thing for me. Thanks for your effort.


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



Re: Attrs in models

2007-06-24 Thread Nathaniel Whiteinge

I hope I understand what you're asking: that you want to add a CSS
class to each form field generated by the form_for_* helpers?

If so, you could make a small `base class`_ to do that::

class BaseYourForm(forms.BaseForm):
def __init__(self, *args, **kwargs):
super(BaseYourForm, self).__init__(*args, **kwargs)
for i in self.fields:
self.fields[i].widget.attrs['class'] = 'yourclassname'

Then just create your form with that one extra argument::

YourForm = form_for_model(YourModel, form=BaseYourForm)

There may be a better way to do that, but it works for me. :-)

Don't forget about the `fields argument`_ if you only want a few of
your model's fields to show up in the form::

YourForm = form_for_model(YourModel, fields=dictOfYourFields,
  form= BaseYourForm)

.. base class: 
http://www.djangoproject.com/documentation/newforms/#using-an-alternate-base-class
.. fields argument: 
http://www.djangoproject.com/documentation/newforms/#using-a-subset-of-fields-on-the-form

Cheers.
- whiteinge



On Jun 24, 12:47 pm, l5x <[EMAIL PROTECTED]> wrote:
> Hello,
>
> is there any possibility in django to put a widget into a model
> instead of creating the whole forms for each model (using widgets
> render)? I only need to add a css class to each field in a model...
>
> Best regards


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



Re: Custom Form Validation

2007-06-22 Thread Nathaniel Whiteinge

Sorry, accidentally hit the submit button.

Here's your example finished (don't forget self in the def!):

def clean_lines(self):
if not format_is_correct( lines ):
raise forms.ValidationError('Bug..')
return self.cleaned_data.get(lines)

Good luck!
- whiteinge


On Jun 22, 4:54 pm, Mario Gonzalez <[EMAIL PROTECTED]> wrote:
> Hello, I've got a model like:
>
> class RecepcionForm(forms.Form):
> drivers =
> forms.ModelChoiceField(queryset=Driver.objects.all().order_by('-
> name'))
> lines = forms.CharField()
>
>def clean_lines():
>   if not format_is_correct( lines ):
>  raise forms.ValidationError('Bug..')
>
>  "lines" is a string with a special format, ex: "23, 24,1,0"  and I
> want to validate it with clean(), I've been reading the documentation
> and writing some lines but I think my English is not good enough.
>
> Can you help me? Regards!


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



Re: Custom Form Validation

2007-06-22 Thread Nathaniel Whiteinge

You're nearly there, you just need to return your cleaned value.
Here's one of mine:

if self.cleaned_data.get(field_name) > assets.get_usable_assets():
raise ValidationError(u'You only have %s points available for
betting.'
% assets.get_usable_assets())

return self.cleaned_data.get(field_name)


On Jun 22, 4:54 pm, Mario Gonzalez <[EMAIL PROTECTED]> wrote:
> Hello, I've got a model like:
>
> class RecepcionForm(forms.Form):
> drivers =
> forms.ModelChoiceField(queryset=Driver.objects.all().order_by('-
> name'))
> lines = forms.CharField()
>
>def clean_lines():
>   if not format_is_correct( lines ):
>  raise forms.ValidationError('Bug..')
>
>  "lines" is a string with a special format, ex: "23, 24,1,0"  and I
> want to validate it with clean(), I've been reading the documentation
> and writing some lines but I think my English is not good enough.
>
> Can you help me? Regards!


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



Re: Django Users Portuguese

2007-06-07 Thread Nathaniel Whiteinge

Have you seen the existing `Django Brasil`__ group? It's got 165
members and seems pretty active.

.. __: http://groups.google.com/group/django-brasil


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



Re: Using login_required with direct_to_template?

2007-06-06 Thread Nathaniel Whiteinge

Until Malcolm swoops in with the answer to your question about the
docs, you can use callables in your urlconf to accomplish what you
want.

from django.contrib.auth.decorators import login_required
from django.views.generic.simple import direct_to_template

urlpatterns = patterns('',
(r'^someurl/', login_required(direct_to_template), { 'template':
'template.html', }),
)

- whiteinge

On Jun 6, 10:09 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > An explanation of what you expect to happen and what is actually
> > happening for a start, along with any error message.
>
> > How are your trying to use login_required in your template? Your initial
> > paragraph says you are trying to use the login_required *decorator*, but
> > that is something that applies to Python code, not inside a template.
>
> I'm sorry, my terminology was probably improper. I think should have
> said I'm trying to use login_required as an argument for a generic
> view.
>
> What I'm trying to do is have a URL that uses direct_to_template to
> send people to my application's main page. I want to require login to
> view this page.
>
> If I were doing it with a regular view, I'd just put the
> login_required decorator above it. Since the page has no logic that
> requires a view to be written, direct_to_template will work nicely.
>
> The documentation says that CRUD generic views take an optional
> argument of login_required.


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



Re: Request specific data in generic views

2007-06-04 Thread Nathaniel Whiteinge

If you're using generic views your templates should already have the
`user` object in their context. You should be able to just use
{{ user }} to get the current user's username.

- whiteinge

On Jun 4, 8:51 am, konryd <[EMAIL PROTECTED]> wrote:
> Is it possible to send username to the template using generic views?
> My site needs to display "hello " but otherwise isn't more
> complicated than just trivial object_list.
>
> I read about serving a callable object to generic view in
> extra_content, but I'm not sure whether I can get request object from
> there.
>
> ... Or should I create my own view?


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



Re: Extending Flatpages

2007-06-02 Thread Nathaniel Whiteinge

Malcom is right, they're not as bad as they sound. :-)

In the case of the two things you mentioned wanting, latest news and a
calendar, the following existing template tags may just hook you up:

James Bennett's get_latest__ is copy-and-paste-able and works very
well. I use a slightly modified version in quite a few places.

.. __: 
http://www.b-list.org/weblog/2006/06/07/django-tips-write-better-template-tags

There's a snippet for a calendar__ template tag on djangosnippets.org.
I tried it out just now and it seems to work as advertised with a few
customizations--I found atoponce's comment at the bottom useful.

.. __: http://www.djangosnippets.org/snippets/129/

Good luck!
- whiteinge

On Jun 2, 9:14 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Sat, 2007-06-02 at 14:54 -0700, [EMAIL PROTECTED] wrote:
> > Oh no, that can not be! I just read this "Writing your own template
> > tags", it is quite complicated. Isn't there another way? Something
> > like "While you fetch the text for the flatpage, check the view
> > 'random_testemonial' and then go render the template."
>
> Since the template tags for Python document is a reference document, not
> a tutorial, realise that it contains a lot more detail than you might
> necessarily need on the first pass. That can't really be helped, because
> reference docs that include all the nitty details are necessary and we
> can't always cater for the people just learning the language at the
> expense of those who are trying to do advanced things (the first group
> graduates to become the second group, but not vice verse, so the second
> group is always growing).
>
> Don't try to code anything up until you reach the "Shortcut for simple
> tags" 
> section:http://www.djangoproject.com/documentation/templates_python/#shortcut...
>
> Many tags require exactly one extra line of code to turn a function
> returning a string into a tag.
>
> Malcolm


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



Re: Generic views: how to use them properly?

2007-06-02 Thread Nathaniel Whiteinge

The only argument that is `required for the create_object generic
view`__ is a model.

.. __:http://www.djangoproject.com/documentation/generic_views/#django-
views-generic-create-update-create-object

I've run into this problem a few times when I was getting started. It
took me a while to get acclimated to reading the built-in
documentation for some reason, but most of the info I've ever needed
turned out to be in there. :-P

I'm afraid I've never used the create and update generic views, so I
can't warn you about any pitfalls. The reason I've never used them is
they haven't been updated for Django's newforms yet--so use caution,
things may change when they're updated.

Good luck.
- whiteinge


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



Re: new forms - processing the form without rebuilding the entire view

2007-04-18 Thread Nathaniel Whiteinge

Personally, I use a toolkit to lessen cross-browser compatibility
problems as well as to speed quick, little functionality (eg.
animations). I chose jQuery because it's small, unobtrusive, and I
love the CSS-like syntax.
- whiteinge

On Apr 18, 3:11 am, Tipan <[EMAIL PROTECTED]> wrote:
> Thanks Guys,
>
> I've read through all the links and I can see plenty of scope with
> Ajax/JSON.
>
> I note that most of the solutions use a Javascript toolkit such as
> Prototype/Dojo/Yahoo/JQuery. Two questions come to mind:
>
> 1. Does using the toolkit save a lot of work - what are the main
> advantages?
> 2. How do you choose between them?
>
> Tim


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



Re: new forms - processing the form without rebuilding the entire view

2007-04-16 Thread Nathaniel Whiteinge

I'm doing something pretty similar sounding with jQuery. I wanted to
check for form validation errors via Ajax and do a regular form
submission otherwise.

The JavaScript:
http://dpaste.com/hold/8571/

The Python:
http://dpaste.com/hold/8572/

The code might be a little weird looking. I'm relying on a 403
response header to detect validation errors and the X-Requested-With
request header to detect Ajax.

Feel free to drop me a line for more explanation if you want.
- whiteinge


On Apr 13, 8:29 am, "Tipan" <[EMAIL PROTECTED]> wrote:
> I've created a view that is made up of several elements such as main
> content, sidebar information navigation bar. The main content is
> derived from specific data dependent on the parameter passed to the
> view. .../page/3 etc.
>
> The view is rendered as a series of template extensions from a master
> base.html. Elements also use inclusion tags.
>
> I want to include a form field in the main part of the view and have
> displayed this as an inclusion tag. The purpose of the form is to
> enable a user to enter a code which can be checked in the database.
> Error messages need to be returned to this view, if code is valid the
> user will be passed to a new view.
>
> However, I'm not sure of the best way to process the form for error
> messages without rebuilding the complete view, which seems to be a lot
> of overhead when you consider all the relevant queries that have to be
> re-done.
>
> Can any one advise on best practice here, or a means by which I can
> cache the original view?


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



Re: Detect ajax request

2007-04-10 Thread Nathaniel Whiteinge

I've been happily using limodou's suggestion with the jQuery framework
for a few weeks, hopefully whatever framework you're using also sends
the X-Requested-With header--it just feels cleaner.

if request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest':
# do stuff...

- whiteinge


On Apr 10, 8:56 am, Tim Chase <[EMAIL PROTECTED]> wrote:
> > Is there a standard way to detect if a request was an ajax one?  I
> > know I could append a key to the ajax request like in Mr. Bennett's
> > post here:
>
> >http://www.b-list.org/weblog/2006/07/31/django-tips-simple-ajax-examp...
>
> > iehttp://website.com/some/request/?xhrand in my view, dump out json
> > accordingly, etc, but I was wondering if there was a standard way
> > without attaching a key (perhaps looking at a request header).
>
> One of the beauties of the web is that a request is a request is
> a request.  Information can be transmitted in the URL, in
> cookies, or in HTTP-authentication.  One might also be able to
> tweak the other HTTP headers.  My interpretation of the web
> philosophy says that you want to refer to the resource:
>
>http://example.com/path/to/resource
>
> If you want to alter the format, you can either make it a
> pseudo-resource:
>
>http://example.com/path/to/resource/json
>
> or pass it as a parameter:
>
>http://example.com/path/to/resource?format=json
>
> I tend to prefer the latter, because it's clearly the same
> resource, just changed-up a bit in the formatting dimension
> (plain-text, HTML, XML, JSON, YAML, CSV, tab-delimited, etc).  I
> do similarly for sorting options:
>
>http://example.com/path/to/resource?order=fieldname
>
> Just my $0.02
>
> -tkc


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



Re: render_to_response with #anchor

2007-03-15 Thread Nathaniel Whiteinge

If it helps, I'm using anchors in a get_absolute_url() function in a
model for a forum app, and they're working just fine (even with
pagination).

def get_absolute_url(self):
paginate_by = 30
posts = self.thread.post_set.count()
if posts > paginate_by:
page = '?page=%s' % ((posts / paginate_by) + 1)
else:
page = ''
return "%s%s#post_%s" % (self.thread.get_absolute_url(),
  page, self.id)

- whiteinge


On Mar 15, 2:19 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2007-03-15 at 07:51 +, char wrote:
> > I'd like to be able to do something like the following in views.py:
>
> > return render_to_response( 'my_app/my_page.html/#my_anchor',
> > context_instance=RequestContext( request ) )
>
> > The above obviously doesn't work because it's just a filepath, not a
> > url. But basically, when I return from a view to a particular web page
> > I'd like to specify an anchor tag to return to. Is there a way to do
> > this? I'd also like to do this with HttpResponseRedirect as well.


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