TemplateSyntaxError exception catches all the rest

2008-04-04 Thread Simone Cittadini

When my app throws some exception I'm no more viewing the nicely 
formatted html.

Actually I'm no more viewing the trace of the exception, all I see, no 
matter what the error is, is attached below:

(I haven't played with settings.py and I don't think is something in my 
code, it happens with every view for every app ...)


Traceback (most recent call last):

  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 
277, in run
self.result = application(self.environ, self.start_response)

  File "/usr/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 
631, in __call__
return self.application(environ, start_response)

  File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 
205, in __call__
response = self.get_response(request)

  File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 
120, in get_response
return debug.technical_500_response(request, *exc_info)

  File "/usr/lib/python2.5/site-packages/django/views/debug.py", line 74, in 
technical_500_response
html = get_traceback_html(request, exc_type, exc_value, tb)

  File "/usr/lib/python2.5/site-packages/django/views/debug.py", line 169, in 
get_traceback_html
return t.render(c)

  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 
176, in render
return self.nodelist.render(context)

  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 
751, in render
bits.append(self.render_node(node, context))

  File "/usr/lib/python2.5/site-packages/django/template/debug.py", line 81, in 
render_node
raise wrapped

TemplateSyntaxError: Caught an exception while rendering: unknown encoding: 
utf_8_euro

Original Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/django/template/debug.py", line 71, in 
render_node
result = node.render(context)
  File "/usr/lib/python2.5/site-packages/django/template/debug.py", line 87, in 
render
output = force_unicode(self.filter_expression.resolve(context))
  File "/usr/lib/python2.5/site-packages/django/template/__init__.py", line 
542, in resolve
new_obj = func(obj, *arg_vals)
  File "/usr/lib/python2.5/site-packages/django/template/defaultfilters.py", 
line 627, in date
return format(value, arg)
  File "/usr/lib/python2.5/site-packages/django/utils/dateformat.py", line 263, 
in format
df = DateFormat(value)
  File "/usr/lib/python2.5/site-packages/django/utils/dateformat.py", line 114, 
in __init__
self.timezone = LocalTimezone(dt)
  File "/usr/lib/python2.5/site-packages/django/utils/tzinfo.py", line 36, in 
__init__
self._tzname = self.tzname(dt)
  File "/usr/lib/python2.5/site-packages/django/utils/tzinfo.py", line 55, in 
tzname
return smart_unicode(time.tzname[self._isdst(dt)], DEFAULT_ENCODING)
  File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line 37, in 
smart_unicode
return force_unicode(s, encoding, strings_only, errors)
  File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line 58, in 
force_unicode
s = s.decode(encoding, errors)
LookupError: unknown encoding: utf_8_euro



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



IDE (UML )

2008-03-07 Thread Simone Cittadini

Since there's an active discussion about ide ..

Back in my java days I was using eclipse with omondo for uml, I really 
miss the uml drawings, someone has some plugin to suggest ?

I've no need for fancy features, just something to draw class and 
sequence diagrams, project is becoming huge and pen and paper is no more 
an option ...

(Last time I tried omondo can only be used with a java project, no way 
of creating a python project with omondo plugin enabled in it)

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



Re: IDE

2008-03-07 Thread Simone Cittadini

Tom Badran ha scritto:
> Do people find eclipse+pydev reliable? I've tried it out a few times 
> over the last year and it never seems to run for more than a few hours 
> without dying. This is both the 3.2 (from eclipse.org 
>  and ubuntu packaged) and 3.3 (from eclipse.org 
> ) using gcj or suns jvm. It does seem quite nice 
> when its running, but my editor crashing on me that often is just 
> unacceptable.
I'm using eclipse+pydev on [k|x]ubuntu, not the packages, both java and 
eclipse downloaded from site and locally installed in my home, never 
crashed.


