FormWizard: how to pass in extra keyword arguments into a form's __init__?

2009-08-31 Thread Berco Beute

One of the forms I'm using in a FormWizard takes an aditional keyword
argument in its __init__, e.g.:

=
def __init__(self, arg1=None, *args, **kwargs):
pass
=

I'm at a loss how to make FormWizard construct my form while passing
in the extra keyword argument (arg1). Any ideas?

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



Re: How to show the email field in a UserCreationForm?

2009-08-11 Thread Berco Beute

To reply to my own question...I've extended UserCreationForm as
follows:

==
class UserCreationFormExtended(UserCreationForm):

def __init__(self, *args, **kwargs):
super(UserCreationFormExtended, self).__init__(*args,
**kwargs)
self.fields['first_name'].required = True
self.fields['last_name'].required = True

class Meta:
model = User
fields = ('username', 'email', 'first_name', 'last_name')
==

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



How to show the email field in a UserCreationForm?

2009-08-11 Thread Berco Beute

Hi,

I'm using the UserCreationForm for creating users, but I would like to
show the email, firstname and lastname fields as well (and they should
be required). Much like the view you get when adding a user through
the admin interface. What's the best way to do this? Extend
UserCreationForm? Or create my own forms from scratch?

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



Re: Django/ Python 3 - nervous about starting large project

2009-08-05 Thread Berco Beute

No worries, Python 2.6 will be actively supported for many, many years
to come and the differences between 2.6 and 3 are not that huge. You
can program for 2.6 while keeping in mind the code will be ported to 3
one day. It'll make a shift a breeze.

2B

On Aug 5, 10:47 pm, snfctech  wrote:
> Hello.
>
> We are researching technologies to begin what may become a pretty
> large intranet Dashboard project.
>
> I'm a PHP developer, so the fact that Django uses Python doesn't give
> me a head-start - but I've been wanting to consider it, because I am
> interested in learning Python.
>
> However, I'm nervous about the Python 3 situation.  What if I start
> building a large project based on Django/Python 2.6, and then a year
> or two down the road the project starts limping because of all of the
> cool new Python 3 modules coming out?  And I've got a bunch of Django/
> Python 2.6 code that needs to be ported?
>
> Any tips would be greatly appreciated.  Thanks.
>
> Tony
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Multiple instances of the same form on one page: how to get the right POST data?

2009-08-05 Thread Berco Beute

> You forgot to set the prefix here, so the form that the user is
> submitting their data from doesn't have the fields named correctly. You
> need to set it up exactly the same way at this point as you did in the
> POST path, with the exception of not prepopulating with data.

Thanks, the missing prefix was indeed one issue, although
prepopulating with data is not a problem. It didn't solve the problem
though. The problem arises from the fact that I'm rendering multiple
forms, but the user is POSTing back only one form. Each form has it's
own submit field. How do I know which form was submitted? I've tried
stripping the prefix from the subitted form, but that felt kind of
hacky (and didn't really work).

> Also, you've almost certainly left off an "else" clause here. You only
> want to create new, empty forms if the method is not POST (you can fall
> through to this point with request.method == "POST" and one of the forms
> being invalid).

You are absolutely right, I added that. Thanks.

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



Multiple instances of the same form on one page: how to get the right POST data?

2009-08-04 Thread Berco Beute

I'm trying to add multiple instances of the same form on one page,
each with its own submit button. I know how to use the 'prefix'
argument for a form to differentiate between forms, but I can't figure
out how to get the right data when it is POST'ed back (see view.py
below). Somehow the form stays invalid, no matter what I try. Any
suggestions what I may be doing wrong?

Thanks!

=models.py===
class Invite(models.Model):
invitation= models.ForeignKey(Invitation, verbose_name=_
('User'))
email_address = models.EmailField(_('email address'))
status= models.CharField(_('RSVP status'), max_length=1,
choices=settings.INVITE_RESPONSE_CHOICES)



=views.py===
def invite_resp(request):
invites = Invite.objects.all()
if request.method == 'POST':
invite_formz = [InviteForm(request.POST, prefix=str(index),
instance=invite) for index, invite in enumerate(invites)]
if all([invite_form.is_valid() for invite_form in
invite_formz]):
invite = invite_form.save()
return HttpResponseRedirect('/')
invite_forms = [InviteForm(instance=invite) for index, invite in
enumerate(invites)]
return render_to_response('invite_resp.html', {'invite_forms':
invite_forms}, context_instance=RequestContext(request))


=forms.py
class InviteForm(forms.ModelForm):

def __init__(self, label, *args, **kwargs):
super(InviteForm, self).__init__(*args, **kwargs)
self.fields['status'].label = label

class Meta:
model = Invite
exclude = ('invitation', 'email_address')


=page.html===
{% block content %}
{% for invite_form in invite_forms %}



{{ invite_form.status.label }}
{{ invite_form.status }}




{% endfor %}
{% endblock %}






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



Group-permission inheritance

2009-07-12 Thread Berco Beute

What's the recommended way for implementing (group)permission
inheritance in Django?

