Re: How to translate Lookup values in Django?

2012-10-03 Thread houmie
Thanks guys. I came across myself across django-modeltranslation and I 
must it works very well.




On 03/10/12 16:34, Jair Trejo wrote:
I use django-datatrans for catalog translation, i'ts not perfect but 
good enough for me.


El martes, 2 de octubre de 2012 20:09:46 UTC-5, Houmie escribió:

Thanks Juan.

Well that is certainly possible. But then we have also some other
lookups like the country, which is a lookup of 139 values. It
would be difficult to keep that in the model itself. ;-)
But you are right about smaller lookups.

Regards,
Houman

On 3 Oct 2012, at 01:57, Juan Pablo Martínez <jpm...@gmail.com
> wrote:


|GENDER_CHOICES = (
('male', _(u'Male')),
('female', _(u'Female')),
)
gender=  models.CharField(_(u'Sex'),  max_length=10, 
choices=GENDER_CHOICES)|


On Tue, Oct 2, 2012 at 7:23 PM, Houmie <hou...@gmail.com
> wrote:

Django has an excellent support for internationalization, any
English expression within Models, Forms, View or template can
easily be marked for translation. However I came across an
interesting situation I don't know how to deal with.

I have a Gender lookup (Male, Female). Now even if I
translated the site into German, the Gender dropdown is still
pointing to the values saved in database, which happens to be
in English. So How am I supposed to mark the values in the
database to be translated in PO files?

|class  Gender(models.Model):
 gender=  models.CharField(_(u'Sex'),  max_length=10) 



 def  __unicode__(self):
 return  self.gender
 class  Meta:


 verbose_name=  _(u'Sex')
 verbose_name_plural=  _(u'Sexes')


|


Many Thanks,

-- 
You received this message because you are subscribed to the

Google Groups "Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/mLjpKAPU1NAJ
<https://groups.google.com/d/msg/django-users/-/mLjpKAPU1NAJ>.
To post to this group, send email to
django...@googlegroups.com .
To unsubscribe from this group, send email to
django-users...@googlegroups.com .
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
<http://groups.google.com/group/django-users?hl=en>.




-- 
juanpex


-- 
You received this message because you are subscribed to the

Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com
.
To unsubscribe from this group, send email to
django-users...@googlegroups.com .
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
<http://groups.google.com/group/django-users?hl=en>.


--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/3U8FtzKa9IIJ.

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.


--
You received this message because you are subscribed to the Google 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 translate Lookup values in Django?

2012-10-02 Thread Houmie
 

Django has an excellent support for internationalization, any English 
expression within Models, Forms, View or template can easily be marked for 
translation. However I came across an interesting situation I don't know 
how to deal with.

I have a Gender lookup (Male, Female). Now even if I translated the site 
into German, the Gender dropdown is still pointing to the values saved in 
database, which happens to be in English. So How am I supposed to mark the 
values in the database to be translated in PO files?

class Gender(models.Model):
gender   = models.CharField(_(u'Sex'), max_length=10)
def __unicode__(self):
return self.gender
class Meta:
verbose_name = _(u'Sex')
verbose_name_plural = _(u'Sexes')


Many Thanks,

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/mLjpKAPU1NAJ.
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.



Ordering the forms within a formset? (How to override __iter__())

2012-09-24 Thread Houmie
 

deals_formset_factory = modelformset_factory(Deal, form=DealCForm, extra=1, 
can_delete=True, max_num=5)   
deals_formset = deals_formset_factory(queryset=query)

Is there a way to say the one extra form shall always be the first form no 
matter how many more instance forms are within the deals_formset?

I found this bit in the 
documentation
:

Iterating over the formset will render the forms in the order they were 
created. You can change this order by providing an alternate implementation 
for the __iter__() method.

Formsets can also be indexed into, which returns the corresponding form. If 
you override __iter__, you will need to also override __getitem__ to have 
matching behavior.

