Strange "problem" with tutorial

2009-02-03 Thread Joshua Russo

I'm working through the tutorials and have encountered a strange
problem. So far everything works but Python doesn't acknowledge my
base site as a package. So everywhere that you see a reference like
"mysite.poll" I need to use only "poll". I think that my problems stem
from the following section that starts on line 263 of tutorial01.txt:

To create your app, make sure you're in the :file:`mysite` directory
and type
this command:

.. code-block:: bash

python manage.py startapp polls

I ran the above command from my MySite directory that holds the
manage.py file. Is that correct? Anyone have any ideas why I can't
reference my base package? (I think I'm using the term package
correctly here.)

Thanks
Josh

--~--~-~--~~~---~--~~
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: Strange "problem" with tutorial

2009-02-03 Thread Joshua Russo



On Feb 3, 6:04 pm, Adam Yee  wrote:
> On Feb 3, 9:49 am, Joshua Russo  wrote:
>
> > I'm working through the tutorials and have encountered a strange
> > problem. So far everything works but Python doesn't acknowledge my
> > base site as a package. So everywhere that you see a reference like
> > "mysite.poll" I need to use only "poll". I think that my problems stem
> > from the following section that starts on line 263 of tutorial01.txt:
>
> Make sure you're not mispelling 'polls'.  You've typed 'poll' above.
> If you're talking about the settings, yes you don't need to specify
> mysite.polls since the settings.py file is already in the mysite
> directory.  You could just put 'polls' into installed apps.
>
>
>
>
>
> > To create your app, make sure you're in the :file:`mysite` directory
> > and type
> > this command:
>
> > .. code-block:: bash
>
> >     python manage.py startapp polls
>
> > I ran the above command from my MySite directory that holds the
> > manage.py file. Is that correct? Anyone have any ideas why I can't
> > reference my base package? (I think I'm using the term package
> > correctly here.)
>
> > Thanks
> > Josh
>
> As far as I see your doing it correctly.  For technical purposes, the
> way that I see it (and the way django defines it):
> mysite = project
> polls = app
> I'm not quite sure what you're referring to as base package.  Hope
> this helps.

Ya, what you suggest for settings.py is what I did. I just wanted to
make sure that I wasn't doing something wrong in my order of
operations for creating my project and app.

I'm most of the way though part two of the tutorial and have run into
three places where I needed to remove "mysite." from in front of the
reference to polls. Once for the settings.py like you mentioned and
twice for the two tables in the admin.py in the second part of the
tutorial. It seems to me it's just a "bug" in the tutorial.

Thanks for the reply
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Verbose field name DjangoUnicodeDecodeError

2009-02-11 Thread Joshua Russo

I'm developing an app and want to use Portuguese characters in the
verbose field names for my models. The tables were created fine but
when I tried to implement the admin pages I received a
DjangoUnicodeDecodeError when it hit the first non-ASCII character. Is
this just a bug with the admin page processing?
--~--~-~--~~~---~--~~
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: Verbose field name DjangoUnicodeDecodeError

2009-02-11 Thread Joshua Russo

On Feb 11, 1:38 pm, Ramiro Morales  wrote:
> On Wed, Feb 11, 2009 at 11:22 AM, Joshua Russo  
> wrote:
>
> > I'm developing an app and want to use Portuguese characters in the
> > verbose field names for my models. The tables were created fine but
> > when I tried to implement the admin pages I received a
> > DjangoUnicodeDecodeError when it hit the first non-ASCII character. Is
> > this just a bug with the admin page processing?
>
> No,  Django and its admin app supports internationalization.
>
> Don't forget to specify the encoding of your Python source code files
> (models.py in this case) as described 
> athttp://www.python.org/dev/peps/pep-0263/
>
> Also, make your to wrap your Portuguese literals with a call to the
> django.utils.translation.ugettext_lazy() function as described in the
> Django I18n documentation:
>
> http://docs.djangoproject.com/en/dev/topics/i18n/#lazy-translation
>
> Regards,
>
> --
>  Ramiro Morales

Thanks for the tip. I had done the first but not the second. I'm away
from the computer I was working on but I'll let you know if that fixes
it

Josh
--~--~-~--~~~---~--~~
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: Verbose field name DjangoUnicodeDecodeError

2009-02-11 Thread Joshua Russo

On Feb 11, 1:38 pm, Karen Tracey  wrote:
> On Wed, Feb 11, 2009 at 8:22 AM, Joshua Russo wrote:
>
> > I'm developing an app and want to use Portuguese characters in the
> > verbose field names for my models. The tables were created fine but
> > when I tried to implement the admin pages I received a
> > DjangoUnicodeDecodeError when it hit the first non-ASCII character. Is
> > this just a bug with the admin page processing?
>
> What level of Django are you using?
>
> What's the traceback you get that goes with the error?
>
> What level of Python are you using?
>
> What does your model look like -- specifically does it have a __unicode__
> method that returns unicode?
>
> Karen

Ok, I'm still having issues.

I'm using Django 1.0.2-final and Python 2.5.4

The models.py starts with the proper encoding string of: # -*- coding:
utf-8 -*-

Here is the line from my models.py that it's tripping up on:
NumTeleMov  = models.CharField(u'Numero de telemóvel', max_length=20)

Here is the trace back:
Environment:

Request
Method: GET
Request URL: http://localhost:8000/admin/pesoa/pesoa/add/
Django Version: 1.0.2 final
Python Version: 2.5.4
Installed Applications:
['django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites',
'django.contrib.admin', 'pesoa', 'matriz']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Traceback:
File "c:\python25\Lib\site-packages\django\core\handlers\base.py" in
get_response 86. response = callback(request, *callback_args,
**callback_kwargs)
File "c:\python25\Lib\site-packages\django\contrib\admin\sites.py" in
root 157. return self.model_page(request, *url.split('/', 2))
File "c:\python25\Lib\site-packages\django\views\decorators\cache.py"
in _wrapped_view_func 44. response = view_func(request, *args,
**kwargs)
File "c:\python25\Lib\site-packages\django\contrib\admin\sites.py" in
model_page 176. return admin_obj(request, rest_of_url)
File "c:\python25\Lib\site-packages\django\contrib\admin\options.py"
in
__call__ 191. return self.add_view(request)
File "c:\python25\Lib\site-packages\django\db\transaction.py" in
_commit_on_success 238. res = func(*args, **kw)
File "c:\python25\Lib\site-packages\django\contrib\admin\options.py"
in
add_view 478. ModelForm = self.get_form(request)
File "c:\python25\Lib\site-packages\django\contrib\admin\options.py"
in
get_form 277. return modelform_factory(self.model, **defaults)
File "c:\python25\Lib\site-packages\django\forms\models.py" in
modelform_factory 335. 'formfield_callback': formfield_callback})
File "c:\python25\Lib\site-packages\django\forms\models.py" in __new__
195. opts.exclude, formfield_callback)
File "c:\python25\Lib\site-packages\django\forms\models.py" in
fields_for_model 162. formfield = formfield_callback(f)
File "c:\python25\Lib\site-packages\django\contrib\admin\options.py"
in
formfield_for_dbfield 106. return db_field.formfield(**kwargs)
File
"c:\python25\Lib\site-packages\django\db\models\fields\__init__.py" in
formfield 418. return super(CharField, self).formfield(**defaults)
File
"c:\python25\Lib\site-packages\django\db\models\fields\__init__.py" in
formfield 306. defaults = {'required': not self.blank, 'label':
capfirst(self.verbose_name), 'help_text': self.help_text}
File "c:\python25\Lib\site-packages\django\utils\functional.py" in
wrapper 251. return func(*args, **kwargs)
File "c:\python25\Lib\site-packages\django\utils\text.py" in
 9. capfirst = lambda x: x and
force_unicode(x)[0].upper() + force_unicode(x)[1:]
File "c:\python25\Lib\site-packages\django\utils\encoding.py" in
force_unicode 70. raise DjangoUnicodeDecodeError(s, *e.args)
Exception Type: DjangoUnicodeDecodeError at /admin/pesoa/pesoa/add/
Exception Value: 'utf8' codec can't decode bytes in position 15-18:
invalid data. You passed in 'Numero de telem\xf3vel' ()


--~--~-~--~~~---~--~~
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: Verbose field name DjangoUnicodeDecodeError

2009-02-11 Thread Joshua Russo

On Feb 11, 1:38 pm, Ramiro Morales  wrote:
> On Wed, Feb 11, 2009 at 11:22 AM, Joshua Russo  
> wrote:
>
> > I'm developing an app and want to use Portuguese characters in the
> > verbose field names for my models. The tables were created fine but
> > when I tried to implement the admin pages I received a
> > DjangoUnicodeDecodeError when it hit the first non-ASCII character. Is
> > this just a bug with the admin page processing?
>
> No,  Django and its admin app supports internationalization.
>
> Don't forget to specify the encoding of your Python source code files
> (models.py in this case) as described 
> athttp://www.python.org/dev/peps/pep-0263/
>
> Also, make your to wrap your Portuguese literals with a call to the
> django.utils.translation.ugettext_lazy() function as described in the
> Django I18n documentation:
>
> http://docs.djangoproject.com/en/dev/topics/i18n/#lazy-translation
>
> Regards,
>
> --
>  Ramiro Morales

Ramiro,  I don't need the I18n functionality. The app is just an
internal one and so will only be in Portuguese.


--~--~-~--~~~---~--~~
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: Verbose field name DjangoUnicodeDecodeError

2009-02-11 Thread Joshua Russo

On Feb 11, 6:03 pm, Karen Tracey  wrote:
> On Wed, Feb 11, 2009 at 12:29 PM, Joshua Russo 
> wrote:
>
>
>
> > Ok, I'm still having issues.
>
> > I'm using Django 1.0.2-final and Python 2.5.4
>
> > The models.py starts with the proper encoding string of: # -*- coding:
> > utf-8 -*-
>
> Except apparently your file is not actually encoded in utf-8, see below.
>
>
>
> > Here is the line from my models.py that it's tripping up on:
> > NumTeleMov  = models.CharField(u'Numero de telemóvel', max_length=20)
>
> Did you really have the u'' there?  Because specifying the encoding
> declaration of utf-8 and using u'' around a string that is not properly
> utf-8 encoded should have (and does in my tests) generate an error on any
> attempt to import your models file, not an error later on.
>
>
>
> > Here is the trace back:
> > Environment:
>
> > [snip]
>
> File "c:\python25\Lib\site-packages\django\utils\encoding.py" in> 
> force_unicode 70. raise DjangoUnicodeDecodeError(s, *e.args)
> > Exception Type: DjangoUnicodeDecodeError at /admin/pesoa/pesoa/add/
> > Exception Value: 'utf8' codec can't decode bytes in position 15-18:
> > invalid data. You passed in 'Numero de telem\xf3vel' ( > 'str'>)
>
> The fact that the type specified in that error message is  also implies
> you did not have u'' around this string when you got this traceback, because
> it would have been a unicode string to start with.  The error is happening
> because that string is not utf-8 encoded:
>
> Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40)
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> s = 
> 'Numero de telem\xf3vel'
> >>> print unicode(s,'utf8')
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "encodings/utf_8.py", line 16, in decode
> UnicodeDecodeError: 'utf8' codec can't decode bytes in position 15-18:
> invalid data>>> print unicode(s,'iso8859-1')
>
> Numero de telemóvel
>
>
>
> Looks more likely it is iso8859-1.  So, you could change your Python
> encoding declaration for this file to match the reality of the file (and use
> u'' around all strings, since Django is going to assume utf-8 for any
> bytestrings passed to it), or you can re-encode your file to really be in
> utf-8.  How to do that depends on what editor you are using.
>
> Karen

Thanks so much. I think you are right. I will let you know tomorrow if
I was able to fix it. I just need to figure out where the encoding is
set in NetBeans and Textpad. I use a combination of both of them.

It's possible that I didn't have the "u" when I created the message,
though I was receiving an error of some sort with and without the "u".

Josh
--~--~-~--~~~---~--~~
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: Verbose field name DjangoUnicodeDecodeError

2009-02-11 Thread Joshua Russo

On Feb 11, 4:54 pm, Ramiro Morales  wrote:
> On Wed, Feb 11, 2009 at 3:29 PM, Joshua Russo  
> wrote:
>
> > Ok, I'm still having issues.
>
> > I'm using Django 1.0.2-final and Python 2.5.4
>
> > The models.py starts with the proper encoding string of: # -*- coding:
> > utf-8 -*-
>
> Adding that encoding string isn't enough, the other thing you need to be
> sure is that the file is really using that encoding (UTF-8 in your
> case). It could be you editor created it with a iso-8859-1 encoding and
> just adding the # -*- coding: utf-8 -*- header wouldn't solve things.
>
> Using
>
> $ file models.py
>
> can tell you the real encoding, and it isn't the one you expect, you can
> re-code it using the iconv utility or re-create the models.py file from
> scratch making sure you tell from the beginning your text editor you want
> the file to use UTF-8 encoding.
>
> HTH
>
> (sorry for not making this clear in the previous reply)
>
> --
>  Ramiro Morales

Are those Linux commands or part of the Python shell? I'm running this
on Windows. XP to be exact.


--~--~-~--~~~---~--~~
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: Verbose field name DjangoUnicodeDecodeError

2009-02-12 Thread Joshua Russo

