Re: Rails-style form value deserializer?

2009-12-19 Thread Matt Schinckel
On Dec 20, 2:22 pm, Todd Blanchard  wrote:
> I think what i actually want is a form set, but I don't find that all that 
> well done either.
>
> What I'm finding lacking is the ability to put a master/detail relationship 
> in a single form.  For instance, Author/Books.

You can achieve this with an inline formset.

> Furthermore, I don't see a nice way to work with dynamically expanding forms 
>- IOW, allow the user to keep adding books to an Author using DHTML.

This, however, is harder. I have been thinking about the best way to
do this, and with a formset, you need to make sure that the POSTed
values match up with what the form management tags say.

More recently, I have been using jQuery, and the RESTful interface I
provided for my apps, to add an object. I haven't combined this with a
formset as yet, but one way might be to have a formset with a large
number of extra forms, that are hidden until a new one is added.  This
feels a little hacky, however.

> So far my impression of forms is - ick - lame.

I think of forms as simply the method of sanitising the input from the
user. I have had to subclass the forms quite heavily, but it can
generally do what I want.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Cron vs event triggered action

2009-12-19 Thread creecode
Hello Tim,

On Dec 19, 6:28 am, Tim Daniel  wrote:

> Brian & Creecode Django Custom management commands are really the same
> as this:
>
> from django.core.management import setup_environ
> import settings
> setup_environ(settings)
>
> or am I wrong? I'm just running the scripts with these three lines on
> top (even before the other import statements).

They both do the above.  Its just that the custom management commands
give you a little extra with it's built-in switches and such.  Use
whatever system works for your needs.

Toodle-l...
creecode

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: choice model with objects.values_list options

2009-12-19 Thread GoSantoni

Found this (old) post 
http://oebfare.com/blog/2008/feb/23/changing-modelchoicefield-queryset/

So i tried

class Post(models.Model):
blog = models.ForeignKey(blog)
.
url = models.ModelChoiceField
(queryset=Image.objects.values_list())

def __init__(self, *args, **kwargs):
super(Post, self).__init__(*args, **kwargs)
self.fields["url"].queryset = Image.objects.values_list
('image')

But i run into an AttributeError: 'module' object has no attribute
'ModelChoiceField'

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Rails-style form value deserializer?

2009-12-19 Thread Todd Blanchard
I think what i actually want is a form set, but I don't find that all that well 
done either.

What I'm finding lacking is the ability to put a master/detail relationship in 
a single form.  For instance, Author/Books.  Furthermore, I don't see a nice 
way to work with dynamically expanding forms - IOW, allow the user to keep 
adding books to an Author using DHTML.

So far my impression of forms is - ick - lame.

-Todd Blanchard


On Dec 19, 2009, at 4:37 PM, Karen Tracey wrote:

> On Fri, Dec 18, 2009 at 7:27 PM, Todd Blanchard  wrote:
> One thing I'm keenly missing from rails is the form input naming convention 
> that causes the form values to be converted into a hierarchy.  For instance,
> 
> 
> 
> 
> will result in the request values being stored as { 'foo'  : {'bar' : 'one', 
> 'baz' : 'two' }}
> 
> this is very handy when updating multiple related objects in a single form 
> submit.
> 
> Is there a similar facility for django/python or will I need to write it?
> 
> 
> I think you might be looking for the form prefix argument:
> 
> http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms
> 
> Karen
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: Rails-style form value deserializer?

2009-12-19 Thread Todd Blanchard
Clear as mud.  Where does it show how I update two objects in one form?

On Dec 19, 2009, at 1:16 PM, Antoni Aloy wrote:

> 2009/12/19 Todd Blanchard :
>> How does this solve the problem of having two related objects that have the
>> same attribute name (like "name") on the same html form?  As I see it, it
>> doesn't.  There will be a conflict and it will be impossible to keep them
>> separate.
>> IOW,
>> 
>> {{ account_form }}
>> {{ contact_form }}
>> 
>> 
>> def update_account_and_contact
>> if(request.POST)
>> account_form = AccountForm(request.POST, instance=get_object_or_404(Account,
>> id=request.POST['id'])
>> contact_form = ContactForm(request.POST, instance=get_object_or_404(Contact,
>> id=request.POST['id'])
>> if(account_form.is_valid() && contact_form.is_valid())
>> account_form.save()
>> contact_form.save()
>> .
>> 
>> The rails solution is much superior.
>> 
> 
> Thi is clearly explained in the Django documentation about forms
> http://docs.djangoproject.com/en/dev/ref/forms/api/#ref-forms-api
> 
> Django documentation us much superior :-P
> 
> 
> -- 
> Antoni Aloy López
> Blog: http://trespams.com
> Site: http://apsl.net
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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.




announcement: SHPAML (alternative to haml)

2009-12-19 Thread Steve Howell
Hi, I have ported some haml concepts to Python in my implementation of
SHPAML.  Details here:

http://shpaml.webfactional.com/

For those of you not aware of haml, haml is a markup language
implemented in Ruby that allows you to eliminate end tags in HTML.
Like Python itself, haml and SHPAML use indentation to eliminate the
need for block-ending syntax.  Whereas Python eliminates the end-
squiggly in scripting code, haml/SHPAML eliminates the need for end
tags in HTML.  If you hate Python, you will undoubtedly hate haml and
SHPAML.  If you like Python, you might like haml/SHPAML.

When I originally wrote SHPAML, I attempted to eliminate end tags in
my Django templates, such as endfor, endblock, endwith, and friends.
I decided to back off that strategy and just DRY up the HTML.  So
SHPAML has no explicit support for Django now, other than letting
Django template constructs gently pass through the preprocessor.

But the whole SHPAML website is still written in Django.  You can see
the markup here:

http://shpaml.webfactional.com/long_example

The Django markup for my website is now back to being lexically
repetitive, but that's okay.  Removing all the crufty syntax of HTML
lets the Django syntax stand out more clearly.

If you are passionate about DRY markup, please join the mailing list
on the site above and help me evolve this product!

One thing you might like about SHPAML is that you can try before you
buy.  Try it here:

http://shpaml.webfactional.com/try_it

Thanks,

Steve

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




choice model with objects.values_list options

2009-12-19 Thread GoSantoni
Hey just a newbie question about the design of the models.py What is
the best way to use the result of objects.values_list for  a choices
model ?

** shell ***
In [1]: from photos.models import Image, Pool

In [3]: Image.objects.values_list('image')
Out[3]: [(u'photologue/photos/wielrenfiets.jpg',), (u'photologue/
photos/example2.jpg',)]


** models.py ***

"""Post model."""
URL_CHOICES = (
(1, _(' generated from image list (so
wielrenfiets.jpg) . ')),
(2, _(' generated from image list (so
example2.jpg ). ')),
(3, _(' generated from image list .
')),
etc
)

url   = models.IntegerField(_('url'), choices=URL_CHOICES,
default=1)


Is this something for a ModelChoiceField or Formset ? This replacement
failed
url = ModelChoiceField(queryset=Image.objects.values_list
('image'))

thanks in advance

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: LDAP-groups problem

2009-12-19 Thread Peter Herndon

On Dec 18, 2009, at 10:15 AM, Peter Herndon wrote:

>> 
>> The error message came from command: python manage.py syncdb
>> Creating table ldap_groups_ldapgroup
>> Traceback (most recent call last):
>> 
> [snip]
>> cx_Oracle.DatabaseError: ORA-02329: column of datatype LOB cannot be
>> unique or a
>> primary key
>> 
> 
> In ldap_groups/models.py, the LDAPGroup.org_unit field is a TextField, and is 
> marked unique=True.  I'm thinking that the cx_Oracle backend is translating 
> the TextField into a Large Object (LOB) field in Oracle, and Oracle cannot 
> ensure uniqueness of a Large Object.  In short, remove the "unique=True" from 
> the ldap-groups code and try again.  It should work after that.
> 
> This error arises from an inconsistency between the behavior of Oracle and 
> the behavior of PostgreSQL, as Mike noted.  It works under Postgres.  I'll 
> check with the dev list and see if this behavior difference is known, and 
> whether the fix is to never use unique=True on a TextField (a bug in my 
> code), or something that needs to be smoothed over in the SQL generation for 
> Oracle specifically (a bug in the underlying Django behavior).
> 

Hi Wayne,

The limitation is known, there's a note in the Oracle backend mentioning that 
TextFields do not support indexes, which includes unique constraints.  For your 
use, just remove the unique=True from the model definition and run syncdb again.

Regards,

---Peter

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: install question:django-admin.py for help

2009-12-19 Thread Bob
Thank you very much for your quick response.  That seems to have fixed
it.  The site I used was 
http://codemagnet.blogspot.com/2008/12/py-association-in-vistawindows-missing.html
.  I had to go into the windows registry,   into the Computer/
HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command and
change the append a %* to the key which said "C:\Python26\python.exe"
"%1"  .


This was a real bear to figure out.  Thanks again

On Dec 19, 7:25 pm, Karen Tracey  wrote:
> On Sat, Dec 19, 2009 at 7:04 PM, Bob  wrote:
> > Hi,
> > I am trying to get started with django on windows vista.  I have
> > successfully installed it as "import django" works in python.
> > However, whenever I try at the command prompt
> > "django-admin.py startproject myproject"
> > I get "Type 'django-admin.py help' for usage".
> > I have tried four installs on 3 different machines and each time I get
> > this.  What am I doing wrong?
>
> Something is broken with the association of .py files to the python
> executable on the Vista machines -- whatever association is in place is not
> passing arguments along.  I don't know why this happens but I know I've seen
> it reported before.  I also don't have a Vista machine so I can't describe
> how to fix it but if you Google terms like Vista .py association you'll find
> plenty of hits of people who have run into the same thing, and some describe
> ways to fix the association.
>
> Karen

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Rails-style form value deserializer?

2009-12-19 Thread Karen Tracey
On Fri, Dec 18, 2009 at 7:27 PM, Todd Blanchard  wrote:

> One thing I'm keenly missing from rails is the form input naming convention
> that causes the form values to be converted into a hierarchy.  For instance,
>
> 
> 
>
> will result in the request values being stored as { 'foo'  : {'bar' :
> 'one', 'baz' : 'two' }}
>
> this is very handy when updating multiple related objects in a single form
> submit.
>
> Is there a similar facility for django/python or will I need to write it?
>
>
I think you might be looking for the form prefix argument:

http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms

Karen

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: very noob : DRY violation in views.py

2009-12-19 Thread Ethan Jucovy
Lately I have really liked using custom template tags for these sorts of
queries.

Once you get the hang of writing them, it's very quick to build a little
library of queries in custom tags for your application.  These are *very*
convenient to use because you don't have to modify views.py -- or any Python
code -- to use them in template in your entire project, e.g.

{{{
{% load my_custom_tags %}
{% get_all_properties limit 4 as all_properties %}

Viewing the first four properties:
{{all_properties.0.name}}
[...]
}}}

They also make reusable apps much more reusable, since you can use the
templatetags provided to integrate their data into your project.  And you
can even extend a reusable app's "template-ready query library" by defining
your own templatetags that use its models .. it's very powerful and
flexible.

-Ethan

On Sat, Dec 19, 2009 at 6:17 PM, Osiaq  wrote:

> @Brian
> Thank you very much for clear explanation!
> I gives me much more than enormous pages of manuals.
>
> @Itay
> Thanks for suggestion, but refractoring inside views.py looks more
> clear to manage.
> I wasn't also sure, if such simple solution requires middleware
> involved. I will probably have
> more than only this one example, so I was looking for as simple
> solution as it's possible.
>
> Thanks to both of you.
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: install question:django-admin.py for help

2009-12-19 Thread Karen Tracey
On Sat, Dec 19, 2009 at 7:04 PM, Bob  wrote:

> Hi,
> I am trying to get started with django on windows vista.  I have
> successfully installed it as "import django" works in python.
> However, whenever I try at the command prompt
> "django-admin.py startproject myproject"
> I get "Type 'django-admin.py help' for usage".
> I have tried four installs on 3 different machines and each time I get
> this.  What am I doing wrong?
>
>
Something is broken with the association of .py files to the python
executable on the Vista machines -- whatever association is in place is not
passing arguments along.  I don't know why this happens but I know I've seen
it reported before.  I also don't have a Vista machine so I can't describe
how to fix it but if you Google terms like Vista .py association you'll find
plenty of hits of people who have run into the same thing, and some describe
ways to fix the association.

Karen

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




install question:django-admin.py for help

2009-12-19 Thread Bob
Hi,
I am trying to get started with django on windows vista.  I have
successfully installed it as "import django" works in python.
However, whenever I try at the command prompt
"django-admin.py startproject myproject"
I get "Type 'django-admin.py help' for usage".
I have tried four installs on 3 different machines and each time I get
this.  What am I doing wrong?

Thanks,
Bob

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




install question:django-admin.py for help

2009-12-19 Thread Bob
Hi,
I am trying to get started with django on windows vista.  I have
successfully installed it as "import django" works in python.
However, whenever I try at the command prompt
"django-admin.py startproject myproject"
I get "Type 'django-admin.py help' for usage".
I have tried four installs on 3 different machines and each time I get
this.  What am I doing wrong?

Thanks,
Bob

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: very noob : DRY violation in views.py

2009-12-19 Thread Osiaq
@Brian
Thank you very much for clear explanation!
I gives me much more than enormous pages of manuals.

@Itay
Thanks for suggestion, but refractoring inside views.py looks more
clear to manage.
I wasn't also sure, if such simple solution requires middleware
involved. I will probably have
more than only this one example, so I was looking for as simple
solution as it's possible.

Thanks to both of you.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




Is this right: Modifying the admin changelist?

2009-12-19 Thread yummy_droid
Hi,

I wanted a "sum" of a particular column being listed in the admin list
page. I looked it up and did it the following way. Is this the correct
way of doing it?

I modified the admin.py to do the calculation:

 class CollectionAdmin(admin.ModelAdmin):
list_display = ('supplier', 'collected_date', 'tonnage',)
list_filter = ('collected_date',)

def changelist_view(self, request, extra_context=None):
from django.contrib.admin.views.main import ChangeList
from django.db.models import Sum
if extra_context is None:
extra_context = {}
mycl = ChangeList(request, self.model, list(self.list_display),
self.list_display_links, self.list_filter, self.date_hierarchy,
self.search_fields, self.list_select_related, self.list_per_page,
self.list_editable, self)
fieldsum = mycl.get_query_set().aggregate(Sum('tonnage'))
extra_context['tonnage__sum'] = fieldsum['tonnage__sum']
return super(CollectionAdmin, self).changelist_view(request,
extra_context=extra_context)

then i added the following line to change_list.html:

  {% if tonnage__sum %}Total tonnage: {{ tonnage__sum }}{% endif
%}

Am I doing something bad in the changelist_view function above? Or is
it the right way to do this?

the reason I want to use the admin list is because I like the
filtering option, and I can then see directly the sum of the column
based on whatever is currently filtered.

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-us...@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: Rails-style form value deserializer?

2009-12-19 Thread Antoni Aloy
2009/12/19 Todd Blanchard :
> How does this solve the problem of having two related objects that have the
> same attribute name (like "name") on the same html form?  As I see it, it
> doesn't.  There will be a conflict and it will be impossible to keep them
> separate.
> IOW,
> 
> {{ account_form }}
> {{ contact_form }}
> 
> 
> def update_account_and_contact
> if(request.POST)
> account_form = AccountForm(request.POST, instance=get_object_or_404(Account,
> id=request.POST['id'])
> contact_form = ContactForm(request.POST, instance=get_object_or_404(Contact,
> id=request.POST['id'])
> if(account_form.is_valid() && contact_form.is_valid())
> account_form.save()
> contact_form.save()
> .
>
> The rails solution is much superior.
>

Thi is clearly explained in the Django documentation about forms
http://docs.djangoproject.com/en/dev/ref/forms/api/#ref-forms-api

Django documentation us much superior :-P


-- 
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: very noob : DRY violation in views.py

2009-12-19 Thread Brian Victor
Osiaq wrote:
> def services(request):
>   property = Property.objects.all().order_by('name')[:4]
>   city = City.objects.all()
>   category=PropertyCategory.objects.all()
>   status=PropertyStatus.objects.all()
>   return render_to_response('website/services.html',{'property':
> property, 'city':city,'category':category,'status':status})
>
> def profile(request):
>   property = Property.objects.all().order_by('name')[:4]
>   city = City.objects.all()
>   category=PropertyCategory.objects.all()
>   status=PropertyStatus.objects.all()
>   return render_to_response('website/profile.html',{'property':
> property, 'city':city,'category':category,'status':status})
>
> How to define "property" just once and use it in many defs?

If you're looking to avoid repetition of more than just "property,"
there are a couple of simple refactorings you could use without having
to resort to context processors.

def get_standard_context():
return {
'property': Property.objects.all().order_by('name')[:4],
'city': City.objects.all(),
'category': PropertyCategory.objects.all(),
'status': PropertyStatus.objects.all(),
}

def services(request):
return render_to_response('website/services.html', 
get_standard_context())

def profile(request):
return render_to_response('website/profile.html', 
get_standard_context())


Or, you could move render_to_response into the refactored function:

def my_render_to_response(template):
property = Property.objects.all().order_by('name')[:4]
city = City.objects.all()
category=PropertyCategory.objects.all()
status=PropertyStatus.objects.all()
return render_to_response(template,{'property': property, 
'city':city,'category':category,'status':status})

def services(request):
return my_render_to_response('website/services.html')

def profile(request):
return my_render_to_response('website/profile.html')

-- 
Brian

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




Combine multiple Autopaginate on 1 page

2009-12-19 Thread GoSantoni
Guys got 2 columns generated by



{% autopaginate blogs_one 3 %}


{% for blog_post in blogs_one %}
{% show_blog_post blog_post %}
{% endfor %}

{% paginate %}




{% autopaginate blogs_two 3 %}

{% for blog_post in blogs_two %}
{% show_blog_post blog_post %}
{% endfor %}

{% paginate %}


Though like to show just one autopaginate navigator (previous, 1, 2
etc, next)
How do i combine them?

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-us...@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: SQL transaction style in django?

2009-12-19 Thread Christophe Pettus

On Dec 19, 2009, at 4:06 AM, Yusuf Mohsinally wrote:

> In your experience, would it be better to use the
> "@transaction.commit_on_success" decorator for the functions that need
> it, or turn on transaction middleware for the whole app?

My general approach, when using PostgreSQL as the backend, is to turn  
on Autocommit, and then use either the commit_on_success decorator or  
manual transaction calls for those functions that update the database.

The ideal situation is to have functions that just query the database  
run outside of an explicit transaction, wrapping those update  
operations that require it in their own transactions.

The downside of that is that using Autocommit affects the entire  
project, so other applications that you didn't write may be surprised  
when the default Django behavior of opening a transaction for each  
view method is defeated.
--
-- Christophe Pettus
x...@thebuild.com

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Humble-structure sites on Django // Suggestion needed

2009-12-19 Thread Brian McKeever
I'm not sure I'm entirely understanding your question, but yes, that
does look easy to implement with django.

What part is troubling you? You seem to have a good idea of what you
want.

On Dec 17, 6:42 am, tezro  wrote:
> Hello everyone. Making well-structured websites on Django is a very
> comprehensive process. All these blogs, news, user-related stuff -
> easy. But what about, say, corporate website? I mean I got a project
> to do, thought it would be great to base it on Django as usual, but...
>
> Look at the structure, it's pretty easy.
>
> /
> ––/about/
> ––/contacts/
> ––/history/
> ––/projects/
> /project1/
> /project2/
> /project3/
>
> All the pages should have some meta fields, text field to show, slug -
> something that is common for all pages. Now what is different for all
> that pages.
>
> Contacts page in addition to common fields should have fields in admin
> to edit: 2-4 phone numbers, link to Gmap, ImageField  and a ForeignKey
> for people related to contacts page (separate model with some fields).
>
> Projects page should have an ImageField too and a ForeignKey for some
> projects (separate model with some fields).
>
> About page should have ImageField, 2-5 FileFields, another TextField
> and some files as a ForeignKey model.
>
> So, as you see, there should be a number of different editable...
> things. All of them with differend fields and some with related
> models...
>
> Is it really easy to implement using Django? I'm not really sure how
> to do that...
>
> Thanks for replies ahead.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Strange problem when starting project in Windows XP

2009-12-19 Thread Dane
Ok, figured this one out with google.

Idle had taken over .py files. It was as simple as going to My
Computer, Tools, Folder Options, File Types, scrolling down to .py,
and clicking Restore Default (which is python).

Thanks for the help all!

On Dec 19, 2:14 pm, Dane  wrote:
> C:\Python26\Scripts is where django-admin.py is, and it's in my PATH
> variable. It's strange because C:\Python26 (the path to python itself)
> is also in the same PATH variable, and that is working. If I just type
> 'python', I do get the shell.
>
> If idle.pyw has taken over .py associations, how would I check/change
> that?
>
> On Dec 18, 12:59 pm, OkaMthembo  wrote:
>
> > Hi Dane,
>
> > Yes, when you have to specify an absolute path to get it working, it
> > definitely sounds like a PATH environ config. problem. When you check your
> > PATH variables, do you see the folder to django-admin.py listed?
>
> > Regards,
> > Lloyd
>
> > On Fri, Dec 18, 2009 at 7:27 PM, Dane  wrote:
> > > It worked with 'python c:\python26\scripts\django-admin.py
> > > startproject newsite'. Does that mean the PATH got messed up somehow?
>
> > > On Dec 18, 7:52 am, Shawn Milochik  wrote:
> > > > What happens when you type 'python django-admin.py'?
>
> > > > If that doesn't work, try replacing 'python' there with the full path to
> > > your Python executable in Windows. I've never heard of this problem, but 
> > > it
> > > sounds like it could be something odd in the environment.
>
> > > > Shawn
>
> > > --
>
> > > You received this message because you are subscribed to the Google Groups
> > > "Django users" group.
> > > To post to this group, send email to django-us...@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.
>
> > --
> > Regards,
> > Sithembewena Lloyd Dubehttp://www.lloyddube.com

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Strange problem when starting project in Windows XP

2009-12-19 Thread Dane
C:\Python26\Scripts is where django-admin.py is, and it's in my PATH
variable. It's strange because C:\Python26 (the path to python itself)
is also in the same PATH variable, and that is working. If I just type
'python', I do get the shell.

If idle.pyw has taken over .py associations, how would I check/change
that?

On Dec 18, 12:59 pm, OkaMthembo  wrote:
> Hi Dane,
>
> Yes, when you have to specify an absolute path to get it working, it
> definitely sounds like a PATH environ config. problem. When you check your
> PATH variables, do you see the folder to django-admin.py listed?
>
> Regards,
> Lloyd
>
>
>
> On Fri, Dec 18, 2009 at 7:27 PM, Dane  wrote:
> > It worked with 'python c:\python26\scripts\django-admin.py
> > startproject newsite'. Does that mean the PATH got messed up somehow?
>
> > On Dec 18, 7:52 am, Shawn Milochik  wrote:
> > > What happens when you type 'python django-admin.py'?
>
> > > If that doesn't work, try replacing 'python' there with the full path to
> > your Python executable in Windows. I've never heard of this problem, but it
> > sounds like it could be something odd in the environment.
>
> > > Shawn
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@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.
>
> --
> Regards,
> Sithembewena Lloyd Dubehttp://www.lloyddube.com

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Rails-style form value deserializer?

2009-12-19 Thread Todd Blanchard
How does this solve the problem of having two related objects that have the 
same attribute name (like "name") on the same html form?  As I see it, it 
doesn't.  There will be a conflict and it will be impossible to keep them 
separate.

IOW,


{{ account_form }}
{{ contact_form }}



def update_account_and_contact
if(request.POST)
account_form = AccountForm(request.POST, 
instance=get_object_or_404(Account, id=request.POST['id'])
contact_form = ContactForm(request.POST, 
instance=get_object_or_404(Contact, id=request.POST['id'])
if(account_form.is_valid() && contact_form.is_valid())
account_form.save()
contact_form.save()
.


The rails solution is much superior.



On Dec 19, 2009, at 2:15 AM, Jani Tiainen wrote:

> 
> 
> 
> Result is stored in request.POST (or you can do same with get params, 
> ?foo=one=two). 
> 
> for example request.POST.getlist('foo'). Default getitem implementation 
> returns only last occurence from list.
> 
> See: 
> http://docs.djangoproject.com/en/1.1/ref/request-response/#querydict-objects 
> for more info.
> 
> On Sat, Dec 19, 2009 at 2:27 AM, Todd Blanchard  wrote:
> One thing I'm keenly missing from rails is the form input naming convention 
> that causes the form values to be converted into a hierarchy.  For instance,
> 
> 
> 
> 
> will result in the request values being stored as { 'foo'  : {'bar' : 'one', 
> 'baz' : 'two' }}
> 
> this is very handy when updating multiple related objects in a single form 
> submit.
> 
> Is there a similar facility for django/python or will I need to write it?
> 
> -Todd Blanchard
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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-us...@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: very noob : DRY violation in views.py

2009-12-19 Thread Itay Donenhirsch
i'm quite a noob myself but my best guess is to use context processor,
see 
http://stackoverflow.com/questions/557460/django-having-middleware-communicate-with-views-templates



On Sat, Dec 19, 2009 at 8:14 PM, Osiaq  wrote:
> VIEWS:
>
> def services(request):
>        property = Property.objects.all().order_by('name')[:4]
>        city = City.objects.all()
>        category=PropertyCategory.objects.all()
>        status=PropertyStatus.objects.all()
>        return render_to_response('website/services.html',{'property':
> property, 'city':city,'category':category,'status':status})
>
> def profile(request):
>        property = Property.objects.all().order_by('name')[:4]
>        city = City.objects.all()
>        category=PropertyCategory.objects.all()
>        status=PropertyStatus.objects.all()
>        return render_to_response('website/profile.html',{'property':
> property, 'city':city,'category':category,'status':status})
>
> How to define "property" just once and use it in many defs?
> 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-us...@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-us...@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.




very noob : DRY violation in views.py

2009-12-19 Thread Osiaq
VIEWS:

def services(request):
property = Property.objects.all().order_by('name')[:4]
city = City.objects.all()
category=PropertyCategory.objects.all()
status=PropertyStatus.objects.all()
return render_to_response('website/services.html',{'property':
property, 'city':city,'category':category,'status':status})

def profile(request):
property = Property.objects.all().order_by('name')[:4]
city = City.objects.all()
category=PropertyCategory.objects.all()
status=PropertyStatus.objects.all()
return render_to_response('website/profile.html',{'property':
property, 'city':city,'category':category,'status':status})

How to define "property" just once and use it in many defs?
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-us...@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: Cron vs event triggered action

2009-12-19 Thread Tim Daniel
David, Celery sounds really good, thanks for the tip, I'll have a
deeper look into it as soon as I've got some time, if I can't get it
up for this project I'll study it's details and put it up later maybe
for a new release or a new project. For what I've seen until now it
seems to be perfect, because you completly control the whole process,
once a job has completed it even returns you a backtrace in case of
failure or a success message. Only the setup/installation looks quite
complex, one question: Is it capable of running on every web server
that supports Python? or are there any other requirements or things to
think about?

John your solution is very smart too, but sometimes it could cause
some overhead, if I do actions while the user is offline or seeing
another section, the user won't notice it, but if you do it inside a
request the user may has to wait a little longer, it depends on the
complexity of the operation you want to do.

Brian & Creecode Django Custom management commands are really the same
as this:

from django.core.management import setup_environ
import settings
setup_environ(settings)

or am I wrong? I'm just running the scripts with these three lines on
top (even before the other import statements).

The apscheduler looks like a good and simple implementation for A,
thanks Guilherme.

And finally Mateus the at(if it's available) command would be a very
easy solution for A too.

On 15 dic, 11:42, David De La Harpe Golden
 wrote:
> Tim Daniel wrote:
> > So how can I implement solution B? Is there a posibility to create a
> >cronon a user action that executes only one time?
>
> > NOTE: I don't want to rely on a thread that should stay alive for two
> > hours ore more inside the server memory.
>
> Well, celery uses a "celeryd" daemon process and a message queue, so
> that is a thread staying alive om the server, but it's a completely
> separate and manageable process from your web server:
>
> http://ask.github.com/celery/introduction.html
>
> It may look a little complex, but it really makes all sorts of long
> running and scheduled tasks easy and well-integrated with django.
>
> FWIW, doing something two hours after someeventis basically a 
> one-liner:http://ask.github.com/celery/userguide/executing.html#eta-and-countdown

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Migrating ForeignField to OneToOneField

2009-12-19 Thread Jonathan
Solved.
It wasn't the OS, django, Python or MySQL versions...
It was the South version. Locally I was using 0.6.2 whereas the on the
development server I had 0.6-pre installed.
btw, if you encounter this and try to "python setup.py install" the
new South - remember to erase the old South folders and egg files from
the site-packages directory... Interestingly enough if you don't do
that in Python's shell you'll get the new South version, whereas in
django's shell you'll get the old south version.
Jonathan

On Dec 19, 1:34 pm, Jonathan  wrote:
> I'm using South to migrate a certain field from ForeignField to
> OneToOneField.
> Initial state is that I have model A pointing to model B using a
> ForeignField. Of course there's only one instance of A pointing to a B
> instance.
>
> I wasn't sure if this would work directly, or that I should do a 3-
> stage migration (1- add a different field, 2- copy the id from
> ForeignField to OneToOneField, 3- erase the ForeignField), so I tried
> it and it worked flawlessly on my local machine - Windows\django 1.1.0
> final\Python 2.6.4\MySQL 5.1.41
>
> Unfortunately, I ran the migration on our development server which is
> a Debian\django 1.1.0 beta\Python 2.5.0\MySQL 5.0.32 and the migration
> failed with the following error:
>
> Traceback (most recent call last):
>   File "/usr/lib/python2.5/site-packages/South-0.6_pre-py2.5.egg/south/
> migration.py", line 315, in run_migrations
>     runfunc(orm)
>   File "/usr/share/", line 19, in forwards
>     db.create_unique('tree_family_name', ['base_id'])
>   File "/usr/lib/python2.5/site-packages/South-0.6_pre-py2.5.egg/south/
> db/generic.py", line 346, in create_unique
>     self.execute("ALTER TABLE %s ADD CONSTRAINT %s UNIQUE (%s)" % (qn
> (table_name), qn(name), cols))
>   File "/usr/lib/python2.5/site-packages/South-0.6_pre-py2.5.egg/south/
> db/mysql.py", line 29, in execute
>     return generic.DatabaseOperations.execute(self, sql, params)
>   File "/usr/lib/python2.5/site-packages/South-0.6_pre-py2.5.egg/south/
> db/generic.py", line 70, in execute
>     cursor.execute(sql, params)
>   File "/usr/lib/python2.5/site-packages/django/db/backends/util.py",
> line 19, in execute
>     return self.cursor.execute(sql, params)
>   File "/usr/lib/python2.5/site-packages/django/db/backends/mysql/
> base.py", line 84, in execute
>     return self.cursor.execute(query, args)
>   File "/usr/lib/python2.5/site-packages/MySQLdb/cursors.py", line
> 163, in execute
>     self.errorhandler(self, exc, value)
>   File "/usr/lib/python2.5/site-packages/MySQLdb/connections.py", line
> 35, in defaulterrorhandler
>     raise errorclass, errorvalue
> OperationalError: (1061, "Duplicate key name
> 'tree_family_name_base_id'")
>
> Is this due to the django version? Python version? MySQL version? Any
> thoughts? Should I change to the 3-stage migration model?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: question about django-pagination

2009-12-19 Thread Rodrigo Cea
You can paginate whatever you want. From the docs:

"Note that you can give Paginator a list/tuple, a Django QuerySet, or
any other object with a count() or __len__() method. "

On Dec 19, 3:33 am, Continuation  wrote:
> In the django-pagination, it uses the example:
> {% autopaginate object_list %}
>
> My question is does object_list have to be the **entire** list over
> which I want to paginate, or can I limit the length of object_list? If
> I limit the length of object_list, will autopaginate still go through
> the entire list?
>
> As an example, say I want to paginate over the list a.field_set.all().
> Let's say that list has 1 objects. I might not want my database to
> return such a large result set. So I might want to do something like:
>
> object_list = a.field_set()[:5]
>
> Now if I use {% autopaginate object_list %} in my template, would I
> still be able to paginate over the entire list of 1 objects? Or my
> list would be shortened to 5 objects?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: SQL transaction style in django?

2009-12-19 Thread Yusuf Mohsinally
Thanks! The blog post was very very helpful.

In your experience, would it be better to use the
"@transaction.commit_on_success" decorator for the functions that need
it, or turn on transaction middleware for the whole app?

Thanks




On Sat, Dec 19, 2009 at 10:34 AM, Christophe Pettus  wrote:
>
> On Dec 18, 2009, at 9:58 PM, yummy_droid wrote:
>> I read that we can overwrite the save() for any model to do something
>> before/after its save. But my issue is, how can I be sure that what i
>> save + what the model needs to save happen as a transaction, so if
>> either fails, the whole thing fails.
>
> Django has a reasonably complete set of transaction control
> functionality.  The official documentation is at:
>
>        http://docs.djangoproject.com/en/dev/topics/db/transactions/
>
> I also wrote a blog entry about it:
>
>        
> http://thebuild.com/blog/2009/11/07/django-postgresql-and-transaction-management/
>
> (The blog entry is with regards to PostgreSQL, but it's pretty
> generally applicable.)
>
> None of it involved overriding .save(), I'm pleased to report.
>
> --
> -- Christophe Pettus
>    ...@thebuild.com
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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.




Feeds from the Tag Framework

2009-12-19 Thread Tim Sawyer
Hi Folks,

The complex example of an Atom feed
(http://docs.djangoproject.com/en/1.1/ref/contrib/syndication/#a-complex-example)
 

is based on a model where it's possible to work out from a single 
element in the feed (in this case a Crime), what the driving object is 
(a Beat).  So there's a many (Crime) to one (Beat) relationship going on.

I'm using the django tags framework on a blog. Each entry has multiple 
tags.  I'd like to create a feed for each tag.

Following this example, I can't figure out what to put in the title 
method - I can get *all* the tags for a given Blog Entry, but not the 
one that the feed is for.

Am I missing something?  Does anyone have an example of this?

Cheers,

Tim.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Rails-style form value deserializer?

2009-12-19 Thread Jani Tiainen



Result is stored in request.POST (or you can do same with get params,
?foo=one=two).

for example request.POST.getlist('foo'). Default getitem implementation
returns only last occurence from list.

See:
http://docs.djangoproject.com/en/1.1/ref/request-response/#querydict-objectsfor
more info.

On Sat, Dec 19, 2009 at 2:27 AM, Todd Blanchard  wrote:

> One thing I'm keenly missing from rails is the form input naming convention
> that causes the form values to be converted into a hierarchy.  For instance,
>
> 
> 
>
> will result in the request values being stored as { 'foo'  : {'bar' :
> 'one', 'baz' : 'two' }}
>
> this is very handy when updating multiple related objects in a single form
> submit.
>
> Is there a similar facility for django/python or will I need to write it?
>
> -Todd Blanchard
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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.