Logger parameters not accepted in AdminMailHandler?

2011-10-16 Thread momo2k
Hello,

strange Problem here:

LOGGER = logging.getLogger('somename')
LOGGER.error('Could not do something: %s', err.output, exc_info=True)

In the mail it shows 'Could not do something: %s', but in the logfile
(RotatingFileHandler) %s is correcly substituted by err.output. Am I
missing the paragraph were this behaviour is described in the docs or
is it a bug?

Greets
momo

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



Re: "Dynamic" Typing for Models?

2011-10-03 Thread momo2k
A minute ago I have understood what proxy inheritance is good for.
sorry!

On 4 Okt., 01:26, momo2k  wrote:
> Hello,
>
> this may be a python-general question, but it came across my way while
> working with django:
> Imagine you have a model:
>
> class A(Model)
>     name = CharField()
>     type = SmallIntegerField(choices=SOME_TYPES)
>
>     def do_something(self):
>         fancy_things
>
> I want do_something() do different things based on the actual type of
> the instance. I know that this is a typical use case of subclassing,
> but for some reasons (mostly avoiding generic m2m-relationships) I
> decided to keep everything in one table.
> My current implementation uses python-style switches to solve this
> problem::
>
> def do_something(self):
>     try:
>         {TYPE1: do_something1,
>          TYPE2: do_something2}[self.type]()
>     except KeyError:
>         raise ValueError('type not known')
>
> This is very verbose and not DRY.
> I thought about solving this problem by changing the base class on the
> fly using __bases__. But this seems to be very dirty. In addition,
> this would have to be done every time self.type changes. I don't know
> which hook I could use for this.
> Second thought was using a read property self.impl which provides the
> particualar implementations for a type:
>
> class _Type1Impl(object):
>     def  do_something(self):
>         ...
>
> @property
> def impl()
>     type_switch_here ...
>
> def do_something(self):
>     return self.impl.do_something()
>
> But this is also some verbose because of the "redirection" to
> self.impl and I can imagine python provides much better ways to
> achieve my goal.
>
> Any suggestions?
>
> Greets
> momo

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



"Dynamic" Typing for Models?

2011-10-03 Thread momo2k
Hello,

this may be a python-general question, but it came across my way while
working with django:
Imagine you have a model:

class A(Model)
name = CharField()
type = SmallIntegerField(choices=SOME_TYPES)

def do_something(self):
fancy_things

I want do_something() do different things based on the actual type of
the instance. I know that this is a typical use case of subclassing,
but for some reasons (mostly avoiding generic m2m-relationships) I
decided to keep everything in one table.
My current implementation uses python-style switches to solve this
problem::

def do_something(self):
try:
{TYPE1: do_something1,
 TYPE2: do_something2}[self.type]()
except KeyError:
raise ValueError('type not known')

This is very verbose and not DRY.
I thought about solving this problem by changing the base class on the
fly using __bases__. But this seems to be very dirty. In addition,
this would have to be done every time self.type changes. I don't know
which hook I could use for this.
Second thought was using a read property self.impl which provides the
particualar implementations for a type:

class _Type1Impl(object):
def  do_something(self):
...

@property
def impl()
type_switch_here ...

def do_something(self):
return self.impl.do_something()

But this is also some verbose because of the "redirection" to
self.impl and I can imagine python provides much better ways to
achieve my goal.

Any suggestions?

Greets
momo

-- 
You received this message because you are subscribed to the Google 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: form.is_valid() NOT triggering model validation?

2011-09-29 Thread momo2k
Well, with the new knowledge about the debugger I found the place
where BaseModelForm calls all three form-validation methods in forms/
models.py:306:_post_form

Sorry.

On Sep 29, 9:26 pm, momo2k  wrote:
> That explains my thoughts that the debugger is "disturbing" the
> correct execution of the code, but this discussion does *not* (!)
> answer my question where the *model* of a *ModelForm* gets full_clean-
> ed - and why it doesn't do so in my case.
>
> On Sep 29, 8:48 pm, Shawn Milochik  wrote:
>
>
>
>
>
>
>
> > This exact thing was just discussed on this list.
>
> >https://groups.google.com/d/topic/django-users/R2HUGqZ1BAQ/discussion

-- 
You received this message because you are subscribed to the Google 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: form.is_valid() NOT triggering model validation?