On Feb 11, 6:44 pm, Karen Tracey  wrote:
> On Wed, Feb 11, 2009 at 2:30 PM, Joshua Russo wrote:
>
> > Thanks so much. I think you are right. I will let you know tomorrow if
> > I was able to fix it. I just need to figure out where the encoding is
> > set in NetBeans and Textpad. I use a combination of both of them.
>
> > It's possible that I didn't have the "u" when I created the message,
> > though I was receiving an error of some sort with and without the "u".
>
> Yes, you would get an error both with and without the u'', just at different
> times, and the one you showed was the one you would get without the u'', not
> with it.
>
> When you specify an encoding declaration of utf-8 in the file, and use u''
> around a string that is not in fact utf-8 encoded, the Python interpreter
> will raise an error when you try to import the file.  Python uses the
> encoding declaration for the file to decode the string inside the u'' when
> the file is loaded; if the string can't be decoded using the file-declared
> encoding, you'll get an error.  But that is not the error your reported.
>
> If you don't use u'' around the string, Python doesn't do anything special
> with it when the file is imported, it's just a bytestring.  Later on when
> Django has to convert it to unicode, it tries to do so assuming a utf-8
> encoding, which will fail if the string isn't utf-8 encoded.  This is the
> error you reported.
>
> Karen

Success!!! The files where absolutely in iso8859-1. I found where I
needed to set UTF-8 in NetBeans and TextPad and everything worked
perfectly. Karen and Ramiro thanks for all your help!


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



ManyToManyField admin save problem

2009-02-20 Thread Joshua Russo

Ok, so I believe I'm following the documentation properly for a
ManyToManyField with the Through=xxx option here:
http://docs.djangoproject.com/en/dev/ref/models/fields/#manytomanyfield

class Pessoa(models.Model):
Nome= models.CharField('Nome', max_length=100)
Localidade  = models.CharField('Moradas', max_length=200)

** Snip **

def __unicode__(self):
return self.Nome + ' (' + self.Localidade + ')'

class Matriz(models.Model):
NumOrd= models.IntegerField('Número de ordem (artigo da
matriz)',
primary_key=True)

** Snip **

Proprietarios = models.ManyToManyField(Pessoa,
through='MatrizPropri')

** Snip **

def __unicode__(self):
return unicode(self.NumOrd) + ' - ' + self.SitPredios

class MatrizPropri(models.Model):
NumOrd = models.ForeignKey(Matriz)
Pessoa = models.ForeignKey(Pessoa)
PrimerioFg = models.BooleanField(default=False)

** Snip **

def __unicode__(self):
return unicode(self.Pessoa) + ' (Primerio: ' + unicode
(self.PrimerioFg) + ')'


Then I setup the admin using an Inline class to manage the
MatrizPropri model within the Matriz change form:

class MatrizPropriInline(admin.TabularInline):
model = MatrizPropri
extra = 1

class MatrizAdmin(admin.ModelAdmin):
inlines = [MatrizPropriInline]

admin.site.register(Matriz, MatrizAdmin)


My problem is that I get an error in regards to the Pessoa_id in
MatrizPropri. I pulled the following out of the MySQL sql.log:

SELECT `matriz_matriz`.`NumOrd`, `matriz_matriz`.`SitPredios`,
`matriz_matriz`.`Ano`, `matriz_matriz`.`Descricao`,
`matriz_matriz`.`Rendimento`, `matriz_matriz`.`RendTypoCD`,
`matriz_matriz`.`Observacoes`, `matriz_matriz`.`MdUsr`,
`matriz_matriz`.`MdDT`, `matriz_matriz`.`CrUsr`,
`matriz_matriz`.`CrDT` FROM `matriz_matriz` INNER JOIN
`matriz_matrizpropri` ON (`matriz_matriz`.`NumOrd` =
`matriz_matrizpropri`.`NumOrd_id`) WHERE
`matriz_matrizpropri`.`Pessoa_id` =
''  ORDER BY `matriz_matriz`.`_order` ASC LIMIT 21


Obviously the Pessoa_id value in the where clause is wrong. How can I
fix 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: ManyToManyField admin save problem

2009-02-20 Thread Joshua Russo

Here is the traceback:

Environment:

Request
Method: POST
Request URL: http://localhost:8000/admin/matriz/matriz/add/
Django Version: 1.0.2 final
Python Version: 2.5.4
Installed Applications:
['django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites',
'django.contrib.admin', 'pessoa', 'matriz']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Traceback:
File "c:\python25\Lib\site-packages\django\core\handlers\base.py" in
get_response 86. response = callback(request, *callback_args,
**callback_kwargs)
File "c:\python25\Lib\site-packages\django\contrib\admin\sites.py" in
root 157. return self.model_page(request, *url.split('/', 2))
File "c:\python25\Lib\site-packages\django\views\decorators\cache.py"
in _wrapped_view_func 44. response = view_func(request, *args,
**kwargs)
File "c:\python25\Lib\site-packages\django\contrib\admin\sites.py" in
model_page 176. return admin_obj(request, rest_of_url)
File "c:\python25\Lib\site-packages\django\contrib\admin\options.py"
in
__call__ 191. return self.add_view(request)
File "c:\python25\Lib\site-packages\django\db\transaction.py" in
_commit_on_success 238. res = func(*args, **kw)
File "c:\python25\Lib\site-packages\django\contrib\admin\options.py"
in
add_view 494. self.save_model(request, new_object, form, change=False)
File "C:\!Dev\adminTributaria\matriz\admin.py" in save_model 47.
obj.save()
File "c:\python25\Lib\site-packages\django\db\models\base.py" in save
311. self.save_base(force_insert=force_insert,
force_update=force_update)
File "c:\python25\Lib\site-packages\django\db\models\base.py" in
save_base 377. values.append((meta.get_field_by_name('_order')[0],
manager.filter(**{field.name: getattr(self, field.attname)}).count()))
File "c:\python25\Lib\site-packages\django\db\models\query.py" in
count
296. return self.query.get_count()
File "c:\python25\Lib\site-packages\django\db\models\sql\query.py" in
get_count 237. data = obj.execute_sql(SINGLE)
File "c:\python25\Lib\site-packages\django\db\models\sql\query.py" in
execute_sql 1734. cursor.execute(sql, params)
File "c:\python25\Lib\site-packages\django\db\backends\util.py" in
execute 19. return self.cursor.execute(sql, params)
File "c:\python25\Lib\site-packages\django\db\backends\mysql\base.py"
in execute 83. return self.cursor.execute(query, args)
File "C:\Python25\Lib\site-packages\MySQLdb\cursors.py" in execute
168.
if not self._defer_warnings: self._warning_check()
File "C:\Python25\Lib\site-packages\MySQLdb\cursors.py" in
_warning_check 82. warn(w[-1], self.Warning, 3)
File "C:\Python25\lib\warnings.py" in warn 62. globals)
File "C:\Python25\lib\warnings.py" in warn_explicit 102. raise message
Exception Type: Warning at /admin/matriz/matriz/add/
Exception Value: Incorrect integer value:
'' for column 'Pessoa_id' at row 1


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



Found (and fixed?) a bug in ManyToManyField class

2009-02-27 Thread Joshua Russo

Think I found a bug in the ManyRelatedManager that occurs when you try
to include a ManyToManyField relation in an admin edit page. I
personally tried to have the relational table/module as an inline
display of primary entity module. It seems to have been missing the
__unicode__ / __str__ methods. If you add the following code to the
ManyRelatedManager it seems to work fine.

def __str__(self):
return self.__unicode__()

def __unicode__(self):
return unicode(self._pk_val)

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



Problem with admin validation

2009-02-27 Thread Joshua Russo

I have a model admin page where I want to edit a ManyToMany relation
model as an inline model but It is treating the extra entries for the
inline relation as required. How do I make the inline model not
required?
--~--~-~--~~~---~--~~
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: Problem with admin validation

2009-03-02 Thread Joshua Russo

Ok, I figured out what was going on. I was testing some custom save
logic and was just reloading the page to have my browser (Firefox)
resend the post data. The validation of the inline models works just
fine if I come into the model change page normally.

On Feb 27, 7:29 pm, Joshua Russo  wrote:
> I have a model admin page where I want to edit a ManyToMany relation
> model as an inline model but It is treating the extra entries for the
> inline relation as required. How do I make the inline model not
> required?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Formatted currency output question

2009-03-10 Thread Joshua Russo

I found this in my searches for formatting a decimal as a proper
currency output: http://www.djangosnippets.org/snippets/552/

The problem I'm running into is that the setLocale() line seems to be
choking on the non-base 128 characters that display in my site. I'm
creating the site to display Portuguese. I'm also passing in the
settings.LANGUAGE_CODE to the second argument of the method. Has
anyone run into this difficulty?


--~--~-~--~~~---~--~~
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: Formatted currency output question

2009-03-10 Thread Joshua Russo

Oh ya, I forgot to mention that I'm not using the snippet as
advertised either. I'm trying to make a CurrencyField object. Of
course then I realized that the formatting of at least the admin list
display was done outside of the Field objects, this (I believe the
file is called result_list.py) is where I am attempting to put the
currency format at the moment.

On Mar 10, 8:11 am, Joshua Russo  wrote:
> I found this in my searches for formatting a decimal as a proper
> currency output:http://www.djangosnippets.org/snippets/552/
>
> The problem I'm running into is that the setLocale() line seems to be
> choking on the non-base 128 characters that display in my site. I'm
> creating the site to display Portuguese. I'm also passing in the
> settings.LANGUAGE_CODE to the second argument of the method. Has
> anyone run into this difficulty?
--~--~-~--~~~---~--~~
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: Formatted currency output question

2009-03-10 Thread Joshua Russo

