Strange bug when admin list-editing

2010-06-08 Thread Eugene Mirotin
We have Django as DB editor for our customers. We have 2 installations
on different servers - one talking to dev DB and used for testing new
features (we do some customizations to admin), another used on
production.

It's convenient for customer to use list editing mode for batch
updating one field for one model. The set of list-editable fields for
this model is (was) actually bigger - there were 6 fields, one of
which had choices (thus being drop-down select).
The strange bug which occurred twice on production but is not
reproducible by me on any of our servers is really strange.
Consider there are 17 records on the list page (filtered by some parameter).
The user edited some text field for 3 of them.
But Django updated another - drop-down field for 10 records.
Any idea?

As an acceptable fix I made this drop-down field non editable in list mode.

Django 1.1.1, Python 2.5, Debian Lenny.



Thanks.

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



Re: Filtering by the intermediary table using the GET parameters

2010-02-03 Thread Eugene Mirotin
Thanks!
Adding the m2m field helped, and the address was simply /product/?
has_standard="pk"


On Feb 3, 12:42 am, Woongcheol Yang  wrote:
> Let's say your model looks like the following:
>
> class Standard(models.Model):
>
> class Product(models.Model):
>     has_standard = models.ManyToManyField(Standard,
> through="ProductStandard")
>
> class ProductStandard(models.Model):
>     standard = models.ForeignKey(Standard)
>     product = models.ForeignKey(Product)
>
> then you can get all products that have relation with specific standard by:
>
> Product.objects.filter(has_standard='specific_standard_id')
>
> Hope it helps.
>
> wy
>
>
>
> On Tue, Feb 2, 2010 at 2:50 PM, Eugene Mirotin  wrote:
> > I have 3 models - Standard, Product, and ProductStandard.
>
> > Standards represents some standardization document.
> > Product represents some product.
> > ProductStandard is the intermediary table having 2 FKs (Standard and
> > Product) as well as some extra fields (like comments about the
> > Standard for the specific Product - it's not important, I just try to
> > explain why we need this table).
>
> > So, we have the m2m relation trough the intermediary table.
>
> > We can use GET parameters for filtering in the products list, like
> > /?title="product_title"&company__foundation_date__lte="2009-12-01"
>
> > I need the query of such type for the following filter:
> > "Get all the products that have the relation with the specific
> > standard", which means:
> > "There's record in the product.productstandard_set, where
> > standard=='specific_standard_id'"
>
> > Is it possible?
>
> > Thanks in advance!
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com > groups.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.



Filtering by the intermediary table using the GET parameters

2010-02-02 Thread Eugene Mirotin
I have 3 models - Standard, Product, and ProductStandard.

Standards represents some standardization document.
Product represents some product.
ProductStandard is the intermediary table having 2 FKs (Standard and
Product) as well as some extra fields (like comments about the
Standard for the specific Product - it's not important, I just try to
explain why we need this table).

So, we have the m2m relation trough the intermediary table.

We can use GET parameters for filtering in the products list, like
/?title="product_title"&company__foundation_date__lte="2009-12-01"

I need the query of such type for the following filter:
"Get all the products that have the relation with the specific
standard", which means:
"There's record in the product.productstandard_set, where
standard=='specific_standard_id'"

Is it possible?

Thanks in advance!

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



Underscores in PKs

2009-10-23 Thread Eugene Mirotin

I have an application working with legacy DB.
Some tables have humen-redable PKs, and some of them contain underscores.
Django admin escapes them (for what reason?) and seems not unescaping.
So these objects are unavailable for editing.
The relevant bug (2 years old!) is here:
http://code.djangoproject.com/ticket/1375
Unfortunately, the patch is too old and can't be applied since the
code has changed.
The biggest changes seem to be in the views/main.py file.

Did somebody encounter such a problem? What is the simplest solution?

--~--~-~--~~~---~--~~
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: Models mixins/inheritance

2009-10-07 Thread Eugene Mirotin

OK, I've tried the proxy models and they solved part of my problems.
But not all.

Consider I have an auto-generated model called COmpany which I have
manually (and can then make it automatically) renamed to CompanyAuto.
I have created the Company proxy model for the CompanyAuto model and
added the __unicode__ method. Then I have registered the (new proxy)
Company model in admin and can use __unicode__ attribute as list item,
for example.

But when it comes to Many-to-One self-relations...
The Company(Auto) has the 'self'-referencing 'branch_of' attribute.
'self'==CompanyAuto, so in the company editing form I have the combo-
box containing dozens of 'CompanyAuto object' entries.
I tried to manually changed 'self' to 'Company' reference (I put the
Company definition in the same models.py file where moved the auto-
generated models), but it has no effect.

On Oct 7, 5:04 pm, Eugene Mirotin  wrote:
> I have tried it earlier and (as far as I remember) with the same
> (void) result.
> I have read more docs and proxy models seem to be the solution to my
> problem. I will give them a try later today.
>
> On Oct 7, 2:54 pm, greatlemer  wrote:
>
> > What sort of errors are you getting when you try this with the django
> > model?
>
> > Have you tried just assigning the function over the top of the
> > __unicode__ function already on Company?
>
> > i.e.
>
> > import Company
>
> > def CompanyUnicode(self):
> >     return '%s [%s]' % (self.nick, self.legal_name)
>
> > Company.__unicode__ = CompanyUnicode
>
> > __
>
> > G
>
> > On Oct 7, 12:07 pm, Eugene Mirotin  wrote:
>
> > > Let me provide more details.
>
> > > When I make simple python project with the same idea, everything works
> > > fine.
>
> > > # file test2.py
> > > class A:
> > >     b = 2
> > > # file test1.py
> > > from test2 import *
>
> > > class A(A):
> > >         a = 1
> > > # file test.py
> > > from test1 import *
>
> > > a = A()
> > > print a.b, a.a
>
> > > print A.__module__
>
> > > The output is
> > > 2 1
> > > test1
>
> > > So class A is imported from test2 to test1, then overloaded (actually
> > > extended) there, then imported to test, cool.
>
> > > When I do the same in django, everything goes wrong.
>
> > > I do import models_auto in models_business_logic, then overload the
> > > Company class, then import it in models, then import models in admin
> > > file and try
> > > print Company.__module__
> > > And this gives me the dbadm.models_auto output
>
> > > On Oct 6, 4:10 pm, Eugene Mirotin  wrote:
>
> > > > We have an existing app written in perl with Postgre as DB.
> > > > I want to add the django admin as the interface to this existing DB.
> > > > The main app is in constant development, so the DB scheme may change
> > > > in the future.
> > > > I have checked the inspectdb output and it is quite good (I do also do
> > > > some automatic fixing of the results of inspectdb, but these fixes are
> > > > minor).
> > > > So, if we would only want to have the 'dumb' db editing tool, the
> > > > auto-generated models are OK.
> > > > But what we really want is adding some additional logic (such as
> > > > __unicode__ representations and save validations). Of course, it is
> > > > unacceptable to have this code in the auto-generated file, not is is
> > > > good to always manually insert it after every db scheme update (the
> > > > models file generated by inspectdb is 1000+ lines long).
>
> > > > What I have tried looked like
> > > > - have the models_auto.py file - the inspectdb patched output
> > > > - have the models_business_logic.py module looking like
>
> > > > from models_auto import *
>
> > > > Company_ = Company
> > > > del Company
>
> > > > class Company(Company_):
> > > >     def __unicode__(self):
> > > >         return '%s [%s]' % (self.nick, self.legal_name)
>
> > > > - have the models.py file simpli importing * from models_business_logic
>
> > > > But dues to inheritance mechanism and Foreign keys (or may be dues to
> > > > some other reasons) this approach do not work.
> > > > Any ideas?
>
> > > > Thanks in advance.
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Models mixins/inheritance