As I am still a bit new to python/django, I don't know where to begin. Is 
there any short example how __iter__() and __getitem() override have to 
look like? 

many Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/2_mvgRg0R-AJ.
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 create a formset that contains forms with a dropdown? (Crucial)

2012-08-17 Thread houmie

Thanks Melvyn,

To be honest I would be willing to purchase a widget if there was one. 
iw ill look into the list you have sent me.


On another note, Simone mentioned to extend the Formset in order to run 
my own dropdown solution.


I was just looking at the modelformset_factory class and - surpise 
surprise - it accepts a formfield_callback parameter, which could solve 
my dilemma.


I have used callbacks previously within a form to set localized to True:

class CallsForm(ModelForm):

def contact_date_callback(self, field, **kwargs) :

return field.contact_date(localize=True, **kwargs)


But I have no idea how to use it from view

formset_type = modelformset_factory(SalesItem, form=SalesItemFSForm, extra=0, 
formfield_callback= )


Do you happen to know how to use it?

If I was able to set the queryset for the sales_item field in that 
callback, I wouldn't have to extend the factory at all.



Many Thanks,
Houman



On 17/08/12 14:24, Melvyn Sopacua wrote:

On 17-8-2012 15:00, houmie wrote:


Yes, I know about overriding a widget. I could override a Charfield with
a TextArea.  For simple stuff it makes sense.
Against which widget do I override the existing M2M widget though?

If the one that Tomas linked doesn't work for you, you'll need to
consult the roll-your-own department or keep looking around for
different widgets, for example:
<http://www.djangopackages.com/grids/g/widgets/>



--
You received this message because you are subscribed to the Google 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 create a formset that contains forms with a dropdown? (Crucial)

2012-08-17 Thread houmie

Thanks Melvyn,

Yes, I know about overriding a widget. I could override a Charfield with 
a TextArea.  For simple stuff it makes sense.

Against which widget do I override the existing M2M widget though?


On 17/08/12 01:01, Melvyn Sopacua wrote:

On 17-8-2012 1:05, Houman wrote:


What I am trying to achieve would be deal type having a m2m
relationship to sales items. I don't like the m2m widget,

So change it. All ModelForm derivatives have a widgets argument that is
a dictionary of fieldname => widget 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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to create a formset that contains forms with a dropdown? (Crucial)

2012-08-17 Thread houmie

Thanks Thomas.

Just trying to apply the DropDownMultiple Widget that you have 
suggested. I have followed the instruction:


|class MyForm(forms.ModelForm):
categories = forms.Field(widget=DropDownMultiple)

def __init__(self, *args, **kwargs):
self.base_fields['categories'].widget.choices = 
Category.objects.values_list('id', 'name')
super(MyForm, self).__init__(*args, **kwargs)|


And I get an exception at python level.  This code seems to have been 
written in 2008. I wonder if its still working with the latest python 
and django. :(


As soon as I add the line

|categories = forms.Field(widget=DropDownMultiple)|

to my form i get this exception:

Traceback:

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in 
get_response

  111. response = callback(request, *callback_args, 
**callback_kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" 
in _wrapped_view

  20. return view_func(request, *args, **kwargs)

File "/home/houman/projects/my/my_app/views.py" in deal_template_view

  303. form = DealTypeForm(instance=deal)

File "/home/houman/projects/my/my_app/forms.py" in __init__

  252. super(DealTypeForm, self).__init__(*args, **kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py" in __init__

  247. error_class, label_suffix, 
empty_permitted)

File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py" in __init__

  95. self.fields = copy.deepcopy(self.base_fields)

File "/usr/lib/python2.7/copy.py" in deepcopy

  174. y = copier(memo)

File "/usr/local/lib/python2.7/dist-packages/django/utils/datastructures.py" in 
__deepcopy__

  129.for key, value in self.iteritems()])

File "/usr/lib/python2.7/copy.py" in deepcopy

  174. y = copier(memo)

File "/usr/local/lib/python2.7/dist-packages/django/forms/fields.py" in 
__deepcopy__

  180. result.widget = copy.deepcopy(self.widget, memo)