On Mar 10, 8:29 am, Malcolm Tredinnick 
wrote:
> On Tue, 2009-03-10 at 02:11 -0700, Joshua Russo wrote:
> > I found this in my searches for formatting a decimal as a proper
> > currency output:http://www.djangosnippets.org/snippets/552/
>
> Oh, that's a really bad idea. :-(
>
> Calling setlocale() in multi-threaded applications is simply not
> something you should do. It changes the locale for *everything*.
> Including things that expect numbers to be formatted in the C locale
> (such as serialisation and deserialisation). In a multi-lingual
> application, it's also going to lead to most threads of execution seeing
> the wrong locale.
>
> Please don't use that snippet. It's broken for anything but the most
> simple, single-threaded use-cases.
>
> If you really want currency formatting and the like at the moment, the
> "babel" project is the place to look. At some point (maybe in 1.1, but I
> wouldn't hold my breath at the moment), Django will have native support
> for some of this stuff, although probably not for things like adding
> commas to long numbers. We do want to add support for the appropriate
> decimal separator in a locale-aware fashion (so you can enter 1,23 in a
> form in  Europe and have it validate correctly). But for all the really
> advanced bells and whistles, use babel.
>
> Regards,
> Malcolm

Great, thanks for the info


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



Makemessages not finding strings in my templates?

2009-06-19 Thread Joshua Russo

I'm trying to use the makemessages command to create .po files and I'm
running into a problem scanning .html files. I'm running XP Pro and
using libiconv (1.9.2) and gettext (0.13).

None of the {% trans 'text' %} entries are being picked up in the
scan. I'm loading the I18n library in all of my templates, though I'm
not sure it matters for gettext. The command I'm using is:

manage.py makemessages -l pt -e=html,py

It's picking up the strings in the code but not the templates. Oh ya,
and the template directory is within the directory structure from
where I'm running makesmessages.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Gettext needs iconv.dll but I only have libiconv2.dll

2009-06-19 Thread Joshua Russo

When I installed Libiconv (1.9.2)  and gettext (0.13) on my XP Pro
machine and tried to run makemessages it initially gave me an error
message saying that it could not find iconv.dll. I went to the install
directory and I had a libiconv2.dll but no iconv.dll. I tried copying
and renaming the file and it seemed to work. Is this common or is
there something that I did wrong in the install process?

I used the exe installer for Libiconv because the zip download was not
working from SourceForge. I wouldn't image that that would make any
difference, but I thought I'd mention it anyway.

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



What editor do you use for .po files?

2009-06-19 Thread Joshua Russo

I started using PoEdit but it seems to thing that the .po files
created by makemessages are malformed, or at least don't have all the
right headers. Is there a better editor for Windows?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Makemessages not finding strings in my templates?

2009-06-22 Thread Joshua Russo

On Jun 19, 7:08 pm, Joshua Russo  wrote:
> I'm trying to use the makemessages command to create .po files and I'm
> running into a problem scanning .html files. I'm running XP Pro and
> using libiconv (1.9.2) and gettext (0.13).
>
> None of the {% trans 'text' %} entries are being picked up in the
> scan. I'm loading the I18n library in all of my templates, though I'm
> not sure it matters for gettext. The command I'm using is:
>
> manage.py makemessages -l pt -e=html,py
>
> It's picking up the strings in the code but not the templates. Oh ya,
> and the template directory is within the directory structure from
> where I'm running makesmessages.

For whatever reason, it seems that the -e option I used actually broke
makemessages. If you simply leave off the -e option everything works
fine and it searches both code files and templates.
--~--~-~--~~~---~--~~
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: Gettext needs iconv.dll but I only have libiconv2.dll

2009-06-22 Thread Joshua Russo

On Jun 20, 3:35 pm, Ramiro Morales  wrote:
> On Fri, Jun 19, 2009 at 5:15 PM, Joshua Russo wrote:
>
> > When I installed Libiconv (1.9.2)  and gettext (0.13) on my XP Pro
> > machine and tried to run makemessages it initially gave me an error
> > message saying that it could not find iconv.dll. I went to the install
> > directory and I had a libiconv2.dll but no iconv.dll. I tried copying
> > and renaming the file and it seemed to work. Is this common or is
> > there something that I did wrong in the install process?
>
> > I used the exe installer for Libiconv because the zip download was not
> > working from SourceForge. I wouldn't image that that would make any
> > difference, but I thought I'd mention it anyway.
>
> I would recommend going straight to use a version of gettext tools win32
> binaries equal or greater to 0.15 (currently 0.17 is available) instead.
>
> For this, follow the modified instructions proposed by this
> documentation patch attached to ticket  #10741:
>
> http://code.djangoproject.com/attachment/ticket/10741/10741-updated-w...
>
> If you decide to do so, please post back your experiences with
> the new instructions. This will help us to decide if offering
> these updated instructions would be a documentation change
> worth doing.
>
> Regards,
>
> --
> Ramiro Moraleshttp://rmorales.net

That works perfectly. Thanks!

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



Re: Gettext needs iconv.dll but I only have libiconv2.dll

2009-06-22 Thread Joshua Russo

On Jun 20, 3:35 pm, Ramiro Morales  wrote:
> On Fri, Jun 19, 2009 at 5:15 PM, Joshua Russo wrote:
>
> > When I installed Libiconv (1.9.2)  and gettext (0.13) on my XP Pro
> > machine and tried to run makemessages it initially gave me an error
> > message saying that it could not find iconv.dll. I went to the install
> > directory and I had a libiconv2.dll but no iconv.dll. I tried copying
> > and renaming the file and it seemed to work. Is this common or is
> > there something that I did wrong in the install process?
>
> > I used the exe installer for Libiconv because the zip download was not
> > working from SourceForge. I wouldn't image that that would make any
> > difference, but I thought I'd mention it anyway.
>
> I would recommend going straight to use a version of gettext tools win32
> binaries equal or greater to 0.15 (currently 0.17 is available) instead.
>
> For this, follow the modified instructions proposed by this
> documentation patch attached to ticket  #10741:
>
> http://code.djangoproject.com/attachment/ticket/10741/10741-updated-w...
>
> If you decide to do so, please post back your experiences with
> the new instructions. This will help us to decide if offering
> these updated instructions would be a documentation change
> worth doing.
>
> Regards,
>
> --
> Ramiro Moraleshttp://rmorales.net

One thing you may want to add to the documentation is adding the bin
directory to the system path. I did it out of reflex and so I'm not
sure if it's needed our not but it seems to make sense.

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



Re: Django - how to work with Ajax requests?

2009-06-23 Thread Joshua Russo

On Jun 23, 12:49 pm, "http://groups.google.com/group/django-users/";
 wrote:
> Hello everyone,
> i got a problem with working with Ajax requests @ the Admin models.
> How can i get requests from Ajax to the AdminModel to get 4 example
> from a dropdownmenu my manytomanyfield changed.
> its tricky! Have not found something @ the docu or something else...
>
> Thanks 4 reading,
> Chris

This is what I did: http://www.djangosnippets.org/snippets/1588/
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Common report values?

2009-07-06 Thread Joshua Russo

I have a seriese of reports that have a signature section with the
name below. The name does not change very often but it will change at
some point and I want a layman to be able to change the name without
having to edit the scary looking template files. Can I specify an
arbitrary field from an arbitrary table in a template or should I
create a ReportInfo model and associate it (through a relation) to the
different models that have reports where I need to use the info?

--~--~-~--~~~---~--~~
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: Common report values?

2009-07-06 Thread Joshua Russo

I'll check it out. Thanks.

On Jul 6, 1:23 pm, Daniel Hilton  wrote:
> Couldn't you use something like django-chunks for this?
>
> Specify a single chunk something like footer and then pull it in for every
> report?
>
> HTH
> Dan
>
> 2009/7/6 Joshua Russo 
>
>
>
> > I have a seriese of reports that have a signature section with the
> > name below. The name does not change very often but it will change at
> > some point and I want a layman to be able to change the name without
> > having to edit the scary looking template files. Can I specify an
> > arbitrary field from an arbitrary table in a template or should I
> > create a ReportInfo model and associate it (through a relation) to the
> > different models that have reports where I need to use the info?
>
> --
> Dan Hilton
> 
> DanHilton.co.uk
> 
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



New to unit testing, need advice

2009-07-15 Thread Joshua Russo

I'm in the process of implementing testing (both doc tests and unit
tests) though I'm having some conceptual difficulty. I'm not sure how
far to take the testing. I'm curious what people concider an
appropriate level of testing.

This thought struck me most when I was going through the testing
documentation, in the section regarding the testing of models. It
seems to me that very little logic generally goes into the model
classes. At least for me, I have far more logic in admin.py and
views.py.

What are peoples thoughts on testing models? What exactly are you
testing for there? How do you gauge code that should be tested versus
code that doesn't really need it?

Thanks for your help
Josh
--~--~-~--~~~---~--~~
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: New to unit testing, need advice

2009-07-16 Thread Joshua Russo

> besides the testing issues (which are certainly a heated debate!), i have to 
> say that my Django projects became far better organized and a lot more 
> flexible when i learned to put most of the code on the models, and not on the 
> views.

I find this really interesting because I wanted to put more code into
the models but couldn't seem to find the right hooks to accomplish my
specific tasks.

What are some examples of mutating operations (and other operations
for that matter) that you use in your models?

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



How do you unit test forms

2009-07-16 Thread Joshua Russo

I want to test my forms but I'm not sure the best way to go about it.
It seems like it might be similar to views but I can't find much
discussion of form testing in any of the discussions about unit
testing.

Any suggestions are much appreciated.

Thanks
Josh
--~--~-~--~~~---~--~~
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: New to unit testing, need advice

2009-07-16 Thread Joshua Russo

On Jul 16, 1:35 pm, Javier Guerra  wrote:
> On Thu, Jul 16, 2009 at 9:27 AM, Joshua Russo wrote:
> > What are some examples of mutating operations (and other operations
> > for that matter) that you use in your models?
>
> the most obvious are:
>
> - 'calculated' fields.  the first example is the __unicode__() method,
> but lots others, like multiplying widht/height fields to get an 'area'
> field, (en/de)coding JSON data in one field to/from a python object,
> fetching a filesize from the filesystem,  things like that.
>
> - 'pre-made filters'. like alex's example
>
> - overriding the save() method, to add some consistency checks, update
> other tables (like maintaining denormalized fields), override one
> field with another, etc.
>
> - other kinds of objects that could present a nicer API than just a
> bunch of DB records and tables, for example a tag soup, even if it's
> an extra table, it's presented as extra fields and operations on the
> 'tagged' model.
>
> - anything that Java developers could call the 'business layer', or
> anything that a DB manager would like to put into an stored procedure
> (unless you're able to actually do that!)
>
> a worthwhile goal is to make view functions really really thin.  maybe
> just a few lines before calling the template or a generic view.
>
> if your model layer presents an API that is close to the concepts the
> user manages, but at the same time isn't tied to the specific web
> interface, you'll be able to easily rework the whole appearance of
> your website, quite possibly even change the whole user experience
> without rewriting the 'operational' code.
>
> --
> Javier

Great suggestions. Thanks for helping me clear that up.
--~--~-~--~~~---~--~~
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: New to unit testing, need advice

2009-07-16 Thread Joshua Russo

Great ideas! I've started moving some of my logic that I had in
admin.py and views.py into model.py and things are already starting to
look easier in terms of testing.

My only real hurdle now is testing validation logic on the admin pages
and the form creation logic that is the main page to the application.

Any thoughts on form testing via the unit test. It seems like I just
want to use the test client, find a good group of post data sets, and
use the assertContains() and assertFormError().

Does that sound about right?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Current user in model.save() context

2009-07-16 Thread Joshua Russo

I think I might be overlooking something simple here. I have a set of
4 fields in almost every table (user create & modified and date create
& modified). The date (datetime) is easy with auto_now and
auto_now_add options.

The user has been much trickier. I can't figure out how (if possible)
to get access to the current user information in the context of a
model. The work around that I've implemented is a method that takes
the model, user id, and a boolean indicating modification or new. I
then use this in location where I still have a request object (and
thus request.user.id) like my views or save_model() of the admin form.

Is this as good as I can do, or can I access the current user (or
request object) from within the model?

Thanks
Josh
--~--~-~--~~~---~--~~
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 do you unit test forms

2009-07-17 Thread Joshua Russo

On Jul 16, 11:11 pm, Russell Keith-Magee 
wrote:
> On Thu, Jul 16, 2009 at 10:46 PM, Joshua Russo wrote:
>
> > I want to test my forms but I'm not sure the best way to go about it.
> > It seems like it might be similar to views but I can't find much
> > discussion of form testing in any of the discussions about unit
> > testing.
>
> > Any suggestions are much appreciated.
>
> Well, a Form is just a class with a bunch of member functions - in
> your views you instantiate instances of the form and give it data,
> call is_valid() to validate and clean data.
>
> So a test is exactly that. Instantiate your form, give it some sample
> data, and assert that the data has either thrown an error (i.e., that
> is_valid() == False and form.errors is populated), or that
> form.cleaned_data contains the right output.
>
> Keep in mind that you don't need to test the core behaviour - Django's
> test suite will check that a simple integer field will reject
> character input, etc. All you need to test is your own local
> extensions, like clean_* methods.
>
> Yours
> Russ Magee %-)

Thanks. I'm guess I need to take a closer look at the forms
functionality. I don't think I'm using it properly. This is my first
Django project and I guess I don't always know enough of what I'm
asking about to ask a full question.

Thanks for the input.

--~--~-~--~~~---~--~~
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: Expert System

2009-07-17 Thread Joshua Russo
I second that. In my experience they are inherently very context specific,
with very unique databases and code bases. With that said, you
can definitely develop an expert system using django. It's more about
the algorithms you produce than the environment you produce them in.

On Fri, Jul 17, 2009 at 11:22 PM, Joshua Partogi
wrote:

> What kind of expert system do you want to know. I think expert system is a
> very broad topic.
>
> On Sat, Jul 18, 2009 at 10:05 AM, Carlos Eduardo Sotelo Pinto <
> csot...@aqpglug.org.pe> wrote:
>
>>
>> -BEGIN PGP SIGNED MESSAGE-
>> Hash: SHA1
>>
>> Hi peolple
>>
>> some one knows somthing about works about expert system maden on python
>> with django
>>
>> thanks a lot
>>
>
> --
> http://blog.scrum8.com
> http://twitter.com/scrum8
>
>
> >
>

--~--~-~--~~~---~--~~
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: Expert System

2009-07-18 Thread Joshua Russo
>
> I was thinkin about using the powerful of django for dabase admin and
> templates for web and make the
> algorithms on python modules... after that call them as a simple module...
> my question is about a
> maden job about it.


Its an excellent idea to use the django admin app to manage any kind of
database. Though I'm not familiar with a maden job. Could you explain what
you are referring to?

--~--~-~--~~~---~--~~
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 do you unit test forms

2009-07-18 Thread Joshua Russo
On Sat, Jul 18, 2009 at 9:38 AM, V  wrote:

> Some time ago I wrote down my experience on testing, including testing
> forms: http://viktornagy.com/blog/2009/05/24/what-test-django/
>
> moreover, I would recommend to check out the tests of some existing
> projects, that might give you some clues on how to test forms, views,
> models, etc.


Thanks for the link to your blog post. I'm trying to read up on as many
tutorials/examples as I can to make sure I'm getting the most out of what
Django offers.

There are a ton of projects out there, do you have any recomendations as to
a few that have good examples of solid testing methodology?

--~--~-~--~~~---~--~~
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: Current user in model.save() context

2009-07-18 Thread Joshua Russo
On Sat, Jul 18, 2009 at 8:06 AM, Matthias Kestenholz <
matthias.kestenh...@gmail.com> wrote:

> If you really need to do that (or if you are just extremely lazy)
> there is a cookbook recipe for achieving this sort of thing:
>
> http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
>
> That's deep in the category of 'give them rope to hang themselves
> with' though. You should understand the implications and design
> decisions involved before hacking your way around it.


I appreciate the concern in regards to breaking concepts. I'm not sure I
understand the concept (the portion of MVC) that would be broken. Could you
(or anyone for that matter) explain the ramifications?

--~--~-~--~~~---~--~~
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: Expert System

2009-07-18 Thread Joshua Russo
On Sat, Jul 18, 2009 at 11:42 AM, Carlos Eduardo Sotelo Pinto <
csot...@aqpglug.org.pe> wrote:

>
> Hi
> >
> > Its an excellent idea to use the django admin app to manage any kind of
> > database. Though I'm not familiar with a maden job. Could you explain
> > what you are referring to?
>
> Iam talkin about a python expert system with django
>

I realize that, but you need a more specific. What is a maden job?

--~--~-~--~~~---~--~~
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 do you unit test forms

2009-07-18 Thread Joshua Russo
On Sat, Jul 18, 2009 at 12:17 PM, Russell Keith-Magee <
freakboy3...@gmail.com> wrote:

> As is often the case in the Django community, one answer is "find
> anything James Bennett has done, and follow his lead". :-)
>
> James has just finished reworking django-registration [1]. One of the
> offshoots of this work is a test suite that (last time I spoke to
> James) had almost 100% source line coverage. There are plenty of other
> examples, but this is a great place to start. As a bonus, a lot of the
> tests for django-registration are directly relevant to your interests
> - testing forms.
>
> [1] http://bitbucket.org/ubernostrum/django-registration/wiki/Home
>