2009-10-07 Thread Eugene Mirotin

I have tried it earlier and (as far as I remember) with the same
(void) result.
I have read more docs and proxy models seem to be the solution to my
problem. I will give them a try later today.

On Oct 7, 2:54 pm, greatlemer  wrote:
> What sort of errors are you getting when you try this with the django
> model?
>
> Have you tried just assigning the function over the top of the
> __unicode__ function already on Company?
>
> i.e.
>
> import Company
>
> def CompanyUnicode(self):
>     return '%s [%s]' % (self.nick, self.legal_name)
>
> Company.__unicode__ = CompanyUnicode
>
> __
>
> G
>
> On Oct 7, 12:07 pm, Eugene Mirotin  wrote:
>
> > Let me provide more details.
>
> > When I make simple python project with the same idea, everything works
> > fine.
>
> > # file test2.py
> > class A:
> >     b = 2
> > # file test1.py
> > from test2 import *
>
> > class A(A):
> >         a = 1
> > # file test.py
> > from test1 import *
>
> > a = A()
> > print a.b, a.a
>
> > print A.__module__
>
> > The output is
> > 2 1
> > test1
>
> > So class A is imported from test2 to test1, then overloaded (actually
> > extended) there, then imported to test, cool.
>
> > When I do the same in django, everything goes wrong.
>
> > I do import models_auto in models_business_logic, then overload the
> > Company class, then import it in models, then import models in admin
> > file and try
> > print Company.__module__
> > And this gives me the dbadm.models_auto output
>
> > On Oct 6, 4:10 pm, Eugene Mirotin  wrote:
>
> > > We have an existing app written in perl with Postgre as DB.
> > > I want to add the django admin as the interface to this existing DB.
> > > The main app is in constant development, so the DB scheme may change
> > > in the future.
> > > I have checked the inspectdb output and it is quite good (I do also do
> > > some automatic fixing of the results of inspectdb, but these fixes are
> > > minor).
> > > So, if we would only want to have the 'dumb' db editing tool, the
> > > auto-generated models are OK.
> > > But what we really want is adding some additional logic (such as
> > > __unicode__ representations and save validations). Of course, it is
> > > unacceptable to have this code in the auto-generated file, not is is
> > > good to always manually insert it after every db scheme update (the
> > > models file generated by inspectdb is 1000+ lines long).
>
> > > What I have tried looked like
> > > - have the models_auto.py file - the inspectdb patched output
> > > - have the models_business_logic.py module looking like
>
> > > from models_auto import *
>
> > > Company_ = Company
> > > del Company
>
> > > class Company(Company_):
> > >     def __unicode__(self):
> > >         return '%s [%s]' % (self.nick, self.legal_name)
>
> > > - have the models.py file simpli importing * from models_business_logic
>
> > > But dues to inheritance mechanism and Foreign keys (or may be dues to
> > > some other reasons) this approach do not work.
> > > Any ideas?
>
> > > Thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Models mixins/inheritance

2009-10-07 Thread Eugene Mirotin

Let me provide more details.

When I make simple python project with the same idea, everything works
fine.

# file test2.py
class A:
b = 2
# file test1.py
from test2 import *

class A(A):
a = 1
# file test.py
from test1 import *

a = A()
print a.b, a.a

print A.__module__


The output is
2 1
test1

So class A is imported from test2 to test1, then overloaded (actually
extended) there, then imported to test, cool.

When I do the same in django, everything goes wrong.

I do import models_auto in models_business_logic, then overload the
Company class, then import it in models, then import models in admin
file and try
print Company.__module__
And this gives me the dbadm.models_auto output


On Oct 6, 4:10 pm, Eugene Mirotin  wrote:
> We have an existing app written in perl with Postgre as DB.
> I want to add the django admin as the interface to this existing DB.
> The main app is in constant development, so the DB scheme may change
> in the future.
> I have checked the inspectdb output and it is quite good (I do also do
> some automatic fixing of the results of inspectdb, but these fixes are
> minor).
> So, if we would only want to have the 'dumb' db editing tool, the
> auto-generated models are OK.
> But what we really want is adding some additional logic (such as
> __unicode__ representations and save validations). Of course, it is
> unacceptable to have this code in the auto-generated file, not is is
> good to always manually insert it after every db scheme update (the
> models file generated by inspectdb is 1000+ lines long).
>
> What I have tried looked like
> - have the models_auto.py file - the inspectdb patched output
> - have the models_business_logic.py module looking like
>
> from models_auto import *
>
> Company_ = Company
> del Company
>
> class Company(Company_):
>     def __unicode__(self):
>         return '%s [%s]' % (self.nick, self.legal_name)
>
> - have the models.py file simpli importing * from models_business_logic
>
> But dues to inheritance mechanism and Foreign keys (or may be dues to
> some other reasons) this approach do not work.
> Any ideas?
>
> Thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



Models mixins/inheritance

2009-10-06 Thread Eugene Mirotin

We have an existing app written in perl with Postgre as DB.
I want to add the django admin as the interface to this existing DB.
The main app is in constant development, so the DB scheme may change
in the future.
I have checked the inspectdb output and it is quite good (I do also do
some automatic fixing of the results of inspectdb, but these fixes are
minor).
So, if we would only want to have the 'dumb' db editing tool, the
auto-generated models are OK.
But what we really want is adding some additional logic (such as
__unicode__ representations and save validations). Of course, it is
unacceptable to have this code in the auto-generated file, not is is
good to always manually insert it after every db scheme update (the
models file generated by inspectdb is 1000+ lines long).

What I have tried looked like
- have the models_auto.py file - the inspectdb patched output
- have the models_business_logic.py module looking like

from models_auto import *

Company_ = Company
del Company

class Company(Company_):
def __unicode__(self):
return '%s [%s]' % (self.nick, self.legal_name)

- have the models.py file simpli importing * from models_business_logic

But dues to inheritance mechanism and Foreign keys (or may be dues to
some other reasons) this approach do not work.
Any ideas?


Thanks in advance.

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



Re: How to send form via email

2009-07-30 Thread Eugene Mirotin

So put join's arguments in a list or tuple