File "/usr/lib/python2.7/copy.py" in deepcopy

  190. y = _reconstruct(x, rv, 1, memo)

File "/usr/lib/python2.7/copy.py" in _reconstruct

  334. state = deepcopy(state, memo)

File "/usr/lib/python2.7/copy.py" in deepcopy

  163. y = copier(x, memo)

File "/usr/lib/python2.7/copy.py" in _deepcopy_dict

  257. y[deepcopy(key, memo)] = deepcopy(value, memo)

File "/usr/lib/python2.7/copy.py" in deepcopy

  163. y = copier(x, memo)

File "/usr/lib/python2.7/copy.py" in _deepcopy_dict

  257. y[deepcopy(key, memo)] = deepcopy(value, memo)

File "/usr/lib/python2.7/copy.py" in deepcopy

  190. y = _reconstruct(x, rv, 1, memo)

File "/usr/lib/python2.7/copy.py" in _reconstruct

  329. y = callable(*args)

File "/usr/lib/python2.7/copy_reg.py" in __newobj__

  93. return cls.__new__(cls, *args)

Exception Type: TypeError at /deal/add/

Exception Value: object.__new__(NotImplementedType) is not safe, use 
NotImplementedType.__new__()


On 17/08/12 02:22, Tomas Neme wrote:

DropDownMultiple widget

http://djangosnippets.org/snippets/747/



--
You received this message because you are subscribed to the Google 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 create a formset that contains forms with a dropdown? (Crucial)

2012-08-16 Thread houmie

Hi Xavier,

This wasn't the whole story.

I actually have a DealType class:

|class  DealType(models.Model): 
deal_name=  models.CharField(max_length=40)
sales_item=  models.ManyToManyField(SalesItem) 
price=  models.DecimalField(decimal_places=2)

|



DealType class has a many to many relationship to sales_item. Therefore 
using inline formsets wouldn't be possible.  I have tried it and inlines 
need foreign key.


What I am trying to achieve is to edit DealType like this:




Unlike the Many2Many widget, the one above is compatible to touch pads.

So I thought having an custom form that has a choiceField. I would feed 
the queryset of the choicefield with all entries of SalesItems.
And the user can Add these forms (as part of the formset) and select 
which sales item to put in the deal.


Once I get in the request.POST I could see which ones are added and do a 
manual custom save on DealType class.


Is it now a bit more clear what I am trying to achieve?

Many Thanks,
Houman



On 16/08/12 22:47, Xavier Ordoquy wrote:

Hi,

I'm not sure I understood what you're trying to do.

If you want to display all the SaleItem linked to a company in a formset, then 
inlines are what you're looking for.
You'll find the documentation about them there: 
https://docs.djangoproject.com/en/1.4/topics/forms/modelforms/#inline-formsets

Regards,
Xavier Ordoquy,
Linovia.



--
You received this message because you are subscribed to the Google 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 create a formset that contains forms with a dropdown? (Crucial)

2012-08-16 Thread Houmie
The question might seem too simplistic, but it seems formsets can only work 
with forms that have simple type fields such as charfield.
But has anyone tried to use a form with a dropdown and use that form to 
instantiate a formset?

Let me give you an example why this fails:

*Model:*

class SalesItem(models.Model):
item_description= models.CharField(max_length=40)
company = models.ForeignKey(Company)

Here I create a form with a dropdown, hoping to pass in the company as a 
source for the dropdown. Hold on to this thought, as I think that is not 
possible in my scenario.

*Form:*

class SalesItemFSForm(Form):
sales_item  =   forms.ModelChoiceField(required=False, queryset = '')

def __init__(self, company, *args, **kwargs):
super(SalesItemFSForm, self).__init__(*args, **kwargs)
self.fields.sales_item.queryset = company.salesitem_set.all()

Now within my view I would like to create a formset with this form:

formset_type = formset_factory(SalesItemFSForm, extra=0)