Awesome! Thanks for the tip.

--~--~-~--~~~---~--~~
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 do you unit test forms

2009-07-18 Thread Joshua Russo
On Sat, Jul 18, 2009 at 10:54 AM, V  wrote:

> wow, that's a tough question as I'm not self-confident enough to judge
> other's projects and testing, but my guess would be that the
> django.contrib applications have good tests, and I think that the
> tests for my django-donation project (https://launchpad.net/django-
> donation) are quite simple and still show you what and how should be
> tested.


I'll check it out, thanks.

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



Re: Expert System

2009-07-18 Thread Joshua Russo
On Sat, Jul 18, 2009 at 1:15 PM, Carlos Eduardo Sotelo Pinto <
csot...@aqpglug.org.pe> wrote:

>
> I understand. Well I mean a papper, page resource to explain hoy to use
> django for expert system or
> mayme an application resource example about using django on expert system
> to take it as a start poit
> to study about it
>

I found these with a simple Google search for "expert system python":
http://pyke.sourceforge.net/
http://pyclips.sourceforge.net/web/
http://www.awaretek.com/python.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-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: Expert System

2009-07-18 Thread Joshua Russo
On Sat, Jul 18, 2009 at 1:31 PM, Joshua Russo wrote:

> On Sat, Jul 18, 2009 at 1:15 PM, Carlos Eduardo Sotelo Pinto <
> csot...@aqpglug.org.pe> wrote:
>
>>
>> I understand. Well I mean a papper, page resource to explain hoy to use
>> django for expert system or
>> mayme an application resource example about using django on expert system
>> to take it as a start poit
>> to study about it
>>
>
> I found these with a simple Google search for "expert system python":
> http://pyke.sourceforge.net/
> http://pyclips.sourceforge.net/web/
> http://www.awaretek.com/python.html
>

Sorry I should have added that Django is more like the glue that connects
your code (logic for an expert system for instance) more easily to html
output and databases. An expert system is just one engine you can slap into
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: User login

2009-07-18 Thread Joshua Russo
On Sat, Jul 18, 2009 at 8:51 PM, AKK  wrote:

>
> hi,
>
> i have a form like this:
>
>  
>User name:
>
>Password:
> id="password">
>
>
>
>
>  
>
> and the next  field is where the user should be redirected assuming
> they have the correct details.
>
> When they login i want them to be redirected to myurl.com/blog/ but
> what i have above redirects them to myurl.com/accounts/login/blog/. Is
> it possible to get them where i want without using the absolute url?


Just put a forward slash in front of the Next 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-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 Validation

2009-07-18 Thread Joshua Russo
On Sat, Jul 18, 2009 at 9:03 PM, sjtirtha  wrote:

> class AbstractContent(models.Model):
> viewed   = models.PositiveIntegerField(max_length=7,
> blank=True, null=True)
> #rating   =
> #ranking  =
> created_by   = models.ForeignKey(User)
> changedBy= models.ForeignKey(Use, related_name='_changedBy')
> created_at   = models.DateTimeField(auto_now_add=True)
> changed_at   = models.DateTimeField(auto_now=True, blank=True,
> null=True)
>
> class Meta:
> abstract = True
>

Looks like you misspelled User (as Use) for the ChangedBy field

--~--~-~--~~~---~--~~
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, MySQL - bug?

2009-07-19 Thread Joshua Russo
2009/7/19 Tomasz Zieliński 

> So, should m.save() set m.id to some other value than None
> or this is relaxed when Warning exception is thrown?


It's the database that gives m.id a value upon a valid save. So because the
record couldn't be saved it never received a 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-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: Current user in model.save() context

2009-07-20 Thread Joshua Russo
On Mon, Jul 20, 2009 at 9:23 AM, Matthias Kestenholz <
matthias.kestenh...@gmail.com> wrote:

> thread locals have all the problems which are generally associated
> with global variables. They might be overwritten by other code, they
> make testing extremely difficult because the behavior of methods may
> depend on non-obvious circumstances and it's not clear from the method
> signatures which variables are really used -- in short, it makes code
> maintenance much harder than it needs to be.
>
> I'll try giving a few examples:
>
> - You have a field on your model called last_modified_by, and you
> automatically assign request.user in the save() method. You made this
> piece of code much harder to test in an unittest than it needs to be,
> because now you have to provide the complete environment including the
> variables from the threadlocals space in your testsuite. More code is
> needed, and the probability that the code and the testsuite (and
> eventual documentation) get out of sync gets bigger and bigger.
>
> - Something which I've done for a CRM system which we've developped
> for internal use together with another company was giving Tasks access
> levels, so that we were able to make certain tasks viewable only by
> the management. I built a manager which uses the user information from
> thread local space to filter the queryset automatically according to
> the profile of the currently authenticated user. With this seemingly
> simple move I've made it impossible to use loaddata/dumpdata, because
> no user exists, and I made it very non-obvious that the list of
> viewable tasks depends on the user. You would not get the idea that
> filtering is going on in the templates or even in a big part of the
> code. This is not a big problem when developping alone, but it can
> really hamper progress if someone else takes over the codebase.
>
> In short: It's easy and it gets the job done, but will come back and
> bite you later for sure. Don't give in to the temptation -- it's much
> better to write custom template tags where you can pass the user
> explicitly to the function, which makes it very clear that the
> output/the result of a certain function depends on the user. It also
> makes testing a breeze, because the behavior of methods is only
> determined by their arguments (as it should be), not by other
> circumstances or the current weather.


Matthias, thanks. I really appreciate you taking the time to explain that. I
always wondered why the objected oriented world crucified
global variables. :o)

--~--~-~--~~~---~--~~
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: Exception Value: coercing to Unicode: need string or buffer, ContentType found

2009-07-20 Thread Joshua Russo
On Mon, Jul 20, 2009 at 8:30 PM, sjtirtha  wrote:

>
> class ContentAssoc(models.Model):
> object_a = models.PositiveIntegerField()
> type_a = models.ForeignKey(ContentType, related_name='type_a')
> object_b = models.PositiveIntegerField()
> type_b = models.ForeignKey(ContentType, related_name='type_b')
>
> class Meta:
> unique_together = ('object_a', 'type_a', 'object_b', 'type_b')
>
> def __unicode__(self):
> return self.type_a
>

The __unicode__ method expects a unicode value to be returned. Try: return
unicode(self.type_a)

--~--~-~--~~~---~--~~
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: Making Django ldapauth more sophisticated

2009-07-20 Thread Joshua Russo
On Mon, Jul 20, 2009 at 9:35 PM, Daniele Procida
wrote:

>
> I finally have ldapauth working now, and a user who is in our LDAP
> database can connect as a Django User.
>
> But it's not entirely satisfactory. Before the LDAP user becomes a
> Django User they have to try logging (which fails of course). Then they
> become a Django User, and then they can have their privileges set so
> that they can log in.
>
> That's all a bit messy - can it be improved, somehow?
>
> A second question. I have a class called Person; every Person is also a
> User.
>
> What I would like, when creating a new Person, is to be able to attach
> the Person to a user from the LDAP database (based on their LDAP
> canonical name).
>
> Our LDAP database has many thousands of people in it, by the way.
>
> (Later I might need to deal with Persons who are Users who aren't in the
> LDAP database, but that can be dealt with another time.)
>
> Any suggestions on how to proceed there?


This might help you out:
http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-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-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: customizing admin template - how to refer to specific field

2009-07-20 Thread Joshua Russo
On Mon, Jul 20, 2009 at 10:26 PM, sico  wrote:

>
> thats cool to know, but not quite what I'm after I don't think.  If
> there was a simple way to display the label, field and any errors all
> at once would be nice otherwise it gets quite cumbersome to be
> repeating that all each time.
>
> Basically what I want to be able to do is to show different fields
> depending on a data value
>
> e.g.
>
> if field1 = 1 then hide field7 else hide field8


I think you want to look at the different IF tags here:
http://docs.djangoproject.com/en/dev/ref/templates/builtins/

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



Customizing context by opening up BoundField, is it ok?

2009-07-21 Thread Joshua Russo

I have a complex form that where I generate a grid (for lack of a
better term) of fields for data entry. To simplify the template
context I have a dictionaries within dictionaries so I can just use
FOR loops within FOR loops in the template.

My problem was that, unless I wrapped my fields in a BoundField, I
would only receive the field's object reference output instead of the
rendered widgets. So I added BoundField to the list of available
objects in forms.py and everything is hums along merrily.

My question is, am I breaking any Django commandments by opening up
the BoundField (other than not monkey patching)?
--~--~-~--~~~---~--~~
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: What editor do you use for .po files?

2009-07-22 Thread Joshua Russo
That looks really slick. Thanks for the link.

On Tue, Jul 21, 2009 at 8:44 PM, Jonas Obrist  wrote:

>
> Haven't started by i18n yet but rosetta looks good:
> http://code.google.com/p/django-rosetta/
>
> bittin wrote:
> > i also use PoEdit =)
> >
> > On Fri, Jun 19, 2009 at 11:05 PM, Joshua Russo
> > mailto:joshua.rupp...@gmail.com>> wrote:
> >
> >
> > I started using PoEdit but it seems to thing that the .po files
> > created by makemessages are malformed, or at least don't have all the
> > right headers. Is there a better editor for Windows?
> >
> > 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-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: Customizing context by opening up BoundField, is it ok?

2009-07-22 Thread Joshua Russo
On Wed, Jul 22, 2009 at 10:51 AM, Russell Keith-Magee <
freakboy3...@gmail.com> wrote:
>
> Secondly, it's difficult to give an appraisal of a technique when all
> you have to go by is a vague description. Your explanation is a bit
> hard to follow - you talk at length about fields, but don't mention
> the form that holds those fields. Then you talk about the lengths you
> have gone to in order to expose BoundField ... but don't appear to
> acknowledge that if you iterate over the fields in a form, what you
> get are instances of BoundField. I can appreciate that code can get in
> the way of understanding a broader idea, but sometimes, a small amount
> of code brings a lot of clarity.


Sorry for the cryptic explanation. I think I was a little self conscious
about how complex this form was getting and thought that people would skip
on by to the next post if I gave too much info. Anyway, here's the structure
that I'm working with. I have lists of people, properties, and payments.
(Side note: The application is for a Portuguese speaking community and I've
used some of the language in the code because I'm not going to be the one
maintaining the app over the long term.)

class Pessoa(models.Model):
"""
A person who is responsible for paying taxes.
"""
id  = models.IntegerField('Número',
primary_key=True, blank=True)
Nome= models.CharField('Nome', max_length=100)
...

class Matriz(models.Model):
"""
Locales where a person needs to pay taxes
"""
NumOrd= models.IntegerField('Número',
primary_key=True, blank=True)
SitPredios= AutoCompleteCharField('Situação dos prédios',
max_length=50)
...

class MatrizPagamento(models.Model):
"""
Payments for a Matriz
"""
NumOrd = models.ForeignKey(Matriz)
Pessoa = models.ForeignKey(Pessoa)
Quantia = CurrencyField('Quantidade paga', max_digits=15)
Ano = models.IntegerField('Ano',
default=datetime.datetime.today().year)
...

I only have one view outside of the admin app and generic views I use for
reports. This view starts very simply with a field to select a person
(Pessoa) (I created a couple of util functions/classes to be able to use the
ForeignKeySearch field outside of the admin app because I liked the popup)

Once they select a person it shows them all of their valid properties
(Matriz) and if any of them need payment. If a payment is due then they can
edit and save the amount with a save button for each row/payment. In my
template context I have a property list (matrizList) and for each entry in
that I have a payment list. It's in the payment list that I wanted to use
BoundField because it would be easier that trying to reference the field in
the standard list of fields. I had to give each a unique name and so doing
contextually (in my payment list) was much easier than recreating the name
in the template syntax (I'm not even sure if I could have).

You can see how things got a little complex, and at first I completely
bypassed the built-in forms functionality and did *everything*  for the
view. Then I started to think about unit testing and my head exploded.

What I've arrived at today is actually using multiple forms (and no longer
need BoundField). Each payment row is it's own form and then I check to see
which type of button they used to submit and create form objects
accordingly.

This seems to work well. I have two form objects, my primary search form and
a payment form. Tho I'm still working through were to put the code that
generates the list of properties and payments. It's currently in the init
for the search form, but I will probably move that out into the view
tomorrow.

Does this sound reasonable, or am I still over thinking the plumbing? I get
the nagging impression I should just bite the bullet and split this into
more than one view.

Thanks for your advice
Josh

--~--~-~--~~~---~--~~
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: Creating radio button search app

2009-07-22 Thread Joshua Russo
On Wed, Jul 22, 2009 at 10:58 AM, Divesh Gidwani wrote:

>
> Also, what kind of views do I need? I'm really confused about that
> part.


If you want to mimic the current application you will need to create custom
views and forms. It's really easy once you get the idea, but it's taken me a
couple of go-a-rounds to get the concepts solidified in my own head. The
following is an extremely simplified version of a form I have on the home
page of the app I'm working on.

I'll start from urls.py:

from adminTributaria.matriz import views
...
urlpatterns = patterns('',
...
(r'^$', views.bemvindo)
)

Next views.py in my app called matriz:

from django import template
from django.shortcuts import render_to_response

from adminTributaria.matriz.forms import BemvindoForm