On Jul 29, 5:47 pm, el_k...@interia.pl wrote:
> Thank you for your answer but there is error
> "join() takes exactly one argument (3 given)"
>
> "Jeremy Boyd"  pisze:
>
>
>
>
>
> > Kolo,
>
> > I'm not positive this is what you're asking, but it seems to me that
> > a) you might want to build up a string with the message as you'd like
> > it to be displayed. So, for example:
>
> > subject = field1 + " has sent you a new message"
> > message = " ".join("You have a new message! Here are the form
> > fields:", field1, field2, field3)
>
> > send_mail(subject, message, "your_from_addr...@gmail.com",
> > ["recipie...@domain.com"], fail_silently=True)
>
> > Hope this helps.
>
> > On Jul 29, 9:08 am, el_kolo  wrote:
> > > Hi,
>
> > > I have a form (class myForm(forms.Form)) with a few fields. I want to
> > > send this form to my email account. I have put this form to my
> > > template with button SEND. Everything works fine but using send_mail
> > > function I can send only ONE field from my from to my email account.
> > > send_mail('Subject here', 'Here is the message', 'f...@example.com',
> > > ['@example.com'], fail_silently=False)
>
> > > Do you know how to send whole form or 2-3 fields?
>
> > > ps. sorry for my english:P
>
> --
> Chcesz czuc sie bezpiecznie podczas wakacyjnych podrozy?
> Nie zapomnij o tym, by sie ubezpieczyc.
> Najtaniej zrobisz to nahttp://link.interia.pl/f2284Kliknij i sprawdz.
--~--~-~--~~~---~--~~
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: Editing model based forms.

2009-07-28 Thread Eugene Mirotin

AKK, the previous response from Daniel Roseman completely answers your
question - the user field is HIDDEN on the form and AUTOMATICALLY
filled in the form handling action.
You should read the Django 'topics', I think.

On Jul 27, 10:52 pm, AKK  wrote:
> Thanks, that will work for time.
>
> I want the username value to be added without the user typing it in
> because they can type anything and its a bit silly to get them
> to type in there username everytime they want to comment. So i want
> the {{ user.username }} value to be automatically detected and entered
> but i don't know if you can do this with a model based form or if you
> have to manually create it.
>
> On 27 July, 12:35, Daniel Roseman  wrote:
>
> > On Jul 27, 12:15 am, AKK  wrote:
>
> > > Hi, I have a form based on a model which allows users to add comment.
> > > A comment is made up of the comment is about, the body, the date and
> > > time and also who made the comment.
>
> > > I am mainly interested in the datetime and user fields. What i would
> > > like to know is how i can automatically have these entered. For the
> > > username i  know if i created the form myself i could have a hidden
> > > field with the value of {{ user.username }}. I'm not sure how i could
> > > automatically specify the time. But since the form is created
> > > automatically i could do with some help.
>
> > > Thanks,
>
> > > Andrew
>
> > If you want values to be entered without user interaction, then
> > there's no point in having them in the form at all. Use the 'exclude'
> > property in the form's Meta class to exclude user, date and time. Then
> > in your view, when you save the form use commit=False, then add the
> > values you want to the model instance before saving.
>
> >     ...
> >     if form.is_valid():
> >         instance = form.save(commit=False)
> >         instance.user = request.user
> >         instance.datetime = datetime.datetime.now()
> >         instance.save()
>
> > Alternatively, you might want to use the auto_now_add parameter in the
> > model definition for the datetime field.
> > --
> > DR
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Model Formsets Have an Extra Blank Form?

2009-07-25 Thread Eugene Mirotin

set the extra parameter to 0

On Jul 24, 9:44 pm, derek  wrote:
> I'm following the instructions here:
>
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/
>
> But when I do this kind of thing:
>
> formset = AuthorFormSet(queryset=Author.objects.filter
> (name__startswith='O'))
>
> I always get an extra blank form at the end of my formset - regardless
> of how I set up the query set. How can I prevent 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to create this filter

2009-07-25 Thread Eugene Mirotin

Have you tried making manual formatting, i.e.

val1 = 'col1'
val2 = 'col2'
op = '>'

# Python 2.6+ string formatting
.extra(where=["{0} {1} {2}".format(val1, op, val2)])

On Jul 25, 2:28 am, David  wrote:
> anybody likes to give me help? thanks so much.
>
> On Jul 24, 4:23 pm, David  wrote:
>
> > I used this syntax
>
> > .extra(where=['%s >= %s - %s'], params=['criteria1_metric1',
> > 'criteria1_metric2',  'criteria1_value'])
>
> > however I got error.
>
> > On Jul 24, 4:16 pm, David  wrote:
>
> > > Here comes a new problem. I do not know which columns' values to use;
> > > all I know is that they are represented with variables. These
> > > variables are
>
> > > col_var_1, condition_operator, col_var_2, manipulation_operator,
> > > constant_value
>
> > > where:
> > > col_var_1:  col1, or col2, or col3, etc
> > > condition_operator: >, >=, <, =, etc
> > > col_var_2: col1, or col2, etc
> > > manipulation_operator: +, -, x, /
> > > constant_value: float value
>
> > > in the where clause, I have to use these variables. What's the
> > > syntax?
>
> > > any help? thanks so much.
>
> > > On Jul 24, 2:39 pm, David  wrote:
>
> > > > Great. I go to pick up extra() to use.
>
> > > > Thanks Tim.
>
> > > > On Jul 24, 2:33 pm, Tim Chase  wrote:
>
> > > > > > Such a transformation is fine. I found that my Django has no F().
> > > > > > Checking the Django doc I saw that this new feature is "New in 
> > > > > > Django
> > > > > > Development version".
>
> > > > > > So I have to wait for the new version? Are there any other ways to
> > > > > > create such a filter?
> > > > > >>  col1_value >= col2_value * 2
>
> > > > > >> something like col1__gte=F('col2') * 2
>
> > > > > You can always fall back to the .extra() method[1]:
>
> > > > >    results = MyFoo.objects.extra(where=[
> > > > >      "col1_value >= col2_value * 2",
> > > > >      ])
>
> > > > > which is how it was done back in the day before ya'll young
> > > > > whippersnappers had such fancy shenanigans as F() objects...and
> > > > > to get data, we walked up hill, in the snow.  Both ways.  ;-)
>
> > > > > -tim
>
> > > > > [1]http://docs.djangoproject.com/en/dev/ref/models/querysets/#extra-sele...text
> > > > >  -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -
>
>
--~--~-~--~~~---~--~~
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: never_cache doesn't work for login page

2009-07-20 Thread Eugene Mirotin

May be the order of middleware classes does matter here?

On Jul 19, 4:08 pm, Ronghui Yu  wrote:
> It proves that it is introduced by
> django.middleware.http.ConditionalGetMiddleware. It returns 304 when
> requesting the same login page, so at last the browser uses the former one.
> It works fine after removing this middleware.
> I believe this middleware cannot work with never_cache.
>
> Eugene Mirotin ??:
>
>
>
> > Isn't adding a timestamp to the url a workaround?
> > I mean making all links to /login/ look like /login/?_=timestamp
> > This can be easily done on the client side with some JS library, or,
> > on the server side.
>
> > Not nice, but it should help, I guess.
>
> > On Jul 17, 5:24 pm, Ronghui Yu  wrote:
>
> >> Hi, All,
>
> >> I have a project that have CsrfMiddleware enable, all forms work fine,
> >> but the login form doesn't, for all browsers(IE,Chrome,Firefox,Safari).
> >> Most of the time, it throws 403, which is thrown by CsrfMiddleware.
> >> That's because the browser cache the login page, so each time the login
> >> page is opened, the csrfmiddlearetoken value doesn't get update. If the
> >> browser cache is cleaned before opening the login page, then it works
> >> fine. But this is not what I expect.
>
> >> When look into django.contrib.auth.views, the login view is decorated by
> >> never_cache, but actually it doesn't work for me. I have no idea what's
> >> wrong with it. Has anybody ever encounted this situation? Or could
> >> anybody give me some hints?
>
> >> Thanks in advance.
>
> >> --
> >> Ronghui Yu <mailto:stone...@163.com>
>
> --
> Ronghui Yu <mailto:stone...@163.com>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Howto add button to certain field

2009-07-18 Thread Eugene Mirotin

The button you want is client-specific.
So you really have to write the loop and make the check if the
rendered field corresponds to the user name. And if so, render your
button with onclick making ajax call next to the rendered field.

On Jul 17, 8:19 pm, zayatzz  wrote:
> Hello
>
> I have this form with username and other user information. Since user
> needs to set his own username and it has to be unique, i was going to
> add some button to the form that does some ajax magic and checks if
> the username is already in use.
>
> What i wanted to know is that if there is some way to add this buttong
> right next to the username field through the way how the form itself
> is set up - (widget?). I know that i can of course ditch this :
>                 {% for field in aform %}
>                         {{ field.label_tag }} class="field">
> {{ field }}
>                 {% endfor %}
>
> And write all that markup without for loop and just add the button
> after usename field. What i wanted to know was if it can be done
> differently?
>
> Alan
--~--~-~--~~~---~--~~
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: Getting a dynamic model form

