Re: DB based translations?

2011-08-21 Thread rebus_
On 21 August 2011 04:41, Joshua Russo  wrote:
> Ok, I've been looking into the different database based translation
> solutions out there and I can't find what I really had in mind. I need to
> have non-technical people easily update the translations. So I wanted a
> solution where I could create an interface to ease the process.
> One problem is that none of the solutions seem to talk about translating
> static text. I'm thinking I need to create a site_content table to handle my
> static text translations and then use one of these solutions against it.
>
> If this is an appropriate solution, what are people's experience with the
> different database driven translation solutions? I tried
> django_multilingual, and django_multilingual_ng but they seemed to have
> issues with South. (Of course that was a few months back and I can't
> remember the exact problems I was having.) I'm now looking at
> django_modeltranslation, but none of these products really give the
> impression of being production worthy.
> I'm willing to give them a shot because I need something and it's small
> enough project that I can take a little more risk. What are people's
> experience with them?
> Thanks in advance
> Josh
>
> --
> 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/-/4sSq3y1mGKcJ.
> 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.
>

Check django-datatrans [0] out

[0] https://github.com/citylive/django-datatrans

-- 
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: Linking to Django Admin from 1.3

2011-07-14 Thread rebus_
On 14 July 2011 16:35, eric.frederich  wrote:
> Hello,
>
> I am moving from 1.0.2 to 1.3 and am having problems linking to the
> admin site from within a template.
> I used to have this in my template...
>
>    Django Admin
>
> And I used to have this in my urls.py
>
>    url(r'^admin/(.*)'      , admin.site.root, name='the-django-
> admin'),
>
> I'm sure this was hacky even back in 1.0.2
> How should I link to the admin site's index from within a template?
>
> I cannot hard code it to /admin because while this would work on
> development, on production it needs to be /apps/admin
> So I need to use the URL resoving mechanism so that the prefix gets
> picked up based on which environment it is on.
>
> So... simple question.  How do I link to the Django admin site from
> within a template?
>
> Thanks,
> ~Eric
>
> --
> 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.
>

Try:

{% url admin:index %}

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#reversing-admin-urls

-- 
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: Initial save()

2011-03-12 Thread rebus_
On 13 March 2011 00:40, Julian Hodgson  wrote:
> I need to set up some default values on a ManyToMany field only when a model
> is first created.
>
> How can I find out in the save() override if the object is being created for
> the first time?
>
> Do I check the table for rows which have self.id or is this not defined till
> after the save?
>
> Julian
>

It is enough to check if self.id [1] is set in save().

[1] 
http://docs.djangoproject.com/en/dev/ref/models/instances/#auto-incrementing-primary-keys

-- 
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: Admin without template (no colors, no css, just simple html)

2010-10-26 Thread rebus_
On 26 October 2010 06:48, marcoarreguin  wrote:
> I'm starting with Django and I have a bluehost, yesterday I have been
> installing all the stuff, I found a tutorial about how to install
> django in bluehost, so I'm using fcgi.
>
> My problem is that when I uncomment the necesary things to run my
> admin, it runs, but it hasn't a layout like the images in the
> tutoriales, like the login box is centered and have a blue rectangle,
> I just have a little login in the left part of my screen without
> colors and that stuff, and when I login, it happens the same I can see
> my groups and all stuff but without format. ¿Do you know why is happen
> this to me?
>
> A hug, and I'm glad to be part of the community.
>
> --
> 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.
>
>

Check your ADMIN_MEDIA_PREFIX setting, the url it defines should serve
static media content by a web server, yours is probably been handled
by Django and thus not serving any static files (such as css)

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/;, "/media/".
ADMIN_MEDIA_PREFIX = '/admin-media/'

-- 
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: where is the link of password reset page on djangoproject.com ?

2010-08-09 Thread rebus_
On 9 August 2010 14:30, nyambaa  wrote:
> Hello guys,
> please help, I've not found the password reset page on
> djangoproject.com
> where is it?
>
> 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.
>
>

http://www.djangoproject.com/accounts/password/reset/

-- 
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: Help with Filters

2010-05-02 Thread rebus_
On 3 May 2010 00:46, rebus_ <r.dav...@gmail.com> wrote:
> On 3 May 2010 00:34, Magal, Ganesh <ganeshma...@gmail.com> wrote:
>> I have created a filter which wikifies (i.e.  input text of the form
>> HelloWorld to an output with rendered font like say - HelloWorld ). The
>> problem is that when I apply the filter, it is not getting rendered. Below
>> is the  code for the filter and the output text in HTML
>>
>> CODE:
>> from django import template
>> import re
>> wikilink=re.compile("\\b([A-z][a-z]+[A-Z][a-z]+)\\b")
>> register= template.Library()
>> @register.filter
>> def wikify(value):
>>     return wikilink.sub(r"\1", value)
>>
>>
>> OUTPUT:
>> HelloWorld
>>
>> Without any style. Can you please help in finding where I am making a
>> mistake.
>>
>> 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.
>>
>
> {% wikify|safe %} ?
>
> http://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe
>

Or more accurately

http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#filters-and-auto-escaping

-- 
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: Help with Filters

2010-05-02 Thread rebus_
On 3 May 2010 00:34, Magal, Ganesh  wrote:
> I have created a filter which wikifies (i.e.  input text of the form
> HelloWorld to an output with rendered font like say - HelloWorld ). The
> problem is that when I apply the filter, it is not getting rendered. Below
> is the  code for the filter and the output text in HTML
>
> CODE:
> from django import template
> import re
> wikilink=re.compile("\\b([A-z][a-z]+[A-Z][a-z]+)\\b")
> register= template.Library()
> @register.filter
> def wikify(value):
>     return wikilink.sub(r"\1", value)
>
>
> OUTPUT:
> HelloWorld
>
> Without any style. Can you please help in finding where I am making a
> mistake.
>
> 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.
>

{% wikify|safe %} ?

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe

-- 
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: ORM Query question

2010-04-12 Thread rebus_
On 13 April 2010 01:09, zweb  wrote:
> how do i do this kind of condition in django orm filter:
>
> ( 1 < a < 5)  or ( 20 < b < 70)
>
> select * from table where (a between 1 and 5) or (b between 20 and 70)
>
> --
> 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.
>
>

http://docs.djangoproject.com/en/dev/ref/models/querysets/#range

-- 
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: View on site

2010-03-12 Thread rebus_
On 12 March 2010 01:04, Robert  wrote:
> There is a "View on site" link when you edit a user in admin.
>
> The link calls the url user/user_name but you have to make the url-
> view configuration yourself apparently.
>
> I wonder if there is a "built-in" way to do this. I looked up an other
> thread from 2006 that deals with the same question related to
> "flatpages". The thread was started by Mary Adel. You may look it up
> by searching with the keywords "View on site".
>
> It seems that the problem was solved by the recommendation:
>
> "Put (r'^r/', include('django.conf.urls.shortcut')), in your URLConf.
> "
>
> This shortcut contains this line of code that seems to be on the right
> track:
>
> (r'^(?P\d+)/(?P\d+)/$',
> 'defaults.shortcut'),
>
> However django is not able to match this url.
>
> Is this supposed to work?
>
> Please advise.
>
> Thanks.
>
> Robert
>
> --
> 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.
>
>

http://docs.djangoproject.com/en/dev/ref/models/instances/#get-absolute-url
http://docs.djangoproject.com/en/dev/ref/contrib/sites/#how-django-uses-the-sites-framework

-- 
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: circular import in two models.py

2010-03-10 Thread rebus_
On 10 March 2010 11:31, Viktor  wrote:
> Hi,
>
> I have two django applications, an issue tracker where an Issue is
> related to a Partner
> and a Partner model where partners can be grouped, etc
> I would like to add an issue to every group to provide an easy
> messaging for groups, so I don't have to write the message sending
> logic again
>
> could someone give me some ideas how can I cross-connect the two apps,
> but save them as seemingly separate?
> by seemingly separate I mean that I can change the Partner models by
> simply writing
>
>    from app.models import Partner1 as Parner
>
> instead of
>
>    from app.models import Partner2 as Parner
>
> in the messaging app
>
> thanks,
> Viktor
>
> --
> 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.
>
>

Instead of giving a class try giving a string in format 'myapp.MyModelName'.

class Foo(models.Model):
  bar = models.ForeignKey('myapp.MyModelName')

-- 
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: making query using filter()

2010-03-10 Thread rebus_
On 10 March 2010 12:06, jimgardener  wrote:
> Hi
> I need to make a query as follows
> Select all entries where categories=mycategory
>
> In the db there are entries and categories as follows
> Category.objects.all() -->[ , hiscategory>,]
>
> MyEntry.objects.all() --> [  , [u'mycategory',u'hiscategory' ]>, ]
>
>
> I tried like this
> mycategory=Category.objects.get(name='mycategory')
> MyEntry.objects.filter(categories=mycategory)
>
> But this returns entries where the categories field contains
> 'mycategory' and 'hiscategory' also.
> How do I mention to retrieve only 'mycategory'.
>
> I went through the Queryset docs ..but couldn't figure it out...
> Any help would be appreciated
> thanks
> jim
>
>
> p.s:
>
>
> My models are
> class MyEntry(models.Model):
>    categories=models.ManyToManyField(Category)
>
>
> class Category(models.Model):
>    name=models.CharField(unique=True,max_length=50)
>
> --
> 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.
>
>

[  , 

Well that's what it is supposed to do, both Entry objects have
relation to "mycategory".

-- 
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: Secret key

2010-03-09 Thread rebus_
On 9 March 2010 15:16, Joan Miller  wrote:
> For what is used the key `SECRET_KEY`?
>
> --
> 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.
>
>

A secret key for this particular Django installation. Used to provide
a seed in secret-key hashing algorithms. Set this to a random string
-- the longer, the better. django-admin.py startproject creates one
automatically.

http://docs.djangoproject.com/en/dev/ref/settings/#secret-key

-- 
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: more than 1 foreign key

2010-03-09 Thread rebus_
On 9 March 2010 13:30, knight  wrote:
> I have the following models: http://slexy.org/view/s20T8yOiKZ.
> When I try to click add button for worlds in admin page it shows me
> the following error:
>  has more than 1 ForeignKey
> to .
> I think it's something to do with inline.
> What can it be?
>
> Regards, Arshavski Alexander.
>
> --
> 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.
>
>

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-a-model-with-two-or-more-foreign-keys-to-the-same-parent-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: Does anybody meet this strange Error

2010-03-09 Thread rebus_
On 9 March 2010 15:22, Forrest Liu  wrote:
> Hi,
> I am struck with this strange error message:
> AttributeError at /products/
>
> 'function' object has no attribute 'objects'
>
> Request Method:GET
> Request URL:http://127.0.0.1:8000/products/
> Exception Type:AttributeError
> Exception Value:
>
> 'function' object has no attribute 'objects'
>
> Exception Location:E:\workspace\biotech\biotech\..\biotech\bio\views.py in
> product, line 35
> my views.py:
> def product(request):
>     products = product.objects.all().order_by('name')
>     return
> object_list(request,products,paginate_by=10,template_name='products/index.html',allow_empty=True)
> my model.py:
> class product(models.Model):
>     name = models.CharField(max_length=100)
>     description = models.TextField(blank=True)
>     def __unicode__(self):
>         return self.name
>
> and my index.html is :
> {% for n in object_list %}
> 
> {{n.name}}
> 
> {% endfor %}
> my Django version:1.1.1
> python version: 2.6
> Could you be so kind to give me some help,Thank you
> --
>
> Best regards,
> Forrest
>
> --
> 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.
>

Rename your model to Product with capital P.

Right now when you say

def product(request):
products = product.objects.all().order_by('name')

you are calling def product function instead of class product model.


Try something like:

def product(request):
products = Product.objects.all().order_by('name')
return 
object_list(request,products,paginate_by=10,template_name='products/index.html',allow_empty=True)

class Product(models.Model):
name = models.CharField(max_length=100)
description = models.TextField(blank=True)
def __unicode__(self):
return self.name


Further reading:

http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces

-- 
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: How to use pre-built HTML forms in Django

2010-03-09 Thread rebus_
On 9 March 2010 15:22, MMRUser <oshadha.ro...@gmail.com> wrote:
> The problem I's having is that my HTML form depends upon lot of
> external resources like javascript validation libraries and lots of
> css on fields (and some may differ from each other), and I think that
> I don't need to use re-usable templates because I just want to design
> a one simple form so there's only one HTML file.Do you think that is
> it ok to just ignore the Django's template system and get along with
> the normal way.
>
> On Mar 9, 2:32 pm, rebus_ <r.dav...@gmail.com> wrote:
>> On 9 March 2010 05:54, MMRUser <oshadha.ro...@gmail.com> wrote:
>>
>>
>>
>> > Thanks another doubt,what about the css mappings class="field text
>> > medium" do they also need to include in the class definition in
>> > Django.
>>
>> > On Mar 9, 9:21 am, rebus_ <r.dav...@gmail.com> wrote:
>> >> On 9 March 2010 05:04, MMRUser <oshadha.ro...@gmail.com> wrote:
>>
>> >> > I have an pre-built HTML form (means I design the HTML form
>> >> > separately) and I need to reuse it with Django form class
>> >> > (django.forms), So how do I incorporate my HTML form with Django form
>> >> > class. for example
>>
>> >> > HTML:
>>
>> >> > 
>> >> >  
>> >> >  Username
>> >> >  *
>> >> >  
>> >> >  
>> >> >  
>> >> >  
>> >> > 
>>
>> >> > How do I map this HTML in to Django form definition, I know that it
>> >> > can be done by modifying Django form fields according to this HTML.
>> >> > But I guess it's a time consuming approach,so I would like to know
>> >> > that is there any easy and time saving solutions for this issue.
>>
>> >> > 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 
>> >> > athttp://groups.google.com/group/django-users?hl=en.
>>
>> >> Well usually you first create a form in django and use its instance to
>> >> generate the HTML.
>>
>> >> You can also write the HTML by yourself and all you need to be careful
>> >> of is that name and id attributes of you inputs and input type are
>> >> same as in the class you define.
>>
>> >> Your HTML corresponds to:
>>
>> >> class MyForm(forms.Form):
>> >>    Field11 = forms.CharField(label="Username",  max_length=255)
>>
>> >> I highly recommend to first setup a form class then write HTML and
>> >> making form fields have more sensible names then Field11.
>>
>> >> Also i suggest these links as further reading:
>>
>> >>http://docs.djangoproject.com/en/dev/topics/forms/http://docs.djangop...
>>
>> > --
>> > 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 
>> > athttp://groups.google.com/group/django-users?hl=en.
>>
>> No, CSS classes are not defined in form class (as far as i know).
>>
>> I would suggest using reusable form templates [1] and putting the CSS
>> classes on field wrappers for example.
>>
>> This is what you are interested in:
>>
>> http://docs.djangoproject.com/en/dev/topics/forms/#reusable-form-temp...http://docs.djangoproject.com/en/dev/topics/forms/#displaying-a-form-...
>>
>> Which ever approach you decide to use is valid, but writing a bunch of
>> your own HTML for forms takes more time but is also more customisable,
>> on the other hand using shortcut methods such as "as_p" [1] or
>> "as_table" [2] is faster but you have less control over the outputted
>> HTML.
>>
>> [1]http://docs.djangoproject.com/en/dev/ref/forms/api/#as-p
>> [2]http://docs.djangoproject.com/en/dev/ref/forms/api/#as-table
>
> --
> 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.
>
>

Well, if you need a high level of customization you can write your own
HTML for forms of course.

-- 
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: Register multiple models to show in admin page

2010-03-09 Thread rebus_
On 9 March 2010 10:31, andrew_scfc  wrote:
> Hi,
>
> I'm new to using Django and have come across some redundancy in my
> implementation that I would like to irradicate.
>
> I have defined several models in the models.py file as normal. I would
> like to register all of my models to be available via the admin
> interface. Currently I need to register models one by one in the
> admin.py as show below:
>
> from mysite.models import model1, model2, model3, model4, model5
> from django.contrib import admin
>
> admin.site.register(model1)
> admin.site.register(model2)
> admin.site.register(model3)
> admin.site.register(model4)
> admin.site.register(model5)
>
>
> Is it possible to just register all models? Perhaps get hold of a
> collection containing all the models. I am quite new to python so I
> may have missed something quite simple, if so, I apologise.
>
> Cheers
> Andy
>
> --
> 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.
>
>

models = [model1, model2, model3, model4, model5]
admin.site.register(models)

This should work i think.

-- 
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: How to use pre-built HTML forms in Django

2010-03-09 Thread rebus_
On 9 March 2010 05:54, MMRUser <oshadha.ro...@gmail.com> wrote:
> Thanks another doubt,what about the css mappings class="field text
> medium" do they also need to include in the class definition in
> Django.
>
> On Mar 9, 9:21 am, rebus_ <r.dav...@gmail.com> wrote:
>> On 9 March 2010 05:04, MMRUser <oshadha.ro...@gmail.com> wrote:
>>
>>
>>
>> > I have an pre-built HTML form (means I design the HTML form
>> > separately) and I need to reuse it with Django form class
>> > (django.forms), So how do I incorporate my HTML form with Django form
>> > class. for example
>>
>> > HTML:
>>
>> > 
>> >  
>> >  Username
>> >  *
>> >  
>> >  
>> >  
>> >  
>> > 
>>
>> > How do I map this HTML in to Django form definition, I know that it
>> > can be done by modifying Django form fields according to this HTML.
>> > But I guess it's a time consuming approach,so I would like to know
>> > that is there any easy and time saving solutions for this issue.
>>
>> > 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 
>> > athttp://groups.google.com/group/django-users?hl=en.
>>
>> Well usually you first create a form in django and use its instance to
>> generate the HTML.
>>
>> You can also write the HTML by yourself and all you need to be careful
>> of is that name and id attributes of you inputs and input type are
>> same as in the class you define.
>>
>> Your HTML corresponds to:
>>
>> class MyForm(forms.Form):
>>    Field11 = forms.CharField(label="Username",  max_length=255)
>>
>> I highly recommend to first setup a form class then write HTML and
>> making form fields have more sensible names then Field11.
>>
>> Also i suggest these links as further reading:
>>
>> http://docs.djangoproject.com/en/dev/topics/forms/http://docs.djangoproject.com/en/dev/ref/forms/api/http://docs.djangoproject.com/en/dev/ref/forms/fields/
>
> --
> 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.
>
>

No, CSS classes are not defined in form class (as far as i know).

I would suggest using reusable form templates [1] and putting the CSS
classes on field wrappers for example.

This is what you are interested in:

http://docs.djangoproject.com/en/dev/topics/forms/#reusable-form-templates
http://docs.djangoproject.com/en/dev/topics/forms/#displaying-a-form-using-a-template

Which ever approach you decide to use is valid, but writing a bunch of
your own HTML for forms takes more time but is also more customisable,
on the other hand using shortcut methods such as "as_p" [1] or
"as_table" [2] is faster but you have less control over the outputted
HTML.

[1] http://docs.djangoproject.com/en/dev/ref/forms/api/#as-p
[2] http://docs.djangoproject.com/en/dev/ref/forms/api/#as-table

-- 
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: How to use pre-built HTML forms in Django

2010-03-08 Thread rebus_
On 9 March 2010 05:04, MMRUser  wrote:
> I have an pre-built HTML form (means I design the HTML form
> separately) and I need to reuse it with Django form class
> (django.forms), So how do I incorporate my HTML form with Django form
> class. for example
>
> HTML:
>
> 
>  
>  Username
>  *
>  
>  
>  
>  
> 
>
> How do I map this HTML in to Django form definition, I know that it
> can be done by modifying Django form fields according to this HTML.
> But I guess it's a time consuming approach,so I would like to know
> that is there any easy and time saving solutions for this issue.
>
> 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.
>
>

Well usually you first create a form in django and use its instance to
generate the HTML.

You can also write the HTML by yourself and all you need to be careful
of is that name and id attributes of you inputs and input type are
same as in the class you define.

Your HTML corresponds to:

class MyForm(forms.Form):
   Field11 = forms.CharField(label="Username",  max_length=255)


I highly recommend to first setup a form class then write HTML and
making form fields have more sensible names then Field11.

Also i suggest these links as further reading:

http://docs.djangoproject.com/en/dev/topics/forms/
http://docs.djangoproject.com/en/dev/ref/forms/api/
http://docs.djangoproject.com/en/dev/ref/forms/fields/

-- 
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: join channel #django

2010-03-08 Thread rebus_
On 9 March 2010 05:02, sajuptpm  wrote:
> I cant join #django,
>
> [09:20] [Channel] Cannot join channel (+r) - you need to be identified
> with services
>
> What is the problem?. How join this channel?. What are the other
> popular django channels?.
>
> Please help me.
>
> --
> 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.
>
>

Maybe this could help

http://freenode.net/faq.shtml#nicksetup

The error message says you need to be registered before joining the channel.

-- 
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: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread rebus_
On 4 March 2010 18:02, Phlip  wrote:
> Djangoids:
>
> Consider this line:
>
>   foo = Foo.object.get(name='bar')
>
> If foo is not found, I want it to contain a NullObject, such as an
> empty Foo(). In the parlance, that could be like this:
>
>   foo = Foo.object.get(name='bar', _default=Foo())
>
> I naturally don't expect (v 1.1.1) of Django to support my magic
> _default keyword.
>
> What's the absolute shortest stretch of code which pops a NullObject
> into my foo if the record 'bar' is not found?
>
> --
>  Phlip
>  http://c2.com/cgi/wiki?ZeekLand
>
> --
> 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.
>
>

I'd say:

from django.core.exceptions import ObjectDoesNotExist
try:
  foo = Foo.object.get(name='bar')
except ObjectDoesNotExist:
  foo = bar()

but then again, there are all kinds of magic out there. :)

-- 
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: reverse in settings.py, is it possible?

2010-03-03 Thread rebus_
On 3 March 2010 12:33, Aljosa Mohorovic  wrote:
> i would like to set LOGIN_URL = reverse('custom_url_name') so i'm
> wondering if something like that is possible?
> i've tried with reverse but it fails. any ideas?
>
> Aljosa Mohorovic
>
> --
> 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.
>
>

Quite an old thread but maybe it helps.

http://www.mail-archive.com/django-users@googlegroups.com/msg26096.html
http://www.mail-archive.com/django-users@googlegroups.com/msg26097.html

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Handling input of external urls

2010-02-27 Thread rebus_
On 27 February 2010 02:17, russianbandit  wrote:
> Sorry for being sort of a newb when it comes to regex. But what
> exactly does that line do?
>
> On Feb 26, 3:59 pm, "ge...@aquarianhouse.com"
>  wrote:
>> Check it with regex?
>>
>> re.compile("[a-z0-9]\.[a-z]{2,6}$", re.I)
>
> --
> 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.
>
>

well this regex would translate to:

any lowercase letter in range from a to z or digit appearing once
([a-z0-9]) followed by a literal dot (.) and then followed by 2 to 6
occurrences of any lowercase letter in range from a to z followed by
the end of the string.

But this regex doesn't seem all that useful, and it is not a raw string.

You could just check to see if the protocol was specified and based on
that append it or not.

r'^http:\\'

Google search for "url regex" gives:
http://www.geekzilla.co.uk/view2D3B0109-C1B2-4B4E-BFFD-E8088CBC85FD.htm

Learn more about regular expressions:
http://www.regular-expressions.info/reference.html

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

2010-02-27 Thread rebus_
On 27 February 2010 11:46, Sven Richter  wrote:
> Hi everybody,
>
> i am wondering if there is a tool which converts existing mysql
> databases with table structure into a django model?
>
>
> Greetings
> Sven Richter
>
> --
> 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.
>
>

http://docs.djangoproject.com/en/dev/ref/django-admin/#inspectdb

-- 
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: Custom button for imagefield form

2010-02-25 Thread rebus_
On 22 February 2010 14:06, CrabbyPete  wrote:
> I have form with where users can upload an image. All works well but I
> want a graphic instead of the default browse button that shows up. Can
> I change it and if so how do you change it in the form field or
> template?
>
>
> class ProfileForm(SignUpForm):
>
>    mugshot         = forms.ImageField      (required = False)
>
> --
> 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.
>
>

I don't really understand what are you trying to do, but if you want
to change the appearance of the forms buttons you should try to use
CSS, it has nothing to do with Django AFAIK (except maybe you could
create your own widget but i don't see how that would help).

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

2010-02-25 Thread rebus_
On 24 February 2010 20:51, ktemo  wrote:
> hi
> i working in a desktop app with django mysql,  and wxpython, and i
> need to make transaction
>  i read the doc online, but i dont know if is possible work with a
> desktop app
>
> --
> 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.
>
>

As far as i know, to use transactions in MySQL you need to use InnoDB
storage engine because MyISAM does not support transactions.

-- 
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: How to make the login forms available to the entire site?

2010-02-21 Thread rebus_
On 21 February 2010 19:38, Timothy Kinney  wrote:
> There may be a more elegant way, but I think you could just call the login
> view from whatever view the url directs the user too. So it fills in the
> login info and then renders the rest of the page...but on second thought
> maybe you need to include the login form in every view...
>
>
>
> On Sun, Feb 21, 2010 at 10:44 AM, Patrick  wrote:
>>
>> I thought that if I put the login forms on the base template and then
>> extend all others from that base template, the login forms would be
>> available all the way through. But there is a problem: the login forms
>> are only displayed if the url is processed by the 'login' view. That
>> login view provides the forms needed for authentication, among other
>> things.
>>
>> The thing is, what I want is to allow user to authenticate no matter
>> what page from the site he is visitting. How can that be done?
>>
>> Many thanks in advance,
>>
>> Patrick Steiger
>>
>> --
>> 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.
>

Well you could put form HTML in base.html for example and just make it
post on login URL.
Or perhaps you could put it in context processor [1].

Can't think of more elegant solution right now.

[1] http://docs.djangoproject.com/en/dev/ref/templates/api/

-- 
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: photos

2010-02-20 Thread rebus_
2010/2/21  :
> Photos
>
> bisou
> Ariel
>
>
>
> --
> Infomed - Red de Salud de Cuba
> http://www.sld.cu/
>
>
> --
>
> Este mensaje le ha llegado mediante el servicio de correo electronico que 
> ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
> Nacional de Salud. La persona que envia este correo asume el compromiso de 
> usar el servicio a tales fines y cumplir con las regulaciones establecidas
>
> Infomed: http://www.sld.cu/
>
> --
> 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.
>
>

Interesting thing is, the guy on the photo has "django colours" t-shirt :)

-- 
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: Change display of (None) in admin change lists?

2010-02-18 Thread rebus_
On 18 February 2010 15:12, Derek  wrote:
> Is there a way to alter the display of fields in the Django Admin change
> lists so that they do not show (None) - for text - or None - for numeric.
>
> I'd prefer to use " " or "-" for display of items instead.
>
> Thanks
> Derek
>
> --
> 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 could create custom methods on Model and use them in ModelAdmin
list_display instead of real fields.

Read more here:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display

You could even create these methods in runtime with setattr in
__init__ for example, but be careful though, if you "curry" your
methods there's a good chance you'll have problems serializing them
(but this can be taken care of by defining __getstate__ and
__setstate__ methods).

-- 
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: User permissions to see a view

2010-02-18 Thread rebus_
On 18 February 2010 14:02, Alexey Kostyuk  wrote:
> Hi ALJ!
>
> Why can not you add a model 'reports' (in your example) and add the
> required permissions?
> Also you can add custom permissions[1] to any other models of your app
> and use them.
>
> [1]http://docs.djangoproject.com/en/dev/topics/auth/#id2
>
> On Thu, 2010-02-18 at 04:29 -0800, ALJ wrote:
>> Hi Alexey,
>>
>> But how do you set a permission for a view? There's no underlying
>> model to which to add the custom meta permissions.
>>
>> ALJ
>>
>> On Feb 18, 12:48 pm, Alexey Kostyuk  wrote:
>> > On Thu, 2010-02-18 at 02:30 -0800, ALJ wrote:
>> > > First project and struggling a bit.
>> >
>> > > I have some views that I want to restrict access to, depending on user
>> > > type. How do I do that?
>> >
>> > > For example, I have a 'reports' view that I only want teachers to
>> > > see ... not students. I can't see how to create a custom permission
>> > > because there is no underlying model for the view. So do I need to
>> > > create a custom user model or would it be better to just use
>> > > profiles?
>> >
>> > > :-(
>> >
>> > You can use decorator @permission_required in your views.
>> > See link[1] for details.
>> >
>> > [1]http://docs.djangoproject.com/en/dev/topics/auth/#the-permission-requ..
>> >
>> > --
>> > Alexey Kostyuk 
>>
>
>
> --
> 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.
>
>

Permissions are defined per Model basis.

You define a permission for each Model in Models Meta class.

class UserType(models.Model):
   id = models.CharField(max_length=3, primary_key=True)
   name = models.CharField(max_length=30)

   def __unicode__(self):
   return u'%s' % (self.name)

   class Meta:
permissions = (
("can_do_stuff", "Can do stuff"),
)

After running syncdb you can assign that custom permission to some
User or Group which will then have permission "can_do_stuff" for
objects of that 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: User permissions to see a view

2010-02-18 Thread rebus_
On 18 February 2010 13:29, ALJ  wrote:
> Hi Alexey,
>
> But how do you set a permission for a view? There's no underlying
> model to which to add the custom meta permissions.
>
> ALJ
>
> On Feb 18, 12:48 pm, Alexey Kostyuk  wrote:
>> On Thu, 2010-02-18 at 02:30 -0800, ALJ wrote:
>> > First project and struggling a bit.
>>
>> > I have some views that I want to restrict access to, depending on user
>> > type. How do I do that?
>>
>> > For example, I have a 'reports' view that I only want teachers to
>> > see ... not students. I can't see how to create a custom permission
>> > because there is no underlying model for the view. So do I need to
>> > create a custom user model or would it be better to just use
>> > profiles?
>>
>> > :-(
>>
>> You can use decorator @permission_required in your views.
>> See link[1] for details.
>>
>> [1]http://docs.djangoproject.com/en/dev/topics/auth/#the-permission-requ...
>>
>> --
>> Alexey Kostyuk 
>
> --
> 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.
>
>

same page...

http://docs.djangoproject.com/en/dev/topics/auth/#id2

-- 
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: any suggestions for managing DB schema with visual ERD tool?

2010-02-18 Thread rebus_
On 18 February 2010 01:03, snfctech  wrote:
> I just built a complicated schema with MySQL workbench and am looking
> at Python frameworks to start implementation.
>
> Does anybody in the Django community do this?  What's your practice
> for going back and forth between the ERD and the ORM?  I saw
> DjangoGraphviz http://code.djangoproject.com/wiki/DjangoGraphviz -
> which looks like you manage your schema in your Django models and can
> then export those to a visual representation.  Does anyone use that?
>
> I would love a visual DB design tool that automatically generated my
> framework models - but I'm sure that 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-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.
>
>

http://code.google.com/p/django-command-extensions/
http://code.google.com/p/django-command-extensions/wiki/GraphModels

-- 
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: Union of two querysets?

2010-02-15 Thread rebus_
On 16 February 2010 03:28, ydjango  wrote:
> I have two query sets with two different where clauses on same table
> and same columns in select. Is it possible to have their union.
>
> I tried qryset = qryset1 + qryset2
>  It gave me - "+ unsupported operand"
>
> --
> 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.
>
>

Perhaps you could try to use OR lookup using Q objects?

http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-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: Noob question: Templates: How to count for loop?

2010-02-15 Thread rebus_
On 16 February 2010 02:58, mhulse  wrote:
>> Hrmm, forloop.counter. It is one of those days. :P
>
> But, how can I tell if it is every third item?
>
> Also, is there a way to check if the current number is even?
>
> In a PHP template, I might do this:
>
> ... forloop ...
> 
> ... endforloop ...
>
> Sorry if silly question.
>
> Thanks!
> M
>
> --
> 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.
>
>

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#divisibleby
http://groups.google.com/group/django-developers/browse_thread/thread/20c309376c46590d?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: Noob question: Templates: How to count for loop?

2010-02-15 Thread rebus_
On 16 February 2010 02:58, mhulse  wrote:
>> Hrmm, forloop.counter. It is one of those days. :P
>
> But, how can I tell if it is every third item?
>
> Also, is there a way to check if the current number is even?
>
> In a PHP template, I might do this:
>
> ... forloop ...
> 
> ... endforloop ...
>
> Sorry if silly question.
>
> Thanks!
> M
>
> --
> 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.
>
>

{% for photo in photos %}

stuff
{% endfor %}

You could do it like this. There was a discussion recently about mod
operator and what happens when you want to do something every N times
but can't find it now for some reason :(

-- 
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: Noob question: Templates: How to count for loop?

2010-02-15 Thread rebus_
On 16 February 2010 02:52, mhulse  wrote:
>> Is this possible? I am sure it is... Any tips ya'll could send my way
>> would be spectacular!
>
> Hrmm, forloop.counter. It is one of those days. :P
>
> --
> 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.
>
>

Check out "cycle"  template tag too.

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#cycle

-- 
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: admin template object context

2010-02-15 Thread rebus_
On 15 February 2010 20:11, jb  wrote:
> im editing admin/change_form.html for one of my models and i need to
> access the context of the object being edited, eg. admin/hotel/
> change_form.html and in the template i need to call
> {{ actual_hotel.its_value }}
>
> --
> 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.
>
>

Try {{ original.its_value }}

-- 
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: Django IDE

2010-02-15 Thread rebus_
On 15 February 2010 10:29, bruno desthuilliers
 wrote:
> On Feb 15, 5:59 am, dj_vishal <2009vis...@gmail.com> wrote:
>> Hello
>>
>>    Hi to all am new to the Django Framework.am learning django
>>    Which IDE is suitable for Django ..plz help me in right way
>
> IDE ??? What's that ?-)
>
> More seriously : any decent code editor will do.
>
> --
> 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.
>
>

I find WingIDE to be a really cool thingy.

http://www.wingware.com/

But as Bruno pointed out, any decent code editor will do, just a
matter of preference.

-- 
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: weird request.user problem in view

2010-02-13 Thread rebus_
On 13 February 2010 13:46, Anders Eide  wrote:
> did a stupid PEBCAK i the urls.py file. Works fine now
>
> On Feb 13, 1:33 pm, Anders Eide  wrote:
>> Why on earth doesn't this user_page view work? Getting "404, No User
>> matches the given query."
>>
>> from django.contrib.auth.models import User
>> from django.template import RequestContext
>> from django.shortcuts import render_to_response, get_object_or_404
>>
>> def user_page(request):
>>     user = get_object_or_404(User,
>> username=request.user.username)
>>     movies = user.mymovie_set.all()
>>     variables = RequestContext(request, {
>>         'movies': movies,
>>     })
>>     return render_to_response('user_page/user_page.home.view.html',
>> variables)
>>
>> The user is loged in
>
> --
> 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.
>
>

user = User.get_object_or_404(User, username=request.user.username)

I don't think you need this, request.user is already an instance of User.
Try:

movies = request.user.mymovie_set.all()

-- 
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: relation "django_session" does not exist

2010-02-12 Thread rebus_
On 12 February 2010 11:26, chiranjeevi muttoju
 wrote:
> Hi,
> When i'm using the session in django i'm getting this error relation
> "django_session" does not exist. what is that error.. if any one of u know
> please help me..
> My code is:
>
 from django.contrib.sessions.backends.db import SessionStore
 s = SessionStore(session_key='2b1189a188b44ad18c35e113ac6ceead')
>
 from datetime import datetime
 s['last_login'] = datetime.datetime(2005, 8, 20, 13, 35, 10)
> Traceback (most recent call last):
>   File "", line 1, in 
>
> AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
 import datetime
 s['last_login'] = datetime.datetime(2005, 8, 20, 13, 35, 10)
> Traceback (most recent call last):
>
>   File "", line 1, in 
>   File
> "C:\Python26\lib\site-packages\django\contrib\sessions\backends\base.py",
> line 49, in __setitem__
> self._session[key] = value
>   File
> "C:\Python26\lib\site-packages\django\contrib\sessions\backends\base.py",
> line 172, in _get_session
>
> self._session_cache = self.load()
>   File
> "C:\Python26\lib\site-packages\django\contrib\sessions\backends\db.py", line
> 16, in load
> expire_date__gt=datetime.datetime.now()
>   File "C:\Python26\lib\site-packages\django\db\models\manager.py", line
> 119, in get
>
> return self.get_query_set().get(*args, **kwargs)
>   File "C:\Python26\lib\site-packages\django\db\models\query.py", line 323,
> in get
> num = len(clone)
>   File "C:\Python26\lib\site-packages\django\db\models\query.py", line 74,
> in __len__
>
> self._result_cache = list(self.iterator())
>   File "C:\Python26\lib\site-packages\django\db\models\query.py", line 261,
> in iterator
> for row in self.query.results_iter():
>   File "C:\Python26\lib\site-packages\django\db\models\sql\query.py", line
> 281, in results_iter
>
> for rows in self.execute_sql(MULTI):
>   File "C:\Python26\lib\site-packages\django\db\models\sql\query.py", line
> 2373, in execute_sql
> cursor.execute(sql, params)
>   File "C:\Python26\lib\site-packages\django\db\backends\util.py", line 19,
> in execute
>
> return self.cursor.execute(sql, params)
> ProgrammingError: relation "django_session" does not exist
>
>
> --
> Thanks & Regards,
> Chiranjeevi.Muttoju
>
> --
> 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.
>

Have you tried running

python manage.py syncdb

-- 
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: What hosting companies do you use for django hosting?

2010-02-09 Thread rebus_
On 9 February 2010 21:10, Brandon Taylor  wrote:
> WebFaction. They are simply awesome.
>
> On Feb 9, 9:52 am, adamjamesdrew  wrote:
>> 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.
>
>

http://www.hetzner.de/en/hosting/produktmatrix/rootserver-produktmatrix/

-- 
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: how to redirect to 'next'

2010-02-09 Thread rebus_
On 9 February 2010 16:47, harryos  wrote:
> hi
> In my login_view I am redirecting to an archive page as below
>
> def login_view(request):
>        if request.method=='POST':
>                username=request.POST['username']
>                password=request.POST['password']
>                user = authenticate(username=username, password=password)
>                if user is not None and user.is_active:
>                        login(request, user)
>                        return redirect('myapp_archive_index')#default page
>                else:
>                        return render_to_response('myapp/login.html')
>        else:
>                return render_to_response('myapp/login.html')
>
> In login template for I am using the hidden field 'next'
>
> ...
> 
>        
>
> I have given the LOGIN_URL as '/myapp/login/and in urlconf  set this
> to the above login_view method .
> url(r'^','myapp.views.login_view',name='myapp_login'),
>
> Also I have many views to list the entries belonging to an year,month
> etc..All of them have @login_required .
> eg:
> @login_required
> def entry_archive_year(request,year,month):
>        
>        return render_to_response('myapp/archive_month.html',somedict)
>
>
> Now if I try to access /myapp/entries/1999/jan/ ,I will get the login
> page .The url on browser search field is /myapp/login/?next=/myapp/
> entries/1999/jan/.If I login correctly ,I would like the page to go
> to /entries/1999/jan/  and not to the 'myapp_archive_index' page I
> provided in the login_view method.Is there a way to redirect to the
> value pointed to by this  'next'?
>
> thanks
> harry
>
> --
> 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.
>
>

Seems to me you done all that work just to redirect a user to your URL
after login?
You can use LOGIN_REDIRECT_URL [1] setting for this.

This way djangos auth login does all the work and redirects user on
successful login to URL set with LOGIN_REDIRECT_URL

[1] http://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url

-- 
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: how to define DJANGO_SETTINGS_MODULE for multiple sites.

2010-02-09 Thread rebus_
On 9 February 2010 03:25, neridaj  wrote:
> I'm trying to setup my first cron job and I think the reason my script
> is not running is because I don't have DJANGO_SETTINGS_MODULE defined
> for my environment i.e., .profile script. I'm using mod_wsgi so my
> DJANGO_SETTINGS_MODULE is defined in the respective wsgi file for each
> site, so my question is how do I setup a crontab that imports the
> correct settings module? I tried this but no luck:
>
> * * * * * django-admin.py shell --settings=sitename.settings /home/
> username/cron/syncr.py >> /home/username/croninfo.txt
>
> Thanks,
>
> Jason
>
> --
> 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.
>
>

Perhaps you can create your own management command and call it from cron.

http://docs.djangoproject.com/en/dev/howto/custom-management-commands/

-- 
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: I can't get urls with explicit keyword arguments to reverse correctly.

2010-02-08 Thread rebus_
On 8 February 2010 17:33, Luke Sneeringer  wrote:
> Good morning, Django e-mail list! Happy Monday! I have a problem. :) I 
> checked the Django documentation and Stack Overflow with no success, so you 
> guys are my next line of defense. This is an issue I've encountered several 
> times; this is just the first time working around it has bothered me enough 
> to send an email.
>
> So I have a couple URLs. The idea here is to use the same view but get 
> slightly different results. In particular, I have a registration page. We 
> have our regular packages, and then special nonprofit pricing. So, my 
> database stuff to power this is all set up.
>
> I have my basic url:
> ('^register/$', 'mysite.myapp.views.register', name = 'register')
>
> I want another one for nonprofits...same thing, and almost identical 
> functionality, so I changed the above and added a line:
> (r'^register/$', 'mysite.myapp.views.register', { 'nonprofit': False }, name 
> = 'register')
> (r'^register/nonprofit/$', 'mysite.myapp.views.register', { 'nonprofit': True 
> }, name = 'register')
>
> In the view, I am passing the value of the "nonprofit" variable to the 
> template under the same name. Simple enough.
>
> Now, the problem: In the template, the reverse URL matching totally barfs. I 
> want...
> {% url register nonprofit=nonprofit %}
> ...to work.
>
> But I get a NoReverseMatch error:
> Reverse for 'register' with arguments '()' and keyword arguments 
> '{'nonprofit': False}' not found.
>
> The Django documentation (as well as an answer on Stack Overflow) suggest 
> that I really ought to be using named URL patterns to solve this 
> problem...so, instead of naming my non-profit registration page "register", I 
> name it "register-nonprofit".
>
> I really do not want to do this if I can avoid it. That would require me to 
> have something to the effect of...
> {% if nonprofit %}
>        {% url register-nonprofit %}
> {% else %}
>        {% url register %}
> {% endif %}
> ...on the relevant pages. That's substantially less clean.
>
> I also am hoping to avoid a /register/forprofit/ type of URL. My boss would 
> kill me. :)
>
> Any thoughts?
>
> Regards,
> Luke
>
> --
> 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.
>
>


And those suggestions are quite good.

For example:

(r'^register/$', 'mysite.myapp.views.register', { 'nonprofit': False
}, name = 'register_nonprofit')
(r'^register/$', 'mysite.myapp.views.register', { 'nonprofit': True },
name = 'register_profit')

and in your form action field something along the line of:

{% if nonprofit %}
   {% url register_nonprofit %}
{% else %}
   {% url register_profit %}
{% endif %}

With correctly handled template inheritance [1] and include [2] you
should be able to have this if statement block only in one place in
your templates, and that is where the html for your form is located.

[1] http://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance
[2] http://docs.djangoproject.com/en/dev/ref/templates/builtins/#include

-- 
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: editing an entry ,how to call the form action

2010-02-08 Thread rebus_
Opps, for you view context it should be "entryform" not "form":


{{entryform.as_ul }}

 

-- 
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: editing an entry ,how to call the form action

2010-02-08 Thread rebus_
On 8 February 2010 16:52, jimgardener  wrote:
> hi
> I created a view function to edit an entry.
> def edit_entry(request,id):
>        entry=get_object_or_404(MyEntry,id=id)
>        if request.method=='POST':
>                form=MyEntryForm(request.POST,instance=entry)
>                if form.is_valid():
>                        form.save()
>                        redirect('myapp_entry_archive_index')
>        else:
>                form=MyEntryForm(instance=entry) #for GET method and invalid 
> forms
>
>        return render_to_response('myapp/myentry_edit_entry.html',
> {'entryform':form})
>
> then I created the urls like
> url(r'^editentry/(?P\d+)/
> $','myapp.views.edit_entry',name='myapp_edit_entry'),
>
> My problem here is how I should give the action in form in the
> template.
> I tried
> 
> {{entryform.as_ul }}
> 
> 
>
> But since the /myapp/editentry/ doesn't match any urls ,it gives a
> 404. How should I pass the id  of entry(which is to be edited) to
> action?
>
> I know this is a silly doubt..But I am a newbie to web programming..If
> anyone can help please do
>
> jim
>
> --
> 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.
>
>

Depends on the way you included your app url.py in projects urls.py.

If in your project's urls.py you have included your apps urls like
url(r'^myapp/$', include('myapp.urls')), then your URL would look like
/myapp/editentry/1/

And instead of hard-coding action url in the template try using
built-in url template tag:
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url

For example:


{{entryform.as_ul }}



-- 
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: django-debug-toolbar with runserver not running on localhost

2010-02-04 Thread rebus_
On 4 February 2010 22:06, HARRY POTTRER  wrote:
> I've noticed that if I run the django dev server on localhost, debug-
> toolbar works, but if I try to run he server like this:
>
> ./manage.py runserver 192.168.1.145:8000
>
> the site will work, but the toolbar won't show up. Is there a work-
> around for this?
>
> --
> 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.
>
>

Do you maybe have INTERNAL_IPS set in your settings?
It's used to decide on which addresses the toolbar will be shown.

Read more about this on:
http://github.com/robhudson/django-debug-toolbar.

-- 
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: Division with Python/Django

2010-01-29 Thread rebus_
On 29 January 2010 14:40, Chris McComas  wrote:
> I have this view with my form: http://dpaste.com/152046/ when I try to
> submit the form I'm getting this error: unsupported operand type(s)
> for //: 'unicode' and 'int' what did I do wrong?
>
> --
> 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.
>
>
Are you sure cogability.* attributes are integers?

Full error message would also be helpfull.

-- 
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: No such table:django_sesion error when using django with lighttpd + mod_fastcgi

2010-01-01 Thread rebus_
2010/1/1 sangho :
> hello, i`m korean, and english is the starter, so please understanding
>
> i want access to admin page, if i run with developserver, it's working
> but if i run with lighttpd + mod_fastcgi + manage.py runfcgi server,
> it's not working
> i can access to http://222.122.31.234:81, and it's working when using
> lighttpd,
> but http://222.122.31.234:81/admin page is not working
>
> how can i solve this problem?
>
>
> Lighttpd Error log is here:
> http://dpaste.com/139809/
>
> Django settings.py is here:
> http://dpaste.com/139810/
>
> Django urls.py is here:
> http://dpaste.com/139811/
>
> Django panel(app name) models.py is here:
> http://dpaste.com/139812/
>
>
> http://222.122.31.234
> http://222.122.31.234/admin
>
> both url is work on lighttpd with django, not develop server
> please help!
>
> --
>

Are you sure you ran pythom manage.py syncdb?
Or set up database any other way?

--

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: You are already login...I want to get this message when a user is already login to my site(two different location)

2009-12-28 Thread rebus_
2009/12/28 Daniel Roseman :
> On Dec 28, 11:26 am, NMarcu  wrote:
>> Hello all,
>>
>>    I want to let only one same user to be login in the same time. If I
>> connect from Paris with admin, and other user try to connect with
>> admin from other location, to get a message like it is already
>> connected. How can I do something like this?
>
> That's not easy. 'Logged in' status is not something that is stored on
> the server, but on the client (in the session). So the server does not
> actually know who is logged in at any one time. It does record the
> last time a particular user logged in, and I suppose you could create
> a user profile that records the last time the user performed an
> action, but it's not clear how you would determine that a user had
> logged out or that the session had expired.
> --
> DR.
>
> --

Actually i think it is stored on the server. You only get cookie in
your browser with the sessions key and session is stored in
django_session table in your database, and each record has session key
and expire time (providing you use SessionMiddleware).

You could override the login view to check if the user is logged in or
not and has the session expired. Though i _think_ you would need to
modify/hack the django.contrib.admin to use your login view rather the
the one built into django.

But all this seems a bit clumsy. I had a case where we should let one
type of users login only after the correct amount of other type of
users had been registered. But this was only for site login and none
of the plain users could use admin. So we just overrided built in
login view.

It looks something like:

@csrf_protect
@never_cache
def login(request, template_name='registration/login.html',
  redirect_field_name=REDIRECT_FIELD_NAME,
  authentication_form=None):

users = User.objects.filter(user_type="some_type").aggregate(Count('id'))
if users['id__count'] > 50:
 from django.contrib.auth.views import login
 return login(request, template_name, redirect_field_name,
authentication_form)
else:
raise SomeError # Or mess with POST data so the auth fails

This could be done much more elegantly with lower level API but this
was "just make it work" solution.

Instead of counting users you could say

if request.user.is_authenticated():
return HttpResponseRedirect(reverse('home'))

In this example if the user is authenticated he gets redirected to
some home page of his/hers.

You can look in from django.contrib.auth.views.login source and see
how the developers do it and then copy the login function and work
your magic there but still you should hack the django.contrib.admin to
use that new login AFAIK.

It's not a perfect solution but it's all I've got ATM.

Davor

--

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: {% url admin:index %} generating wrong urls

2009-12-25 Thread rebus_
2009/12/24 Chris Withers :
> Hi All,
>
> My django site is served up with the following in Apache's config:
>
> WSGIScriptAlias /studio /django/studio/bin/django.wsgi
>
> My urls.py looks like:
>
> urlpatterns += patterns(
>     'django.contrib',
>     (r'^admin/', include(admin.site.urls)),
>     (r'^accounts/login/$', 'auth.views.login'),
>     (r'^accounts/logout/$', 'auth.views.logout'),
>     )
>
> ...and yet:
>
> [admin]
>
> ...generates a link to /admin rather than /studio/admin.
> Bizarrely, the urls within the admin interface itself are fine.
>
> I'm using:
>
> Python 2.5.2-3
> Django 1.1.1
> mod_wsgi  2.5-1~lenny1
> apache2 2.2.9-10+lenny6
>
> Can anyone tell me what I'm doing wrong?
>
> cheers,
>
> Chris
>
> --
> Simplistix - Content Management, Batch Processing & Python Consulting
>            - http://www.simplistix.co.uk
>
> --
>

Seems to me you are missing namespace definitions in your URL for that to work.

http://docs.djangoproject.com/en/dev/topics/http/urls/#defining-url-namespaces

--

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: Clickable url in the admin

2009-12-22 Thread rebus_
2009/12/22 Zeynel <azeyn...@gmail.com>:
> Thank you. Can you give me more detailed instructions about how to do
> this? I couldn't parse the referenced section of the documentation.
> How do I create the method "to generate anchor?" Where does the
> "method name" go in the admin.py?
>
> Thanks again.
>
> On Dec 14, 6:41 pm, rebus_ <r.dav...@gmail.com> wrote:
>> Create method on your model that generates anchor (html link tag)
>> which points to wanted URL and put that methods name in list_display
>> property of AdminModel object in your admin.py
>>
>> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...
>

Hey,

Well, i was really short on my explanation there so let me elaborate.
I assume you have knowledge on what AdminModel is and what
list_display is used for.

Lets say you have model such as:

class SomeModel(models.Model):
somefield = models.CharField(max_length=20)
url = models.CharField(max_length=100)

def some_url(self):
""" This returns a HTML anchor (hyperlink) to somewhere  """
return u'Link'  % self.url
some_url.allow_tags = True

This model has some_url method defined which returns a plain HTML
link. When you create your AdminModel all you need to do is add the
name of them method to list_display attribute.

class SomeModelAdmin(admin.ModelAdmin):
list_display = ('somefield', 'some_url')
site.register(SomeModel, SomeModelAdmin)

Using list_display attribute of AdminModel you can choose which fields
are to be display on change list in admin for that model.

So when the admin app parses the list_display attribute on AdminModel,
for each item in the sequence it tries to see if it is a field on
model, callable on Model or callable on AdminModel.

So what you need to do is create a method on your model that returns
the complete HTML link to lawyers bio and put that methods name in
list_display and your set to go.

Also notice the "some_url.allow_tags = True" under the method
definition. This tells Django's admin that it's ok not to encode HTML
tags. Without this the returned string would not be clickable but
rather shown as plain text.

Hope this helps.

Davor

--

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: pass to a template many querysets

2009-12-21 Thread rebus_
2009/12/21 Francesco Benincasa :
> Hi all,
> I need to pass to a template more than one list of diffent models objects.
>
> Now I'm using a date_based.archive_index but I can pass it only a queryset as
> argument, isn't it?
>
> What's the correct approach? To try to pass in a same queryset all objects I
> need (and in this case, how?) or I can also pass two or three different
> querysets?
>
> Thank you very much.
>


extra_context: A dictionary of values to add to the template context.
By default, this is an empty dictionary. If a value in the dictionary
is callable, the generic view will call it just before rendering the
template.


http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-date-based-archive-index

--

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: Display images in template using ManyToMany

2009-12-20 Thread rebus_
{% for a in p.gallery.all %}
<--- TRY THIS
{% endfor %}

http://docs.djangoproject.com/en/dev/ref/files/file/#django.core.files.File.url

--

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: Error message

2009-12-18 Thread rebus_
2009/12/18 reactosguy :
> I get this message every time I go on http://localhost:8000/ with the
> Django server running:
>
> Traceback (most recent call last):
>
>  File "C:\Python26\lib\site-packages\django\core\servers
> \basehttp.py", line 279, in run
>    self.result = application(self.environ, self.start_response)
>
>  File "C:\Python26\lib\site-packages\django\core\servers
> \basehttp.py", line 651, in __call__
>    return self.application(environ, start_response)
>
>  File "C:\Python26\lib\site-packages\django\core\handlers\wsgi.py",
> line 241, in __call__
>    response = self.get_response(request)
>
>  File "C:\Python26\lib\site-packages\django\core\handlers\base.py",
> line 122, in get_response
>    return self.handle_uncaught_exception(request, resolver,
> sys.exc_info())
>
>  File "C:\Python26\lib\site-packages\django\core\handlers\base.py",
> line 166, in handle_uncaught_exception
>    return callback(request, **param_dict)
>
>  File "C:\Python26\lib\site-packages\django\views\defaults.py", line
> 23, in server_error
>    t = loader.get_template(template_name)
>
>  File "C:\Python26\lib\site-packages\django\template\loader.py", line
> 81, in get_template
>    source, origin = find_template_source(template_name)
>
>  File "C:\Python26\lib\site-packages\django\template\loader.py", line
> 74, in find_template_source
>    raise TemplateDoesNotExist, name
>
> TemplateDoesNotExist: 500.html
>
> --

Create template with the name 500.html in your base template directory.
It tries to use 500.html on server error if you have DEBUG=False.

Davor

--

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: ORM using tons of memory and CPU

2009-12-15 Thread rebus_
2009/12/15 Tracy Reed :
>
> I have code which looks basically like this:
>
> now        = datetime.today()
> beginning  = datetime.fromtimestamp(0)
> end        = now - timedelta(days=settings.DAYSTOKEEP)
>
> def purgedb():
>    """Delete archivedEmail objects from the beginning of time until
>    daystokeep days in the past."""
>    queryset   = archivedEmail.objects.all()
>    purgeset   = queryset.filter(received__range=(beginning, end))

You don't need both queries (altghou they are lazy). You could just say:

purgeset = archivedEmail.filter(received__range=(beginning, end))


>    for email in purgeset:
>        print email
>        try:
>            os.unlink(settings.REAVER_CACHE+"texts/%s"     % email.cacheID)
>            os.unlink(settings.REAVER_CACHE+"prob_good/%s" % email.cacheID)
>            os.unlink(settings.REAVER_CACHE+"prob_spam/%s" % email.cacheID)
>        except OSError:
>            pass
>    purgeset.delete()
>
> if __name__ == '__main__':
>    purgedb()
>
> The idea is that we are stuffing a bunch of emails in a database for
> customer service purposes. I want to clear out anything older than
> DAYSTOKEEP. The model looks like this:
>
> class archivedEmail(models.Model):
>    subject     = models.CharField(blank=True, max_length=512, null=True)
>    toAddress   = models.CharField(blank=True, max_length=128, db_index=True)
>    fromAddress = models.CharField(blank=True, max_length=128, db_index=True)
>    date        = models.DateTimeField()
>    received    = models.DateTimeField(db_index=True)
>    crmScore    = models.FloatField()
>    spamStatus  = models.CharField(max_length=6, choices=spamStatusChoices, 
> db_index=True)
>    cacheHost   = models.CharField(max_length=24)
>    cacheID     = models.CharField(max_length=31, primary_key=True)
>
>    class Meta:
>        ordering = ('-received',)
>
> But when purgedb runs it deletes emails 100 at a time (which takes
> forever) and after running for a couple of hours uses a gig and a half
> of RAM. If I let it continue after a number of hours it runs the
> machine out of RAM/swap.
>
> Am I doing something which is not idiomatic or misusing the ORM
> somehow? My understanding is that it should be lazy so using
> objects.all() on queryset and then narrowing it down with a
> queryset.filter() to make a purgeset should be ok, right? What can I
> do to make this run in reasonable time/memory?
>
> PS: I used to have ordering set to -date in the class Meta but that
> caused the db to always put an ORDER BY date on the select query which
> was unnecessary in this case causing it to take ages sorting a couple
> million rows since there is no index on date (nor did there need to
> be, so I thought, since we never select on it). Changing it to
> received makes no difference to my app but avoids creating another
> index. Django's is the first ORM I have ever used and these sneaky
> performance issues are making me wonder...
>
> --
> Tracy Reed
> http://tracyreed.org
>


When you execute a query set that operates on millions of rows you
should remember that ORM will create a python object for each row.
This could take a while. Though i am not sure how it handles memory
issues.

You could issue plain SQL query which returns result as tuple (only
returning cache ID for example) and might be faster if you don't
really need ORM, then loop through the tuple and delete files on disk.
I think this should use less memory and processing time.

Also, I am not SQL guru but i guess BETWEEN should work on most DB
servers so you should not have portability issues (but i cant
guarantee this).

Don't use try ... except for checking if the file exists. Rather use
"if" statement with os.path.exists or os.path.isfile and if it does
exist delete the file. Exceptions are expensive in CPython.

Read this topic about deleting objects in bulk (though i think you
already have it never hurts to refresh your memory).

http://docs.djangoproject.com/en/dev/topics/db/queries/#deleting-objects

Just my 2 cents

Davor

--

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: Django authentication, not permit 2 users with the same name to login in same time

2009-12-14 Thread rebus_
2009/12/14 NMarcu :
> Hi all,
>
>   How can I do, to not let the same user to be logged from 2
> different location, in the same time. I want, when a user admin is
> login, and another user try to login with the same user admin, to have
> a message, you are already login. How can I do something like this?
>
> All the best,
> Nicu Marcu
>
> --
>

You extend auth login view so it checks if the user that wants to
login already has active session and if he does tell him he can't
login.

But if he forgets to logout on remote location how will he be able to
login again?

--

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: Clickable url in the admin

2009-12-14 Thread rebus_
Create method on your model that generates anchor (html link tag)
which points to wanted URL and put that methods name in list_display
property of AdminModel object in your admin.py

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display

--

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: Foreign key links in Django.admin

2009-12-14 Thread rebus_
2009/12/14 fredlab :
> Hey,
>
> I've looking for hours and I could not find what I am looking for. It
> is probably a basic question but I am a newcomer to Django (will
> probably forget PHP in a few days !!!).
>
> Imagine I have a blog post application but many users can create
> posts. A post is written by a user. In the admin site, when I list all
> post, there is a column with the user name. I would like to be able
> to :
>
> * click on the user name and directly switch to the user view
> * add a field "more from that user" so that when you clik on it, the
> posts list is automatically filtered based on that user name.
>
> I imagine we can do it from the model file definition (or admin.py
> file) but I could not find how.
>
> In advance, thanks for the help.
>
> Regards,
>
> Fredlab
>

Maybe these can help:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter

--

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: ProgrammingError: relation "django_session" does not exist

2009-12-13 Thread rebus_
2009/12/12 newpublic :
> when migrate djange from ubuntu 910 to fedora 12, there are so much
> trouble ..
> #- -
>
> ==
> error information:
>
> Traceback (most recent call
> last):
>  File "/usr/lib/python2.6/site-packages/mod_python/importer.py", line
> 1537, in HandlerDispatch\n    default=default_handler, arg=req,
> silent=hlist.silent)
>  File "/usr/lib/python2.6/site-packages/mod_python/importer.py", line
> 1229, in _process_target\n    result = _execute_target(config, req,
> object, arg)
>  File "/usr/lib/python2.6/site-packages/mod_python/importer.py", line
> 1128, in _execute_target\n    result = object(arg)
>  File "/usr/lib/python2.6/site-packages/django/core/handlers/
> modpython.py", line 228, in handler\n    return ModPythonHandler()
> (req)
>  File "/usr/lib/python2.6/site-packages/django/core/handlers/
> modpython.py", line 205, in __call__\n    response = middleware_method
> (request, response)
>  File "/usr/lib/python2.6/site-packages/django/contrib/sessions/
> middleware.py", line 36, in process_response\n    request.session.save
> ()
>  File "/usr/lib/python2.6/site-packages/django/contrib/sessions/
> backends/db.py", line 52, in save\n    session_key = self.session_key,
>  File "/usr/lib/python2.6/site-packages/django/contrib/sessions/
> backends/base.py", line 152, in _get_session_key\n
> self._session_key = self._get_new_session_key()
>  File "/usr/lib/python2.6/site-packages/django/contrib/sessions/
> backends/base.py", line 144, in _get_new_session_key\n    if not
> self.exists(session_key):
>  File "/usr/lib/python2.6/site-packages/django/contrib/sessions/
> backends/db.py", line 25, in exists\n    Session.objects.get
> (session_key=session_key)
>  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
> line 120, in get\n    return self.get_query_set().get(*args, **kwargs)
>  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
> line 300, in get\n    num = len(clone)
>  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
> line 81, in __len__\n    self._result_cache = list(self.iterator())
>  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
> line 238, in iterator\n    for row in self.query.results_iter():
>  File "/usr/lib/python2.6/site-packages/django/db/models/sql/
> query.py", line 287, in results_iter\n    for rows in self.execute_sql
> (MULTI):
>  File "/usr/lib/python2.6/site-packages/django/db/models/sql/
> query.py", line 2369, in execute_sql\n    cursor.execute(sql, params)
>  File "/usr/lib/python2.6/site-packages/django/db/backends/util.py",
> line 19, in execute\n    return self.cursor.execute(sql, params)
> ProgrammingError: relation "django_session" does not exist\nLINE
> 1: ...ession_data", "django_session"."expire_date" FROM "django_se...
> \n
>
>
> ==
> OS: Fedora 12 i386 ( base system  )
> Linux constantine 2.6.31.5-127.fc12.i686.PAE #1 SMP i686 i386 GNU/
> Linux
>
> apache: httpd 2.2
> django.VERSION = (1, 1, 0, 'final', 0)
> postgresql, postgresql_psycopg2
> mod_python/3.3.1 Python/2.6.2
>
> --
>

My first guess would be that you did not setup your database correctly.
Have you run "syncdb" or restored your database dump back after
migrating to Fedora?

Davor

--

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: access legacy data without model.py

2009-12-13 Thread rebus_
2009/12/12 dundeemt :
> I need to access data in other databases.  I don't want them listed in
> model.py as I won't be using django's orm for them. Given this, where
> is the preferred place to put the db connection for this data?  The
> only references I could find show creating a db connection in the
> view, http://www.djangobook.com/en/beta/chapter05/  -- while valid for
> my purposes, is there a better place to cache the connection?
>
> Also, I will be accessing 7+ other databases of varying types, some
> have hundreds of tables and I have no desire to create a model when
> for them when I only need to get to a few values.  I will not be
> updating data in these other databases, only doing lookups.  So I am
> not interested in making a proper django data connection to them.
>
>
>
> Best,
>
> Jeff
>
> --

In upcoming 1.2 version of django there should be support for multiple
database. Thought Django 1.2 is scheduled for release on March 9,
2010.

More information:

http://code.djangoproject.com/wiki/Version1.2Roadmap
http://code.djangoproject.com/wiki/Version1.2Features
http://code.djangoproject.com/wiki/MultipleDatabaseSupport
http://code.djangoproject.com/ticket/1142

Sorry i can't be more helpfull.

Davor

--

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: Is there any way to make USStateField() to not have a pre-selected value?

2009-12-02 Thread rebus_
2009/12/2 Continuation :
> I use USStateField() from localflavor in one of my  models:
>
> class MyClass(models.Model):
>   state  = USStateField(blank=True)
>
> Then I made a form from that class:
>
> class MyClassForm(forms.ModelForm):
>    class Meta:
>        model   = MyClass
>
> When I display the form, the field "State" is a drop-down box with
> "Alabama" pre-selected.
>
> Is there any way to make the drop-down box to show no pre-selected
> value at all?
>
> --
>
> 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.
>
>
>

Maybe using default as argument to your field?

http://docs.djangoproject.com/en/dev/ref/models/fields/#default

--

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: Trouble with Pythonpath and getting my server to start

2009-12-02 Thread rebus_
2009/12/1 Dave :
> Hi all,
>
> I created a django project and when I try to start the server I get
> this:
>
> Traceback (most recent call last):
>  File "manage.py", line 2, in 
>    from django.core.management import execute_manager
> ImportError: No module named django.core.management
>
> I did some Googling and I think it's because I got an error when
> trying to create a symlink in the installation instructions:
>
> "Next, make sure that the Python interpreter can load Django's code.
> There are various ways of accomplishing this. One of the most
> convenient, on Linux, Mac OSX or other Unix-like systems, is to use a
> symbolic link:
>
> ln -s `pwd`/django-trunk/django SITE-PACKAGES-DIR/django"
>
> I changed SITE-PACKAGES-DIR to my directory and got this error:
>
> $ ln -s `pwd`/django-trunk/django /Library/Frameworks/Python.framework/
> Versions/2.6/lib/python2.6/site-packages/django
> ln: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
> site-packages/django: File exists
>
> I'm not sure what it means by "file exists". The other option was
> changing the Pythonpath to include the Django directory, but I'm not
> sure how to do that. Answers on Google didn't make sense to me or
> didn't seem to apply. Any help would be greatly appreciated!
>
> --
>
> 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.
>
>
>

My first guess would be that destination file exists and `ln` doesn't
want to overwrite the file
First try moving file or directory named "django" from site-packages
somewhere else and then try to link again.

$ mv 
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django
/tmp/DJANGO_TMP
$ ln -s `pwd`/django-trunk/django /Library/Frameworks/Python.framework/

Davor

--

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: Dynamicly preset forms in the admin interface

2009-12-01 Thread rebus_
models.py
=
from django.db import models

class Country(models.Model):
name  = CharField(max_length=70)

def __unicode__(self):
return '%s' % (self.name)


admin.py
=
from django.contrib import admin
from your_app.models import Country

site.register(Country)


When you runserver and visit add view for this model you should get
simple *empty* form to add new country in your database.

http://127.0.0.1:8000/admin/invest_core/country/add/


Ok, now we want to preset the name of the country. To test this you
can go to this URL:

http://127.0.0.1:8000/admin/invest_core/country/add/?name=Croatia

The field name should now contain "Croatia". I think this explains all
my muttering about GET and model attributes.

=

Now we want to do this but through admin not through URL. For this we
change admin.py like this:

admin.py
=
from django.contrib import admin
from your_app.models import Country

class CountryAdmin(admin.ModelAdmin):
def add_view(self, request, form_url='', extra_context=None): #
Override built in add_view
request.GET = request.GET.copy() # GET is immutable
QueryDict so we need to get a copy() as explaind in docs
request.GET.update({'name':'Croatia'}) # This sets value
for field "name"
return super(CountryAdmin, self).add_view(request,
form_url=form_url, extra_context=extra_context) #This calls original
add_view method
site.register(Country, CountryAdmin)


Now when you open up add_view again the name should also be set to "Croatia"

http://127.0.0.1:8000/admin/invest_core/country/add/


Background:

Class ModelAdmin is located in django/contrib/admin/options.py and has
add_view method which gets called when you open add view in your
Django admin.
URL pattern for this view is located in get_url method on the same class.

This means when you subclass admin.ModelAdmin to create admin pages
for you model you can override all the methods that ModelAdmin has by
default or add your own methods (for custom views or whatever). So to
change behaviour of add_view method you simply override it in your
CountryAdmin. It still needs to return same thing (HttpResponse with
some Context) as the built in add_view.

I hope this casts some light on what i am trying to say.
Anyway, the best way is to read docs and look in django code. Sorry i
can't help more.

Davor

--

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: Dynamicly preset forms in the admin interface

2009-12-01 Thread rebus_
2009/11/30 Kai Timmer <em...@kait.de>:
> 2009/11/29 rebus_ <r.dav...@gmail.com>:
>> I  imagine some of core devs or django gurus would maybe have better
>> ideas on how to do this (or can even tell you if this is documented
>> somewhere).
> What i wonder is: Isn't this a fairly common thing? I could think of
> so many situations where you would preset fields with values from the
> database. So I am pretty suprised that it seems like there is no
> "default" way of doing this. This maybe because i never used a
> framework like django before and I'm missing a general design
> principle. If so, please tell me ;)
>
Well default would be to set "default" on your models.

class SomeModel(models.Model):
   level = IntegerField(default=22)

When you open add view in admin this field would have number 22 already set.
But it would always have 22 set, and you would have to work some magic
to change it in runtime.

Usually, i don't care if people can set preset fields, so i override
save_model method and populate fields i want with the values i want.
For example if i want to set author of the article i just set it
before it gets written to database to value of
request.user.get_full_name()

request.user.get_full_name() would return the full name of the user
that is currently logged in (in other words owns a request)

Still i am not sure about read-only fields. But i guess you could use
custom templates in admin to achieve this, or override form widgets.

>> As far as readonly fields go i found snippet [3] but i haven't look at
>> it closely to tell you is it any good or not.
>> But if you set your fields read only how would you make them editable
>> if necessary? With JavaScript?
> It is more like the fields should be either preset and editable XOR
> preset and not editable. Nothing to change there once the page is
> rendered
>
>> Hope i helped this time :)
> Too much Information :) I'm just getting started with django ;)

Example i gave in previous email can be used to set different values
for different cases in different requests and wrapping add_view method
seems fairly easy.
Of course, to do this you have to be familiar with Django at least a
bit. All you need to do is create your AdminModel (which is described
in Django tutorial among other places) and inside of that class create
method add_view (for which i gave example in previous mail).

Also using GET methods to retrieve data is common in HTTP protocol and
it is not something specific to Django.

If your URL looks like http://127.0.0.1/?variable=value in PHP you
would use $_GET["variable"]; to get the value while in Django you
would use request.GET["variable"].

If any of variables in request.GET have the same name as some
attribute on your model, fields for that attribute is set to value of
request.GET["that_var"].

I can give you full code example if it would make it easier to understand.
I believe this can sound overwhelming but as people tend to say, it's
just python :)

And as i have said, there might be easier ways to do this, but i can't
think of any, and if there are i would like to see them myself too.

Also, i would suggest further reading:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/
http://docs.djangoproject.com/en/dev/topics/forms/
http://docs.djangoproject.com/en/dev/ref/request-response/

Davor

--

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: Difficulty using anchor tags in templates

2009-11-29 Thread rebus_
BTW here is an example:

When you click this link:
http://en.wikipedia.org/wiki/Fragment_identifier#Processing

your browser will open up
http://en.wikipedia.org/wiki/Fragment_identifier page and then scroll
down to the Processing title without wikipedia even knowing that you
specifically want to see that part of the page, it will just send you
the page and let your browser worry about scrolling.

Also i apologize, since English is not my native language i might have
trouble explaining some thing with it :)

Davor

--

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: Difficulty using anchor tags in templates

2009-11-29 Thread rebus_
I have seem to overcomplicated and I hope i understand your question right :)

You just need to render the template with your titles and content (i
guess you call it resources).

If you have a link such as link anywhere
on your site, once you click on it you should return HttpResponse and
render your template with titles and content normally.

You don't need HttpResponseRedirect in resources view and you don't
need to do any special handling of fragment id in Django. It is done
by your client (browser).

so instead of

def resources(request):
   return HttpResponseRedirect('/resources/')

you would have something like:

def resources(request):
  articles = Context({'articles': Articles.objects.all()})
  return render_to_response('resources.html', articles)

If anywhere in your resources.html (once it's rendered) there is a
title or any other element which has id="title" your browser will
position that page on that element.

I suggest you read more on fragment identifiers.

http://en.wikipedia.org/wiki/Fragment_identifier

Davor

--

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: Dynamicly preset forms in the admin interface

2009-11-29 Thread rebus_
2009/11/29 Kai Timmer <em...@kait.de>:
> 2009/11/29 rebus_ <r.dav...@gmail.com>:
>> Have you tried using fieldsets [1] in you ModelAdmin. Also you can
>> override save_model method on the ModelAdmin to set values for some
>> object attributes when the object is being saved [2].
>
> I don't see how I can use fieldsets to achieve this. I thought with
> the fieldsets I just tell django what forms to show in the interface,
> but not what to put in it.
> And when I overwrite the save_model method, there is no way to show
> the user what will end up in the database, right? So that is not the
> right way when I want to have the user to have the opportunity, to
> change the default data.
>
> Greets,
> --
> Kai Timmer | http://kaitimmer.de
> Email : em...@kaitimmer.de
> Jabber (Google Talk): k...@kait.de
>

Yes, fieldsets are used to decide what form fields to display and how
to lay them out on admin add/change views.
And yes, user would have no knowledge of what data is eventually
written in database at the time of object saving.

I must confess i haven't look into this up until now.

Seems that the add_view checks data passed through GET [1] (which is
of type QueryDict [2]) to see if any of the keys in GET correspond to
the attribute on Model, and if it finds any sets the value of that key
as initial value for the field in the admin form.

You can even set M2M fields this way by giving list of coma separated
PK's through GET for you M2M attribute.

So in your case, you can pass var though GET like so:

 /admin/app/article/add/?author=ante

and once it renders your author filed should contain word "ante".

But since you probably do not want to set your defaults directly
through URL you can wrap add_view in your ModelAdmin like this:

class ArticleAdmin(admin.ModelAdmin):
   def add_view(self, request, form_url='', extra_context=None):
  # GET is immutable QueryDict so we need to get a copy() as
explaind in docs
  request.GET = request.GET.copy()
  request.GET.update({'author':'ante'})
  return super(ArticleAdmin, self).add_view(request,
form_url=form_url, extra_context=extra_context)

When you refresh your article add view author field should contain
value of "ante".

Or if you want a full name of current user you could say:
request.GET.update({'author':request.user.get_full_name()})

I  imagine some of core devs or django gurus would maybe have better
ideas on how to do this (or can even tell you if this is documented
somewhere).

As far as readonly fields go i found snippet [3] but i haven't look at
it closely to tell you is it any good or not.
But if you set your fields read only how would you make them editable
if necessary? With JavaScript?

[1] 
http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.GET
[2] 
http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.QueryDict
[3] http://www.djangosnippets.org/snippets/937/

Hope i helped this time :)

Davor

--

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: Difficulty using anchor tags in templates

2009-11-29 Thread rebus_
2009/11/29 Andy :
> I have a model named Articles with title and content fields.  Each
> page of my site should display a list of the titles, linked with
> anchor tags to the corresponding area of the Resources page which
> displays all the titles and content.  I am having trouble figuring out
> how to pass the #title info.  I've read a previous post:http://
> groups.google.com/group/django-users/browse_thread/thread/
> bf5bae5b333aae/b8627d237d34fd69?lnk=gst=anchor+tag#b8627d237d34fd69,
> but am still struggling.
>
> Views(snippet):
> articles = Context({'articles': Articles.objects.all()})
> def index(request):
>        return render_to_response('index.html', articles)
> def resources(request):
>        return HttpResponseRedirect('/resources/')
>
> Base Template(snippet):
>        
>                Resources
>                
>                {% for articles in articles %}
>                
> {{ articles }}
>        {% endfor %}
>                
>        
>
> I am getting a 'too many redirect' error with this code.  Can anybody
> help me with this?
>

With assumption you have set your url like:

url(r'^resources/$', 'resources',  name='resources')

each time you open "resources" view you would get redirected to the
"resources" view and you have endless loop, which browsers would
terminate after certain number of repetitions.

resources view should return html page with titles and content rather
then redirect to it self.

Basically, when you click on "/some/page/#fid", view which handles
/some/page/ url should return HTML page, and if there is a fragment id
("#fid" in this case) in that page your browser should position your
page on that fragment id (if possible).

Hope i didn't overcomplicated this :)

Davor

--

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: Dynamicly preset forms in the admin interface

2009-11-29 Thread rebus_
2009/11/29 Kai Timmer :
> Hello,
> I'm new to django, so this question may look a bit stupid, but I
> couldn't find the information in the documentation.
>
> I have a pretty simple model which looks like this:
> class article(models.Model):
>  headline = models.CharField(max_length=140)
>  newsentry = models.TextField()
>  pub_date = models.DateTimeField('date published', null=True,
> blank=True)
>  write_date = models.DateTimeField('started writing')
>  published = models.BooleanField()
>  author = models.CharField(max_length=20)
>
> What i want to do now, is that some of these fields are preset when a
> new article is written. Lets say a user named Peter is going to write
> a new article, then the author field should be preset to "Peter" and
> shouldn't be editable. Same thing for write_date, which should be set
> to the time Peter started to write this article. How do I do this?
>
> Greets,
> Kai
>
> --

Have you tried using fieldsets [1] in you ModelAdmin. Also you can
override save_model method on the ModelAdmin to set values for some
object attributes when the object is being saved [2].

[1] 
http://docs.djangoproject.com/en/dev/intro/tutorial02/#customize-the-admin-form
[2] 
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model

Davor

--

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: CSRF Flatpages

2009-11-29 Thread rebus_
2009/11/28 John Leith :
> I have a problem with the CSRF framework, and i'm just checking here
> to see if anyone else ran into this problem and hopefully found a
> solution. Here is my problem:
>
> I have a login form on the base template of my site. The home page is
> just a flatpage. My login processor is csrf protected. I have the
> middleware and the {% csrf_token %} is set in the template.
>
> The problem is that there is no output from the template tag, it
> dosen't contribute anything at all to the rendered HTML. So naturally,
> I can't login from the homepage.
>
> I poked around in the code, and i planning on digging some more.
> However, if someone else has encountered this, i sure would appreciate
> some guidance.
>
> --
>
> 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.
>
>
>

Flat pages are used to store plain HTML [1], you can't use filter nor
templatetags in them (perhaps you could with some weird middleware or
something but it would not be good solution).

Create custom HTML template for you login view, pass the template name
to your login url pattern (if you don't need custom view) and
everything should work out fine i think.

 url(r'^login/$', 'login',
{'template_name': 'registration/login.html'},
name='login'),

[1] 
http://docs.djangoproject.com/en/dev/ref/contrib/flatpages/#module-django.contrib.flatpages

--

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: CSRF gone haywire

2009-11-28 Thread rebus_
2009/11/27 Tim Valenta :
> Also, I've figured out just now while rereading the reply I got, that
> "AFAIK" must mean "as far as I know".  Please... can we not use
> ridiculous short forms for a language that works better when not
> profusely abbreviated?  That would have been a hundred times harder to
> figure out if I were a not a native speaker of English.  I can handle
> a few of those, like IMHO, but I can't say that I've come across
> "AFAIK" often enough to compute that in record time.
>

You must be joking :)

--

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: CSRF gone haywire

2009-11-27 Thread rebus_
2009/11/27 Tim Valenta :
> Has anybody else experienced a senseless failure of the dev trunk's
> CSRF verification?  Very suddenly this morning, Django won't let me
> change anything in my admin sites.  I didn't update my copy of the SVN
> trunk, but as soon as I took myself off of the admin-ui branch, it
> flipped out.
>
> Step by step, all I did was move my copy of the main trunk to
> "_django" instead of "django".  I then uncompressed the admin-ui
> branch to "django" as a replacement.  All was well.  There are some
> broken "Add new item" links in that branch, and I got sick of it not
> working.  So I moved my admin-ui trunk to "admin-ui" for safekeeping,
> and then put back my original copy of the main trunk.
>
> Everything seemed right and good in the world, but for some reason the
> changelist view wouldn't show any items in its list.  Every model
> suffered from the lack of display.  It was weird.  It showed a correct
> total number of items that *should* have been in the list, but no
> items were present.  The HTML was literally not there.
>
> And when I jump directly to a changeform page via the id I knew I was
> working with, the page would should up, but saving the model keeps
> triggering the CSRF error response.  I don't think the CSRF token is
> being rendered in the changeform.
>
> Has anybody else experienced this?  I seriously haven't touched my
> copy of the main trunk between my little adventure with the admin-ui
> branch.  For good measure, I updated the repository just now, and it
> didn't fix it.  I removed all of the .pyc files in the Django
> directory and my project home.
>
> I'm just totally at a loss for what happened.  I've dropped the
> database and rebuilt it... no luck.  I'm ready to swear that I didn't
> change anything at all, and I don't use the CSRF system explicitly, so
> it's not like I've got bad imports.
>
> Any help?
>

AFAIK admin uses CSRF by default in SVN version.

http://docs.djangoproject.com/en/dev/ref/contrib/csrf/

--

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: applying a patch

2009-11-26 Thread rebus_
2009/11/26 paulh :
> Thank's for the reply. I do use tortoise and I tried what you
> suggested: nothing happened. Now I look at the patch file I think
> maybe it was generated by git (which I am not familiar with). The
> first few lines of the patch file (downloaded from django source) are:
>
> diff --git a/django/contrib/admin/media/js/admin/
> RelatedObjectLookups.js b/django/contrib/admin/media/js/admin/
> RelatedObjectLookups.js
> index 1bc78f8..3941752 100644
> --- a/django/contrib/admin/media/js/admin/RelatedObjectLookups.js
> +++ b/django/contrib/admin/media/js/admin/RelatedObjectLookups.js
>
> so I guess that explains it, but I thought django used used svn!
>
> Paul Hide
>

Django uses SVN as the official repository, but AFAIK git is often
used for development of new features etc cos it is not centralized and
it is very simple to create branches in it and so on.

For patching on windows you could use either gnuwin32 [1] or unxutils
[2] for comand line, both of which should be able to use patch files
produced by any diff (svn, git or just diff) like Tim said:

patch -p0 < /path/to/patch.diff

If your are fan of GUI apps then there are TortoiseSVN or  Eclipse but
i am not too sure how to apply patches with them, though a quick
google search would answer that question probably.

[1] http://gnuwin32.sourceforge.net/packages/patch.htm
[2] http://sourceforge.net/projects/unxutils/

Davor

--

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 style difference between development and production

2009-11-26 Thread rebus_
2009/11/26 andreas schmid :
> hi,
>
> i just noticed that the css is interpreted differently between my
> development environment on my local machine and the deployment on the
> server.
>
> locally i run the django project trough runserver and on production im
> using wsgi with apache.
>
> the proportions are all right but everything is bigger if i look at
> online site. i use the same browser to look at it.
>
> how is that possible?
>
> --
>
> 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.
>
>
>
This may sound silly, but are you sure you haven't used zoom in
firefox for you production server? Try hitting Crtl+0 ?

Davor

--

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: Per-object permissions

2009-11-25 Thread rebus_
2009/11/25 Gamliel Roi <roi.gaml...@gmail.com>:
> Any idea when 1.2 will be released?
>
>
>
> On Wed, Nov 25, 2009 at 3:31 PM, rebus_ <r.dav...@gmail.com> wrote:
>>
>> 2009/11/25 Russell Keith-Magee <freakboy3...@gmail.com>:
>> > On Tue, Nov 24, 2009 at 11:16 PM, rebus_ <r.dav...@gmail.com> wrote:
>> >> 2009/11/24 nek4life <nek4l...@gmail.com>:
>> >>> You should look into django-authority.  I'm pretty sure that has per-
>> >>> object-permissions.
>> >>>
>> >>> http://packages.python.org/django-authority/index.html
>> >>>
>> >>> On Nov 24, 7:00 am, gamliel roi <roi.gaml...@gmail.com> wrote:
>> >>>> Hello all,
>> >>>>
>> >>>> I have the admin site up and running but I need to create a group of
>> >>>> users,
>> >>>> such that each of the users will be able to edit objects that are
>> >>>> only
>> >>>> relevant to them (e.g Project objects that the user is also the
>> >>>> ProjectManager).
>> >>>>
>> >>>> I know that in the past Django had a Per-object permissions branch,
>> >>>> which is
>> >>>> now abandoned.
>> >>>>
>> >>>> Should I peruse this direction and try to incorporate this branch to
>> >>>> my
>> >>>> current code? is it documented and running properly?
>> >>>>
>> >>>> Any other ideas/suggestions/resources regarding this problem?
>> >>>>
>> >>>
>> >> Row level permisions should be implemented in Django version  1.2 [1]
>> >> if you have the time to wait...
>> >>
>> >> [1] http://code.djangoproject.com/wiki/Version1.2Features
>> >
>> > To be clear - that ticket *doesnt'* implement row-level permissions;
>> > it modifies the calls for permission checks to allow you to build a
>> > row-level permissions checker external to Django.
>> >
>> > Yours,
>> > Russ Magee %-)
>> >
>>
>> That's true, i probably wasn't too clear on this.
>>
>> But i would rather use Django API to implement row-level permissions
>> then start building my own implementation from scratch, if you have
>> the luxury of waiting till it hits trunk or comes out in 1.2 that is.
>>
>> Davor
>>
>> --
>>
>> 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.
>>
>>
>
>
>
> --
> Best
> Roi Gamliel
>
> --

http://code.djangoproject.com/wiki/Version1.2Roadmap

--

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: Per-object permissions

2009-11-25 Thread rebus_
2009/11/25 Russell Keith-Magee <freakboy3...@gmail.com>:
> On Tue, Nov 24, 2009 at 11:16 PM, rebus_ <r.dav...@gmail.com> wrote:
>> 2009/11/24 nek4life <nek4l...@gmail.com>:
>>> You should look into django-authority.  I'm pretty sure that has per-
>>> object-permissions.
>>>
>>> http://packages.python.org/django-authority/index.html
>>>
>>> On Nov 24, 7:00 am, gamliel roi <roi.gaml...@gmail.com> wrote:
>>>> Hello all,
>>>>
>>>> I have the admin site up and running but I need to create a group of users,
>>>> such that each of the users will be able to edit objects that are only
>>>> relevant to them (e.g Project objects that the user is also the
>>>> ProjectManager).
>>>>
>>>> I know that in the past Django had a Per-object permissions branch, which 
>>>> is
>>>> now abandoned.
>>>>
>>>> Should I peruse this direction and try to incorporate this branch to my
>>>> current code? is it documented and running properly?
>>>>
>>>> Any other ideas/suggestions/resources regarding this problem?
>>>>
>>>
>> Row level permisions should be implemented in Django version  1.2 [1]
>> if you have the time to wait...
>>
>> [1] http://code.djangoproject.com/wiki/Version1.2Features
>
> To be clear - that ticket *doesnt'* implement row-level permissions;
> it modifies the calls for permission checks to allow you to build a
> row-level permissions checker external to Django.
>
> Yours,
> Russ Magee %-)
>

That's true, i probably wasn't too clear on this.

But i would rather use Django API to implement row-level permissions
then start building my own implementation from scratch, if you have
the luxury of waiting till it hits trunk or comes out in 1.2 that is.

Davor

--

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: Per-object permissions

2009-11-24 Thread rebus_
2009/11/24 nek4life :
> You should look into django-authority.  I'm pretty sure that has per-
> object-permissions.
>
> http://packages.python.org/django-authority/index.html
>
> On Nov 24, 7:00 am, gamliel roi  wrote:
>> Hello all,
>>
>> I have the admin site up and running but I need to create a group of users,
>> such that each of the users will be able to edit objects that are only
>> relevant to them (e.g Project objects that the user is also the
>> ProjectManager).
>>
>> I know that in the past Django had a Per-object permissions branch, which is
>> now abandoned.
>>
>> Should I peruse this direction and try to incorporate this branch to my
>> current code? is it documented and running properly?
>>
>> Any other ideas/suggestions/resources regarding this problem?
>>
>> --
>> Best
>> Roi Gamliel
>
> --
>
> 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.
>
>
>
Row level permisions should be implemented in Django version  1.2 [1]
if you have the time to wait...

[1] http://code.djangoproject.com/wiki/Version1.2Features

--

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: How to resolve the view name from a url

2009-11-24 Thread rebus_
2009/11/24 bcurtu <bcu...@gmail.com>:
> No, I don't.
>
> I want to know the name of the url for a given url pattern. So, when I
> get in my method the url someone is asking for (next='/people/'), I
> want to know the name of the url that identifies this pattern
> (people_name). It's not for a HttpRedirect, it's for statistical
> porpouses.
>
> It's something like resolve, but not reverse.
>
> Thanks
>
> On 24 nov, 11:15, rebus_ <r.dav...@gmail.com> wrote:
>> 2009/11/24 bcurtu <bcu...@gmail.com>:
>>
>>
>>
>> > Hi,
>>
>> > I want to get the url name from a url. For example, having:
>>
>> >    url(
>> >        regex   = r'^people/$',
>> >        view    = 'people_view',
>> >        name    = 'people_name'
>> >        ),
>>
>> > and
>>
>> > @login_required
>> > def people_view(request)...
>> >     _some_code_here...
>>
>> > I'm looking for a function that accepts "people/" and returns
>> > "people_name". I have tried to use django.core.urlresolvers.resolve,
>> > however it returns a wrapper fuction for login_required.
>>
>> > Is it posible?
>>
>> > --
>>
>> > 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 
>> > athttp://groups.google.com/group/django-users?hl=en.
>>
>> Usually what you want to do is:
>>
>> from django.core.urlresolvers import reverse
>> reverse('people_name')
>>
>> http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse
>>
>> I don't see why you need url name, i think the name is meant to be
>> used to resolve urls not other way around.
>
> --
>
> 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.
>
>
>

How about this?

path = request.path
url = request.build_absolute_uri(path)
resolver = get_resolver(None)
view_func, url_args, url_kwargs = resolver.resolve(path)
sigs = resolver.reverse_dict.getlist(view_func)
url_name = None

# Loop through all the items in the reverse dictionary.
for key, value in resolver.reverse_dict.items():
  # Check if the value of the mapping is one of our matching signatures and
  # that the key is a string.
if value in sigs and type(key) == str:
try:
# See if we have the right parameters to use this reversal and that
# it produces the correct url.
if resolver.reverse(key, *url_args, **url_kwargs) == path[1:]:
# No exceptions were thrown so we have the right parameters and
# the path matched therefore we've found the url name we were
# seeking - which of course means we can stop looking.
url_name = key
break
except NoReverseMatch, e:
# The parameters were wrong - ah well, maybe the next one will
# succeed.
pass
print url, url_name, url_kwargs

This is taken from the greatlemers-django-tools [1]. It seems like
lots of code, guess you could use it as middleware or
context_processor.
It should return something like: http://127.0.0.1:8000/home/ home {}
where "home" is url name

[1] 
http://code.google.com/p/greatlemers-django-tools/source/browse/trunk/gdt_nav/models.py#158

Hope this helps
Davor

--

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: How to resolve the view name from a url

2009-11-24 Thread rebus_
2009/11/24 bcurtu :
> Hi,
>
> I want to get the url name from a url. For example, having:
>
>    url(
>        regex   = r'^people/$',
>        view    = 'people_view',
>        name    = 'people_name'
>        ),
>
> and
>
> @login_required
> def people_view(request)...
>     _some_code_here...
>
> I'm looking for a function that accepts "people/" and returns
> "people_name". I have tried to use django.core.urlresolvers.resolve,
> however it returns a wrapper fuction for login_required.
>
> Is it posible?
>
> --
>
> 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.
>
>
>
Usually what you want to do is:

from django.core.urlresolvers import reverse
reverse('people_name')

http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse

I don't see why you need url name, i think the name is meant to be
used to resolve urls not other way around.

--

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: How to use French accent on django template?

2009-11-12 Thread rebus_
2009/11/12 NMarcu :
> Hello all,
>
>   How to use French accent on django template? It's very strange. in
> one template is working very well, but in other(templatetag) not, I
> got this error:
>
> TemplateSyntaxError at /operators/ajax
>
> Caught an exception while rendering: 'ascii' codec can't encode
> character u'\xe9' in position 2: ordinal not in range(128)
>
>
> Do you have any idea what I'm doing wrong?
> My template look like this:
> {% load i18n %}
> 
>    {{ column.caption }}
>    {% if column.href %}
>        Sort
>    {% endif %}
>    {% if column.filtered %}
>        (filtered)
>    {% endif %}
> 
>
>  {{ column.caption }}  -> return a French word.
>
> --

Is column.caption unicode string?
Also does this happen when you call AJAX view or while rendering?
Perhaps you need to explicitly set encoding of python source files by
putting  # -*- coding: utf-8 -*- at the top of the file.

--

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=.




Re: Imports, works from directory but not from file

2009-11-12 Thread rebus_
I am not sure if i got the problem right, but this is what i think you could do.

If you want to keep your views in directory:

app/
   views/
  __init__.py <- This is where you keep your views so you don't
even need to change your urls.py or anthing
  something_else.py <- something else

Also you can keep your models in models/__init__.py and don't need to
change any imports, like:

app/
   models/
  __init__.py <- this is where your keep your models

On the other hand you can have

app/
   models/
  other_models.py <- this is where the models are for example
  __init__.py <- this is where you import your models so they can
be imported

in __init__.py you say
from other_models import * (or Model1, Model2 etc)

And where every you used your models like
from app.models import Model still works as expected.

Same goes for views.

--

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=.




Re: forms.ChoiceField and empty values

2009-11-12 Thread rebus_
2009/11/12 Monika Sulik :
> As I haven't had any replies so far, I'll add some more information...
>
> The empty label appears if I redefine the form like this:
>
> class CompetitionSearchForm(forms.ModelForm):
>    class Meta:
>        model = Competition
>        fields = ('name','type')
>
> It disappears again if I make the changes I need to on the fields
> (i.e. "unrequire" them):
>
> class CompetitionSearchForm(forms.ModelForm):
>    name = forms.CharField(required=False)
>    type = forms.ChoiceField(choices=COMPETITION_TYPE_CHOICES,
> required=False)
>    class Meta:
>        model = Competition
>        fields = ('name','type')
>
> Should I be defining my type field somehow differently? Or is this a
> bug in Django that I should report?
>

What does model Competition look like?
Do you have choices defined in your models.py and use choices argument
when creating that field in models?

--

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=.




Re: Model validation

2009-11-12 Thread rebus_
2009/11/12 Dirk Uys <dirkc...@gmail.com>:
> On Thu, Nov 12, 2009 at 2:23 PM, rebus_ <r.dav...@gmail.com> wrote:
>
>>
>> You can add custom clean methods in your form:
>>
>> class Event (models.Model):
>>    start_date = models.DateField()
>>    end_date = models.DateField()
>>
>>   def clean(self):
>>       start = self.cleaned_data.get('start_date', False)
>>       end = self.cleaned_data.get('end_date', False)
>>       if not start or not end:
>>          raise forms.ValidationError('message')
>>       if start > end:
>>          raise forms.ValidationError('start is greater then end')
>>       return self.cleaned_data
>>
>> This is just an example code.
>>
>> Using this approach validation errors will not be associated with and
>> field.
>> You could write clean_start_date and clean_end_date methods which
>> would evaluate each field and all validation errors would be
>> associated with specific field.
>>
>> To learn more about form validation read [1] or [2]:
>>
>> [1] http://docs.djangoproject.com/en/dev/ref/forms/validation/
>> [2]
>> http://code.djangoproject.com/browser/django/trunk/docs/ref/forms/validation.txt
>>
>
> Thanks! This is actually what I have done. The only problem is that I do not
> always use forms to supply data (sometimes I import from CVS) and would like
> to avoid doing the validation at two different points.
>
> For the time being, I guess this will do
>
> Cheers
> Dirk
>

Technically, i think you should be able iterate over dataset imported
from CVS and bound each data row to form, validate the form and then
use the cleaned_data to create an object of the Model and save it or
whatever. Not sure what performance impacts this would have, if any,
but i guess that would depend on the amount of data that needs
validation.

Take a look at [1] forms API for example.

Also you could factor out the clean code into standalone function for
example and then use that function to validate the given data both in
form and the place you use imported data.

But then again i am no guru on the subject, these are just my opinions.

[1] http://docs.djangoproject.com/en/dev/ref/forms/api/

--

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=.




Re: Model validation

2009-11-12 Thread rebus_
2009/11/12 Dirk Uys :
> I have a model with a from and to date:
>
> class Event (models.Model):
>     start_date = models.DateField()
>     end_date = models.DateField()
>
> In order to ensure start_date is always before end_date i can think of 3
> options:
>
> 1. Use form validation iow in the clean method of an inherited form
> 2. Use the django.db.models.signals.pre_save signal
> 3. Create a custor field that takes an parameter of the date field wich must
> allways be greater than or less than
>
> What is the easiest way to achieve this?
>
> Regards
> Dirk
>
> --

You can add custom clean methods in your form:

class Event (models.Model):
start_date = models.DateField()
end_date = models.DateField()

   def clean(self):
   start = self.cleaned_data.get('start_date', False)
   end = self.cleaned_data.get('end_date', False)
   if not start or not end:
  raise forms.ValidationError('message')
   if start > end:
  raise forms.ValidationError('start is greater then end')
   return self.cleaned_data

This is just an example code.

Using this approach validation errors will not be associated with and field.
You could write clean_start_date and clean_end_date methods which
would evaluate each field and all validation errors would be
associated with specific field.

To learn more about form validation read [1] or [2]:

[1] http://docs.djangoproject.com/en/dev/ref/forms/validation/
[2] 
http://code.djangoproject.com/browser/django/trunk/docs/ref/forms/validation.txt

--

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=.




Re: Prevent brute-force password attacks?

2009-11-12 Thread rebus_
How about using some system that after few failed logins gives some
CAPTCHA to solve? I think it's ok way to get rid of some bots.

I think it could be easily done by setting up custom login view.

--

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




Re: Model field validation for admin

2009-11-10 Thread rebus_

2009/11/10 pixelcowboy :
>
> Hello, I want to make a field optional (blank=True), only if another
> text field's options match a certain value in the admin. Is there any
> way to do this? Thanks!
>

This is from the top of my head, but you probably want to say
null=True (i am guessing you'll leave this field empty in some cases)
and blank=True on certain model field, then override models save()
method to check for some conditions under which you want or do not
want to allow the field to be empty.

I am not sure how you would rise validation error from save() though.

--~--~-~--~~~---~--~~
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: domains vs sub-domains

2009-11-10 Thread rebus_

Hi,

I personally also use option #1 due to performance, scalability and
"prettiness" of URL, etc, reasons all mentioned in above posts.

On the other hand if you spread your content over a bunch of sub
domains you could, instead of increasing performance, downgrade it due
to numerous DNS queries which can be quite expensive sometimes.

So don't get carried away with static content serving domains.

--~--~-~--~~~---~--~~
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 internationalization problem: Error: errors happened while running xgettext on __init__.py /bin/sh: xgettext: command not found

2009-11-09 Thread rebus_

2009/11/9 NMarcu :
>
> Hello all,
>
>   When I run django-admin.py makemessages -l ro I got this:
> Error: errors happened while running xgettext on __init__.py
> /bin/sh: xgettext: command not found
>
> You know why, I need to install somethng else?
> >
>

are you sure you have gettext installed on your computer?

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---