>
> Tom
>
> On Thu, Mar 6, 2008 at 6:37 PM, Joel <[EMAIL PROTECTED] 
> > wrote:
>
>
> Two thumbs up for Eclipse+PyDev.
>
> Plus all the other Eclipse goodies:
> * Source control integration
> * Aptana for CSS, JS, and HTML editing
>
> PyDev even has a for-pay python debugger, although I don't use it.
>
> -- Joel
>
> Peter Danielczyk wrote:
> > I agree with casseen.
> >
> > Eclipse & Pydev works great for Django.
> >
> > See
> >
> 
> http://pydev.blogspot.com/2006/09/configuring-pydev-to-work-with-django.html
> > for intructions.
> >
> > BTW: " is a memory hungry monster " --> 1 Gig RAM is 20-25
> Dollars :-)
> >
> >
> >
> >
> >> I use eclipse + pydev. Eclipse is a memory hungry monster( it's
> java
> >> based after all), but in my opinion its still the best free and
> open
> >> IDE out there. And its platform independent which is a double extra
> >> plus for eclipse.
> >>
> >> I see no use for a dedicated django plugin. Any python
> supporting IDE
> >> should work fine. Try some different IDEs and see which one
> fits your
> >> personal requirements best.
> >>
> >> By the way the _free_ eclipse/pydev debugger works like a treat
> with
> >> django.
> >>
> >> On Mar 6, 9:24 am, Jarek Zgoda <[EMAIL PROTECTED]
> > wrote:
> >>> gabriel napisa³(a):
> >>>
>  I am at the point of changing IDE before my next project ( a
> huge one
> >>> ).
>  So far I've used Geany for python but now I am supposed to
> use django.
>  Is it anythong with special support for Django??
>  I know that recommendations include SPE and Eclipse but I
> wonder if
> >>> you
>  happened to work with IDE with a nice django support - does
> anything
>  alike exist??
> >>> I use PIDA (http://pida.co.uk/). While it has no explicit Django
> >>> support, embedded Vim pleases me enough (Vim syntax coloring
> for Django
> >>> templates is enough for me --
> >>> seehttp://www.vim.org/scripts/script.php?script_id=1487).
> >>>
> >>> Other options I tried was Komodo Edit (nice project
> management) and Kate
> >>> (overall good editor, but project management plugin is a
> PITA), but
> >>> neither one appealed to me.
> >>>
> >>> --
> >>> Jarek Zgoda
> >>> Skype: jzgoda | GTalk: [EMAIL PROTECTED]
>  | voice: +48228430101
> >>>
> >>> "We read Knuth so you don't have to." (Tim Peters)
> >>>
> >>
> >
> >
> > >
> >
>
>
>
>
>
>
> -- 
> Tom Badran
> http://badrunner.net
> >


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



assertTemplateUsed -> No templates used to render the response

2007-12-21 Thread Simone Cittadini

I'm doing some "poke around" tests just to get used to the framework, 
this error I can't understand :

Wrote a login view :

user = auth.authenticate(username=request.POST['username'],
 password=request.POST['password'])
if user is not None:
  if user.is_active:
auth.login(request, user)
return HttpResponseRedirect('/index/')
  else:
return render_to_response('profiles/disabled.html', locals(), 
RequestContext(request, {}))


If I "manually test" logging in with a disabled user I get this trace :

[21/Dec/2007 11:57:41] "GET /index HTTP/1.1" 301 0
[21/Dec/2007 11:57:41] "GET /index/ HTTP/1.1" 200 1654
[21/Dec/2007 11:57:43] "GET /profiles/login/ HTTP/1.1" 200 2040
[21/Dec/2007 11:57:53] "POST /profiles/login/ HTTP/1.1" 200 1684

and the browser shows the profiles/disabled.html page


While this test method fails:

def testLoginDisabledUser(self):
response = self.client.post('/profiles/login/', {'username': 
'user', 'password': 'pass'})
self.assertEqual(response.status_code, 302)
self.assertTemplateUsed(response, 'profiles/disabled.html')

First of all I don't understand why the 302 I expected 200, put there 
just to go on, and then :

self.assertTemplateUsed(response, 'profiles/disabled.html')
  File "/usr/lib/python2.5/site-packages/django/test/testcases.py", line 
178, in assertTemplateUsed
self.fail('No templates used to render the response')
AssertionError: No templates used to render the response

Where exactly this test is different from my manual login ? (and 
therefore evidently not testing what I want ?)



(other code)

urls.py :

urlpatterns += patterns('dissipate.views',
(r'^index/$',
 'index'),
)

urlpatterns += patterns('dissipate.profiles.views',
(r'^profiles/login/$',
 'login'),
(r'^profiles/logout/$',
 'logout'),
)


disabled.html :
{% extends "base.html" %}

{% block content %}

Disabled

{% endblock %}





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



Re: creating user and profile in just one form

2007-12-11 Thread Simone Cittadini

Joe ha scritto:
> I've done this but with a manually built form.
>
> You can just add the extra form fields to the template, then reference
> those extra fields in your view.
>   
 Yes, after trying with inline options to no result, I've resolved too 
in using the fields instead of the form to have more granularity :


This is the template :


[..]
Password: {{ f_user.password }}
Clid: {{ f_customer.clid }}
[..]



And the view:

[..]
if request.method == 'POST':
user = User(username=request.POST['username'])
user.set_password(request.POST['password'])
user.save()
customer = CustomerProfile(user=user,
   clid=request.POST['clid'])
customer.save()
[..]


It's not that inelegant in the end ... probably it can get better with 
the fields meta-option of ModelForm


> j
>
> On Dec 10, 5:15 am, Simone Cittadini <[EMAIL PROTECTED]> wrote:
>   
>> I have this code to add a new user :
>>
>> class CustomerForm(ModelForm):
>>
>> class Meta:
>> model = CustomerProfile
>>
>> def add(request):
>> [..]
>> if request.method == 'POST':
>> form = CustomerForm(customer, request.POST)
>> f.save()
>> else:
>> form = CustomerForm(customer)
>> return render_to_response('customer/add.html', locals(),
>> RequestContext(request, {}))
>> [..]
>>
>> which automagically creates a web form where you choose among existing
>> users as one of the CustomerProfile fields.
>>
>> Now since my app as to be (subnormal)user-friendly I want the code to
>> render just one form with name/password fields among the profile ones,
>> and no existing users choice-list, is it possible ?
>> 
> >
>
>   


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



creating user and profile in just one form

2007-12-10 Thread Simone Cittadini

I have this code to add a new user :

class CustomerForm(ModelForm):
   
class Meta:
model = CustomerProfile

def add(request):
[..]
if request.method == 'POST':
form = CustomerForm(customer, request.POST)
f.save()
else:
form = CustomerForm(customer)
return render_to_response('customer/add.html', locals(), 
RequestContext(request, {}))
[..]


which automagically creates a web form where you choose among existing 
users as one of the CustomerProfile fields.

Now since my app as to be (subnormal)user-friendly I want the code to 
render just one form with name/password fields among the profile ones, 
and no existing users choice-list, is it possible ?

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



Re: ChoiceField get choices from objects.all(), but isn't updated

2007-11-02 Thread Simone Cittadini

Malcolm Tredinnick ha scritto:
> On Fri, 2007-11-02 at 11:25 +0100, Simone Cittadini wrote:
>>
>> class FormFilters(forms.Form):
>> filter_name = forms.ChoiceField(choices = [(f.name, f.name) for f in 
>> Filter.objects.all()])
>>
>>
>> One view lists all the objects given the POST of FormFilters, but if I 
>> delete/add a Filter object (from my apps interface or the automagic 
>> admin one) the choices in FormFilter won't change, it remains stuck with 
>> values in the db found when the engine is started (manage runserver or 
>> apache mod_python).
>
> If you want to update the choices dynamically, you will need to assign
> to filter_name.choices just before rendering it (and that's perfectly
> legal to do; 'choices' is a writable attribute).
>   

I think I'm in need of a for dummy example here ...

in the view code :

def list_filters(request):
[...]
else:
form = FormFilters()
form.filter_name.choices = [(f.name, f.name) for f in 
Filter.objects.all()]
return render_to_response('list_filters.html', locals(), 
RequestContext(request, {}))

gives :

AttributeError - 'FormFilters' object has no attribute 'filter_name' 

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



ChoiceField get choices from objects.all(), but isn't updated

2007-11-02 Thread Simone Cittadini

Stripping down my app to what isn't working as expected I have :

models :

class Filter(models.Model):
name = models.CharField()
object = models.ManyToManyField(Object)

class Object(models.Model):
name = models.CharField()
[...]

forms :

class FormFilters(forms.Form):
filter_name = forms.ChoiceField(choices = [(f.name, f.name) for f in 
Filter.objects.all()])


One view lists all the objects given the POST of FormFilters, but if I 
delete/add a Filter object (from my apps interface or the automagic 
admin one) the choices in FormFilter won't change, it remains stuck with 
values in the db found when the engine is started (manage runserver or 
apache mod_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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



About the absence of double primary key ...

2007-10-12 Thread Simone Cittadini

I was wondering if the limit on one primary key field only was coming 
out of the "encouraging of clean design" or was just a technical limitation.

I have some classes in my "legacy" app that are uniquely identified by 
two or more attributes, and I was just catching db layer exception when 
the user tried to insert something already there, wrapping them in "user 
error exceptions".

Now when saving I have to search for an equivalent object and in the 
case is found abort the save and throw the error.

Was something I miss in the first method wrong ? Or I miss something 
from django framework which allows me to solve the problem in a more 
elegant way ?


PS: Of course catching / wrapping exception in java is still more lines 
than doing an if/else in python, so maybe the answer is "stop being anal 
about concise code" :)

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



manage.py test can't find the fixtures

2007-10-11 Thread Simone Cittadini

I have this directories structure

site/app_one/models.py
site/app_one/tests.py
site/app_one/fixtures/test.json

if I 'manage.py loaddata test' it works

if I 'manage.py test' it doesn't find fixtures

the test class starts with :

import unittest
from models import *
   
class TestSmooth(unittest.TestCase):
fixtures = ['test.json']
   
def testGetPrefisso(self):
p = Prefisso.objects.get(pre='01')
self.assertEquals(p.distretto, 'Italia Mobile')

[...]

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



overriding FileField.save() to do something with the file

2007-10-04 Thread Simone Cittadini

I have such a Model :

class FileToProcess(models.Model):
file = models.FileField(upload_to='somewhere')
   
def save(self):
super(FileToProcess, self).save()
f = open([???], 'r')
for line in f.read():
  


How I get the name/path oh the "just saved" file so I can process it ?

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



Re: Creating a Form with some uneditable fields

2007-10-02 Thread Simone Cittadini

Was a "look all the fields type before asking problem" ...
I've solved with HiddenField and disabled option ...

class RuoteForm(forms.Form):
line_name = forms.ChoiceField(choices=get_lines(), 
widget=forms.HiddenInput)
prefix = forms.ChoiceField(choices=get_prefixes(), 
widget=forms.HiddenInput)
shown_pre = forms.ChoiceField(choices=get_prefixes(), 
widget=forms.TextInput(attrs={'disabled': 'disabled'}))
termination_name = forms.ChoiceField(choices=get_terminations())

This way the international prefix is shown but uneditable and the 
subsequent POST data let me choose the correct Route object to update.
(One page shows more than one RouteForm for a given line_name)

I need both prefix and shown_pre because when adding the 'disabled' attr 
POST doesn't have data for that field, I suppose that's the way html 
works ...



>> I have some models like :
>>
>> class UserOfSomeStuff(models.Model):
>> [...]
>>
>> class AvailableStuffToUse(models.Model):
>> [...]
>>
>> class CurrentlyUsedStuff(models.Model):
>> user = models.ForeignKey(UserOfSomeStuff)
>> used_stuff = models.ForeignKey(AvailableStuffToUse)
>>
>>
>> In my application I don't need to add new Users or new Stuff, I only
>> need to change what Stuff is currently Used [1]
>> So I want to create a form which when bounded to an instance of
>> CurrentlyUsedStuff renders the "user" in plain text, and when saved  
>> just
>> updates the data, without creating a new object.
>>
>> Is there a clean way to do this ?
>>
>>
>>
>> [1] : it's a GUI for routing calls with asterisk/python/mysql if  
>> you mind
>>
>>
>>
>> 
>
>
> >
>
>   


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



Creating a Form with some uneditable fields

2007-09-20 Thread Simone Cittadini

I have some models like :

class UserOfSomeStuff(models.Model):
[...]

class AvailableStuffToUse(models.Model):
[...]

class CurrentlyUsedStuff(models.Model):
user = models.ForeignKey(UserOfSomeStuff)
used_stuff = models.ForeignKey(AvailableStuffToUse)


In my application I don't need to add new Users or new Stuff, I only 
need to change what Stuff is currently Used [1]
So I want to create a form which when bounded to an instance of 
CurrentlyUsedStuff renders the "user" in plain text, and when saved just 
updates the data, without creating a new object.

Is there a clean way to do this ?



[1] : it's a GUI for routing calls with asterisk/python/mysql if you mind



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