2009-07-18 Thread Eugene Mirotin

So, the value is a string, but the widget you want to display to the
user should be changed according to the key value?
Probably you have to create your custom tag (e.g. render_value_widget)
and then use something like {% render_value_widget key value %} in
your view.
If you provide the same name for the input you render, the submit
handling view would be simple.

On Jul 17, 10:51 am, "~Young Devil"  wrote:
> I've a generic model to save the user preference with a key and value
> However the view would change depending upon the key.
>
> Example,
> key : newsletter
> view : radio button, yes and no
>
> key : template type
> value: drop down box [blue, white, brown]
>
> Is anything like this possible in Django, I am kinda new to this
> framework I did google it but couldn't get a good solution.
>
> Thanks in Advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: building directory path with user table

2009-07-18 Thread Eugene Mirotin

What you have written (this join for user_dir_path) is evaluated only
once on model class creation, but what you need is evaluating it for
each specific object.

I recommend you overloading the model save method to alter the image
save path.

On Jul 17, 10:44 am, "neri...@gmail.com"  wrote:
> Hello,
>
> I'm trying to build a photo upload path which corresponds to the
> selected user i.e., when the user is selected from the drop down the
> username gets appended to the file upload path dynamically. If you
> have any ideas I would like to hear them:
>
> class Listing(models.Model):
>         user = models.ForeignKey(User, unique=True)
>         user_directory_path = os.path.join(settings.MEDIA_ROOT, 'listings',
> user)
>         user_directory = models.FilePathField(path=user_directory_path,
> recursive=True)
>         photo = models.ImageField(upload_to=user_directory)
>         name = models.CharField(max_length=50)
>         order = models.ForeignKey('Order')
>
>         def __unicode__(self):
>                 return self.name
>
> I keep getting this error:
>
> AttributeError: 'ForeignKey' object has no attribute 'startswith'
--~--~-~--~~~---~--~~
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: never_cache doesn't work for login page

2009-07-18 Thread Eugene Mirotin

Isn't adding a timestamp to the url a workaround?
I mean making all links to /login/ look like /login/?_=timestamp
This can be easily done on the client side with some JS library, or,
on the server side.

Not nice, but it should help, I guess.

On Jul 17, 5:24 pm, Ronghui Yu  wrote:
> Hi, All,
>
> I have a project that have CsrfMiddleware enable, all forms work fine,
> but the login form doesn't, for all browsers(IE,Chrome,Firefox,Safari).
> Most of the time, it throws 403, which is thrown by CsrfMiddleware.
> That's because the browser cache the login page, so each time the login
> page is opened, the csrfmiddlearetoken value doesn't get update. If the
> browser cache is cleaned before opening the login page, then it works
> fine. But this is not what I expect.
>
> When look into django.contrib.auth.views, the login view is decorated by
> never_cache, but actually it doesn't work for me. I have no idea what's
> wrong with it. Has anybody ever encounted this situation? Or could
> anybody give me some hints?
>
> Thanks in advance.
>
> --
> Ronghui Yu 
--~--~-~--~~~---~--~~
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: url as folder path possible?

2009-07-15 Thread Eugene Mirotin

Never mind.
If you wish to understand the regex stuff (and you really have to :),
read this tutorial:
http://www.regular-expressions.info/tutorial.html


On Jul 15, 2:50 am, theiviaxx  wrote:
> awesome, thats exactly what i needed.  im still trying to figure out
> regex stuff.
>
> Thank you!
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: html file (UTF-8) generated from template does not displayed correctly using MS internet explorer 6.0

2009-07-14 Thread Eugene Mirotin

Most probably your html is incorrect, but FF is smart enough to handle
it.
Try the following:
* switch to the Strict XHTML instead of Transitional (as the latter is
not recommended)
* create a static HTML file (replace the remplate logic with some
dummy values) with the desired layout
* validate it using the w3c validator

I expect your file to have some validation errors. After you fix them,
update the template according to your fixes.