What I want to accomplish is a a hierarchy of groups where subgroups
inherit permissions from the parent group. I have seen
'comaie' (http://code.google.com/p/comaie-django-groups/) but that is
based on 'django-mptt' and both which seem at an early development
stage. Are there alternatives?

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



Re: Your IDE of choice

2009-01-06 Thread Berco Beute

On Jan 6, 2:35 pm, Pigletto  wrote:

> So, Netbeans is currently my IDE of choice. Good svn integration,
> faster than eclipse and komodo, stable, nice markup highlighting.

+1
I'm using SciTe and emacs for simple, single file editing.
I've used pydev for a while but eclipse's startup time is too long.
I've tried Eric (which is really nice), but the editor is less feature
rich than pydev and the auto-completion is hard to configure
Then I switched to Netbeans (after having used it 10 years ago for
Java development) and I'm really suprised by its speed and feature
richnes. The auto-completion is the best I've encountered. Highly
recommended.

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, 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: Redirect parent from within iframe without losing session

2009-01-05 Thread Berco Beute

This one still has me flabbergasted. It may be a browser restriction
(firefox 3), but there is no way I can have the iFrame redirect the
parent page to another page in the same domain (as the previous parent
page) without invalidating the session. Is there maybe another common
solution for iFrames to give back control to the parent page?

2B



On Jan 5, 10:43 am, Berco Beute <cybe...@gmail.com> wrote:
> The iFrame is from a different domain, which is likely causing the
> problem. I can see that the session is lost since the logged in user
> is suddenly logged out.
>
> 2B
>
> On Jan 5, 1:15 am, Daniel Roseman <roseman.dan...@googlemail.com>
> wrote:
>
> > Personally, I can't see how that redirect could be causing a session
> > to be 'lost'. As long as you stay within the same domain, your session
> > should remain valid. Are you sure that you are using 'localhost:8000'
> > as the original address as well as the redirected one? How are you
> > ascertaining that the session is being lost?
> > --
> > DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Port large webapp from PHP to Django: tips, experiences, links needed

2009-01-05 Thread Berco Beute

Still looking for some feedback. :)
In the meantime I've collected a few links that might be useful for
others with the same questions:

http://www.egenix.com/library/presentations/EuroPython2008-Designing-Large-Scale-Applications-in-Python/
http://highscalability.com/ebay-architecture
http://highscalability.com/
http://www.infoq.com/articles/ebay-scalability-best-practices
http://highscalability.com/unorthodox-approach-database-design-coming-shard
http://www.scribd.com/doc/429986/Scaling-an-early-stage-startup
http://www.coggeshall.org/resources/slideshow/id/530124
http://www.slideshare.net/directi/building-a-scalable-architecture-for-web-apps?src=embed
http://www.slideshare.net/davemitz/7-stages-of-scaling-web-applications
http://www.facebook.com/note.php?note_id=39391378919

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, 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: Redirect parent from within iframe without losing session

2009-01-05 Thread Berco Beute

The iFrame is from a different domain, which is likely causing the
problem. I can see that the session is lost since the logged in user
is suddenly logged out.

2B

On Jan 5, 1:15 am, Daniel Roseman 
wrote:
> Personally, I can't see how that redirect could be causing a session
> to be 'lost'. As long as you stay within the same domain, your session
> should remain valid. Are you sure that you are using 'localhost:8000'
> as the original address as well as the redirected one? How are you
> ascertaining that the session is being lost?
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Redirect parent from within iframe without losing session

2009-01-04 Thread Berco Beute

I'm still searching for a solution for this problem.
Which other forums should I try?

Thanks,
2B

On Jan 3, 5:33 pm, Berco Beute <cybe...@gmail.com> wrote:
> My page shows a (logged in) user an iFrame but when the iframe
> redirects the browser after it's done, the session is lost. The
> redirecting of the parent (by the iframe) is done as follows:
>
> =
> 
>     
>         function load() {
>             parent.location.href='<a  rel="nofollow" href="http://localhost:8000/somewhere">http://localhost:8000/somewhere</a>';
>         }
>     
> 
> ==
>
> Is there a way to keep the session alive (e.g. keep the user logged
> in)?
>
> Thanks,
> 2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Redirect parent from within iframe without losing session

2009-01-03 Thread Berco Beute

My page shows a (logged in) user an iFrame but when the iframe
redirects the browser after it's done, the session is lost. The
redirecting of the parent (by the iframe) is done as follows:

=


function load() {
parent.location.href='http://localhost:8000/somewhere';
}


==

Is there a way to keep the session alive (e.g. keep the user logged
in)?

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



Port large webapp from PHP to Django: tips, experiences, links needed

2009-01-02 Thread Berco Beute

I'm looking for additional information that could help me decide
whether I should port a large web application to Python/Django. The
application handles transactions, which often come in bursts. Peaks
may go up to tens of thousands of transactions per second. There are 3
views on the system: users (front-end), customers (back-end) and
admins. The current version of the application is built upon LAMP
(linux, apache, mysql, php) and the Smarty templating framework with a
separate database-server and file-server.