The problem becomes right away clear, as there seem to be no way that I 
could pass in the company to determine the source for the dropdown.

How would you solve this please?

Many Thanks,
Houman



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/YGT3FYCdYbUJ.
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.



(demo included) Switching Languages still relies on LANGUAGE_CODE for forms

2012-08-14 Thread Houmie
Hello,

I have created a small demo to show the problem. Please open the demo here: 
http://sandbox.chasebot.com/

When you click on British English, you can see how both the date- and Time 
format change.

Now if you click on Add, you will see how both date and time are 
pre-populated for you.  However they still carry the American date format, 
instead of the British language selection.

The only way to fix that was to change LANGUAGE_CODE = 'en-us' to 
LANGUAGE_CODE = 'en-gb' in settings.py. 
This approach would be obviously useless.

I have created formats.py to override the 'en' and 'en_GB' so I am clueless 
what else I could do.

Please be so kind and download my demo (22 kb) from my dropbox: 
https://dl.dropbox.com/u/4430/Sandbox.zip
All you have to do is to edit settings.py and adjust the path to sqlite.db 
to your path.

Have I overlooked something or is this a Django bug?

Many Thanks for your help,
Houman

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/GCMlI0kRGqsJ.
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: How to get American date format in a form?

2012-08-14 Thread houmie
I found here what I needed: 
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date

There are shortcuts to customize the settings.

Thanks for your kind help Melvyn.

Regards,
Houman


On 13/08/12 21:52, Melvyn Sopacua wrote:

On 13-8-2012 22:41, Melvyn Sopacua wrote:

On 13-8-2012 17:40, houmie wrote:


Its just a bit odd that templates show 11:15 p.m. Slight difference in
the formatting.  Also the dates within templates are defined like Aug
13, 2012.  Doesn't confirm with my definition in formats.py.
Are they stored somewhere else?

No, but you need the localize filter or tag:
<https://docs.djangoproject.com/en/1.4/topics/i18n/formatting/#controlling-localization-in-templates>

Wait, if this is the same data from the model, then you need to change
the DATE_FORMAT. DATE_INPUT_FORMAT is for form fields, since the form
field needs to be able to change it back to a format that python's
datetime.date will understand. DATE_FORMAT is used for plain output.



--
You received this message because you are subscribed to the Google 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: How to get American date format in a form?

2012-08-13 Thread houmie

Yes you are absolutely right about Date_Format and Time_Format.

But the Time_Format gives me trouble. By default it is defined as 
TIME_FORMAT = 'P' and the output is p.m. (see two dots)


My TIME_INPUT_FORMATS = ('%I:%M %p',)  produces PM (in capital case and 
I prefer it this way)


I tried to change TIME_FORMAT = 'P' to TIME_FORMAT = '%p', but it breaks.



On 13/08/12 21:52, Melvyn Sopacua wrote:

On 13-8-2012 22:41, Melvyn Sopacua wrote:

On 13-8-2012 17:40, houmie wrote:


Its just a bit odd that templates show 11:15 p.m. Slight difference in
the formatting.  Also the dates within templates are defined like Aug
13, 2012.  Doesn't confirm with my definition in formats.py.
Are they stored somewhere else?

No, but you need the localize filter or tag:
<https://docs.djangoproject.com/en/1.4/topics/i18n/formatting/#controlling-localization-in-templates>

Wait, if this is the same data from the model, then you need to change
the DATE_FORMAT. DATE_INPUT_FORMAT is for form fields, since the form
field needs to be able to change it back to a format that python's
datetime.date will understand. DATE_FORMAT is used for plain output.



--
You received this message because you are subscribed to the Google 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: How to get American date format in a form?

2012-08-13 Thread houmie
This is brilliant.  Thank you so much Melvyn.  Now I can switch the 
cultures between British and US without having to change any code. :)


I was also surprised to see that Django is using by default the military 
(24h) time. From what I remember the Americans usually prefer 12 hours 
AM/PM.