On Jul 14, 7:57 am, kk  wrote:
> I have these lines in my template file "base.html", and save the
> template file as "utf-8" format as I want to support Chinese
> characters.
>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> http://www.w3.org/1999/xhtml";>
>
> My amzing site
> 
>  rel=stylesheet>
> .style1 {
>         COLOR: #ff}
>
> 
> 
>
> I type "python manage.py" to start web service.
> When I used MS IE6.0 to visit my server, the output web page displayed
> quite strange ( the main content does not appear in the center of the
> webpage).
> But  the webpage displayed correctly when I used Firefox.
> I examined the generated webpage and found nothing abnormal.
>
> However, strange things happened when I downloaded the webpage to my
> local directory("D:\file\") from "127.0.0.1:8000".
> If I downloaded the webpage using firefox, everything worked fine.
> But if I used MS IE6.0, the downloaded webpage lost the html header
> dtd declaration
>            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
> If I open the webpage from my local directory ("D:\file\mysite.html"),
> it displayed also abnormally just like the same as I mentioned above.
> After I manually added the lost dtd declaration to ("D:\file
> \mysite.html"), the webpage can displayed correctly as Firefox.
>
> My questions are:
> 1) why does my webpage displays not correctly using MS IE 6.0.
> 2) why does the dtd declaration get lost when I download the page to
> my local directory ("D:\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-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: url as folder path possible?

2009-07-14 Thread Eugene Mirotin

The problem is still unclear.
Do you want to handle the path example.com/some/path/ and route it to
some view that would get the 'some/path' as argument?
If so,
* write the url conf like r'^([\w_\/]+)/$', handle_path
* write the handle_path(request, path) view
* in view split the pass by slashes
* determine the object based on the path (using some getattr calls on
modules or objects)
* call the desired methods on the obtained object


On Jul 14, 4:22 am, theiviaxx  wrote:
> Sorry i didnt explain very well.  The folder objects are django
> objects, not file system paths
>
> On Jul 13, 6:19 pm, Almir Karic  wrote:
>
>
>
>
>
> > For real world deployment you should use your web server to do that.
> > For apache that would be an Alias (and make sure the Alias get's to be
> > served before everything is passed to django).
>
> > For development purposes you should have a look 
> > athttp://docs.djangoproject.com/en/dev/howto/static-files/
>
> > python/django hacker & sys 
> > adminhttp://almirkaric.com&http://twitter.com/redduck666
>
> > On Mon, Jul 13, 2009 at 5:39 PM, TheIvIaxx wrote:
>
> > > I tried searching but didnt really find much.
>
> > > Is there a way to set up a url conf to get a url of a folder path?
> > > Basically i have a site that has folder-ish objects that contain
> > > stuff.  However i cannot seem to find a way to get a url pattern to
> > > work.  how would i get:
>
> > >http://example.com/path/to/folder
>
> > > to work?
>
>
--~--~-~--~~~---~--~~
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: Question regarding post_save signal and ManyToMany field objects

2009-07-14 Thread Eugene Mirotin

If I understand right, the problem is that you want the signal after
all related fields are already saved. If so, this is exactly the
problem I have too.
You see, when you have such a relation (and, for example, edit the
parent object with inlined related objects from the admin page, Django
_has to_ save the parent object first, and only then it saves the
related objects (you can verify it by adding print statements to your
save methods or handlers and running the dev server from terminal).
The reason is that when you initially create the object, related
objects have to link to the existing object, so the parent object is
saved before them.

On Jul 13, 9:27 pm, Ryan K  wrote:
> Recently I've been trying to get answers about the post_save signal
> behavior and perhaps have been asking too much of readers without
> narrowing down the problem enough myself. So here is my effort to ask
> a rather straightforward question:
>
> The code that connects to the post_save signal, according to the
> signal docs, is passed three objects and I am only concerned about
> one: the instance that was saved. Now this instance has a
> ManyToManyField and what I am finding out according to be debugging is
> that the instance's ManyToMany field is NOT being updated after save
> is called.
>
> So, for example, when the signal calls the handler (this is being done
> via the admin interface but it shouldn't matter) and I check
> instance.manytomanyfield, it does not show the most recent changes.
> What is the best way to "force" the update of the table so I can get
> accurate data from the ManyToMany field? Even if I explicitly do
> something like this:
>
>     def __init__(self, sender, instance):
>         self.sender = sender
>         self.instance = sender.objects.select_related().get
> (id=instance.id)
>
> What seems like cached data is being when I test:
>
> self.instance.manytomanyfield.all()
>
> Can anyone help with this behavior?
>
> Cheers,
> Ryan
--~--~-~--~~~---~--~~
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: parsing urls with dot

2009-07-14 Thread Eugene Mirotin

The idea is probably in the following.
when somebody (may be not Django, but your browser) sees that the last
part of the URL does not have dots, it understands that it's the
"directory", so the trailing slash should be added (like in the
ancient times when URLs really represented files and directories)/
But when it sees the dot in the last part, it understands, that it's a
"file with extension", so the trailing slash is incorrect to be put.

On Jul 13, 1:06 pm, Dids  wrote:
> It is working.
>
> When I was creating a link to a page, I was not adding the tailling
> '/' explicitely. It seems Django did it for me.
> But for some reason, if there was a dot in the url, that trailling '/'
> was not added ... no idea why.
>
> Anyway, explicitly adding the '/' does the job and is probably better
> anyway.
>
> Thanks for your help.
>
> Regards,
> Dids,
>
> On Jul 10, 10:20 pm, Aaron Maxwell  wrote:
>
> > On Thursday 09 July 2009 05:47:48 am Dids wrote:
>
> > > > Why not to add dots to your regexp? For example, [\w\d\-\.]+ ?
>
> > > I guess my question should have been: How come \. doesn't appear to be
> > > matched in url.py?
> > > That's the problem, it doesn't work.
>
> > It should.  Are you using raw strings?
>
> > Post the whole urlpattern here, including the failed regexp, so we can give
> > more specific feedback.
>
> > --
> > Aaron Maxwell
> > Hilomath - Mobile Web Developmenthttp://hilomath.com/
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: submit form

2009-07-13 Thread Eugene Mirotin

The other option is to have the hidden "action" field and fill it with
different values on buttons click events.
The other option is to change the form action dynamically with JS so
you can have separate POST handler views for different actions
(like 

On Jul 12, 3:22 pm, alecs  wrote:
> Thanks, Dennis :)
--~--~-~--~~~---~--~~
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: Ajax call send me the same page

2009-07-13 Thread Eugene Mirotin

There are 3 possible layers of caching that return you the previous
page:
browser
Django
Apache

The 1st is solved by appending the timestamp or random number as
additional fictional GET parameter (jQuery does it automatically when
you pass the cache: false to the ajax call)
The 2nd is solved by using the never_cache decorator on your view.

Most probably (as everything works fine without Apache) you have the
Apache-wide caching. Read the docs on how to configure Apache to
prevent caching for specific URLs (unfortunately it's not what I know
well). But I recommend using the previous methods as well.

On Jul 12, 12:22 pm, Irimi  wrote:
> Hi all,
>
> I'm trying to use Django and especially GeoDjango so I made a "little
> application" where a country is randomly proposed and the user must
> select it on the map (http://www.geotests.net/geogame/).
>
> When the user select the country on the map an ajax request is send by
> the application and call a function of my views.
>
> Everything works fine when I use it with the django server. But when I
> tried to do the same with apache mod-python, the ajax call return me
> the actual page.
>
> I think i've got maybe a problem with the url rewriting...
>
> Do you know what i'm doing wrong?
>
> Here is my ajax call :
>
> JavaScript  :
>
> var url = './getName?';
>                 var country = $('randomCountryName').innerHTML;
>                 XY = map.getLonLatFromPixel(new OpenLayers.Pixel
> (evt.xy.x, evt.xy.y));
>                 url += 'x='+XY.lon;
>                 url += '&y='+XY.lat;
>                 url += '&tryCountry='+tryCountry;
>                 url += '&country='+country;
>                     new OpenLayers.Request.GET({
>                                 url : url,
>                                 success: responseCountry
>                         });
>
> And the view :
>
> def getName(req) :
>     #Geos Point geometry
>     pnt  = Point(float(req.GET['x']), float(req.GET['y']))
>     response = {}
>     if int(req.GET['tryCountry']) == 1 :
>         newCountry = newName(req.GET['country'])
>         response['newCountry'] = newCountry.name
>         response['X'] = newCountry.geom.centroid.x
>         response['Y'] = newCountry.geom.centroid.y
>     try :
>         country = WorldBorders.objects.get(geom__intersects=pnt)
>         if country.name != req.GET['country'] :
>             response['result'] = "false"
>         else :
>             newCountry = newName(country.name)
>             response['newCountry'] = newCountry.name
>             response['X'] = newCountry.geom.centroid.x
>             response['Y'] = newCountry.geom.centroid.y
>             response['result'] = "true"
>     except :
>         response['result'] = "false"
>
>     # Return a json object
>     return  HttpResponse(simplejson.dumps
> (response),mimetype="application/javascript")
>
> Thanks for any help
>
> Regards
>
> Arnaud
--~--~-~--~~~---~--~~
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: Sending JSON response from views

2009-07-12 Thread Eugene Mirotin

I could suggest you creating the json manually (this is bad if you
plan to scale you app) or make the dictionary with the necessary data
and then serialize it.
i.e
users = [{'user': l.user.name, 'status': l.status} for l in
ActiveList.objects.all()]
Also it would be probably better idea to add the status attribute to
the User model itself (by adding the profile information, see Django
Topics; with some 'O' for Offline) and changing the queryset to
User.objects.exclude(status='O')

On Jul 11, 10:43 pm, Oleg Oltar  wrote:
> Hi!
>
> I am trying to implement something like a jubber web application, using
> django and flex
>
> The server code should send a list of users who's online. Here's how I
> defined a model
>
> class ActiveList(models.Model):
>
>     STATUS_CHOISES = (
>         (u'F', u'free'),
>         (u'B', u'busy'),
>         )
>     user = models.ForeignKey(User, unique=True)
>     status = models.CharField(max_length=2, choices = STATUS_CHOISES)
>
> The view look like this
>
> def getActiveUsers(request):
>     activeList = ActiveList.objects.all()
>
>     data = serializers.serialize("json", activeList, fields = (u'user',
> 'status'))
>     return HttpResponse(data, mimetype='application/json')
>
> The question, how can I return username of user in fields. I want the JSON
> response to contain value user.username instead of id of user oject
>
> Thanks,
> Oleg
--~--~-~--~~~---~--~~
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: Some post_related_objects_save signal or workaround?

2009-07-10 Thread Eugene Mirotin

Thanks for your reply, Ryan, but it would be equivalent to simply
calling the self.parent.some_method() from the round save.

And my purpose is to have the signal (or other way of tracking) for
the point when _all_ objects (rounds) related to the specific object
(game) are saved.
Something like admin_form.post_m2m_save
Also notice that this "fixing ordering" method should change all
rounds related to the current game, thus calling their save methods,
which would lead to cyclic calls between save methods of the game and
the round if the game.save is called from the round.save.

Maybe this cycle will always exist and I have to define separate
"freeze" method that will be called before the game begin (consequent
ordering is required only during the game process), or I should extend
the models to work with arbitrary ordering numbers.

On Jul 9, 9:07 pm, Ryan K  wrote:
> Is there any reason you can't create your own signal and put it in the
> rounds save() method and then just call the parents save?
>
> http://docs.djangoproject.com/en/dev/topics/signals/#defining-and-sen...
>
> Cheers,
> Ryan
>
> On Jul 9, 6:12 am, Eugene Mirotin  wrote:
>
> > Hello!
>
> > I have a tricky (as seems to me :) problem.
>
> > Consider I have 2 simply related models - a Game and a Round (with FK
> > to Game). Each has some generic fields like name and description.
> > Also, the Round has the ordering field (called number) (oh, I can
> > imagine your sighs =)
> > They are edited on the single admin page for Game with TabularInline
> > for game rounds.
>
> > I know about the way to use jQuery for inlines reordering, but this is
> > not the question. Currently I am exactly interested in the manual
> > number field filling.
>
> > So what happens when I save the game? First, the game itself is saved
> > because of the need of the saved FK object for rounds saving, and I
> > understand it. Then the rounds are saved in order.
> > At this point due to some reason the rounds' numbers might be any
> > numbers. But my applications requires them to be exactly the
> > consequent positive integers starting from 1.
>
> > This could be easily fixed by a simple loop, but it should be done at
> > the appropriate point - on the per-game basis and _after_ all the
> > related objects are saved (otherwise nasty bugs with incorrect
> > ordering are possible).
>
> > So I have to know the moment when all the current game's related
> > objects are saved. And there is no appropriate standard signal for
> > this.
> > Any thoughts?
>
> > Gene
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Some post_related_objects_save signal or workaround?

2009-07-09 Thread Eugene Mirotin

Hello!

I have a tricky (as seems to me :) problem.

Consider I have 2 simply related models - a Game and a Round (with FK
to Game). Each has some generic fields like name and description.
Also, the Round has the ordering field (called number) (oh, I can
imagine your sighs =)
They are edited on the single admin page for Game with TabularInline
for game rounds.

I know about the way to use jQuery for inlines reordering, but this is
not the question. Currently I am exactly interested in the manual
number field filling.

So what happens when I save the game? First, the game itself is saved
because of the need of the saved FK object for rounds saving, and I
understand it. Then the rounds are saved in order.
At this point due to some reason the rounds' numbers might be any
numbers. But my applications requires them to be exactly the
consequent positive integers starting from 1.

This could be easily fixed by a simple loop, but it should be done at
the appropriate point - on the per-game basis and _after_ all the
related objects are saved (otherwise nasty bugs with incorrect
ordering are possible).

So I have to know the moment when all the current game's related
objects are saved. And there is no appropriate standard signal for
this.
Any thoughts?

Gene
--~--~-~--~~~---~--~~
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: Content blocks editable in Admin

2009-07-09 Thread Eugene Mirotin

Define the model that includes:
* (some) Foreign key to the page the block belongs to (so, most
probably you'll have to define the model for the site page)
* the text field for the block contents
Register this model in the admin, which will generate the form with 2
fields - drop-down select (for the page) and the textarea.
If you have constant number of pages, pre-create exactly one block for
each of them in you application deployment process (through fixtures,
for example)
Then you can hide the select element from the admin form (by
specifying explicit fields attribute on your ModelAdmin class - read
the tutorial if you do not understand what I mean)
If you need the way to distinguish between these blocks, create the
__unicode__ method on the model which will return something like
self.page.title

All of this has nothing to do with urlconf

And finally in the views of your page get the appropriate content
block (thomething like page.content_set.all()[0]) and pass it to the
template as the context variable

On Jul 9, 10:47 am, "paul.dorman"  wrote:
> Hi all,
>
> I'd like to include blocks of content in my templates which is
> editable in the Admin app. I'd design the overall template, but
> include bits that the computer illiterate folks here could change,
> something like this:
>
> [my template]
> 
> [a form which is included in the template]
> [a block of content that can be edited in the Admin application by
> computer illiterate monkeys]
> 
>
> I initially thought that flatpages would be the answer (with TinyMCE),
> but alas, there appears to be no built-in way to include a flatpage
> inside a template.
>
> I don't want the content blocks to have a URL (so no URLConf entry). I
> don't mind if I use a model, but I don't know how to get the Admin app
> to pick up the model without a URLConf entry.
>
> Also, how do I reference a value from the model inside any template?
> I've tried creating a variable (testblock = ContentBlock.objects.get
> (name='testblock')) in my view, and then including {{testblock}} in my
> template, but that does nothing. I know I'm doing it wrong, but I
> can't find documentation to help.
>
> Please help. This is my first real Django application (so yes, I'm a
> newb), but I'd like to stick with common practice as far as possible.
>
> Thanks for your help,
> Paul
--~--~-~--~~~---~--~~
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: Validating imported data

2009-01-13 Thread Eugene Mirotin

My favourite solution for this task is the following:
1) you create the "simple" form with the file upload and submit it
2) in submit handler you parse the file and create the "preview"
formset (is inline formset, form example) filling it with the parsed
data. If the file cannot be parsed, you can return to the user with
the same simple form and the error message
3) otherwise, you show the preview form to the user allowing him (if
necessary) to fix some data (of course, it's optional)
4) when the user confirms the data (submits this preview form), you
can process the plain formset with the regular handler and make custom
"cleaning" with all neccessary validations

All of these can be done on the same URL by adding some hidden field
that indicates the type of the form being submitted, or with other
similar trick.

Gene

On Jan 13, 5:42 am, Peter  wrote:
> Hello,
>
> I'm trying to build an application with django that supports data
> import from a CSV. The problem that I'm having is validating the data.
> I know how to validate data that comes from a form.
>
> However, in my case the user is using a CSV file for imput instead a
> form. Is there a way that I can validate the data without using a
> form? Or is there I can interface with the form validation with using
> a form?
>
> Thanks,
>
> ~Peter
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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-admin.py not working on Vista

2009-01-10 Thread Eugene Mirotin

You can simply append django's bin directory to your _system_ PATH
variable (still the same way as on the earlier versions - through the
computer properties - advanced)
I do not have my Vista laptop on hand, but I believe, this it what I
have done to make it work

On Jan 10, 5:55 am, Rex  wrote:
> I installed Django on my Vista box. Using the Windows command shell, I
> go to the site-packages/django/bin directory and here's what I get
> when I type various commands:
>
> > django-admin.py help
>
> Type 'django-admin.py help' for usage.
>
> > python django-admin.py help
>
> [This gives me the proper help instructions]
>
> Why is it only giving me the correct output when I prepend "python"?
> This is a problem because when I'm in a different folder (such as my
> Django projects folder), I can't type "python django-admin.py", since
> that will not look in different Path directories for the file django-
> admin.py. However, typing "django-admin.py help" in any other
> directory gives me the same output as above.
>
> I Googled around, and the only thing I found was this comment:
>
> "you have to change the file association from (cant remember) to "%1″
> %* and it should work"
> Source:http://i.justrealized.com/2008/04/08/how-to-install-python-and-django...
>
> Does anyone understand what this means?
--~--~-~--~~~---~--~~
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: SQLite iexact problem with non-latin symbols

2008-12-19 Thread Eugene Mirotin

Thank you for the detailed answer.

I'll investigate the question about pysqlite (http://
oss.itsystementwicklung.de/trac/pysqlite/changeset/361 looks
promosing), but switching to other DB is OK, though SQLite is much
more convenient for development and debugging as I work on the project
from several different computers and do not still have hosted SQL.