The reason for considering a complete rewrite is that the current
implementation has grown from a small, one-person project to a very
large web application and has reached its end of life. The minimal
amount of architecture, documentation and testing that went into it
makes that it has reached its limit with regards to scalability and
maintainability. The reason for considering alternatives to PHP is
that its characteristics (limited support for namespaces, no object
orientation (v4), polluted default namespace,...) has lead to a hard
to maintain codebase.

My personal experience with Python/Django gives me good hope that they
are up to the task, but I would like to hear from others what their
experiences are. Here are the topics that I would like to hear your
opinion/experience about:

- Stack. What would currently be a good combination webserver/protocol/
database? Possible options: Lighttpd, Cherokee, apache, FastCGI,
mod_python, wsgi, mysql, progress... I realize there is no 'best'
solution, but I would like to hear your recommendation.

- Database optimization. The database layer is currently the major
bottleneck. There is currently one database with over 150 tables, some
of which are quite large. Some queries take close to minute to execute
(yes, it's that bad). For redundancy reasons the database is
replicated to another server (master/slave), but that doesn't help
speeding up the response time. In the new version of the web
application the database layer should be as scalable and maintainable
as possible. This probably means using techniques such as 'sharding'
and partitioning. The question is what both Python and Django offer in
that respect.

- Advantages of an ORM. Currently the web application doesn't use an
ORM, but it would make development and maintanance a lot easier if it
would. The question is whether an ORM is a wise choice for such large
systems. Will what you gain in development speed and maintainability
outweigh what you (possibly) loose in speed, 'optimizability' and
adaptability?

- SQL optimization. When using an ORM the SQL gets abstracted away,
but as discussed above a certain amount of optimization is
unavoidable. How well does Django support SQL optimization? And if you
optimize your SQL, how do you then migrate to a new version?

- Database Migration. The database will likely change over time but
that should lead to as little downtime as possible. What options does
Django offer?

- Speed. The current version of the application is written in PHP and
is sufficiently fast. How about Django in that regard? Is that
something I should worry about?

- Security. Since the web application involves transactions security
is very important. Any tips/experiences/links/...?

- Templating language. Is Django's templating language up to replacing
Smarty? What are the pitfalls? Is it fast enough?

- Caching. Django has quite some caching support built in, but is it
enough for very demanding sites? What are the limits?

- Build automation and deploy strategy. In the past I have used
'maven' when developing Java applications and I liked it. What are
Python alternatives that I should check out? How do you evolve a
Django application without interrupting your service?

- Unit testing. Python supports many unit testing frameworks. Which
would you recommend when rebuilding a large application from scratch?
How would you set up your test environment? How to test all aspects of
such a large system (preferably automatically)?

- Switching a development team to Python/Django. I'm familiar with
Python/Django myself, but three other developers not (although they
are eager to learn it). Although Python is one of the most 'learnable'
languages, it still takes time to find your way in the standard
library and to become a real Pythonista. Does anyone here have
experience switching a small development team to Python/Django?

- Bzr or Hg? :)

There are most certainly many more relevant aspects that I didn't
mention here but that I would love to hear about. Please share them,
just like links to relevant sites you may have.

Thank you very much.
2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 

Re: Form stays invalid even after required field has been set

2008-12-10 Thread Berco Beute

On Dec 10, 7:24 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> You say you excluded 'product' from the form but the code you posted has not
> excluded 'product', it has excluded 'parent' and 'usePrice'.

Ahem[hides under a rock in shame]...I guess copy/paste got me
there.