So I have overridden it like '%I:%M %p', and it works 11:15 PM within 
the forms.


Its just a bit odd that templates show 11:15 p.m. Slight difference in 
the formatting.  Also the dates within templates are defined like Aug 
13, 2012.  Doesn't confirm with my definition in formats.py.

Are they stored somewhere else?




On 13/08/12 15:30, Melvyn Sopacua wrote:

On 13-8-2012 16:16, houmie wrote:


But looking at this example, 'en/' is not good enough.  British English
is also `en` but the date format is European.  You know what I mean?
Again the culture seems to be forgotten :(
Unless I could define the path as en-GB/ and it would still be
recognized

django/conf/locale/en_GB/ exists.
The internationalization modules first look for specific then for the
less specific match if it doesn't exist.


--
You received this message because you are subscribed to the Google 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: How to get American date format in a form?

2012-08-13 Thread houmie

Thanks Melvyn for the example.

Interesting you get the same problem with American date output as I.  So 
its on purpose to pick the first available input-format from formats.py.
Which is very odd if you ask me. I was expecting this to be culture 
specific too.


Ok, let see how we can fix this. Thanks for the link, yes I could 
override DATETIME_INPUT_FORMATS within a custom-formats.py


mysite/
formats/
__init__.py
en/
__init__.py
formats.py


But looking at this example, 'en/' is not good enough.  British English 
is also `en` but the date format is European.  You know what I mean? 
Again the culture seems to be forgotten :(
Unless I could define the path as en-GB/ and it would still be 
recognized





On 13/08/12 14:49, Melvyn Sopacua wrote:

from django.utils.translation import activate
activate('en-us')
print form

...

...

activate('nl_NL')
print form

...

...

The reason is in django/conf/locale/en/formats.py. Localize uses the
first *_INPUT format available, which happens to be:
DATE_INPUT_FORMATS = (
 '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006',
'10/25/06'

So if you want a different input format, you'll need to override this as
described at:



--
You received this message because you are subscribed to the Google 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: How to get American date format in a form?

2012-08-13 Thread houmie
Thanks Carlos,  Yes I could utilize the format field as you suggested 
and it would work fine but this is bad.


I will have customers in USA and also in Europe. Both would run from the 
same server, hence I need eventually enable the localization according 
to the user's locality.


|MIDDLEWARE_CLASSES=  (
...
'django.middleware.locale.LocaleMiddleware',
)
|


So from then on the Americans can see their date in their format and 
Europeans in theirs.
If I hardcoded the format like this though, this would break it for one 
or the other group.  Django has to do it through the culture automatically.


I don't understand, it works for templates, inputformat for forms works 
as well, only the form-output is not working. So weird...I really am 
curios how the American Django users have setup their date fields in the 
ModelForm. :)   I think I have to wait til later today so they wake up 
and see the emails. :))


Thank you,
Houman


On 13/08/12 14:46, Carlos Palol wrote:

Try configuring your form field directly, like this:

class CallsForm(ModelForm):
contact_date = forms.DateField(
localize=True,
input_formats=['%m/%d/%Y'],
widget=forms.DateInput(attrs={
'placeholder'='Format is m/d/...',
})
)

class Meta:
model = Conversation

This combination of attributes input_formats and localize should make 
this field to use the m/d/y format for forms (always), while printing 
the value in the localized way (Aug. 31, 2012).


Cheers


On Monday, 13 August 2012 14:47:57 UTC+2, Houmie wrote:

Thanks Melvyn,

I have tried this:

def contact_date_callback(self, field, **kwargs) :
 return field.contact_date(localize=True, **kwargs)

But the date still shows as 2012-08-13

note, that Aptana Studio 3.0 complained that I put `self` first.

Nonetheless neither version works.