On Dec 19, 3:28 am, "Karen Tracey"  wrote:
> On Thu, Dec 18, 2008 at 4:53 PM, Eugene Mirotin  wrote:
>
> > Hello.
> > Consider I have a simple model
>
> > class Team(models.Model):
> >    name = models.CharField(max_length=200)
>
> > Then I create some team and try to look for it with iexact match:
> > tt = Team(name='English')
> > tt.save()
> > Team.objects.filter(name__iexact=tt.name.lower()) # this returns the
> > list containing my initial team object
>
> > When I do the same from the terminal and create the Team object by
> > passing the unicode symbols (e.g. u''), it works the
> > same.
> > But when created from the admin interface, the data is not saved in
> > unicode (at least it looks like so, cause the field is varchar).
> > And then name__iexact=name.lower() does not work.
>
> The data is saved using utf-8 encoding.  The issue is the SQLite doesn't
> support case-insensitive matching on anything other than 7-bit ASCII chars.
> See:
>
> http://www.sqlite.org/faq.html#q18
>
> The last time I answered this question I only found reference to this
> behavior as a "bug".  The answer I'm pointing to above, however, considers
> it a design decision and mentions that sqlite provides an extension to get
> case-insensitive Unicode comparisons working.  So, there may actually be a
> way to get this working under Django, but I'm not sure of that.
>
> My guess is this extension would need to be included/supported by pysqlite
> (the Python interface to SQLite that Django uses).  If it is, perhaps there
> is just some switch Django could flip to tell pysqlite to use this ICU
> extension to get case-insensitive unicode matching working.  If pysqlite
> doesn't support this extension then I rather doubt this can be made to work
> under Django, but I'm basically just guessing here.
>
> Switching to a different database, one that supports case-insensitive
> unicode matching out of the box, might be an easier answer for you.
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