> Also, the technique you are using of creating the ModelForm with an instance
> parameter so as to provide values for fields that are excluded from the form
> (as described 
> here:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a...)
> is to avoid errors during model save, not form validation.  This data is not
> used during form validation (after all it's for supplying values for the
> model instance for fields excluded from the form -- so the form knows
> nothing of these fields and won't attempt to validate them.  You seem to be
> confusing two separate things here -- what's a required field on the form
> and what's required when saving an instance to the DB.

Very valuable insight. Thanks. I indeed confused the two, but the real
problem was of course that I was excluding the wrong formfield. :(

Thanks,
2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 stays invalid even after required field has been set

2008-12-10 Thread Berco Beute

Thanks. There are no non-field errors though. Outputting the incoming
request object shows the error:

orderLineForm  is invalid: Product:This field
is required.

The 'product' is required it says, but I just set it 2 lines before...

2B

On Dec 10, 6:32 pm, Tim <[EMAIL PROTECTED]> wrote:
> Try adding this to your template:
>
> {% if form.non_field_errors %}
> {{form.non_field_errors.as_ul}}{% endif %}
>
> This will tell you form errors that aren't specific to a field.
>
> Tim
>
> On Dec 10, 8:26 am, Berco Beute <[EMAIL PROTECTED]> wrote:
>
> > Here's the code:
>
> >http://dpaste.com/97758/
>
> > My modelform stays invalid although the required fields of the
> > instance are set. The 'product' field is excluded from the form
> > because it shouldn't be edited. When the form is posted I'm trying to
> > set the product on the form instance again, but that somehow doesn't
> > work out to well.
>
> > In line 17 the form is found to be invalid although I set the
> > OrderLineForm's OrderLine instance has the required 'product' field
> > set with the appropriate object (tested at line 16). I thought
>
> > I've successfully used this strategy in other projects but I'm at a
> > loss what happens here. I'm also not sure how to debug this properly.
>
> > Any pointers/suggestions would be highly appreciated.
>
> > 2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Form stays invalid even after required field has been set

2008-12-10 Thread Berco Beute

Here's the code:

http://dpaste.com/97758/

My modelform stays invalid although the required fields of the
instance are set. The 'product' field is excluded from the form
because it shouldn't be edited. When the form is posted I'm trying to
set the product on the form instance again, but that somehow doesn't
work out to well.

In line 17 the form is found to be invalid although I set the
OrderLineForm's OrderLine instance has the required 'product' field
set with the appropriate object (tested at line 16). I thought

I've successfully used this strategy in other projects but I'm at a
loss what happens here. I'm also not sure how to debug this properly.

Any pointers/suggestions would be highly appreciated.

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: range-like template tag?

2008-12-08 Thread Berco Beute

Ah! Of course, why didn't I think of that! Works like a charm.

Thx!
2B

On Dec 8, 7:23 pm, Adi Sieker <[EMAIL PROTECTED]> wrote:
> Couldn't you add a method get_range() (or whatever name makes sense in  
> your context)
> to the class the object is an instqnce of.
> The method would look something like this:
>      def get_range(self):
>          return range(self.someInt)
>
> in your template you could then do:
>      {% for i in object.get_range %}
>
> adi
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: range-like template tag?

2008-12-08 Thread Berco Beute

The 'someInt' is an attribute of an object I pass to the template. It
varies with each object. I could of course make a dictionary with the
object and a list of the integers but it would be handy to solve it in
the template (although you may argue that such functionality should
stay out of the view)

2B

On Dec 8, 5:14 am, Jeff FW <[EMAIL PROTECTED]> wrote:
> You could write a very simple filter to do this.  Something like
> (untested):
>
> def range(top):
>     return xrange(0, top)
>
> then use {% for i in someInt|range %}
>
> I think it would still be better to pass it in the context--why can't
> you do that?
>
> -Jeff
>
> On Dec 7, 5:12 pm, Berco Beute <[EMAIL PROTECTED]> wrote:
>
> > Is there a template tag to turn an int into a sequence (like 'range')?
> > What I want to do is populate a select widget with the numbers up to
> > the int, like:
>
> > ==
> > 
> >     {% for i in someInt.range %}
> >         {{i}}
> >     {% endfor %}
> > 
> > ==
>
> > Passing the sequence through the context is not an option in my
> > particular case.
>
> > 2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



range-like template tag?

2008-12-07 Thread Berco Beute

Is there a template tag to turn an int into a sequence (like 'range')?
What I want to do is populate a select widget with the numbers up to
the int, like:

==

{% for i in someInt.range %}
{{i}}
{% endfor %}

==

Passing the sequence through the context is not an option in my
particular case.

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Sending HTML email

2008-09-23 Thread Berco Beute

> You might try reading the 
> documentation:http://docs.djangoproject.com/en/dev/topics/email/#sending-alternativ...

Oops, completely overlooked that. Thanks for the pointer.

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Sending HTML email

2008-09-23 Thread Berco Beute

Currently I'm sending plain text mails using:

###
from django.core.mail import EmailMessage
email = EmailMessage('hi', 'howdy', host, to)
email.send()
###

But now I want to use HTML in the body of the email. How do I format
such a message and can I just send it like above?

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Access help_text in template (for a custom form field)

2008-09-23 Thread Berco Beute

I have one custom field in my form and I can't get the help_text in a
template. In the admin the help_text shows up fine so I assume it has
something todo with my custom field:

###template
{{ form.guests.help_text }} #where 'guests' is a
CommaSeparatedEmailField as specified below


###custom formField###
class CommaSeparatedEmailField(forms.Field):
'''A form field for multiple, comma-separated email adresses'''
widget = forms.Textarea(attrs={'rows':
2,'cols':settings.TEXTAREA_COLS})

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

def clean(self, value):
'''
Checks whether all email adresses are valid and returns the
original string with abundant whitespaces removed
'''
if not value:
#this field may be blank
return ''
#remove leading/trailing whitespaces and empty emails
emails = [email.strip() for email in value.split(',') if
email.strip()]
if len(emails) > settings.EMAIL_MAX_NR_RECIPIENTS:
raise forms.ValidationError('Too many e-mail addresses
(%s), maximum number is %s' %
(len(emails),
settings.EMAIL_MAX_NR_RECIPIENTS))
for email in emails:
if not self.isValidEmail(email):
raise forms.ValidationError('%s is not a valid e-mail
address.' % email)
return ','.join(emails)

def isValidEmail(self, email):
if len(email) > 7:
import re
if re.match("[EMAIL PROTECTED]
{2,6}$", email) != None:
return True
return False
##


thanks,
2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



verbose_name in template?

2008-09-19 Thread Berco Beute

Is the fieldname or verbose_name of a instance-field (not a form-
field) accessible in a template?

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Login a User instance

2008-09-16 Thread Berco Beute

Thanks Rajesh,

I got a similar tip from someone else. I now specify the backend in
settings.py:

AUTH_BACKENDS = ('django.contrib.auth.backends.ModelBackend', )

where 'django.contrib.auth.backends.ModelBackend' is the default
backend. In my view I can then set the backend on the User instance as
follows:

user.backend = settings.AUTH_BACKENDS[0]

and subsequently login the user:

login(request, user)

I must say I find this a rather 'hacky' way of going about, but it
works nonetheless.

Thanks again!

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Login a User instance

2008-09-16 Thread Berco Beute

I have a User instance that I want to login. Normally in a view I
could just invoke authenticate() followed by login(), where the former
takes the username and password from the incoming request. In my case
I retrieve the User object from the db and only have the username, not
the plain password available. I do have the User instance though, so
is there a way to login that instance?

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Documentation for 'django.core.files.images.get_image_dimensions'?

2008-08-28 Thread Berco Beute

As a result of the discussion below I tried to find the documentation
for 'django.core.files.images.get_image_dimensions'

I can't find it in the official documentation. Here:

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

nor here:

http://docs.djangoproject.com

Of course I can find it *some*where on the inter webs, but shouldn't
it be in the official documentation? It was the reason I was
overlooking an elegant solution to my problem. The reason I'm posting
this is that I'm not used to not finding something in the Django docs.
They are usually of extraordinary good quality.

2B


On Aug 28, 12:13 am, Berco Beute <[EMAIL PROTECTED]> wrote:
> Thanks, that works great! I didn't know about 'from
> django.core.files.images import get_image_dimensions'. Where can I
> find documentation about that? I've tried a custom 'clean_image'
> before using PIL, but that was just plain ugly. I never knew about
> 'get_image_dimensions'.
>
> 2B
>
> > It's much simpler (and more appropriate) to do this in your form
> > itself. Specifically, add a clean_image method to your form and check
> > the image dimensions there. Then raise a forms.ValidationError on the
> > appropriate condition. Something along these lines would be a start:
>
> > def clean_image(self):
> > from django.core.files.images import get_image_dimensions
> > image = self.cleaned_data['image']
> > w, h = get_image_dimensions(image)
> > if w > 640:
> > raise forms.ValidationError(u'That image is too wide.')
> > return image
>
> > -Rajesh D
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: setting a form to invalid after having called form.is_valid()

2008-08-27 Thread Berco Beute

Thanks, that works great! I didn't know about 'from
django.core.files.images import get_image_dimensions'. Where can I
find documentation about that? I've tried a custom 'clean_image'
before using PIL, but that was just plain ugly. I never knew about
'get_image_dimensions'.

2B


> It's much simpler (and more appropriate) to do this in your form
> itself. Specifically, add a clean_image method to your form and check
> the image dimensions there. Then raise a forms.ValidationError on the
> appropriate condition. Something along these lines would be a start:
>
> def clean_image(self):
>     from django.core.files.images import get_image_dimensions
>     image = self.cleaned_data['image']
>     w, h = get_image_dimensions(image)
>     if w > 640:
>         raise forms.ValidationError(u'That image is too wide.')
>     return image
>
> -Rajesh D
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



setting a form to invalid after having called form.is_valid()

2008-08-27 Thread Berco Beute

I have an image upload form and I want to INvalidate the form if the
uploaded image it too big.  How can I get an error message in the form
saying the uploaded image is too big?

===Model==
class Image(models.Model):
image = models.ImageField(upload_to='imageupload')

===View===
if imageForm.is_valid():
inst = imageForm.save(commit=False)
if inst.image.width > 640:
#TODO: set the error message of this form to 'image is too
big'
=


Thanks,
2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Discard an uploaded image when returning a form with errors

2008-07-03 Thread Berco Beute

To answer my own question, I now moved the validation code to the form
and create a PIL image using
Image.open(StringIO(uploadedFile.content)):

===forms.py

class ImageForm(forms.ModelForm):

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

def clean_image(self):
uploadedFile = self.cleaned_data['image']
if uploadedFile:
from PIL import Image
from cStringIO import StringIO
try:
image = Image.open(StringIO(uploadedFile.content))
image.load()
image.verify()
if (image.size[0] > maxImgWidth) or (image.size[1] >
maxImgHeight):
raise
return self.cleaned_data['image']
except:
raise forms.ValidationError('Image is too big.')

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Discard an uploaded image when returning a form with errors

2008-07-03 Thread Berco Beute

Something tells me the validation actually belongs to the form, but
how can I get to the image size from within the form?

===forms.py
class ImageForm(forms.ModelForm):

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

def clean_image(self):
uploadedFile = self.cleaned_data['image']
#TODO: check image size, but how?
return self.cleaned_data['image']

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 template tags

2008-07-03 Thread Berco Beute

It should be in:
/project/application/templatetags/

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Discard an uploaded image when returning a form with errors

2008-07-03 Thread Berco Beute

I have a form for uploading images. When uploaded I check for a
maximum size, see snippet below. If it's too big I return the same
form but without the uploaded (big) image. Unfortunately the big image
is part of the returned form (I can tell since I display the image for
a form). Is there a way to reset the file? I've tried 'request.FILES =
None' but I'm not allowed to set request.FILES.

===snippet
newImage = imageForm.save(commit=False)
#image too big?
if (newImage.get_image_width() <= maxImgWidth and
newImage.get_image_height() <= maxImgHeight)
newHscImage.save()
else:
#How to discard the image?
pass
===

2B

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Multiple instances of same form: how to only saved the filled in ones?

2008-07-02 Thread Berco Beute

is_empty() was indeed what I was looking for. :)
For the time being I got it working using
any(form.cleaned_data.values())

Thanks for your great help!
2B

On Jul 2, 5:02 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Wed, 2008-07-02 at 07:58 -0700, Berco Beute wrote:
> > I have multiple instances of same the form (of which all fields are
> > optional), but I only want to save the form in case something is
> > filled in. How can I test that in my view?
>
> After checking that the form is valid (which means each field on the
> form will have to have required=False, since the form could be entirely
> empty), see if form.cleaned_data.values() contains anything. This
> becomes a bit easier once newforms-admin lands because we essentially
> implemented just that logic in the formsets there (and, from memory,
> there's even an is_empty() method to save typing).
>
> If you want to have some fields required if and only if any data is
> supplied, that's a little trickier. You still make each field optional
> in the form, but then clean() method on the form can check if
> cleaned_data contains anything and, if it does, check that *all* the
> required fields are present.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Multiple instances of same form: how to only saved the filled in ones?

2008-07-02 Thread Berco Beute

I have multiple instances of same the form (of which all fields are
optional), but I only want to save the form in case something is
filled in. How can I test that in my view?

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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-08 Thread Berco Beute

Great! A cleaner solution. Thanks!
Is there any effort underway for making overriding default widgets
simpler? I think that's really needed (especially for beginner like
me).

2B

On Jun 8, 1:20 am, Nathaniel Whiteinge <[EMAIL PROTECTED]> wrote:
> 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
-~--~~~~--~~--~--~---



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

2008-06-05 Thread Berco Beute

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. I've tried adding 'null=False' and 'blank=False' to the
ForeignKey but the empty value still appears. Any suggestions?

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Use variables inside an 'include' tag (and/or: how to set a variable in a template)

2008-06-03 Thread Berco Beute

Passing a complete context to a simple_tag doesn't (yet?) work, as
described here:
http://groups.google.com/group/django-users/browse_thread/thread/ee830466be465704/a41d89fd476becb1#a41d89fd476becb1

I finally solved my problem by defining my own tag as follows:

===
from django.template.loader import render_to_string
from django import template
from django.template import Variable
register = template.Library()

class IncludeTemplateNode(template.Node):
tagDir = 'some/dir/'

def __init__(self, template):
self.templateVar = Variable(template)

def render(self, context):
try:
actualTemplate = self.templateVar.resolve(context)
return render_to_string(self.tagDir + actualTemplate,
context_instance=context)
except:
return ''

@register.tag
def includeTemplate(parser, token):
bits = token.split_contents()
return IncludeTemplateNode(bits[1])

==

In my templates I can now simply use:

==
{% includeTemplate "title.html" %}
==

with 'title.html' being a (sub) template containing:

==
{% block title %}
{{ event.title }}
{% endblock %}
==

Thanks for all the help I received here!

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



pass complete context from template to simple_tag

2008-06-02 Thread Berco Beute

I've written a simple tag that renders a template, but to do so it
needs the complete context. How can I pass that from a template?

Thanks,
2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Use variables inside an 'include' tag (and/or: how to set a variable in a template)

2008-06-02 Thread Berco Beute

That's seems to be working, the only thing I've left to do is passing
the complete context from the template to the simple_tag, else the
simple_tag won't be able to render the template. How is that normally
done in Python?

2B

On May 31, 7:32 am, Alex Morega <[EMAIL PROTECTED]> wrote:
> Create your own tag - not an inclusion tag, but a simpletag. Something  
> like this:
>
> from django.template.loader import render_to_string
> from django import template
> register = template.Library()
>
> @register.simple_tag
> def my_include(directory, filename):
>      return render_to_string(directory + filename)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Use variables inside an 'include' tag (and/or: how to set a variable in a template)

2008-05-30 Thread Berco Beute

Unfortunately that doesn't work. This works:

 {{ include dir|concat:"/tag.html" }}

But not this:

 {% include dir|concat:"/tag.html" %}

Thanks, but I'm still searching for a solution...

2B

On May 29, 11:18 pm, Johannes Dollinger
<[EMAIL PROTECTED]> wrote:
> You could use a filter:
>
> @register.filter(name='concat')
> def concat(value, arg):
>         return "%s%s" % (value, arg)
>
> and then {% include dir|concat:"/tag.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: Use variables inside an 'include' tag (and/or: how to set a variable in a template)

2008-05-29 Thread Berco Beute

I can surely pass the path variable into the context from within my
view, but the view doesn't know which filename to include. So in the
template, I would still have to combine path and filename when
creating an include tag such as:

{% include "dir/tag.html" %}

But how can I combine the path 'dir' and the filename 'tag.html'?

Besides, passing the path into the context from within every view
isn't very elegant.

Thanks,
2B

On May 28, 9:57 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Could you set the entire path variable from within your view, then
> pass the path, including the filename, into the context?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: Use variables inside an 'include' tag (and/or: how to set a variable in a template)

2008-05-29 Thread Berco Beute

Inclusion tags sound good, but I'm not sure how it could solve my
problem. In my template I would like to use an inclusion tag this way:

###template
{% showTag 'tagName' %}


###inclusion tag
@register.inclusion_tag('tag.html')
def showTag(tagname):
#...


###tag.html
bla


But how can the inclusion-tag load the tag based on the name that is
passed to it?

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Use variables inside an 'include' tag (and/or: how to set a variable in a template)

2008-05-27 Thread Berco Beute

In the following 'include' tag the 'dir' may vary:

{% include "dir/tag.html" %}

so I would rather use something like:

{% include {{ dir }}"/tag.html" %}

which of course doesn't work. Is there a way to accomplish this? Being
able to set a variable inside a template would solve the problem, but
that is impossible as far as I know.

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



how to test whether an 'include' yields an empty string?

2008-05-27 Thread Berco Beute

How can I test whether the following (example) 'include' tag returns
any text?

{% include "dir/tag.html" %}

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 learning management application

2008-05-15 Thread Berco Beute

Sounds interesting. It would be great if you could share some details
on how you combined Django and Moodle.

2B

On May 15, 4:35 am, "Ariel Mauricio Nunez Gomez"
<[EMAIL PROTECTED]> wrote:
> Moodle and Django can coexist happily (Using same database and writing
> django models for some of the tables), That way you can take advantage of
> all the moodle functionality (Quizzes, lessons, forums) and have some
> business related code on django (Class scheduling, CRM, Billing).
>
> If you like the idea, I can post some details, I did it once.
>
> Moodle quizz module is _very_ complete, I wish we had something similar
> written by django.
>
> BTW, there was a django_quizz app post like 8 months ago on this list,
> search the archives.
>
> Regards,
> Ariel.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: capturing keyword and non-keyword arguments from urls

2008-05-15 Thread Berco Beute

Right! Thanks! I somehow totally missed that section of the
documentation.

2B

On May 14, 5:40 pm, "Scott Moonen" <[EMAIL PROTECTED]> wrote:
> Berco, named and unnamed arguments shouldn't be mixed.  See:
>
> http://www.djangoproject.com/documentation/url_dispatch/#the-matching...
>
> What the second paragraph means is that the URL handler is trying to call
> new(request, name = 'default') and (understandably) it is not working.  You
> should change the id into a named argument.
>
>   -- Scott
>
>
>
> On Wed, May 14, 2008 at 11:32 AM, Berco Beute <[EMAIL PROTECTED]> wrote:
>
> > I want to capture an 'id' and a 'name' from a url (slug) and pass them
> > to a method with signature new(request, id, name='default'). For
> > example I want to capture '8' and 'newname' from:
> > /new/8/newname
>
> > Somehow the following url dispatchers work and don't work. The error
> > says there is a non-keyword argument missing. What am I doing wrong?
>
> > urls.py
> > ==
> > FAILS:     (r'^new/(\d+)/(?P\w+)/$', 'app.views.new'),
> > FAILS:     (r'^new/(\d+)/(?P[a-z]+)/$', 'app.views.new'),
> > WORKS: (r'^new/(\d+)/(\w+)/$', 'app.views.new'),
>
> > views.py
> > ==
> > def new(request, id, name='default'):
> >    ...
>
> > Error
> > ==
> > new() takes at least 2 non-keyword arguments (1 given)
>
> > Passed variables:
> > ==
> > callback_args   ()
> > callback_kwargs         {'name': u'newname'}
>
> --http://scott.andstuff.org/|http://truthadorned.org/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 learning management application

2008-05-14 Thread Berco Beute

I've been using Moodle (moodle.org), which offers the functionality
you are looking for, and would prefer to use a Djange-based system as
well. I haven't found one though.

2B

On May 14, 5:26 pm, Wes Winham <[EMAIL PROTECTED]> wrote:
> Does anyone know of any learning management application written in
> Django? My googlefu is too weak and I wasn't able to find anything on
> django pluggables. I have a few weeks before I have to make the build
> versus integrate decision, but a simple quizzing application seems
> like something that would have potential uses across a variety of
> projects and I was surprised when I couldn't find one.
>
> The application I envision lets a user create quizzes out of multiple
> choice questions that can be automatically graded. Questions and
> quizzes could be linked through generic relations to any object. Quiz
> requirements could be assigned to users and reports could be run
> against those requirements.
>
> If there's really nothing around, then hopefully I'll be able to
> persuade my boss of the merits of open-sourcing such a generic,
> reusable application.
>
> -wes
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



capturing keyword and non-keyword arguments from urls

2008-05-14 Thread Berco Beute

I want to capture an 'id' and a 'name' from a url (slug) and pass them
to a method with signature new(request, id, name='default'). For
example I want to capture '8' and 'newname' from:
/new/8/newname

Somehow the following url dispatchers work and don't work. The error
says there is a non-keyword argument missing. What am I doing wrong?

urls.py
==
FAILS: (r'^new/(\d+)/(?P\w+)/$', 'app.views.new'),
FAILS: (r'^new/(\d+)/(?P[a-z]+)/$', 'app.views.new'),
WORKS: (r'^new/(\d+)/(\w+)/$', 'app.views.new'),

views.py
==
def new(request, id, name='default'):
...

Error
==
new() takes at least 2 non-keyword arguments (1 given)


Passed variables:
==
callback_args   ()
callback_kwargs {'name': u'newname'}
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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: CommaSeparatedEmailField

2008-04-22 Thread Berco Beute

Ah, Django's documentation is a treasure:

http://www.djangoproject.com/documentation/newforms/#a-simple-example
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



CommaSeparatedEmailField

2008-04-21 Thread Berco Beute

Is there something like a 'CommaSeparatedEmailField'? I know there is
a CommaSeparatedIntegerField, which is rather handy...

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 field overrides model attributes?

2008-04-20 Thread Berco Beute

Thanks, Phil! That works perfectly.

The only thing that feels awkward about Django's models is that the
attributes feel like a mixture of stuff that belongs to the view and
stuff that belongs to the model (blank=True, null=True anybody?). But
that's about the only small complaint I have about Django.

After returning to Django now I remember again what was so cool about
it: the community around it. :)

Thanks, everyone!
2B

PS: I'm using this widget: http://www.djangosnippets.org/snippets/391/

On Apr 20, 12:19 pm, "Phil Davis" <[EMAIL PROTECTED]> wrote:
> On 20/04/2008, Berco Beute <[EMAIL PROTECTED]> wrote:
> If you only want to change the widget type for a field you can just
> modify the form
> after creating it or do it in the __init__ method. This has the
> benefit of not having
> to repeat the label/required information in 2 places (model and form):
>
> #forms.py
>class EventForm(forms.ModelForm):
>
>   def __init__(self, *args, **kwargs):
>   super(EventForm, , self).__init__(*args, **kwargs)
>   self.fields['endDate'].widget = DateTimeWidget()
>
>  class Meta:
>   model = Event
>
> --
> Phil Davis
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Custom form field overrides model attributes?

2008-04-20 Thread Berco Beute

Using: Latest from trunk

I'm using a custom widget for datetimefields:

==
#models.py
class Event(models.Model):
endDateTime = models.DateTimeField('Finish', blank=True,
null=True)


#forms.py
class EventForm(forms.ModelForm):
endDateTime = forms.DateTimeField(widget=DateTimeWidget)

class Meta:
model = Event

==

But somehow the 'endDateTime' field is still required when rendering
the form and the label is 'endDateTime' instead of 'Finish'. Resetting
the app, syncing the db etc. doesn't help.

Any suggestions?

2B
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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 for model: how to inline-edit associated objects within the same form?

2008-03-08 Thread Berco Beute

Thank you very much, that was exactly what I was looking for!

2B

On Mar 3, 11:58 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Mon, 2008-03-03 at 14:23 -0800, Berco Beute wrote:
> > I want to create a form for editing existing Poll objects and their
> > associated Choice objects (see below). Editing the Poll objects is no
> > problem, the 'name' textfield shows up nicely. But I also want to edit
> > the associated Choice objects with the same form (much like you can do
> > on the automatically generated admin pages). Although Choices are
> > related to Polls through a ForeignKey they don't show up in the auto-
> > generated modelform.
>
> That's correct. At some point we'll have some "formsets" functionality,
> but that's still work in progress.
>
> Fortunately, it's very easy to do this on your own. Have a read of these
> two links (they're alternate approaches to the same goal) and you should
> be able to extend it to your particular situation:
>
>
> http://collingrady.com/2008/02/18/editing-multiple-objects-in-django-...
>http://www.pointy-stick.com/blog/2008/01/06/django-tip-complex-forms/
>
> Regards,
> Malcolm
>
> --
> Depression is merely anger without 
> enthusiasm.http://www.pointy-stick.com/blog/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google 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
-~--~~~~--~~--~--~---



Form for model: how to inline-edit associated objects within the same form?

2008-03-03 Thread Berco Beute

I want to create a form for editing existing Poll objects and their
associated Choice objects (see below). Editing the Poll objects is no
problem, the 'name' textfield shows up nicely. But I also want to edit
the associated Choice objects with the same form (much like you can do
on the automatically generated admin pages). Although Choices are
related to Polls through a ForeignKey they don't show up in the auto-
generated modelform.

How can I accomplish that? What is the 'sane' way of doing that?

2B

===MODEL
class Poll(models.Model):
name = models.CharField(max_length=200)

class Choice(models.Model):
poll = models.ForeignKey(Poll)
name = models.CharField(max_length=200)

===FORM
class PollForm(forms.ModelForm):

class Meta:
model = Poll

===VIEW
def edit(request, id):
poll = Poll.objects.get(id=id)
if request.method == 'POST':
form = PollForm(request.POST, instance=poll)
if form.is_valid():
form.save()
return HttpResponseRedirect('/home/')
else:
form = PollForm(instance=poll)
return render_to_response('edit.html', {'form': 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
-~--~~~~--~~--~--~---