Any other idea? :(


On 13/08/12 13:20, Melvyn Sopacua wrote:
> def formfield_callback(field, **kwargs) :
> return field.formfield(localize=True, **kwargs)

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/7MlUvieqzRUJ.

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.


--
You received this message because you are subscribed to the Google 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: How to get American date format in a form?

2012-08-13 Thread houmie

Thanks Melvyn,

I have tried this:

def contact_date_callback(self, field, **kwargs) :
return field.contact_date(localize=True, **kwargs)

But the date still shows as 2012-08-13

note, that Aptana Studio 3.0 complained that I put `self` first.

Nonetheless neither version works.

Any other idea? :(


On 13/08/12 13:20, Melvyn Sopacua wrote:

def formfield_callback(field, **kwargs) :
return field.formfield(localize=True, **kwargs)


--
You received this message because you are subscribed to the Google 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: How to get American date format in a form?

2012-08-13 Thread houmie

Ahhh finally now I know what is happening:

MIDDLEWARE_CLASSES = (
...
'django.middleware.locale.LocaleMiddleware',
)

It seems as soon as the LocaleMiddleware is loaded, Django gets the 
settings frommy  browser session, Hence the dateformat is changed to 
European reflect my location. Clever.


Now that the date input is accepted in American dateformat.
Within the template I get // 
<http://127.0.0.1:8000/contact/1/call/delete/1> Aug. 31, 2012, which is 
also correct.

However in the forms, once I try to modify the record I get 2012-08-31

That doesn't seem right. Sure I could use the field format, but isn't 
that hardcoded and bad practice?


How do you guys in US do that?

Thanks,





On 13/08/12 10:48, Houmie wrote:


Hello everyone,

For some reason the American date format is not accepted in my form. I 
wonder if any Django developer from US could help me with this. I 
suspect the timezone in the settings also affect the date format, but 
I am not sure.


*Settings:*

|TIME_ZONE=  'Europe/London'
LANGUAGE_CODE=  'en-us'
USE_I18N=  True
USE_L10N=  True
USE_TZ=  True

|

*ModelForm:*

|class  CallsForm(ModelForm): 
class  Meta:
 model=  Conversation
 widgets=  {

 'contact_date':  forms.DateInput(attrs={'placeholder':  
'Add the date...',  'id':  'datepicker',  'class':  'placeholder_fix_css'},  
format='%m/%d/%Y'),
}
|

enter image description here

Any idea why the American Dateformat still isn't accepted?

Many Thanks,
Houman

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/uuMUxpVhbx4J.

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.


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



Django: How to get American date format in a form?

2012-08-13 Thread Houmie
 

Hello everyone,

For some reason the American date format is not accepted in my form. I 
wonder if any Django developer from US could help me with this. I suspect 
the timezone in the settings also affect the date format, but I am not sure.

*Settings:*

TIME_ZONE = 'Europe/London'
LANGUAGE_CODE = 'en-us'
USE_I18N = True
USE_L10N = True
USE_TZ = True

*ModelForm:*

class CallsForm(ModelForm):
   class Meta:
model = Conversation   
widgets = {
'contact_date': forms.DateInput(attrs={'placeholder': 'Add 
the date...', 'id': 'datepicker', 'class': 'placeholder_fix_css'}, 
format='%m/%d/%Y'),
   }

[image: enter image description here]

Any idea why the American Dateformat still isn't accepted?

Many Thanks,
Houman

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



Django Date formats - Please help

2012-07-11 Thread Houmie
Hi everyone,


class CallsForm(ModelForm):   
class Meta:
model = Conversation
widgets = {
'contact_date': forms.DateInput(),
 }

With a date input like this, my form shows the date like '2012-07-11', 
which seems international to me.

I live in UK and my settings is like the following:

TIME_ZONE = 'Europe/London'
LANGUAGE_CODE = 'en-us'
USE_I18N = True
USE_L10N = True

Eventually I would like to support both British and American date formats.
For the time being since the global language is set as American, I was 
expecting to see the American format.  mm/dd/yyy
But instead I see /mm/dd

How do I fix this in a proper way according to I18N, so that when later my 
users change the language to British English, they get to see the British 
format dd/mm/ without any further hacks?

I would really appreciate your help on this as I am researching since hours 
without any success.

Many Thanks,
Houman

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/QiqKfZYeBVAJ.
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: If using South, does it even matter what the underlying database is?

2012-07-07 Thread houmie

Oh one more thing:

I have created a new superuser for postgre called django_user

Now when I try to connect to it it says:

FATAL:  Peer authentication failed for user "django_user"

But the password is correct, I had no choice than change the settings 
in  /etc/postgresql/9.1/main/pg_hba.conf


from

# "local" is for Unix domain socket connections only
local   all all peer

to

# "local" is for Unix domain socket connections only
local   all all trust


Is this the normal approach?  Do I have to do the same thing on my 
production box?


Many 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: If using South, does it even matter what the underlying database is?

2012-07-06 Thread houmie

Thanks everybody for the encouragement.

Just to let you know you convinced me not giving up on postgresql.

It is actually quite nice that rules are tighter, to see right away what 
might be wrong (e.g. field length etc)


Starting up with postgresql is much harder than MySQL, but then it 
should be ok I think.


I have one further problem I am experiencing with postgre which I didn't 
with mySQL is the following:


I can't use double quotes in values, e.g.

|INSERT INTO app_country (country_code, country_name) VALUES ("AF", 
"Afghanistan")|


I get the error message: |ERROR: column "AF" does not exist|

This however works fine:

|INSERT INTO app_country (country_code, country_name) VALUES ('AF', 
'Afghanistan')

|

|This however gives me now a big headache with
|

|Cote  D'ivoire

The quote there breaks the string in my INSERT statement.

Any idea how to solve this?

Many Thanks,
Houman


|



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



If using South, does it even matter what the underlying database is?

2012-07-06 Thread Houmie
Today I have started my first steps into postgresql, since its recommended 
by the Django team.

I came across several issues, that I solved patiently one by one.

1) Creating tables under postgresql requires to login as a different OS 
login, from which you don't even know the password.  Fine, I found the 
solution and created the database.

2) After running syncdb, you can't simply execute a simple insert sql like 
this:

INSERT INTO App_contacttype (contact_type, company_id) VALUES ('Buyer', 
1),('Seller', 1);

Since Django creates it with quotes the table becomes case sensitive, hence 
it has to be like this:

INSERT INTO "App_contacttype" (contact_type, company_id) VALUES 
('Buyer', 1),('Seller', 1);

But the problems seem never to end. Now suddenly the execution of the 
insert script says 

ERROR: value too long for type character varying(40)
SQL state: 22001

In MySQL this was no problem. I don't know, right now I am getting a bit of 
cold feet, maybe I should just stick to MySQL.

The only reason I was considering postgresql was that some research 
suggested postgresql has much better support for changing Schemas along the 
way than MySQL.  

However considering http://south.aeracode.org/ would take away all the pain 
of syncing Schemas, would I even need to worry about Schema changes at all 
no matter what the underlying database is? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/26gOJtDT6UsJ.
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: Internationalization in Django 1.4 doesn't seem to work

2012-06-02 Thread Houmie

>
> Hi Kenneth,


The good news is the problem is solved. A friendly chap in stackoverflow 
actually bothered to look into it.

The problem is as simple as the translation files couldn't be found.  For 
some odd reason the important information about how Django locates them is 
at the very last section of the documentation. It is really easy to miss.

All you have to do is to move the locale directory with the translation 
files into your Application directory. Thats it !!!

If you need to recreate the translation files you need top use the 
terminal, browse to the Application directory and run your command 
'django-admin.py makemessages -l de' from there.  

You can't do this from Aptana Studio 3.0, since it requires you to run any 
Django command from the root rather than from application directory.  Hence 
you need to do it in the terminal.

Just download my test app and try what I just said here, as I intend to 
remove the test project within the next few days.

Regards,
Houman

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/RpGtuMns31oJ.
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: Internationalization in Django 1.4 doesn't seem to work

2012-06-01 Thread Houmie
Guys,


I have created a new simple test project to demonstrate the problem.  

It is a very simple project and you can switch between German & English at 
main page.  You see the selected Language code actually changes, which is a 
good sign but the translation simply doesn't happen. I wonder if this is a 
bug that needs reported. Your cooperation is highly appreciated.

Please download from here:
http://www.chasebot.com/TestProject.zip

Please let me know if you can reproduce it.

Many Thanks,
Houman

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/_KRPZ3R2PlMJ.
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: Internationalization in Django 1.4 doesn't seem to work

2012-06-01 Thread Houmie
Hi Ivan,

Thank you for your help.

I have already lazy translation implemented for the forms like this:

from django.utils.translation import ugettext_lazy as _

class FriendInviteForm(forms.Form):
name = forms.CharField(label=_("Friend's Name"))
email = forms.EmailField(label= _("Friend's Email"))


Surely at least the form should then change the words according to the
drop down settings.  But still no luck.  Its really hard to get this
working. Do you have any simple working example for me by any chance?
So I could compare line by line? :)