SQLite iexact problem with non-latin symbols

2008-12-18 Thread Eugene Mirotin

Hello.
Consider I have a simple model

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

Then I create some team and try to look for it with iexact match:
tt = Team(name='English')
tt.save()
Team.objects.filter(name__iexact=tt.name.lower()) # this returns the
list containing my initial team object

When I do the same from the terminal and create the Team object by
passing the unicode symbols (e.g. u''), it works the
same.
But when created from the admin interface, the data is not saved in
unicode (at least it looks like so, cause the field is varchar).
And then name__iexact=name.lower() does not work.

The question is: is it possible to fix the issue so that
1) the objects could still be created with admin interfaces with
minimal changes (m.b. some additional arguments to the model fields?)
2) the case-insensitive lookups start working without any additional
magic (so, I do not have to think about unicode and non-unicode data
when filtering the DB)

--~--~-~--~~~---~--~~
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: stupid question

2008-12-14 Thread Eugene Mirotin

Not necessary manually, 'cause you can use "reset App"

On Dec 14, 12:13 am, "Huseyin Berberoglu" 
wrote:
> On Sat, Dec 13, 2008 at 11:08 PM, volk23  wrote:
>
> > i've made a modification in a App i created. run syncdb, it dont show
> > changes made. what could be wrong? thanks in advance
>
> You must delete related table manually. Then manage.py syncdb.
>
> --
> Hüseyin Berberoğluhttp://www.birazkisisel.com- süper blog
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: "Legal" way to have foreign key field in the custom form

2008-12-13 Thread Eugene Mirotin

I have only overriden the title and content blocks, nothing more, so
it really looks strange

On Dec 13, 10:04 pm, Jeff FW  wrote:
> Glad to help.
>
> That's strange that you had to add that JS to your template--it should
> be included automatically.  Looking at the admin default 
> options:http://code.djangoproject.com/browser/django/trunk/django/contrib/adm...
> it should be on every object add/edit page.
>
> Maybe you defined a Media class in your admin class? Or you overrode
> the wrong block in your template?  If you're overriding the block
> "extrahead", make sure to put a {{ block.super }} in there, so it
> includes anything that's been defined by parent templates.
>
> -Jeff
>
> On Dec 12, 2:32 pm, Eugene Mirotin  wrote:
>
> > Thank you very much for the help. It have finally solved the problem.
>
> > BTW, one issue was left - the plus icon redirected to the creation
> > page instead of opening popup.
> > I've solved it by including the
> > 
> > directly in my template, but it's strange since my template extends
> > the "admin/change_form.html".
>
> > On Dec 12, 9:05 pm, Jeff FW  wrote:
>
> > > You're passing your queryset in, but you're never using it in your
> > > widget.  In my code, see how I have:
>
> > > widgets.CategorySelect(
> > >     categories=models.Category.objects.order_by('parent',
> > > 'list_order')
> > > ),
>
> > > I don't have the code on hand for my CategorySelect widget, but I
> > > remember that it takes "categories", and turns it into a list of
> > > choices, which then get passed to Select.__init__() as "choices".
> > > Since you're just using a Select() directly, you'd want to pass the
> > > choices in there.  Here's a simple list comprehension that you may
> > > have to adapt a little to do that:
>
> > > [(t.id, unicode(t)) for t in queryset.all()]
>
> > > That assumes that you add "queryset" as an argument to __init__(),
> > > which you should probably do.
>
> > > -Jeff
>
> > > On Dec 12, 1:06 pm, Eugene Mirotin  wrote:
>
> > > > I was busy for several days and could give it a try only now. Thank
> > > > you for the answer, but I still can't make it work.
> > > > I have the model called Tournament and the model called
> > > > TournamentResult which has foreign keys Team and Tournament.
>
> > > > What I'm doing is a page for bulk upload of the results for the
> > > > specific tournament that should be selected from the drop-down
>
> > > > At the moment my code looks like this:
>
> > > > class TournamentChoiceField(forms.ModelChoiceField):
> > > >     def __init__(self, *args, **kwargs):
> > > >         super(TournamentChoiceField, self).__init__(*args, **kwargs)
> > > >         self.widget = admin_widgets.RelatedFieldWidgetWrapper(
> > > >             forms.Select(),
> > > >             TournamentResult._meta.get_field('tournament').rel,
> > > >             admin.site,
> > > >         )
>
> > > > class UploadFormInitial(forms.Form):
> > > >     tournament = TournamentChoiceField(Tournament.objects.all())
>
> > > > But I don't see any values in the drop-down list.
>
> > > > On Dec 9, 3:55 pm, Jeff FW  wrote:
>
> > > > > To get the plus icon back, you need to wrap the field in a
> > > > > RelatedFieldWidgetWrapper.  Here's an example from my code--obviously,
> > > > > you'll have to adapt it to fit your situation.
>
> > > > > class CategoryChoiceField(forms.ModelChoiceField):
>
> > > > >     def __init__(self, *args, **kwargs):
> > > > >         super(CategoryChoiceField, self).__init__(*args, **kwargs)
> > > > >         self.widget = widgets.RelatedFieldWidgetWrapper(
> > > > >             widgets.c(
> > > > >                 categories=models.Category.objects.order_by('parent',
> > > > > 'list_order')),
> > > > >             models.Category._meta.get_field('parent').rel,
> > > > >             admin.site,
> > > > >         )
>
> > > > > -Jeff
>
> > > > > On Dec 9, 6:50 am, Eugene Mirotin  wrote:
>
> > > > > > Well, looks that the ModelChoiceField solves the problem except of 
> > > > > > th