def bemvindo(request):
if request.method == 'POST':
curForm = BemvindoForm(request.POST)
if curForm.is_valid():
# Your form passed validation, do what you want with the data
here
# The cleaned_data dictionary will have proper Python objects
curMatrizID = curForm.cleaned_data['matrizID']
...
else:
curForm = BemvindoForm()

context = {
'title': _('Home'),
'form': curForm
}

return render_to_response('matriz/index.html', context,
context_instance=template.RequestContext(request))

Now the forms.py in matriz:

from django import forms

class BemvindoForm(MyForm):
matrizID = forms.IntegerField()
...


The only thing that I haven't shown here is the template. For my templates,
I generally take a copy of base.html in
django\contrib\admin\templates\admin\. I'll modify that how I like and then
inherit from it. The template inheritance is really slick.

I would recommend reading these sections of the docs:
http://docs.djangoproject.com/en/dev/topics/http/urls/#topics-http-urls (If
you are weak in the area of regular expressions, take time to understand
them here, it makes all the difference)
http://docs.djangoproject.com/en/dev/topics/http/views/#topics-http-views
http://docs.djangoproject.com/en/dev/topics/forms/#topics-forms-index
http://docs.djangoproject.com/en/dev/topics/templates/#topics-templates

--~--~-~--~~~---~--~~
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: Creating radio button search app

2009-07-22 Thread Joshua Russo
On Wed, Jul 22, 2009 at 10:39 PM, Joshua Russo wrote:

> On Wed, Jul 22, 2009 at 10:58 AM, Divesh Gidwani wrote:
>
>>
>> Also, what kind of views do I need? I'm really confused about that
>> part.
>
>
> If you want to mimic the current application you will need to create custom
> views and forms. It's really easy once you get the idea, but it's taken me a
> couple of go-a-rounds to get the concepts solidified in my own head. The
> following is an extremely simplified version of a form I have on the home
> page of the app I'm working on.
>
> I'll start from urls.py:
>
> from adminTributaria.matriz import views
> ...
> urlpatterns = patterns('',
> ...
> (r'^$', views.bemvindo)
> )
>
> Next views.py in my app called matriz:
>
> from django import template
> from django.shortcuts import render_to_response
>
> from adminTributaria.matriz.forms import BemvindoForm
>
> def bemvindo(request):
> if request.method == 'POST':
> curForm = BemvindoForm(request.POST)
> if curForm.is_valid():
> # Your form passed validation, do what you want with the data
> here
> # The cleaned_data dictionary will have proper Python objects
> curMatrizID = curForm.cleaned_data['matrizID']
> ...
> else:
> curForm = BemvindoForm()
>
> context = {
> 'title': _('Home'),
> 'form': curForm
> }
>
> return render_to_response('matriz/index.html', context,
> context_instance=template.RequestContext(request))
>
> Now the forms.py in matriz:
>
> from django import forms
>
> class BemvindoForm(MyForm):
> matrizID = forms.IntegerField()
> ...
>
>
> The only thing that I haven't shown here is the template. For my templates,
> I generally take a copy of base.html in
> django\contrib\admin\templates\admin\. I'll modify that how I like and then
> inherit from it. The template inheritance is really slick.
>
> I would recommend reading these sections of the docs:
> http://docs.djangoproject.com/en/dev/topics/http/urls/#topics-http-urls (If
> you are weak in the area of regular expressions, take time to understand
> them here, it makes all the difference)
> http://docs.djangoproject.com/en/dev/topics/http/views/#topics-http-views
> http://docs.djangoproject.com/en/dev/topics/forms/#topics-forms-index
> http://docs.djangoproject.com/en/dev/topics/templates/#topics-templates
>

Sorry, cut and paste error

class BemvindoForm(MyForm):
should be
class BemvindoForm(forms.Form):

I subclassed forms.Form in my 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-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
-~--~~~~--~~--~--~---



urls.py import() usage?

2009-07-23 Thread Joshua Russo

Is there any difference between using import() versus not in the url
pattern list?
(r'^accounts/login/$', 'django.contrib.auth.views.login'),
(r'^admin/doc/', include('django.contrib.admindocs.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: urls.py import() usage?

2009-07-23 Thread Joshua Russo
On Thu, Jul 23, 2009 at 2:18 PM, Matthias Kestenholz <
matthias.kestenh...@gmail.com> wrote:

>
> On Thu, Jul 23, 2009 at 4:51 PM, Joshua Russo
> wrote:
> >
> > Is there any difference between using import() versus not in the url
> > pattern list?
> >(r'^accounts/login/$', 'django.contrib.auth.views.login'),
> >(r'^admin/doc/', include('django.contrib.admindocs.urls')),
>
> Are you asking about import or include? Where would your imports be?


Sorry, I meant 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-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: urls.py import() usage?

2009-07-23 Thread Joshua Russo
there should have been a comma after the word not.

On Thu, Jul 23, 2009 at 2:40 PM, Saketh wrote:

> Joshua, could you clarify what you mean by "not in the url pattern list?"
>
> Sincerely,
> Saketh
>
> --
> Saketh Bhamidipati
> Harvard College '11
> http://people.fas.harvard.edu/~svbhamid/
>
>
>
> On Thu, Jul 23, 2009 at 11:33 AM, Joshua Russo wrote:
>
>> On Thu, Jul 23, 2009 at 2:18 PM, Matthias Kestenholz <
>> matthias.kestenh...@gmail.com> wrote:
>>
>>>
>>> On Thu, Jul 23, 2009 at 4:51 PM, Joshua Russo
>>> wrote:
>>> >
>>> > Is there any difference between using import() versus not in the url
>>> > pattern list?
>>> >(r'^accounts/login/$', 'django.contrib.auth.views.login'),
>>> >(r'^admin/doc/', include('django.contrib.admindocs.urls')),
>>>
>>> Are you asking about import or include? Where would your imports be?
>>
>>
>> Sorry, I meant 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-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: urls.py import() usage?

2009-07-23 Thread Joshua Russo
On Thu, Jul 23, 2009 at 3:09 PM, Matthias Kestenholz <
matthias.kestenh...@gmail.com> wrote:
>
> Well, there is a big difference between the two. include() takes the
> python path to an URLconf file while the other form takes a view.
>
> You should read the documentation on this page if you haven't done this
> already:
> http://docs.djangoproject.com/en/dev/topics/http/urls/#topics-http-urls


Gotcha, Thanks. RTFM

--~--~-~--~~~---~--~~
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: Customizing context by opening up BoundField, is it ok?

2009-07-23 Thread Joshua Russo

On Jul 23, 12:41 am, Russell Keith-Magee 
wrote:
> This sounds like you are on the right track. My only other suggestion
> is that it might be worth looking into using FormSets to simplify the
> logic for displaying multiple Payment forms on the page.

Thanks for your input. Just to give you an update. I ended up not
using FormSets. They seem to be more geared toward a single save
button for the page and I wanted to force them to save each payment
individually. Tthe feedback is quick and it comes across as the line
just changing from editable to not. Though it was good to review the
FormSets.

I think I'm just about ready for testing. I just have a few for
strange bugs to work out, like why the errors output isn't being
wrapped in a ul tag. I think I can see the light. :o)

Thanks again for your time.
--~--~-~--~~~---~--~~
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: Customizing context by opening up BoundField, is it ok?

2009-07-23 Thread Joshua Russo

On Jul 23, 12:41 am, Russell Keith-Magee 
wrote:
> The decision about splitting this into more than one view is
> approaching an 'inmates running the asylum' issue [1]. Work out what
> UI will work for your users. Then work out how to make that
> implementation work. Don't let the implementation drive the UI.
>
> [1]http://www.amazon.com/Inmates-Are-Running-Asylum/dp/0672316498

Oh ya, I bought the book too. :o) I think I have a tendency to find
myself in this trap.
--~--~-~--~~~---~--~~
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: ImageField questions

2009-07-23 Thread Joshua Russo
On Thu, Jul 23, 2009 at 9:31 PM, Rusty Greer  wrote:

>
> how do i create a query on the size of an image?
>
> for example:
> class Image(models.Model):
>
>image = models.ImageField(upload_to=upload_to('images'), db_index=True)
>
>
> if i try something like:
>
>for image in Image.objects.filter(image__height_field__gte=100):
>  # do something
>
> i get the following error:
>
> django.core.exceptions.FieldError: Join on field 'image' not permitted.


The filters are translated into SQL for the database and the database
doesn't have a mechanism for reading the image properties. As far as the db
is concerned it's just another binary field. What I would recommend is to
create columns for extra information like height and width. Then you can
override your Image model's save method and extract information and save it
into the column automatically.

class Image(models.Model):
   image = models.ImageField(upload_to=upload_to('images'), db_index=True)
   height = models.IntegerField()
   width = models.IntegerField()

   def save(self, force_insert=False, force_update=False):
# The following is sudo code, I have no experience with image
objects
self.height = self.image.height
self.width = self.image.width
super(Image, self).save(force_insert, force_update) # Call the
"real" save() method.
*
*
*You can read more about models and all the cool stuff  you can do with them
here:
http://docs.djangoproject.com/en/dev/topics/db/models/#topics-db-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-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: problem with forms, ForeignKey, get_or_create

2009-07-24 Thread Joshua Russo
On Thu, Jul 23, 2009 at 10:53 PM, Nail  wrote:

>
> Hello, developers!
>
> Please help me with one problem. I spent 2 days attempting to solve
> it. And now i have some solution, but i don't like it.
>
> My application manages music tracks.
> There is models: Artist, Album, Track.
> Simply:
>
> class Artist:
>  name = CharField()
>
> class Album:
>  title = CharField()
>  artist = ForeignKey(Artist)
>
> class Track:
>  title = CharField()
>  album = ForeignKey(Album)
>  artist = ForeignKey(Artist)
>
> class FeaturedLink:
>  artist = ForeignKey(Artist)
>  track = ForeignKey(Track)
>  text = CharField()
>
> Some explanations: artist may have several tracks, and track may
> belong to several artists - one primary and some featured (e.g. 50
> cents feat. Justin). text field in FeaturedLink contains "feat.",
> "remix by" etc.
>
> User interface needs to be very simple. For example if user creates
> some album, he enters name of artist(ajax name suggestion helps him),
> title and presses save. If artist with this name doesn't exist, it
> must be created.
> This is not a problem. I create AlbumForm(ModelForm), with artist
> field excluded, define custom char field artist_name. __init__
> provides Initial data for artist_name from instance.artist.name. save
> () method gets artist from existing or creates new
> (Artist.objects.get_or_create(name=artist_name)) and fills
> instance.artist.
>
> Problem is in TrackForm. Primary artist is being filled in without
> problems. But featuredlink_set uses InlineFormSet to be able to edit
> any number of featured links in one form. Inline form set uses default
> ModelForm instances for each model instance. So there will be
> ChoiceField for artist field in FeaturedLink. But i need simple char
> field with behavior as in album form. But i don't find a way to do
> this. Changing a form for InlineFormSet doesn't help, formset never
> calls save() method of form, it saves objects by oneself. Overriding
> save method of inline form set is very complex. It handles to many
> tasks.
>
> And what a solution i found: create custom form field, that will
> accept char data from request data and clean() it to artist id. But i
> think this is not a true solution, because such field clean will
> change database in validation stage.


Have you tried the save_formset of the ModelAdmin?
http://docs.djangoproject.com/en/dev/ref/contrib/admin/

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



Re: Django, multiple domains, multiple locales/languages

2009-07-24 Thread Joshua Russo
I ran into some conceptual problems with lazy vs non-lazy too. Any global
context needs to be lazy. This includes everything declared outside of any
function or class context and the class instance variable declarations (tho
not the declarations made in __init__ or __new__ of a class)
On Fri, Jul 24, 2009 at 10:34 AM, MS  wrote:

>
>
> OK, thanks for suggestion - however it seems the problem was somewhere
> else - I was using ugettext where ugettext_lazy was supposed to be
> used (ex. in forms.py).
> The documentation should be more clear that the choice between
> ugettext and ugettext_lazy is quite important and may lead to strange
> problems.
>
>
> > If me, I would seperate those settings binding to domain from those not.
> > And create setting module for each domain.
> > Then in different virtual host configuration, just set setting module
> > pointing to different setting.py
> >
> > Just my opinion, sorry if it doesn't work for 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: fastcgi memory usage

2009-07-26 Thread Joshua Russo
On Sat, Jul 25, 2009 at 9:23 PM, Adi  wrote:

>
> I'm running a couple of django sites on a VPS with nginx and fastcgi
> and I'm a little concerned because of the memory usage.
> According to the "free" command, each site uses about 50MB of RAM
> (I've ran free before and after starting the fastcgi daemons and each
> sites seems to use the same amount).
> ps aux on the other hand says each daemon is using about 15MB (the RSS
> and MEM% fields)
> I'm not too sure how to interpret these results. am I doing something
> wrong, or is this normal? is the actual memory usage 50MB? I tried
> searching about "free" and "ps aux" but didn't find anything about why
> there's this discrepancy. should I use mod_wsgi instead?
> the command used to start the daemons is:
> ./manage.py runfcgi method=threaded host=127.0.0.1 port=11003 pidfile=/
> some/pid/file


It's been a while since I used FastCGI but look into the configuration and
you should be able to control the amount of memory each process uses. I
believe it's just a value you can change somewhere.

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

2009-07-26 Thread Joshua Russo
On Sun, Jul 26, 2009 at 9:13 PM, Vitaly Babiy  wrote:

> How does one go about registering a namespace?


Not quite sure what you mean by that, but my guess is that you are assuming
you need to register your namespace (modules?) before being able to import
them. If this is what you are asking, you don't. The import dot notation is
simply the directory structure, optionally followed by the file, optionally
followed by the object within the file.

It will use the PythonPath list variable to try to find the namespaces you
are referring to. This includes directories in python and your project.

For example, in my urls.py I have:
from django.contrib import admin

urlpatterns = patterns('',
(r'^admin/(.*)', admin.site.root)

This could also be written as:
from django.contrib.admin.site import root

urlpatterns = patterns('',
(r'^admin/(.*)', root)

This (roughly) represents:
C:\python25\Lib\site-packages\django\contrib\admin\site.py (function root())

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



Lazy translation needs help in model.save()?

2009-07-28 Thread Joshua Russo
I'm raising an error in one of my model save forms and it's not converting
the translation string to unicode. If I first pass it into the unicode()
function it works though. The following is the pertinent portions of my
model class.
class Matriz(modelUtils.MyModelAudit):

ULTIMOANO_MISSING_ERROR = _("You need to provided an ending year for a
nulled property.")

def save(self, force_insert=False, force_update=False):
if self.Anular and not self.UltimoAno:
raise ValidationError(unicode(self.ULTIMOANO_MISSING_ERROR))
super(Matriz, self).save(force_insert, force_update)

Without the call to unicode() here I recieve the following:


I used a class property because I use the string in my form validation as
well and it works just fine there.

Is this a bug or am I doing something 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-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: Lazy translation needs help in model.save()?

2009-07-28 Thread Joshua Russo

On Jul 28, 2:00 pm, Joshua Russo  wrote:
> I'm raising an error in one of my model save forms and it's not converting
> the translation string to unicode. If I first pass it into the unicode()
> function it works though. The following is the pertinent portions of my
> model class.
> class Matriz(modelUtils.MyModelAudit):
>
>     ULTIMOANO_MISSING_ERROR = _("You need to provided an ending year for a
> nulled property.")
>
>     def save(self, force_insert=False, force_update=False):
>         if self.Anular and not self.UltimoAno:
>             raise ValidationError(unicode(self.ULTIMOANO_MISSING_ERROR))
>         super(Matriz, self).save(force_insert, force_update)
>
> Without the call to unicode() here I recieve the following:
> 
>
> I used a class property because I use the string in my form validation as
> well and it works just fine there.
>
> Is this a bug or am I doing something wrong?

Sorry, missed the gettext import.

from django.utils.translation import ugettext_lazy as _
--~--~-~--~~~---~--~~
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: ModelForm and saving with excluded Fields

2009-07-28 Thread Joshua Russo
On Tue, Jul 28, 2009 at 8:58 PM, Streamweaver wrote:

>
> To be clear.  Essentially I just want to merge the object instance and
> POST data with the POST data overwriting the instance where it's
> supplied.  Right now if I don't supply a field in my POST data it just
> submits null values.
>
> Thanks again and sorry for any repetition or frustration.
>
> On Jul 28, 5:25 pm, Streamweaver  wrote:
> > I have been struggling with this for a few weeks without resolution
> > and hope someone can help me.
> >
> > I have a model that I edit via a form but the field returned for
> > editing vary depending on the user permissions and group.
> >
> > When I bind a form to POST data some fields may or may not be included
> > in that post.  All I really want to do is take the model I'm editing,
> > change anything submitted by the POST data and leave the rest as is
> > but I don't seem to be able to find a way to do this without having to
> > explicitly declare each field.  Is there a way around this or
> > something I'm missing.
> >
> > Thanks in advance for any help.
>

Take a look here and pay close attention to the section "Using a model
formset in a view"
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/

You should also look here. It's the more generic way forms without tying it
to a given model
http://docs.djangoproject.com/en/dev/topics/forms/#topics-forms-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-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: ANN: Django 1.1 released!

2009-07-29 Thread Joshua Russo
On Wed, Jul 29, 2009 at 5:23 AM, James Bennett wrote:

>
> Tonight we're extremely proud to announce the release of Django 1.1,
> the latest major milestone in Django's development.
>
> To learn about the new release:
>
> * Blog post: http://www.djangoproject.com/weblog/2009/jul/29/1-point-1/
> * Release notes: http://docs.djangoproject.com/en/dev/releases/1.1/
> * Download: http://www.djangoproject.com/download/
>

Congratulations! Can't wait to try it out!

--~--~-~--~~~---~--~~
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: inspectdb and MySQL

2009-07-29 Thread Joshua Russo
On Wed, Jul 29, 2009 at 12:35 PM, Juanjo Conti  wrote:

>
> In http://docs.djangoproject.com/en/dev/ref/django-admin/ i read
> "inspectdb works with PostgreSQL, MySQL and SQLite. Foreign-key
> detection only works in PostgreSQL and with certain types of MySQL
> tables."
>
> Could you tell me the preferred MySQL table types?


InnoDB

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



sqlcustom example?

2009-07-29 Thread Joshua Russo
I'm confused about how sqlcustom fits into the dbsync process.
I ran "manage.py sqlcustom myapp" and it printed the sql properly but that's
all it did. Granted that's all the docs say it does anyway, but then how do
execute those statements?

--~--~-~--~~~---~--~~
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: inspectdb and MySQL

2009-07-29 Thread Joshua Russo
On Wed, Jul 29, 2009 at 2:39 PM, Juanjo Conti  wrote:

> 2009/7/29 Joshua Russo :
> > On Wed, Jul 29, 2009 at 12:35 PM, Juanjo Conti 
> wrote:
> >>
> >> In http://docs.djangoproject.com/en/dev/ref/django-admin/ i read
> >> "inspectdb works with PostgreSQL, MySQL and SQLite. Foreign-key
> >> detection only works in PostgreSQL and with certain types of MySQL
> >> tables."
> >>
> >> Could you tell me the preferred MySQL table types?
> >
> > InnoDB
>
> Thanks, shoudn't this be included in the documentation?


Possibly

>

--~--~-~--~~~---~--~~
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: sqlcustom example?

2009-07-29 Thread Joshua Russo

On Jul 29, 12:48 pm, Joshua Russo  wrote:
> I'm confused about how sqlcustom fits into the dbsync process.
> I ran "manage.py sqlcustom myapp" and it printed the sql properly but that's
> all it did. Granted that's all the docs say it does anyway, but then how do
> execute those statements?

For anyone else who runs into this, the docs are a little lacking. The
rest subcommand is what actually executes the custom sql. I haven't
tried it yet though. I will let you know how it works when I get back
into work tomorrow.
--~--~-~--~~~---~--~~
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: Threaded application + IntegrityError

2009-07-31 Thread Joshua Russo
On Fri, Jul 31, 2009 at 12:41 PM, ramya  wrote:

>
> Hi,
> I have python threaded application + Postgres. I am using Django's ORM
> to save to Postgres..
> I have concurrent save calls. Occasionally 2 threads save with the
> same primary key which leads to an issue.
>
> Postgres log:
> ERROR:  duplicate key value violates unique constraint "store_pkey"
> STATEMENT:  INSERT INTO "store" ("store_id", "address") VALUES
> (E'HAN277', E'101 Ocean Street')
>
> Code:
> In the code I see an IntegrityError. I tried different ways to handle
> this.
>
> a.
> try:
>  a.save()
> except IntegrityError:
>  pass
>
> This causes InternalError
>
> b. Tried to do transaction roll back.. but not sure.. As far as I
> understand you need to distinct save calls to have transactions
>
>  sid = transaction.savepoint()
>  try:
>row.save()
>  except IntegrityError, e:
>transaction.savepoint_rollback(sid)
>pass
>  transaction.commit()
> The first savepoint fails with
>
> AttributeError: 'NoneType' object has no attribute 'cursor'
>
>
> a. I read somewhere django is not 100% thread safe. Is it a good
> choice in my usecase. I was already using Django for other application
> and need an ORM.. So naturally I chose Django
> b. How to handle this situation.. Any comments.


One trick you could try is:

try:
 a.save()
except IntegrityError:
 wait(.1)
 a.save()

This generally only works for lightly used multi-threaded application, and
you should be able to embed the Try-Except blocks to try more than twice.

--~--~-~--~~~---~--~~
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: is Django a good choice for a LAN app?

2009-08-11 Thread Joshua Russo
On Tue, Aug 11, 2009 at 6:06 PM, snfctech  wrote:

>
> I'm about to start a fairly large project for a mid-sized business
> with a lot of integration with other systems (POS, accounting,
> website, inventory, purchasing, etc.) The purpose of the system is to
> try to reduce current data siloing and give employees role-based
> access to the specific data entry and reports they need, as well as to
> replace some manual and redundant business processes. The system needs
> to be cross-platform (Windows/Linux), open source and is primarily for
> LAN use.
>
> My experience is mostly PHP/web/app development, but I have developed
> a few LAN apps using Java/Servoy (like Filemaker). I am leaning
> towards Python/Django - but wondering whether this may be
> unnecessarily web-specific. I really felt Servoy development was very
> rapid, and it was cross-paltform, but it was not open source (not to
> mention that anything custom needed to be Java which I find too
> verbose/ slow to develop in). Or maybe Open Office Base and some
> scripting is sufficient to handle my needs.
>
> So, my main question is: Does a web framework like Django sound like a
> reasonable platform to build a LAN Dashboard for a mid-sized company?
> Or am I thinking too much like a web developer?
>
> Any tips or suggestions would be greatly appreciated.


I'm going to second Antoni's take. Django and Python is probably about the
best choice you could make. Python has all the functionality you could
possibly need (and more if you really get into stuff like meta classes) and
Django just makes the entire development process a breeze.

With that said, it sounds like you want to connect to multiple DBs from a
single app. I don't have experience in the Django environment with multiple
db connections, though I know there is work being done in that direction.
Hopefully someone else here can shed more light on that.

What I would look at for now would be the connectivity availability to your
other systems. You can find info about Django direct support here:
http://docs.djangoproject.com/en/dev/ref/databases/#ref-databases

Though even if it's an odd type of storage system or the need for multiple
connections there should be way to do what needs to be done in Python.

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



Cursor resource cleanup?

2009-08-13 Thread Joshua Russo
Do you need to do any cleanup of resources when you use a cursor (closing of
connection/cursor)?
I have the following method, do I need to do anything to cleanup resources?

def get_next_NumOrd(self):
from django.db import connection
cursor = connection.cursor()
cursor.execute("SELECT COALESCE(max(NumOrd), 1000) FROM matriz_matriz")
row = cursor.fetchone()
return (row[0] + 1)

--~--~-~--~~~---~--~~
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: Logging mechanism in Django

2009-08-17 Thread Joshua Russo
On Mon, Aug 17, 2009 at 1:56 PM, Lokesh  wrote:

>
> I am trying to implement the logging (Code flow tracking) for my
> Django application.
> I would like to store the log messages on daily basis for my
> applications.
>
> Need help or suggestions on how we can implement the logging mechanism
> for an application.


 Are you using the Python logging library or are you trying to create your
own?
http://docs.python.org/library/logging.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-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: Logging mechanism in Django

2009-08-17 Thread Joshua Russo
On Mon, Aug 17, 2009 at 2:17 PM, Lokesh  wrote:

> I am trying to implement logging mechanism using Python library. But,
> I am not sure on which mechanism/methodology used for Django
> applications.
>
> Is there any predefined process or methodology to be followed for
> Django applications for logging mechanism.
>

Not that I know of. Logging isn't really the realm of Django. Though
conversely it won't meddle with your logging functionality. You are free to
do what ever you would like to with your logging.

--~--~-~--~~~---~--~~
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: error message in admin

2009-08-18 Thread Joshua Russo
On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus  wrote:

>
> Hello,
>
> Im doing some validation in ModelAdmin.save_model(). I can cancel
> operation (just dont call parent method), but I also need to show some
> error message to user. Im able to call self.message_user() and show
> INFO message, but how to send ERROR message and maybe show form back
> and force user to correct inputs?
>
> I need validation on level of whole formset, not on field level, so I
> cannot use some custom field to achieve that.
>

What you want is to override the ModelAdmin.form with a custom form and
handle the clean_xxx() methods there. Django form validation is done in the
form objects/classes.

Create a ModelForm (
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then set
your ModelAdmin.form to your new ModelForm.

--~--~-~--~~~---~--~~
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: error message in admin

2009-08-18 Thread Joshua Russo
On Tue, Aug 18, 2009 at 1:23 PM, Marek Palatinus  wrote:

>
> On Tue, Aug 18, 2009 at 12:22 PM, Joshua Russo
> wrote:
> > On Tue, Aug 18, 2009 at 8:52 AM, Marek Palatinus 
> wrote:
> >>
> >> Hello,
> >>
> >> Im doing some validation in ModelAdmin.save_model(). I can cancel
> >> operation (just dont call parent method), but I also need to show some
> >> error message to user. Im able to call self.message_user() and show
> >> INFO message, but how to send ERROR message and maybe show form back
> >> and force user to correct inputs?
> >>
> >> I need validation on level of whole formset, not on field level, so I
> >> cannot use some custom field to achieve that.
> >
> > What you want is to override the ModelAdmin.form with a custom form and
> > handle the clean_xxx() methods there. Django form validation is done in
> the
> > form objects/classes.
> > Create a ModelForm
> > (http://docs.djangoproject.com/en/dev/topics/forms/modelforms/) and then
> set
> > your ModelAdmin.form to your new ModelForm.
> >
>
> Joshua, thanks a lot!
>
> to others: there also exists clean() which have available all fields
> from form at one place.


I often also place checks in the save of a model (like you were doing) to
help catch scenarios when using the models in your own code (outside of the
admin 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-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: Database design question

2009-08-18 Thread Joshua Russo
Yup, that could work too. Let me know what you end up with.

On Tue, Aug 18, 2009 at 9:58 PM, ringemup  wrote:

>
>
> Yes, I think that does make sense.  Thank you!
>
> While pondering this, I also came up with a third option, which is to
> make the alias data part of the Account model, and allow Accounts to
> have parent accounts; then only accounts with no parents are permitted
> to be assigned to users.  (Also prohibiting accounts with parents from
> having children to prevent deeply nested trees.)  I suppose the same
> could be done with the Aliases having parents / children instead of
> the accounts, so as not to have to duplicate other account data.
>
>
> On Aug 18, 6:30 pm, Joshua Russo  wrote:
> > On Tue, Aug 18, 2009 at 8:26 PM, ringemup  wrote:
> >
> > > I have accounts that can have multiple aliases, but each account must
> > > have a primary alias.  I can think of two ways to institute this, but
> > > they both have problems:
> >
> > > 1) reference the primary alias from the account:
> >
> > > class Account(models.Model):
> > >  ...
> > >  primary_alias = models.OneToOneField('Alias',
> > > related_name='accout_if_primary')
> >
> > > class Alias(models.Model):
> > >  name = models.CharField(max_length=50, primary_key=True)
> > >  account = models.ForeignKey(Account)
> >
> > > The trouble with this approach is that basically you can't create an
> > > account without an alias, and you can't create an alias without an
> > > account because of what amount to circular references, so you
> > > essentially can't add any data.
> >
> > > 2) Assign primary status to the alias:
> >
> > > class Account(models.Model):
> > >  ...
> >
> > > class Alias(models.Model):
> > >  name = models.CharField(max_length=50, primary_key=True)
> > >  account = models.ForeignKey(Account)
> > >  is_primary = models.BooleanField(default=False)
> >
> > > The trouble here is that it is a real pain to enforce that each
> > > account has a primary alias (in fact you have to initially create an
> > > account with no aliases and then create aliases and add them to it).
> > > Additionally, enforcing a limit on the number of aliases is
> > > problematic.  Finally, even if you do enforce these constraints
> > > programmatically, it doesn't seem to be feasible to relay error
> > > messages to contrib.admin.
> >
> > > Has anyone else encountered this design problem, and how did you go
> > > about addressing it?
> >
> > I have experienced this situation a couple of times and I would recommend
> > the second option you discussed. Circular referenced like your first
> option
> > can become very problematic and are not recommended from a database
> design
> > perspective.
> >
> > What I would recommend is to create an Alias record automatically when a
> new
> > Account is created. You can do this in the save of the Account model or
> with
> > signals.
> http://docs.djangoproject.com/en/dev/ref/models/instances/http://docs.djangoproject.com/en/dev/ref/signals/
> >
> > Then in the save of the Alias you can manage the primary flag. I just
> check
> > to see if the current record being saved has primary set, if so then I
> reset
> > all others for (in your case) the account to not primary. The only other
> > case is if the current alias isn't set as primary, check to see if there
> are
> > any primary aliases yet and if not automatically set the current one as
> > primary.
> >
> > Ya, it's a little tricky but it's worth not having the headache of the
> > circular reference.
> >
>

--~--~-~--~~~---~--~~
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: Database design question

2009-08-18 Thread Joshua Russo
On Tue, Aug 18, 2009 at 8:26 PM, ringemup  wrote:

>
> I have accounts that can have multiple aliases, but each account must
> have a primary alias.  I can think of two ways to institute this, but
> they both have problems:
>
> 1) reference the primary alias from the account:
>
> class Account(models.Model):
>  ...
>  primary_alias = models.OneToOneField('Alias',
> related_name='accout_if_primary')
>
> class Alias(models.Model):
>  name = models.CharField(max_length=50, primary_key=True)
>  account = models.ForeignKey(Account)
>
> The trouble with this approach is that basically you can't create an
> account without an alias, and you can't create an alias without an
> account because of what amount to circular references, so you
> essentially can't add any data.
>
> 2) Assign primary status to the alias:
>
> class Account(models.Model):
>  ...
>
> class Alias(models.Model):
>  name = models.CharField(max_length=50, primary_key=True)
>  account = models.ForeignKey(Account)
>  is_primary = models.BooleanField(default=False)
>
> The trouble here is that it is a real pain to enforce that each
> account has a primary alias (in fact you have to initially create an
> account with no aliases and then create aliases and add them to it).
> Additionally, enforcing a limit on the number of aliases is
> problematic.  Finally, even if you do enforce these constraints
> programmatically, it doesn't seem to be feasible to relay error
> messages to contrib.admin.
>
> Has anyone else encountered this design problem, and how did you go
> about addressing it?
>

I have experienced this situation a couple of times and I would recommend
the second option you discussed. Circular referenced like your first option
can become very problematic and are not recommended from a database design
perspective.

What I would recommend is to create an Alias record automatically when a new
Account is created. You can do this in the save of the Account model or with
signals.
http://docs.djangoproject.com/en/dev/ref/models/instances/
http://docs.djangoproject.com/en/dev/ref/signals/

Then in the save of the Alias you can manage the primary flag. I just check
to see if the current record being saved has primary set, if so then I reset
all others for (in your case) the account to not primary. The only other
case is if the current alias isn't set as primary, check to see if there are
any primary aliases yet and if not automatically set the current one as
primary.

Ya, it's a little tricky but it's worth not having the headache of the
circular reference.

--~--~-~--~~~---~--~~
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: Database design question

2009-08-19 Thread Joshua Russo
On Tue, Aug 18, 2009 at 11:04 PM, ringemup  wrote:
>
> Well, I'm trying to implement parent / child aliases, but I'm running
> into problems with class declaration order because I need to reference
> the Alias class from within the Account class as well as referencing
> Account from Alias for validation purposes -- and not just in
> ForeignKey declarations and such.
>
> Since one will always have to be declared before the other, is there
> any way to do this?


What I would recommend is to drop the ForeignKey in the Account table. You
can always retrieve the set of Aliases for an Account based on the
ForeignKey from Alias to Account. I believe that you will even be able to
access Account.alias_set in your code, though if not you can always get
Alias.objects.filter(Account_id=xx) and for the primary you will be able to
say either Account.alias_set.filter(parent__isnull=True)or
Alias.objects.filter(Account_id=xx).filter(parent__isnull=True)

--~--~-~--~~~---~--~~
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: Adding model-specific exceptions like DoesNotExist?

2009-08-19 Thread Joshua Russo
On Wed, Aug 19, 2009 at 12:56 PM, Idan Gazit  wrote:

>
> Hey all,
>
> I'd like to add some custom exception to a model of mine,
> Foo.FrobNotAllowed, along the lines of ModelName.DoesNotExist.
>
> From looking at models/base.py, it looks like the pattern is to
> override __new__() and use add_to_class. Something like:
>
> def __new__(cls, name, bases, attrs):
>new_class = super(MyModel, cls).__new__(cls, name, bases, attrs)
>abstract = getattr(attr_meta, 'abstract', False)
>if not abstract:
>new_class.add_to_class('FrobNotAllowed', MyExceptionClass)
>return new_class
>
> Is this the pattern I should be emulating for the kind of thing I'm
> seeking?


All you really need is:

class DoesNotExist(Exception):
pass

I generally create a Utils app in my project with a modelUtils.py where I
put things like that. Then you can just import the exception and use it in
any of your models.py files.

--~--~-~--~~~---~--~~
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: Adding model-specific exceptions like DoesNotExist?

2009-08-19 Thread Joshua Russo
In that case you can create an abstract model class and use that instead of
models.Model:
class MyModel(models.Model):
class Meta:
abstract = True

class DoesNotExist(Exception):
pass


On Wed, Aug 19, 2009 at 1:22 PM, Idan Gazit  wrote:

>
> Yes, and then I also need to import that class into every place that I
> want to use it, no?
>
> The benefit of making it part of the model is that any place I'm using
> it, I already have the exception handy:
>
> try:
># ... do some things
>m = MyModel(foo=bar, baz=bling)
>m.save()
> except MyModel.FrobNotAllowed:
># handle the exception...
>
> It's not a big deal but I figured that emulating the framework isn't a
> bad idea.
>
> On Aug 19, 5:03 pm, Joshua Russo  wrote:
> > All you really need is:
> >
> > class DoesNotExist(Exception):
> > pass
>
> >
>

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



Re: Database design question

2009-08-19 Thread Joshua Russo
You can, it just creates headaches. At least one of the ForeignKeys needs to
not be required (I believe that's the default anyway).

On Wed, Aug 19, 2009 at 1:27 PM, ringemup  wrote:

>
>
> Is having two classes that reference one another just simply something
> that can't be done in Python?
>
>
> On Aug 19, 4:36 am, Joshua Russo  wrote:
> > On Tue, Aug 18, 2009 at 11:04 PM, ringemup  wrote:
> >
> > > Well, I'm trying to implement parent / child aliases, but I'm running
> > > into problems with class declaration order because I need to reference
> > > the Alias class from within the Account class as well as referencing
> > > Account from Alias for validation purposes -- and not just in
> > > ForeignKey declarations and such.
> >
> > > Since one will always have to be declared before the other, is there
> > > any way to do this?
> >
> > What I would recommend is to drop the ForeignKey in the Account table.
> You
> > can always retrieve the set of Aliases for an Account based on the
> > ForeignKey from Alias to Account. I believe that you will even be able to
> > access Account.alias_set in your code, though if not you can always get
> > Alias.objects.filter(Account_id=xx) and for the primary you will be able
> to
> > say either Account.alias_set.filter(parent__isnull=True)or
> > Alias.objects.filter(Account_id=xx).filter(parent__isnull=True)
> >
>

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



Python FOR loop syntax question

2009-08-21 Thread Joshua Russo
Why does this not work?
  >>> import decimal
  >>> tst = {'myTst': (decimal.Decimal, 0)}
  >>> for k, v in tst:
  ...  print('%s: %s' % (k, v))
  ...
  Traceback (most recent call last):
File "", line 1, in 
  ValueError: too many values to unpack
  >>>

I'm assuming the problem is with the tuple. How do I itterate through a
dictionary with a tuple as it's 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-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: Python FOR loop syntax question

2009-08-21 Thread Joshua Russo
Gotcha, Thanks guys

On Fri, Aug 21, 2009 at 8:28 PM, Randy Barlow wrote:

>
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> Joshua Russo declared:
> > Why does this not work?
> >   >>> import decimal
> >   >>> tst = {'myTst': (decimal.Decimal, 0)}
> >   >>> for k, v in tst:
> >   ...  print('%s: %s' % (k, v))
> >   ...
> >   Traceback (most recent call last):
> > File "", line 1, in 
> >   ValueError: too many values to unpack
> >   >>>
> >
> > I'm assuming the problem is with the tuple. How do I itterate through a
> > dictionary with a tuple as it's value?
>
> Try this instead:
>
> >>> import decimal
> >>> tst = {'myTst': (decimal.Decimal, 0)}
> >>> for key in tst.keys():
> >>> print('%s: %s'%(tst[key][0], tst[key][1]))
>
> - --
> Randy Barlow
> Software Developer
> The American Research Institute
> http://americanri.com
> 919.228.4971
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v2.0.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iEYEARECAAYFAkqPEZAACgkQw3vjPfF7QfXq2wCgkmYmswYSqRdvUMuUQMw1gou8
> 3t8AoIjmSFub7TW+Cv5RhHxhlmDkt9Xa
> =klxH
> -END PGP SIGNATURE-
>
> >
>

--~--~-~--~~~---~--~~
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: Reusable/plugable apps integrations best practices

2009-08-23 Thread Joshua Russo
You need to remove the references on one side or the other. You need to make
a choice. will events manage photos, or will photos manage events, and so
on. Then if events manage photos, you need to remove all references to
events from the photos app.
It sounds like it will take some reworking of your application logic, but
that's the nut of it.


On Sun, Aug 23, 2009 at 8:53 AM, Andrea Zilio  wrote:

>
> I'm intrested in the answer too
>
> On Aug 23, 1:36 am, "Chris H."  wrote:
> > So I'm trying to get my head around making my small, tightly focused
> > apps reusable.  I've done this, but right now still have
> > "dependencies" between one another, that I'd like to remove.  For
> > simplicity sake, I have an Articles, Events, and Photos app.
> >
> > Right now each Article has a photos.photo and events.event foreign key
> > relationship and each event has a photos.photo_set fk relationship.
> > Thus, as currently written all three apps are required.  I'd like to
> > rework this such that the installation of each application is not
> > required, and I'd think that additional functionality should live in
> > the newer app.
> >
> > That is, when Photos gets "installed" it looks for Articles, if that
> > is installed it hooks into the Photos model to supply the photo
> > relationship.  And if Events is installed, it'll provide the photoset
> > relationship.  If neither is installed, that's okay too, it just
> > provides it's base functionality.  When Events gets installed, it
> > looks for Articles, and if so allows you to relate an article to an
> > event.
> >
> > Surely, this has done before, right?  Or am I approaching it wrong?
> > My google foo fails me...what do I need to be searching for??
> >
>

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



Test client and form processing

2009-08-25 Thread Joshua Russo
I'm working on putting together parsing logic so that I can extract the form
variables from the response content of the test Client. That way I can just
change a few values and throw it back at the server. This is especially
helpful with large dynamic forms that use formsets.
My question is, has this already been done? My Google-fu came up with nada.

--~--~-~--~~~---~--~~
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: Test client and form processing

2009-08-25 Thread Joshua Russo
Ya, when I'm writing unit tests for my forms. What I wanted was a way in my
testing logic to generate a dictionary of values to post back to the server
based on the initial values of the forms in the content property of the
response object returned from the test client get() and/or post() methods.
Here is the current response object definition
http://docs.djangoproject.com/en/dev/topics/testing/#testing-responses

<http://docs.djangoproject.com/en/dev/topics/testing/#testing-responses>I
actually just finished my work on extracting them (or at least a first pass)
today:
http://dpaste.com/hold/85281/

The following is basic usage. As you can see, it simplifies the generation
of values for post or get.

def test_htmlParse(self):

response = self.client.get('/test/')
self.failUnlessEqual(response.status_code, 200, 'Failed to retrieve
the form test page. (1)')

curVals = response.form_values['frmTest']

response = self.client.post('/test/', curVals)
self.failUnlessEqual(response.status_code, 200, 'Failed to retrieve
the form test page. (2)')


On Tue, Aug 25, 2009 at 7:44 PM, Peter Bengtsson  wrote:

>
> Do you mean when you write tests?
> If so, when you get the response you can extract all the variables
> that was created inside the view if you're using locals().
> That way, you can probably get the form instance (created for example
> by form=MyForm(request.POST)) which you can then untangle to get all
> the fields from the form instance.
>
> On Aug 25, 4:31 pm, Joshua Russo  wrote:
> > I'm working on putting together parsing logic so that I can extract the
> form
> > variables from the response content of the test Client. That way I can
> just
> > change a few values and throw it back at the server. This is especially
> > helpful with large dynamic forms that use formsets.
> > My question is, has this already been done? My Google-fu came up with
> nada.
> >
>

--~--~-~--~~~---~--~~
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: Renaming displayed django application name in admin

2009-09-01 Thread Joshua Russo
On Tue, Sep 1, 2009 at 1:10 AM, Joshua Partogi wrote:

> Dear all,
> How do we change the displayed application name in django admin? Let's say
> I have an application called foo, I wanted it to be displayed as bar instead
> of foo in the admin system.
>
> I've searched the document but failed to get the answer for this.
>
> Thank you in advance for your help.
>

It's in the tutorial. In the docs\intro\ directory you will find 4 tutorial
files that are very worth going through, even if you already know some of
the stuff.

--~--~-~--~~~---~--~~
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: user disappearing when saved

2009-09-01 Thread Joshua Russo
On Tue, Sep 1, 2009 at 5:52 AM, nbv4  wrote:

>
> (Pdb) f0
> 
> (Pdb) f0.cleaned_data
> {'ipc': False, 'xc': 0, 'app': 0, 'pic': 0, 'cfi_checkride': False,
> 'dual_r': 0, 'date': datetime.date(2009, 9, 5), 'dual_g': 0, 'total':
> 5.5996, 'id': None, 'sic': 0, 'night_l': 0, 'holding':
> False, 'act_inst': 0, 'pilot_checkride': False, 'solo': 0,
> 'flight_review': False, 'sim_inst': 0, 'plane': ,
> 'user': , 'remarks': u'', 'tracking': False, 'day_l': 0,
> 'route': , 'person': u'', 'night': 0}
> (Pdb) f=f0.save(commit=False)
> (Pdb) f
> 
> (Pdb) f.user
> *** DoesNotExist:
> (Pdb)
>
>
> What on earth could be causing this? According to cleaned_data, the
> user field is valid. Why the heck is the flight being created not
> having a valid user?
>
> The form in question is coming from a heavily customized modelformset
> where the queryset parameter is set to
> Flight.objects.get_empty_query_set(), and extra parameter is set to
> 20. So it's essentially 20 blank fields. When I use this same
> modelformset with a full queryset and extra set to 0, the formset
> saves just fine.
>
> The Flight form looks like this:
>
> ###
> class FlightForm(ModelForm):
>user = forms.ModelChoiceField(queryset=User.objects.all(),
> widget=HiddenInput)
>[...]
> ###
>
> and in the view I have this:
>
> ###
>if request.POST.get('submit'):
>post = request.POST.copy()
>for pk in range(0, profile.per_page):
>if post["form-" + str(pk) + "-date"]:
>post.update({"form-" + str(pk) + "-user": str
> (request.user.pk)})
>else:
>post.update({"form-" + str(pk) + "-user": u''})
>
>formset = NewFlightFormset(post,
> queryset=Flight.objects.get_empty_query_set())
>
>if formset.is_valid():
>import pdb; pdb.set_trace()
>formset.save()
> ###
>
> any ideas?


Why are you using commit=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-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: user disappearing when saved

2009-09-01 Thread Joshua Russo
On Tue, Sep 1, 2009 at 10:09 AM, buttman  wrote:

>
> On Sep 1, 4:52 am, Joshua Russo  wrote:
> >
> > Why are you using commit=False?
>
> If I don't, I get a database error saying "user_id column can't be
> null".


You might want to look at the clean methods of the form to set the user.
These should only trigger if there is something in the form to save. Some
how it's trying to save the extra forms but I don't know why.

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



Here's a more flexable formset I just posted

2009-09-01 Thread Joshua Russo
If you ever wanted to create formsets without needing to know all of the
initial data at once, this might help you out.
http://www.djangosnippets.org/snippets/1711/

I used it in a data entry table where the forms of the formset were
intermingled with rows of already created data. I tried to do it without a
formset at first but using JavaScript is impossible unless you have decent
names/ids for fields. I almost created my own formset object but the changes
I needed to make to the formset provided turned out to be minimal enough.

Let me know what you think. I was actually thinking of submitting it to the
project too, but I wanted to see what kind of reaction it got first.

Thanks
Josh

--~--~-~--~~~---~--~~
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 field vs Form field vs Widget

2009-09-03 Thread Joshua Russo
On Thu, Sep 3, 2009 at 1:11 PM, alexandre...@gmail.com <
alexandre...@gmail.com> wrote:

>
> Hi, I'm a newbie on Django and would like a reference reading on model
> fields, form fields and widgets.
>
> For example I want to have a model field called CountryField that
> automatically in forms displays as a bombobox with country options.
>
> Furthermore, I want to develop a Zip Code field like the country field
> with one difference the table of Zip Codes has over a million records
> so I want do develop a widget that popus another form that let me
> search over that huge amount of records and fills back do the field.
>
>
> I just want to create model classes with special fields, and they know
> how to display themselves in forms.


The online docs are the best place to start

Models and model fields:
http://docs.djangoproject.com/en/dev/topics/db/models/
http://docs.djangoproject.com/en/dev/ref/models/fields/
http://docs.djangoproject.com/en/dev/howto/custom-model-fields/

Forms and form fields:
http://docs.djangoproject.com/en/dev/topics/forms/
http://docs.djangoproject.com/en/dev/ref/forms/fields/
http://docs.djangoproject.com/en/dev/ref/forms/validation/

Widgets:
http://docs.djangoproject.com/en/dev/ref/forms/widgets/

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



Problem with content type creation order and data recovery scheme

2009-09-04 Thread Joshua Russo
My goal here is to create a backup and recovery scheme, where recovery is
possible on any computer.

I've been performing incremental updates to an application that people have
started to use. The incremental updates seem to have created a problem for
the dump and load data functions when trying to reload into a fresh
database. I tried to use dump data to create an __ initial __ .json file,
but I received a duplication error on load, I think from the unique index
(not the primary key) on the content type. I believe this is because
the tables (and thus content types) are created in a different order when
doing a syncdb from scratch, as opposed to incrementally on the old
production machine.
One possible solution is to create a DB without any of the application data,
only with the Django meta data. Then I could just dump and load my
application data afterward. The only issue with that is that I would really
like to be able to save the admin log.

My brute force solution to this looks like it will end up being to drop all
the FKs pointing at content type, update the IDs in the content type table
and all referencing tables to match a fresh syncdb, then recreate the FKs.
This is definitely not the most elegant solution.

I thought that dump data would work for a backup mechanism but it seems to
break with application modifications (table additions) too easily.

I see a real and an other potential problem here.
Real: The manual operation to create content types in the correct order
belies an automated process to do so.
Potential: Even after the operation is done, the records seem to be dumped
in random order in the json file. I'm not sure that after my operation they
will be dumped in the same order. If they aren't then I believe I'm back to
the same problem.

>From where I stand it looks like the MySQL backup is going to be the way to
go for me.

Firstly, does anyone have a more elegant solution to the dump and load data
problem specifically?
Second, what do you use for a data backup and recovery scheme for your
Django data?

--~--~-~--~~~---~--~~
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: Problem with content type creation order and data recovery scheme

2009-09-04 Thread Joshua Russo
On Fri, Sep 4, 2009 at 10:37 AM, Russell Keith-Magee  wrote:

>
> On Fri, Sep 4, 2009 at 4:57 PM, Joshua Russo
> wrote:
> > My goal here is to create a backup and recovery scheme, where recovery is
> > possible on any computer.
> > I've been performing incremental updates to an application that people
> have
> > started to use. The incremental updates seem to have created a problem
> for
> > the dump and load data functions when trying to reload into a fresh
> > database. I tried to use dump data to create an __ initial __ .json file,
> > but I received a duplication error on load, I think from the unique index
> > (not the primary key) on the content type. I believe this is because
> > the tables (and thus content types) are created in a different order when
> > doing a syncdb from scratch, as opposed to incrementally on the old
> > production machine.
>
> > Firstly, does anyone have a more elegant solution to the dump and load
> data
> > problem specifically?
>
> You've pretty much correctly diagnosed the problem that you are
> experiencing. It's well known to the core, and is logged as #7052.
>
> I've had a solution in mind for a while, but never got around to
> implementing it. However, just before v1.1 was released, a patch was
> offered that implements my proposed solution. I expect this patch (or
> something like it) will be in v1.2.
>
> However, that said...
>
> > Second, what do you use for a data backup and recovery scheme for your
> > Django data?
>
> I'm unclear why normal MySQL backup tools aren't the obvious first
> solution here. Yes, Django does provide data dumping and loading
> tools, but they are primarily designed for small fixtures for tests
> and initial database setup.
>
> I'm not saying that loaddata and dumpdata _can't_ be used on large
> data sets, when you're talking about backing up the entire database,
> the database is going to be able to provide much better tools than
> Django will. Trying to build a backup and recovery system without
> using the tools closest to the data seems like a lot of extra work to
> me.
>
> You also appear to be conflating two separate problems. Talking about
> the fragility of fixtures when the database changes isn't a problem
> specific to fixtures - any data dumping scheme will experience the
> same problems. Some data loading schemes might be more robust to
> simple changes, but for anything other than trivial changes, you're
> going to need a much more sophisticated approach than "dump the data
> and reload it". This is a schema evolution issue, not a backup issue.
>

The reason I was looking at the dump data instead of a MySQL backup is
because it was more obvious to automate. I'm going to take a closer look at
the MySQL backup though.

I have a special case. It's a small app on a computer only connected (via
crossover) to one other. The backup process will include copying onto a pen
drive. There is also the strong likely hood that if they have do have the
need to restore the database, I won't be here.  I'm a volunteer in the Peace
Corps. The app is only suppose to be a stop gap until the national
government brings in their own app,  but that depends on other factors that
could potentially take years. Thus I need to create a simple yet fool proof
process for "disaster recovery".

That said, I see that my only real option should be the MySQL backup and
restore. This is how I ended up moving the data anyway.

--~--~-~--~~~---~--~~
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: Problem with content type creation order and data recovery scheme

2009-09-04 Thread Joshua Russo
On Fri, Sep 4, 2009 at 6:37 PM, James Bennett  wrote:

>
> On Fri, Sep 4, 2009 at 7:35 AM, Joshua Russo
> wrote:
> > The reason I was looking at the dump data instead of a MySQL backup is
> > because it was more obvious to automate. I'm going to take a closer look
> at
> > the MySQL backup though.
>
> I run on PostgreSQL rather than MySQL, but for what it's worth my
> backup scheme is just a little bash script, which runs as a cron job
> each night and:
>
> 1. Runs pg_dump.
> 2. Compresses the result.
> 3. Puts a copy in a local backups directory, and pushes copies to two
> off-site backup systems.
>
> Restoring from this is trivial; all I have to do is create an empty
> database, and pip the dump file to it. The only time I ever used
> fixtures for a dump/restore was when migrating across database
> platforms (e.g., away from MySQL a couple years ago), and that was
> really more of a special case.


Ya, the more I think about it, it's silly to not use the MySQL backup, it's
what it's there for. I'm sure there are some ways I can script 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
-~--~~~~--~~--~--~---



PostgreSQL or MySQL, What are the +'s and -'s?

2009-09-04 Thread Joshua Russo
I personally don't have any experience with PostgreSQL and I'm generally
working in a mixed MS and Linux environment. I'm interested to hear peoples
views on the pluses and minuses of the two different systems. I'm a bit of a
query geek too. How does that play in? I know in MySQL there are limitations
on where you can use subqueries. Is that true with PostgreSQL? (Ya I could
just look that one up but it's just an example.)

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



  1   2   3   >