On Jun 1, 8:49 pm, Iván Raskovsky <raskov...@gmail.com> wrote:
> Besides changing the language per request as you've been indicated in
> SO you might want to look at lazy 
> translations:https://docs.djangoproject.com/en/dev/topics/i18n/translation/#lazy-t...
>
> Regards,
>     Iván
>
>
>
>
>
>
>
> On Fri, Jun 1, 2012 at 2:58 PM, Houmie <hou...@gmail.com> wrote:
> > Hey everyone,
>
> > I would really appreciate it if somebody could help me with this.
> > Working on this since this morning and am totally stuck..
>
> > I have posted it with proper formatting on stack overflow.
>
> >http://stackoverflow.com/questions/10854330/internationalization-in-d...
>
> > Thank you very much,
> > Houman
>
> > --
> > You received this message because you are subscribed to the Google 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 
> > athttp://groups.google.com/group/django-users?hl=en.

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



Internationalization in Django 1.4 doesn't seem to work

2012-06-01 Thread Houmie
Hey everyone,

I would really appreciate it if somebody could help me with this.
Working on this since this morning and am totally stuck..

I have posted it with proper formatting on stack overflow.

http://stackoverflow.com/questions/10854330/internationalization-in-django-doesnt-get-activated

Thank you very much,
Houman

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