2011-09-29 Thread momo2k
That explains my thoughts that the debugger is "disturbing" the
correct execution of the code, but this discussion does *not* (!)
answer my question where the *model* of a *ModelForm* gets full_clean-
ed - and why it doesn't do so in my case.

On Sep 29, 8:48 pm, Shawn Milochik  wrote:
> This exact thing was just discussed on this list.
>
> https://groups.google.com/d/topic/django-users/R2HUGqZ1BAQ/discussion

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



form.is_valid() NOT triggering model validation?

2011-09-29 Thread momo2k
Hello,

after hours of examinating and debugging the Django source code I
decided to post my problem here.

I'm using Django 1.3.1 and its docs say:


The is_valid() method and errors
Changed in Django 1.2: Please, see the release notes

The first time you call is_valid() or access the errors attribute of a
ModelForm has always triggered form validation, but as of Django 1.2,
it will also trigger model validation. This has the side-effect of
cleaning the model you pass to the ModelForm constructor. For
instance, calling is_valid() on your form will convert any date fields
on your model to actual date objects.


I'm using a FormView with a ModelForm. No matter if I add an instance
to the forms kwargs, the model.full_clean method is *not* called by
form.is_valid(). This is working fine later by

def form_valid(.

self.obj= form.save(commit=False)
self.obj.full_clean()

I thought my python skills would be OK after one and a half year of
django programming, but I neither get why the _errors attribute of the
BaseForm (forms.Form:109) is always ErrorDict, even directly after
assigning it to None (forms.Form:84) according to the pydev-debugger,
and therefore form.clean() is never called - nor where the
model.full_clean() method is called at all. The implementation of
ModelForm/BaseModelForm is not that confusing.
I would be lucky if someone could explain to me why model validation
is not triggered with my ModelForm and where to find the piece of code
that does it.

If you need more information, just ask, please.

-- 
You received this message because you are subscribed to the Google 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: ModelAdmin, custom field: default value?

2011-06-28 Thread momo2k
Thanks, working :)

def __init__(self, *args, **kwargs):
super(MealModelForm, self).__init__(*args, **kwargs)
try:
instance = kwargs['instance']
self.fields['price'].initial = instance.price()
except (KeyError, AttributeError):
pass

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



ModelAdmin, custom field: default value?

2011-06-27 Thread momo2k
Hello,

Is there a way to set dynamic default values for custom fields in the
admin?

Description of the problem:

# models.py
# there are two models
class Meal(models.Model):
name = ...

def check_new_price(self, price):
# checks if the price is new and creates a new price if
neccessary

class Price(models.Model):
meal = models.ForeignKey(Meal, )
valid_to = models.DateField() # None for current price
amount = CurrencyField() # nearly identical to IntegerField

# admin.py
# I extended the Admin with a custom form:
class MealModelForm(forms.ModelForm):
price = CurrencyFormField() # Nearly identical to Decimalfield
class Meta:
model = Meal

class MealAdmin(admin.ModelAdmin):
form = MealModelForm

def save_model(self, request, obj, form, change):
super(MealAdmin, self).save_model(request, obj, form, change)
obj.check_new_price(form.cleaned_data['price'])


My question is: How do i tell the django admin to display the current
price in the form field? I already tried to add an "price"-attribute
in the ModelAdmin.get_object() method, but that doesn't work. If I
call the Admin page for a meal, the price is blank instead of
displaying the current price.

So, repeating my first question: Is there a way to set dynamic default
values for custom fields in the admin?

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



Re: __unicode__() addition not working in basic poll application.

2011-05-16 Thread momo2k
Did you restart the interpreter after adding the code?

-- 
You received this message because you are subscribed to the Google 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: Makemessages Multiline

2011-05-08 Thread momo2k
Well, dos2unix solved

-- 
You received this message because you are subscribed to the Google 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: Makemessages Multiline

2011-05-06 Thread momo2k
No one?

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



Makemessages Multiline

2011-05-02 Thread momo2k
I'm using Django for about a year by now and I'm using translation
since users of my website are mixed german/english speaking.

makemessages works well on Windows, but on Debian 5 it doesn't work
with multiple line messages and I can't figure out why. I'm sure it's
a simple problem, but I don't get it :(


self.message = _('This is some error message, '
 'multiple lines!')

On windows:
msgid "This is some error message, multiple lines!"

Linux
msgid "This is some error message, "

There are newlines after the "'" and ")", backslash or plus after the
first line doesn't help...

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