Re: "Legal" way to have foreign key field in the custom form

2008-12-12 Thread Eugene Mirotin

Thank you very much for the help. It have finally solved the problem.

BTW, one issue was left - the plus icon redirected to the creation
page instead of opening popup.
I've solved it by including the

directly in my template, but it's strange since my template extends
the "admin/change_form.html".


On Dec 12, 9:05 pm, Jeff FW  wrote:
> You're passing your queryset in, but you're never using it in your
> widget.  In my code, see how I have:
>
> widgets.CategorySelect(
>     categories=models.Category.objects.order_by('parent',
> 'list_order')
> ),
>
> I don't have the code on hand for my CategorySelect widget, but I
> remember that it takes "categories", and turns it into a list of
> choices, which then get passed to Select.__init__() as "choices".
> Since you're just using a Select() directly, you'd want to pass the
> choices in there.  Here's a simple list comprehension that you may
> have to adapt a little to do that:
>
> [(t.id, unicode(t)) for t in queryset.all()]
>
> That assumes that you add "queryset" as an argument to __init__(),
> which you should probably do.
>
> -Jeff
>
> On Dec 12, 1:06 pm, Eugene Mirotin  wrote:
>
> > I was busy for several days and could give it a try only now. Thank
> > you for the answer, but I still can't make it work.
> > I have the model called Tournament and the model called
> > TournamentResult which has foreign keys Team and Tournament.
>
> > What I'm doing is a page for bulk upload of the results for the
> > specific tournament that should be selected from the drop-down
>
> > At the moment my code looks like this:
>
> > class TournamentChoiceField(forms.ModelChoiceField):
> >     def __init__(self, *args, **kwargs):
> >         super(TournamentChoiceField, self).__init__(*args, **kwargs)
> >         self.widget = admin_widgets.RelatedFieldWidgetWrapper(
> >             forms.Select(),
> >             TournamentResult._meta.get_field('tournament').rel,
> >             admin.site,
> >         )
>
> > class UploadFormInitial(forms.Form):
> >     tournament = TournamentChoiceField(Tournament.objects.all())
>
> > But I don't see any values in the drop-down list.
>
> > On Dec 9, 3:55 pm, Jeff FW  wrote:
>
> > > To get the plus icon back, you need to wrap the field in a
> > > RelatedFieldWidgetWrapper.  Here's an example from my code--obviously,
> > > you'll have to adapt it to fit your situation.
>
> > > class CategoryChoiceField(forms.ModelChoiceField):
>
> > >     def __init__(self, *args, **kwargs):
> > >         super(CategoryChoiceField, self).__init__(*args, **kwargs)
> > >         self.widget = widgets.RelatedFieldWidgetWrapper(
> > >             widgets.c(
> > >                 categories=models.Category.objects.order_by('parent',
> > > 'list_order')),
> > >             models.Category._meta.get_field('parent').rel,
> > >             admin.site,
> > >         )
>
> > > -Jeff
>
> > > On Dec 9, 6:50 am, Eugene Mirotin  wrote:
>
> > > > Well, looks that the ModelChoiceField solves the problem except of the
> > > > plus icon
>
> > > > On Dec 9, 12:34 pm, Eugene Mirotin  wrote:
>
> > > > > Hello. I'm working on the custom admin page  that will serve batch
> > > > > items creation based on the uploaded file.
> > > > > All these items should be linked to the single foreign key item.
> > > > > This item should be selected on the form.
> > > > > Of course, I can investigate the inner structure of the rendered admin
> > > > > pages and mimic it my template, but it doesn't look DRY.
> > > > > So I want to {% include %} the fieldset.html and pass the variable to
> > > > > it that will make it to render the standard ForeignKey control (with
> > > > > "+" icon).
> > > > > Is there a legal way to do it?
--~--~-~--~~~---~--~~
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: "Legal" way to have foreign key field in the custom form

2008-12-12 Thread Eugene Mirotin

I was busy for several days and could give it a try only now. Thank
you for the answer, but I still can't make it work.
I have the model called Tournament and the model called
TournamentResult which has foreign keys Team and Tournament.

What I'm doing is a page for bulk upload of the results for the
specific tournament that should be selected from the drop-down

At the moment my code looks like this:

class TournamentChoiceField(forms.ModelChoiceField):
def __init__(self, *args, **kwargs):
super(TournamentChoiceField, self).__init__(*args, **kwargs)
self.widget = admin_widgets.RelatedFieldWidgetWrapper(
forms.Select(),
TournamentResult._meta.get_field('tournament').rel,
admin.site,
)

class UploadFormInitial(forms.Form):
tournament = TournamentChoiceField(Tournament.objects.all())

But I don't see any values in the drop-down list.


On Dec 9, 3:55 pm, Jeff FW  wrote:
> To get the plus icon back, you need to wrap the field in a
> RelatedFieldWidgetWrapper.  Here's an example from my code--obviously,
> you'll have to adapt it to fit your situation.
>
> class CategoryChoiceField(forms.ModelChoiceField):
>
>     def __init__(self, *args, **kwargs):
>         super(CategoryChoiceField, self).__init__(*args, **kwargs)
>         self.widget = widgets.RelatedFieldWidgetWrapper(
>             widgets.c(
>                 categories=models.Category.objects.order_by('parent',
> 'list_order')),
>             models.Category._meta.get_field('parent').rel,
>             admin.site,
>         )
>
> -Jeff
>
> On Dec 9, 6:50 am, Eugene Mirotin  wrote:
>
> > Well, looks that the ModelChoiceField solves the problem except of the
> > plus icon
>
> > On Dec 9, 12:34 pm, Eugene Mirotin  wrote:
>
> > > Hello. I'm working on the custom admin page  that will serve batch
> > > items creation based on the uploaded file.
> > > All these items should be linked to the single foreign key item.
> > > This item should be selected on the form.
> > > Of course, I can investigate the inner structure of the rendered admin
> > > pages and mimic it my template, but it doesn't look DRY.
> > > So I want to {% include %} the fieldset.html and pass the variable to
> > > it that will make it to render the standard ForeignKey control (with
> > > "+" icon).
> > > Is there a legal way to do it?
--~--~-~--~~~---~--~~
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: "Legal" way to have foreign key field in the custom form

2008-12-09 Thread Eugene Mirotin

Well, looks that the ModelChoiceField solves the problem except of the
plus icon

On Dec 9, 12:34 pm, Eugene Mirotin <[EMAIL PROTECTED]> wrote:
> Hello. I'm working on the custom admin page  that will serve batch
> items creation based on the uploaded file.
> All these items should be linked to the single foreign key item.
> This item should be selected on the form.
> Of course, I can investigate the inner structure of the rendered admin
> pages and mimic it my template, but it doesn't look DRY.
> So I want to {% include %} the fieldset.html and pass the variable to
> it that will make it to render the standard ForeignKey control (with
> "+" icon).
> Is there a legal way to do it?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



"Legal" way to have foreign key field in the custom form

2008-12-09 Thread Eugene Mirotin

Hello. I'm working on the custom admin page  that will serve batch
items creation based on the uploaded file.
All these items should be linked to the single foreign key item.
This item should be selected on the form.
Of course, I can investigate the inner structure of the rendered admin
pages and mimic it my template, but it doesn't look DRY.
So I want to {% include %} the fieldset.html and pass the variable to
it that will make it to render the standard ForeignKey control (with
"+" icon).
Is there a legal way to do it?

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