OpenSource IDE with debugger capabilities of PyCharm

2012-05-31 Thread Houmie
Hi,

I have a question to the seasoned Django developers, I am relatively
new to Django and have been developing on Aptana Studio 3.0 since one
month.  While I think its a great free product, it seems debugging is
only limited to url.py and views.py. Beyond that there is no way to
set a break point in a template.

I just watched a video of pycharm and it seems pycharm is able to do
it.

I was wondering if I have setup Aptana incorrectly, and it would
support template debugging as well.

Otherwise is there any other open source django IDE you would
recommend that could debug templates?

Many thanks,
Houman

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



New to Jdango - What IDE to use?

2012-04-21 Thread Houmie
Hi everyone,

I was wondering which IDE you guys are recommending to use?
Important is ease of use and productivity. Price comes third if its
not free.

I tried already Aptana 3.0, but I get a weird error message upon
creating Django projects:
http://stackoverflow.com/questions/10261037/django-on-aptana-studio-3-0

Highly appreciated,
Houman

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



Hardware requirements for Djando development (Linux vs Mac)

2012-04-20 Thread Houmie
Hi,

This might sound like a strange question.  I am switching from
MVC .NET to Django/Linux environment. It makes most sense to go
completely linux (Ubuntu). But there is also the option of leaving PC
completely behind and start using a Mac for development.

As I am not familiar with Mac, is it true that a let say a Mac Mini is
powerful enough to run Python, Eclipse/PyDev and Django like its done
in Ubuntu without any problem?

Many Thanks,
Houman

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