Re: Unicode and localized characters in view

2010-03-03 Thread Daniel Roseman
On Mar 4, 6:45 am, Joakim Hove  wrote:
> About every once a year I am forced out on the internet to read about
> "encodings and such"; while reading about it all makes sense, but when
> actually trying to get things to work I always go through a period of
> swearing and frustration - I never really get it :-(
>
> Now, in a Django view I have a selectionlist, and one of the seletions
> should contain the Norwegian problem child 'å'. I have tried the
> following:
>
> 1, I have explicitly used the HTML syntax  - however in this
> case Django ended up rendering the '&' as '', i.e. as if I wanted
> a literal '&'.

Nothing to do with encodings, this is autoescaping at work. See
http://docs.djangoproject.com/en/1.1/topics/templates/#id2

> 2. I just entered the 'å' in the Python source code for the view. Then
> a get a Python run.-time error stating that I must declare an encoding
> when using non-ASCII characters. I then tried declaring the encoding
> 'latin-1' in the top of the source file of the view, this gave a
> UnicodeDecodeError triggered by Django:
>
>         'ascii' codec can't decode byte 0xe5 in position 14: ordinal
> not in range(128)
>
> Any hints?

Please show the code.
--
DR.

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



Re: django vs tornado

2010-03-03 Thread Kenneth Gonsalves
On Thursday 04 Mar 2010 12:55:37 pm Continuation wrote:
> > I have stopped using it and till I can get something else up am using
> > nginx proxied to runserver - which is faster than tornado and handles the
> > latest django svn ok.
> > --
> 
> You are running the Django development server in production? Why? Why
> not apache/mod_wsgi?
> 

this is in a small vps with limited RAM. I found apache/mod_wsgi too slow and 
bloated, so rather than spend time tuning apache, I shifted to nginx+tornado 
which was fast and did not eat up RAM. Then I needed to do an svn up to get 
some nifty new features and tornado could not handle the csrf stuff. So as a 
purely temporary measure, I substituted runserver for tornado - intending to 
just keep the clients happy until I could test and set up nginx+fcgi. But it 
is working fine - with the added advantage of not needing to restart anything 
on code changes. Of course I intend to change this, but have some deadlines to 
meet first.
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS
http://certificate.nrcfoss.au-kbc.org.in

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



Re: django vs tornado

2010-03-03 Thread Continuation

> I have stopped using it and till I can get something else up am using nginx
> proxied to runserver - which is faster than tornado and handles the latest
> django svn ok.
> --

You are running the Django development server in production? Why? Why
not apache/mod_wsgi?

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



Unicode and localized characters in view

2010-03-03 Thread Joakim Hove
About every once a year I am forced out on the internet to read about
"encodings and such"; while reading about it all makes sense, but when
actually trying to get things to work I always go through a period of
swearing and frustration - I never really get it :-(

Now, in a Django view I have a selectionlist, and one of the seletions
should contain the Norwegian problem child 'å'. I have tried the
following:

1, I have explicitly used the HTML syntax  - however in this
case Django ended up rendering the '&' as '', i.e. as if I wanted
a literal '&'.

2. I just entered the 'å' in the Python source code for the view. Then
a get a Python run.-time error stating that I must declare an encoding
when using non-ASCII characters. I then tried declaring the encoding
'latin-1' in the top of the source file of the view, this gave a
UnicodeDecodeError triggered by Django:

'ascii' codec can't decode byte 0xe5 in position 14: ordinal
not in range(128)


Any hints?


Joakim

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



Form Dummy Widget

2010-03-03 Thread Nasp
Hey all!

I have a poll app which display Poll model in the admin with Choice
model inlined. What I'm trying to do is to display vote percentage for
those InlinedForm. I've been creating a dummy class which extends
form.Widget and I'm trying to figure out how i can pass the Choice id
or instance to it so it cans retrieve data and display the vote
percentage. I'm not sure i did it the right way but i can't figure out
how to display HTML in form without using a field.

Here's my setup so far.

//models.py
class Choice(models.Model):
"""
A choice
"""
poll = models.ForeignKey(Poll, verbose_name=_("Poll"))
choice = models.CharField(max_length=200,
verbose_name=_("Choice"))
objects = models.Manager()

def __unicode__(self):
return _(self.choice)

def get_vote_count(self):
return self.vote_set.all().count()

def get_vote_count_percentage(self):
return round(self.get_vote_count() /
self.poll.get_votes_count(), 2) * 100;

class Meta:
verbose_name = _("Choice")
verbose_name_plural = _("Choices")

class Vote(models.Model):
"""
A vote
"""
poll = models.ForeignKey(Poll, verbose_name=_("Poll"))
choice = models.ForeignKey(Choice, verbose_name=_("Choice"))
pub_date = models.DateTimeField(auto_now_add=True,
verbose_name=_("Date Published"))
ip_address = models.IPAddressField(verbose_name=_("Author's IP
Address"))

def __unicode__(self):
return _(self.choice.choice)

class Meta:
#unique_together = (("user", "poll"),)
ordering = ['pub_date']
get_latest_by = "pub_date"
verbose_name = _("Vote")
verbose_name_plural = _("Votes")

//admin.py
class ChoiceInlineAdmin(TabularInline):
model = Choice
form = ChoicesForm

class PollAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("title",)}
date_hierarchy = 'pub_date'
list_display = ('title',)
search_fields = ['title']

inlines = [ChoiceInlineAdmin]

admin.site.register(Poll, PollAdmin)

//forms.py
class ChoicesForm(forms.ModelForm):
class Meta:
model = Choice

choice = forms.CharField(label=_('Text'));
vote_percentage = forms.Field(field='id', label=_('Vote %'),
widget=PercentageBarWidget)

//widgets.py
from django.forms import Widget

class PercentageBarWidget(Widget):
def render(self, value):
return "percentage??"

Thanks a lot!

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



Re: django vs tornado

2010-03-03 Thread Kenneth Gonsalves
On Thursday 04 Mar 2010 3:54:48 am Graham Dumpleton wrote:
> On Mar 4, 9:08 am, gvkalra  wrote:
> > hi  i have a presentation to make on django, wherein I have
> > decided to include a section on Tornado  I wish to show
> > performance comparisons between django and tornado . how do I set
> > up the scenario ?? . what I intend to achieve is this
> > graph:http://wiki.developers.facebook.com/images/e/e8/Chart.png
> > Please help me out
> 
> You do understand that those original Tornado benchmarks are to a
> degree bogus as far as they were being used to compare Tornado to
> Apache/mod_wsgi?
> 

as a person who has used django on tornado in production for some months, I 
would like to mention two things:

1. tornado cannot handle urls with spaces in them - for example: 
http://mysite.com/go here/  would be returned as http://mysite.com/go%20here/ 
which confuses the database

2. tornado goes haywire when confronted with {% csrf_token %}, giving 
unpredictable errors.

I have stopped using it and till I can get something else up am using nginx 
proxied to runserver - which is faster than tornado and handles the latest 
django svn ok.
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS
http://certificate.nrcfoss.au-kbc.org.in

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



Re: best practices for creating a template/theming layer for users in a django app

2010-03-03 Thread Nick
It seems like this would be best handled at the view level, you could
pass a url variable in the render_to_response portion, maybe something
like

def theme(request):
# a bunch of view display stuff
   theme = ThemeModel.objects.get('template__name')
   if theme:
   render_to_response('%s' u'path', {'dictionary': dictionary}
   else:
   render the default theme

The path is the directory extension of theme.  Probably just make a
foreign key relationship in the blogs settings Model and link it to a
template Model with name, thumbnail, etc. etc. etc..


On Mar 3,u 6:12 pm, gdup  wrote:
> O crap! that sounds about right. I was thinking of media_url in terms
> of only static files, didnt think of {{ templatename }} variable.
>
> As for the templating part in an app like shopify , i am not familar
> with rails, but i assume it allows you to create custom template tags
> like django. I doubt this is the method they are using? Are they
> probably just using a custom template system from scratch?
>
> On Mar 3, 5:30 pm, Nick  wrote:
>
> > If I'm understanding what you're asking, it should be as simple as
> > adding an entry per user that designates the template/theme you'd like
> > to use and then passing that as a variable (ex. {{ MEDIA_URL }}
> > {{ templatename }} where template name would be the directory name of
> > the template.  Let me know if I have that right.
>
> > On Mar 3, 5:17 pm, gdup  wrote:
>
> > > Hello all,
>
> > > I would really aprreciate it if someone could point me in the right
> > > direction of creating a themeing and template layer for an application
> > > written in django, similar to what tumblar and shopify do.
>
> > > I can almost put my finger on the whole concept. I know u can somehow
> > > serve the MEDIA_URL variable per user to serve static files, but what
> > > about themeing (and views)? Would u create your own tags  or just use
> > > djangos?
>
> > > Knowing django, I wont be surprised if there is already an app for
> > > this. Any direction would be greatly appreciated.

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



Re: best practices for creating a template/theming layer for users in a django app

2010-03-03 Thread Nick
Ideally what you'd want to do is handle all of this

On Mar 3, 6:12 pm, gdup  wrote:
> O crap! that sounds about right. I was thinking of media_url in terms
> of only static files, didnt think of {{ templatename }} variable.
>
> As for the templating part in an app like shopify , i am not familar
> with rails, but i assume it allows you to create custom template tags
> like django. I doubt this is the method they are using? Are they
> probably just using a custom template system from scratch?
>
> On Mar 3, 5:30 pm, Nick  wrote:
>
> > If I'm understanding what you're asking, it should be as simple as
> > adding an entry per user that designates the template/theme you'd like
> > to use and then passing that as a variable (ex. {{ MEDIA_URL }}
> > {{ templatename }} where template name would be the directory name of
> > the template.  Let me know if I have that right.
>
> > On Mar 3, 5:17 pm, gdup  wrote:
>
> > > Hello all,
>
> > > I would really aprreciate it if someone could point me in the right
> > > direction of creating a themeing and template layer for an application
> > > written in django, similar to what tumblar and shopify do.
>
> > > I can almost put my finger on the whole concept. I know u can somehow
> > > serve the MEDIA_URL variable per user to serve static files, but what
> > > about themeing (and views)? Would u create your own tags  or just use
> > > djangos?
>
> > > Knowing django, I wont be surprised if there is already an app for
> > > this. Any direction would be greatly appreciated.

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



ListField() wanted or how to use iterable fields in forms

2010-03-03 Thread coco
Hello,
Is it possible to get some kind of ListField() for some
django.forms.Form fields ?

Here is a typical example problem involving this. Let's try to make
the following kind of form (forms.py):

class mytable(forms.Form):
tags = forms.CharField()
x = forms.FloatField()
y = forms.FloatField()
z = forms.FloatField()

Now, I want to link it with an editable html table like this (4
columns x multiple rows):

tagsx  y   z
"pt1"   0.0   0.0   0.0
"pt2"   1.3   2.1   5.0
"pt3"   2.0   4.5   6.1
and so on...

The FloatField() in mytable() are inapropriates. One need some kind of
FloatList() or TableGrid widget in order to stay DRY : I want to avoid
hardcoding all the fields (x1,x2,x3,x4,x5,x6,... y1,y2,y3,...), but
instead using some kind of (x[i], y[i], z[i]   or  data(i,j)). I can't
figure how to do that. I do not want to use models, neither database
system, but some direct handling like this snippet in views.py:

def myfunct(request):
if request.method == 'POST':
form = mytable(request.POST)
if form.is_valid():
cd = form.cleaned_data
for i in range(len(cd['tags']))
print cd['x'][i] + cd['y'][i] + cd['z'][i]
f = mytable(cd)
return render_to_response('mytemplate.html', {'form': f})
else:
form = mytable()
return render_to_response('mytemplate.html', {'form': form})

Does anyone know how to achieve this ? Thanks,

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



Re: Passing message to 404

2010-03-03 Thread Wiiboy
Thanks for your reply.

One question though: How would I pass the message itself from view to
view (the view raising the error to my 404 view)?

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



Re: Passing message to 404

2010-03-03 Thread Eugene Wee
Hi,

On Thu, Mar 4, 2010 at 11:20 AM, Wiiboy  wrote:
> Is there a way to pass a message when I create a 404 error
> programmatically (i.e. from a view)?  In my case, I'm using
> get_object_or_404, and I'd like to say something like, "That user does
> not exist" (this is for looking at user profiles).

You can create a 404 view:
http://docs.djangoproject.com/en/1.1/topics/http/views/#the-404-page-not-found-view

Regards,
Eugene Wee

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



Passing message to 404

2010-03-03 Thread Wiiboy
Hi,
Is there a way to pass a message when I create a 404 error
programmatically (i.e. from a view)?  In my case, I'm using
get_object_or_404, and I'd like to say something like, "That user does
not exist" (this is for looking at user profiles).

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



Multiple views files

2010-03-03 Thread Wiiboy
Hi guys,
I'm thinking about making multiple views files.  I'm just wondering
whether:
a. There's any problems with that
b. many people do it.

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



Re: Templates sometimes load at bottom of page

2010-03-03 Thread Shawn Milochik
Dude, I have one word for you, and you've heard it already tonight: virtualenv

I do everything on my Mac, and virtualenv and git make it a lot easier than I 
deserve. Let me know if you need help.

Shawn



On Mar 3, 2010, at 9:28 PM, timdude wrote:

> I know I should do it. But I'm such a noob, the idea scares the crap
> out of me. I've got half a dozen sites hanging off the same code
> base...which is all .96 dependant. I'll get the time and the guts up
> one of these days.
> 
> Cheers,
> Tim
> 
> On Mar 3, 5:47 pm, Atamert Ölçgen  wrote:
>> On Wednesday 03 March 2010 07:58:39 timdude wrote:> I'm using .96. Other 
>> than that, what would my problem be?
>> 
>> There has been significant changes since 0.96, you should seriously consider
>> upgrading!
>> 
>> --

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



Re: Templates sometimes load at bottom of page

2010-03-03 Thread timdude
I know I should do it. But I'm such a noob, the idea scares the crap
out of me. I've got half a dozen sites hanging off the same code
base...which is all .96 dependant. I'll get the time and the guts up
one of these days.

Cheers,
Tim

On Mar 3, 5:47 pm, Atamert Ölçgen  wrote:
> On Wednesday 03 March 2010 07:58:39 timdude wrote:> I'm using .96. Other than 
> that, what would my problem be?
>
> There has been significant changes since 0.96, you should seriously consider
> upgrading!
>
> --
> Saygılarımla,
> Atamert Ölçgen
>
>  -+-
>  --+
>  +++
>
> www.muhuk.com
> mu...@jabber.org

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



Re: "ImportError: No module named django" with MacPorts

2010-03-03 Thread Steven R. Elliott Jr
Hello Tim,

I'm a fellow Mac user but I don't quite understand the problem that you are
having installing Django on OS X 10.6.

I installed Django today on a new Mac and it took all of 5 minutes and I
downloaded the tarball, extracted it and threw it in my home directory.

I believe that 10.6 comes comes with Python 2.6.1 out of the box so there
shouldn't have been a need to install 2.5 unless you are married to 2.5 for
some reason. Also, when you ran the python setup.py install command did you
run it as superuser? so, you need to plop sudo in front of your command...
if not, it won't have all the permissions it needs to install into your
system properly. Lastly, do you have the Apple Developer tools installed?

Not sure if any of this helps but I know that when I ran the install command
and didn't use:
*sudo* python setup.py install it crapped itself and complained that it
didn't have permission.

Good luck,
Steve

On Wed, Mar 3, 2010 at 2:15 PM, Tones  wrote:

> Hi --
>
> I'm attempting to run Django on OSX 10.6. I've installed Python2.5 and
> Py25-Django (Django v1.1) via MacPorts. But I am receiving the famed
> "ImportError: No module named django" error.
>
> Django is installed in this directory:
> /opt/local/lib/python2.5/site-packages/django/
>
> To check my $PYTHONPATH, I went to the Python shell and tried "print
> sys.path". The site-packages path is indeed included in my PYTHONPATH.
>
> However, when I try "print sys.modules" in the same Python shell,
> Django is not included.
>
> I can't figure out what's going on. Django's INSTALL.TXT says all
> that's needed to install Django is to copy it into the site-packages
> directory. But in this case that hasn't worked. Is something else
> needed to give Python access to Django?
>
> I suppose I could forget MacPorts and attempt to install from SVN or a
> tarball. But I would really prefer to work through the package
> manager, especially since it's so unclear what has gone wrong.
>
> Any thoughts appreciated. Thanks.
>
> =Tim=
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: "ImportError: No module named django" with MacPorts

2010-03-03 Thread CLIFFORD ILKAY

On 03/03/2010 07:27 PM, Tim Jones wrote:

So I tried specifying the site-packages path at the top of my script
and it removed the ImportError. That makes it seem like my
web-server's pythong is running with different pythonpath settings
than my command-line's python. I think I can probably unravel the
mystery from there.


You'll find virtualenv and virtualenvwrapper are invaluable for such things.
--
Regards,

Clifford Ilkay
Dinamis
1419-3266 Yonge St.
Toronto, ON
Canada  M4N 3P6


+1 416-410-3326

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



Re: How to make django to handle multiple requests at the same time

2010-03-03 Thread Robert Mela

Daniel Roseman wrote:

This isn't a question about Django, but about WSGI deployment.

Although I must say I'm confused, you say you're using WSGI but you're
printing something, so it seems like you're using the development
server since that prints to the console? Is this right? If so, you
can't do this, as the development server is single-process. When
properly deployed on Apache via mod_wsgi, it should be multi-process.

  
With mod_wsgi it could even be multithreaded, though threading requires 
a certain level of developer sophistication to be safe.


Another tidbit - a print to stderr, or output through Python std 
logging, will make its way into the Apache error logs, or at least it 
does on our installations.



If you are definitely already using mod_wsgi, you'll need to post your
Apache configuration.
--
DR.

  


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

<>

Re: "ImportError: No module named django" with MacPorts

2010-03-03 Thread Tim Jones
Sorry, I should clarify.

When I wrote:
> So I tried specifying the site-packages path at the top of my script...

I meant that I added these lines:
~~
import sys
sys.path.insert(0, "/opt/local/lib/python2.5/site-packages")
~~

=T=


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



Re: "ImportError: No module named django" with MacPorts

2010-03-03 Thread Tim Jones
Aha, that is helpful. I think I've partially solved this now.

If I run 'import django' at the command line, then it seems to import fine; 
there is no error message, and 'print sys.modules' now lists it.

So I tried specifying the site-packages path at the top of my script and it 
removed the ImportError. That makes it seem like my web-server's pythong is 
running with different pythonpath settings than my command-line's python. I 
think I can probably unravel the mystery from there. 

I'm actually attempting to run this all in Google App Engine. Just to keep 
things as complicated as possible. So the lines generating the error were
~~
from google.appengine.dist import use_library
use_library('django','1.1')
~~

=T=




On Mar 3, 2010, at 4:20 PM, Shawn Milochik wrote:

> Printing sys.modules won't show django unless you've imported Django.
> 
> What are you trying to do, anyway? You don't normally import Django in a 
> Python script. You usually start a Django project by using django-admin.py 
> and letting it create a manage.py which uses the proper Python.
> 
> Search your system for django-admin.py and see where it lies. Try executing 
> it in a few different ways:
> 
> python django-admin.py startproject fake_project_name
> django-admin.py startproject fake_project_name
> /explicit/path/to/some/python/installation/python django-admin.py 
> startproject fake_project_name
> 
> Let us know what you get.
> 
> Shawn
> 
> 
> On Mar 3, 2010, at 7:12 PM, Tim Jones wrote:
> 
>> Thanks for the reply.
>> 
>> "which python" returns: /opt/local/bin/python
>> 
>> "python -V" returns: Python 2.5.5
>> 
>> I know I've got the OSX default Pythons installed as well, but I've done my 
>> best to avoid running those.
>> 
>> Like I said in my first email, printing sys.path in the python prompt 
>> returns a big list of directories, including  
>> "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages",
>>  which contains the django installation.
>> 
>> But when I run "print sys.modules", Django is not included. It doesnt make 
>> sense to me that Django isn't included in sys.modules even though it's 
>> installed in a dir listed by sys.path.
>> 
>> I'm a noob to both Python and Django so apologies if I'm missing something 
>> obvious.
>> 
>> =T=
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Use a queryset as values for model insert

2010-03-03 Thread geraldcor
Hello all,

I have a form for submitting samples. After the user submits a sample,
I would like to give them a button that says "Use last form to fill in
this form" or whatever. Basically, the way I have thought to do this
is:

last_sample = SSF.objects.filter(ssfvalue=request.user.id).order_by('-
id')[:1].values() which would give me a tuple containing a dictionary
of key:value pairs of the last submitted data.

Now I would like to be able to just plop that into a new row in my
table and then present that to the user to verify/alter etc. I am
using a form wizard which is why intitial values won't work (I think).

I have tried all sort of string concatenation, tuples, lists - can't
figure out how to do

s=SSF(name="the name", test1=1...)
s.save()

Thanks for any advice.

Greg

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



Re: "ImportError: No module named django" with MacPorts

2010-03-03 Thread Shawn Milochik
Printing sys.modules won't show django unless you've imported Django.

What are you trying to do, anyway? You don't normally import Django in a Python 
script. You usually start a Django project by using django-admin.py and letting 
it create a manage.py which uses the proper Python.

Search your system for django-admin.py and see where it lies. Try executing it 
in a few different ways:

python django-admin.py startproject fake_project_name
django-admin.py startproject fake_project_name
/explicit/path/to/some/python/installation/python django-admin.py startproject 
fake_project_name

Let us know what you get.

Shawn


On Mar 3, 2010, at 7:12 PM, Tim Jones wrote:

> Thanks for the reply.
> 
> "which python" returns: /opt/local/bin/python
> 
> "python -V" returns: Python 2.5.5
> 
> I know I've got the OSX default Pythons installed as well, but I've done my 
> best to avoid running those.
> 
> Like I said in my first email, printing sys.path in the python prompt returns 
> a big list of directories, including  
> "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages",
>  which contains the django installation.
> 
> But when I run "print sys.modules", Django is not included. It doesnt make 
> sense to me that Django isn't included in sys.modules even though it's 
> installed in a dir listed by sys.path.
> 
> I'm a noob to both Python and Django so apologies if I'm missing something 
> obvious.
> 
> =T=

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



Re: best practices for creating a template/theming layer for users in a django app

2010-03-03 Thread gdup
O crap! that sounds about right. I was thinking of media_url in terms
of only static files, didnt think of {{ templatename }} variable.

As for the templating part in an app like shopify , i am not familar
with rails, but i assume it allows you to create custom template tags
like django. I doubt this is the method they are using? Are they
probably just using a custom template system from scratch?



On Mar 3, 5:30 pm, Nick  wrote:
> If I'm understanding what you're asking, it should be as simple as
> adding an entry per user that designates the template/theme you'd like
> to use and then passing that as a variable (ex. {{ MEDIA_URL }}
> {{ templatename }} where template name would be the directory name of
> the template.  Let me know if I have that right.
>
> On Mar 3, 5:17 pm, gdup  wrote:
>
> > Hello all,
>
> > I would really aprreciate it if someone could point me in the right
> > direction of creating a themeing and template layer for an application
> > written in django, similar to what tumblar and shopify do.
>
> > I can almost put my finger on the whole concept. I know u can somehow
> > serve the MEDIA_URL variable per user to serve static files, but what
> > about themeing (and views)? Would u create your own tags  or just use
> > djangos?
>
> > Knowing django, I wont be surprised if there is already an app for
> > this. Any direction would be greatly appreciated.

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



Re: "ImportError: No module named django" with MacPorts

2010-03-03 Thread Tim Jones
Thanks for the reply.

"which python" returns: /opt/local/bin/python

"python -V" returns: Python 2.5.5

I know I've got the OSX default Pythons installed as well, but I've done my 
best to avoid running those.

Like I said in my first email, printing sys.path in the python prompt returns a 
big list of directories, including  
"/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages",
 which contains the django installation.

But when I run "print sys.modules", Django is not included. It doesnt make 
sense to me that Django isn't included in sys.modules even though it's 
installed in a dir listed by sys.path.

I'm a noob to both Python and Django so apologies if I'm missing something 
obvious.

=T=




On Mar 3, 2010, at 4:04 PM, Shawn Milochik wrote:

> Please post the results of these commands:
> 
> which python
> 
> python -V
> 
> 
> 
> 
> You can have different versions of Python installed (or even the same 
> version) in multiple places on your Mac. The most likely situation is that 
> when you're trying to actually run things you're using different version of 
> Python than the one that has Django install. your PYTHONPATH is only part of 
> the story, since packages on that path for one version of Python won't work 
> when you're running another Python version.
> 
> For bonus points, run Python at the command line and do these:
> 
> import sys
> sys.path
> 
> That will tell you where your current instance of Python is looking for 
> modules.
> 
> Shawn
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: "ImportError: No module named django" with MacPorts

2010-03-03 Thread Shawn Milochik
Please post the results of these commands:

which python

python -V




You can have different versions of Python installed (or even the same version) 
in multiple places on your Mac. The most likely situation is that when you're 
trying to actually run things you're using different version of Python than the 
one that has Django install. your PYTHONPATH is only part of the story, since 
packages on that path for one version of Python won't work when you're running 
another Python version.

For bonus points, run Python at the command line and do these:

import sys
sys.path

That will tell you where your current instance of Python is looking for modules.

Shawn


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



Re: "ImportError: No module named django" with MacPorts

2010-03-03 Thread Tones
I attempted installation via tarball instead of MacPorts. This had no
effect on things. Same files in the same places, same error.

=T=




On Mar 3, 11:15 am, Tones  wrote:
> Hi --
>
> I'm attempting to run Django on OSX 10.6. I've installed Python2.5 and
> Py25-Django (Django v1.1) via MacPorts. But I am receiving the famed
> "ImportError: No module named django" error.
>
> Django is installed in this directory:
> /opt/local/lib/python2.5/site-packages/django/
>
> To check my $PYTHONPATH, I went to the Python shell and tried "print
> sys.path". The site-packages path is indeed included in my PYTHONPATH.
>
> However, when I try "print sys.modules" in the same Python shell,
> Django is not included.
>
> I can't figure out what's going on. Django's INSTALL.TXT says all
> that's needed to install Django is to copy it into the site-packages
> directory. But in this case that hasn't worked. Is something else
> needed to give Python access to Django?
>
> I suppose I could forget MacPorts and attempt to install from SVN or a
> tarball. But I would really prefer to work through the package
> manager, especially since it's so unclear what has gone wrong.
>
> Any thoughts appreciated. Thanks.
>
> =Tim=

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



Django and WordPress together?

2010-03-03 Thread John Griessen

Does anyone run Django and WordPress together?

I like the P2 theme of WordPress, so I'm wanting to use it with links to 
documents
 in a P2 blog, but I want it all searchable from Django apps.

Anyone do that where Django is the main admin interface to a site's pages and
WordPress is just for a subdomain?  If you do this, is it easy access the 
WordPress
database via Django?

I found this about what I'm asking:  
http://geekscrap.com/2010/02/integrate-wordpress-and-django/

Know any other write ups?

Thanks,

John

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



Restricting Access to Uploaded Files

2010-03-03 Thread Merrick
I wanted to give users who are authenticated the ability to upload
files, that's the easy part that I can handle.

What I cannot figure out is how to restrict the viewing/downloading of
files.

Links, tips, code are appreciated.

Thanks

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



Re: best practices for creating a template/theming layer for users in a django app

2010-03-03 Thread Nick
If I'm understanding what you're asking, it should be as simple as
adding an entry per user that designates the template/theme you'd like
to use and then passing that as a variable (ex. {{ MEDIA_URL }}
{{ templatename }} where template name would be the directory name of
the template.  Let me know if I have that right.

On Mar 3, 5:17 pm, gdup  wrote:
> Hello all,
>
> I would really aprreciate it if someone could point me in the right
> direction of creating a themeing and template layer for an application
> written in django, similar to what tumblar and shopify do.
>
> I can almost put my finger on the whole concept. I know u can somehow
> serve the MEDIA_URL variable per user to serve static files, but what
> about themeing (and views)? Would u create your own tags  or just use
> djangos?
>
> Knowing django, I wont be surprised if there is already an app for
> this. Any direction would be greatly appreciated.

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



Re: Serializing objects with a many-to-many reference

2010-03-03 Thread Russell Keith-Magee
On Thu, Mar 4, 2010 at 1:36 AM, Jim N  wrote:
> I just came across manager methods in the docs:
>
> http://docs.djangoproject.com/en/dev/topics/db/managers/#adding-extra-manager-methods
>
> Could I have used these to create a seriallizable QuerySet, by
> defining, say, a with_user() method inside the Questions model?

If you take this approach, you'll hit up against #5711. Django doesn't
allow for serialization of arbitrary model attributes. This is also
something that needs to be addressed as part of the serialization
teardown.

Yours,
Russ Magee %-)

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



best practices for creating a template/theming layer for users in a django app

2010-03-03 Thread gdup
Hello all,

I would really aprreciate it if someone could point me in the right
direction of creating a themeing and template layer for an application
written in django, similar to what tumblar and shopify do.

I can almost put my finger on the whole concept. I know u can somehow
serve the MEDIA_URL variable per user to serve static files, but what
about themeing (and views)? Would u create your own tags  or just use
djangos?

Knowing django, I wont be surprised if there is already an app for
this. Any direction would be greatly appreciated.

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



Please criticise this storage architecture...

2010-03-03 Thread Andy Robinson
I'm planning a self-service publishing/reporting system.  Django will
likely be the web framework.  I am considering a rather unusual
storage architecture, and would love to know where the pitfalls are.

Users will be companies in a small vertical space.  They want to let
their clients (effectively the public) pull certain kinds of reports.
Users will occasionally log in to 'design stuff' - controlling the
appearance of the reports - or to upload new content.  During this
period they will be working with a fairly rich object graph.The
report tools they have designed will then be available as web services
or web forms, 24x7, to let the public request content.  It ought to
scale up to multiple machines, but is not likely to be a web-scale
app.

Concrete example:  a tour operator logs in from time to time to update
hotel descriptions and destination guides, and to tweak the style of
their publications.  A member of the public can use the system to
input parameters and then get a brochure of all hotels meeting their
price/location/feature criteria.

It would be easy and natural to persist this as a few json objects (or
marshalled/pickled Python data).  It would be a huge PITA to decompose
it into an RDBMS, especially as the 'schema' is bound to evolve.
ACID is not important.

I would like an architecture which
 - is easy to work on.  A developer should be able to set up a working
copy fast, and it should be easy to set up on a new server.  The less
technologies apart from Python, the better.
 - is easy to support:  if a client is having problems, we want to
quickly be able to replicate their environment (content+code) on a
development machine
 - tracks history - maybe not everything, but makes it possible for
clients to save and undo at certain points
 - can provide redundancy later on if needed.

One solution seems absurdly simple and versatile:
 - each client gets a directory on the server(s)
 - their content (images/datasets) and configuration data live in
files under this.  Where possible we store data in line-oriented files
(Python objects saved as pretty-printed JSON or repr'd, tabular data
in delimited files).
 - When the user edits stuff in the web interface, we update a file on
the server.
 - we check everything which matters (app code and client content)
into Mercurial, Git or something similar.  Commit at midnight just in
case, and also when clients want to, or log out, or approve a set of
changes.
 - we can configure new servers through checking out
 - if we want a cluster to preserve transactional data, we could also
use rsync or unison running frequently
 - we can easily have multiple 'publishing' servers and one 'editing'
one, and control publishing/promotion
 - if we need to 'shard' and publish some clients to some servers,
that's easy.

I would still use a database for Django's auth application, but not
much else.  And if this architecture turns out to be wrong, we can
change the storage layer later.

I know that we need to take some precautions to make sure processes
don't clash trying to write files, but we're not talking about massive
concurrency.

So, why don't I hear about architectures like this?  Why would I want
to use more complex things (CouchDB, ZODB, blobs-in-RDBMS-tables)?
Has anyone built a nontrivial system this way, and what happened?

Thanks for all feedback.

Andy

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



Re: HTML & Django (Google App Engine)

2010-03-03 Thread Jervis


On Mar 3, 3:51 pm, slenno1  wrote:
> Hey everyone,
>      I am currently working with a section of a site that takes user
> input using Django forms:
>
>   description = forms.CharField(widget=forms.Textarea(attrs={'rows':
> '10', 'cols': '80'}))
>
> The only problem however is that this ignores any html tags that are
> added in by the user and just prints them along with the text entered
> in by the user. For example, a user may type in "The quick brown fox
> jumps over the lazy dog", with the word 'jumps' intended to be
> bold, but the html tags are just printed a long with the text. Is this
> because I am possibly using the wrong widget? Any feedback is greatly
> appreciated, thanks!

Hi, in your template where you have placed {{ model.description }}
Django will automatically escape the html tags you place have input.
The effect is what you are seeing now, they are displayed as text,
rather than being interpreted as html tags. You can selectively turn
this default behaviour off by marking the text as "safe"

{{ model.description|safe }}

The use of the word "safe" here implies that you are entirely sure
that the content of "description" won't contain anything that will
harm your website or your  customers. The discussion about what can be
considered "safe" has been had many times and it may pay you well to
do some light reading on the matter. Many people use intermediate
markup languages that don't have the full power of html, Django itself
provides template tags that can aid in rendering them
http://docs.djangoproject.com/en/dev/ref/contrib/#markup an example of
on is here http://en.wikipedia.org/wiki/Textile_(markup_language).

Best of luck.

Jervis

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



Re: django static files css headache

2010-03-03 Thread mendes.rich...@gmail.com
Hello Justin,

It's a bit hard to see what's wrong based on this info.
The thing you should check is if you could access the css by
navigating to it in the url bar.

You could check if the following would work.


 @import {{media_url}}style.css;


another thing that is different from the alert.js is that you put a /
behind the style.css not sure if that could cause it
but try without.

if this doesn't work could you post the html code with a link to a
javascript file in the same dir that works and css that doesn't.

regards,

Richard





On Mar 3, 10:58 pm, justin jools  wrote:
> I have setup my static docs in root urls:
>
>  (r'^media/(?P.*)$', 'django.views.static.serve',
> {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
>
> and am serving media_url in with my other data: views.py as follows.
>
> media_url = settings.MEDIA_URL
>
> def dblist(request):
>     obj_list_menu = dbModel1.objects.all()
>     obj_list_model = dbModel2.objects.all()
>     return render_to_response('products/dblist.html',
> {'make_list': obj_list_menu, 'model_list': obj_list_model,
> 'media_url': media_url })
>
> so in my template I can reference images, fine.
>
> 
>  height="100">
>
> but for the life of me I can't figure out why I can't reference the
> style.css the same way. I tried this in base.html and it returns the
> correct url but doesnt execute it.
>
>   (returns media/style.css)
>
> I tried the same thing with a linked alert.js and this works fine:
>
> 
>
> so why doesnt my style.css do anything: it is int the same media
> directory as alert.js...
>
> would greatly appreciate any help, thanks.

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



ModelForms TextInput size= parameter

2010-03-03 Thread PaulM
In the documentation: "Creating forms from models" the "Field types"
list states that the model field CharField converts to the form
CharField with max_length set to the model field's max_length.
However this max_length does not show up on the form's TextInput in
the size attribute.  If I say that a model field has a max_length = 3,
why doesn't the form's TextInput widget have a size=3?
At this point, rather that let ModelForms automatically set up form
fields, I need to list each form field so that I can change the
TextInput widget to the proper size.

Am I missing something?

Thanks
Paul

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



Re: django vs tornado

2010-03-03 Thread Graham Dumpleton


On Mar 4, 9:08 am, gvkalra  wrote:
> hi  i have a presentation to make on django, wherein I have
> decided to include a section on Tornado  I wish to show
> performance comparisons between django and tornado . how do I set
> up the scenario ?? . what I intend to achieve is this 
> graph:http://wiki.developers.facebook.com/images/e/e8/Chart.png Please
> help me out

You do understand that those original Tornado benchmarks are to a
degree bogus as far as they were being used to compare Tornado to
Apache/mod_wsgi?

If you do a legitimate comparison and compare their basic Tornado
hello world program to a basic WSGI hello world program then Tornado
doesn't come out looking so good. On MacOS X, Tornado actually
performs worse than Apache/mod_wsgi for a basic hello world in each
system.

In other words, they should not have been comparing the performance
based on running a heavy weight Python framework like Django on top of
Apache/mod_wsgi to a native hello world program in Tornado.

A more realistic and fair comparison would be to compare Django
running on top of Tornado to Django running on top of Apache/mod_wsgi.

One of the things you will find from that is that any benefits from
Tornado being asynchronous get thrown out the window as to run a WSGI
application such as Django on top of Tornado you need to implement a
pool of blocking threads on top and as soon as you do that, the
overall performance of Tornado will drop.

That this occurs is because once you get a blocking WSGI model in
play, the bottleneck is usually never going to be the underlying
hosting mechanism and instead the bottleneck is your application and
database access.

So, what are you trying to show?

Are you wanting to show that a blocking Django or WSGI application
running on Tornado is faster? If you are, then you will have trouble
doing that.

If instead you want to show that the asynchronous model of web
programming gives you an advantage for your specific application, then
why use Django in the comparison at all. In that case it would be more
realistic to compare custom low level WSGI applications to a custom
low level Tornado specific application.

Help us to understand what result you want, whether that be positive
to Tornado or Apache/mod_wsgi, or somehow show the benefits of Django
for web programming, then there is no doubt a way of slanting the
results to get what you want.

Graham

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



building a form with multiple filters

2010-03-03 Thread Nick
I am trying to build a search form with multiple filters/input
objects. Basically, i want to be able to allow for a simple searhc
based on one criteria or multiple. So if someone searches the name
field(q) they can filter by political party, or city, etc.  Also, I
would like to be able to return results without a search in the name
field(q)

Here is my model:

class Rep(models.Models):

Type = models.CharField(max_length=100, choices=Type_Choices,
blank=True)
Last_Name = models.CharField('Last Name', max_length=100,
blank=True)
First_Name = models.CharField('First Name', max_length=100,
blank=True)
Position = models.CharField('Position', help_text="Only used for
non-council City and Local officials", max_length=100, blank=True,
choices=Position_Choices)
Party = models.CharField(max_length=3, choices=Party_Choices,
blank=True)
District = models.IntegerField(help_text="For State, Federal and
County Commissioners", blank=True, null=True)
Ward = models.IntegerField(help_text="For City Councils",
blank=True, null=True)
City = models.CharField(max_length=100, blank=True)
Phone = models.CharField(max_length=15, help_text="Use the form
(xxx) xxx-", blank=True)
Email = models.EmailField(max_length=100, blank=True)
Contact_URL = models.URLField(max_length=200, blank=True)
DOB = models.DateField('Date of Birth',blank=True, null=True)
Gender = models.CharField(blank=True, max_length=2,
choices=Gender_Choices)
Begin_Serve = models.IntegerField('Began Serving in', blank=True,
null=True)
End_Serve = models.IntegerField('Term Limited in', blank=True,
null=True)
MugShot = models.ImageField('Mug Shot Upload', help_text="images
are to be no larger that 150x200", storage=s3_storage,
upload_to='newsok/images/Government/images', height_field=None,
width_field=None, max_length=300, blank=True)
Committees = models.ManyToManyField('Committees', blank=True)
Approp_Committee = models.ManyToManyField('Approp_Committees',
blank=True)

my view (the search view):


def search(request):
error = False
if 'q' in request.GET:
q = request.GET.['q']
reps = Rep.objects.filter(Last_Name__contains=q)
if 'party' in request.GET:
party = request.GET.['party']
reps = reps.filter(Party__contains=party)
return render_to_response('Government/search_results.html',
{'reps': reps, 'query': q})
return render_to_response('Government/search.html', {'error':
error})


my tpl:


{% if error %}
Please submit a valid search
{% endif %}


Party

Democrat

Republican





It is set up now where I can search against the "q" and filter it
based on the "party" but I can't go beyond that. I'd like to add
district, city, and term limited in fields and have them all build on
one another. But the way I have it now I don't think I can do that.

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



django vs tornado

2010-03-03 Thread gvkalra
hi  i have a presentation to make on django, wherein I have
decided to include a section on Tornado  I wish to show
performance comparisons between django and tornado . how do I set
up the scenario ?? . what I intend to achieve is this graph:
http://wiki.developers.facebook.com/images/e/e8/Chart.png  Please
help me 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Send variable from view function to a templatetag

2010-03-03 Thread pjrhar...@gmail.com


On Mar 3, 4:52 pm, alecs  wrote:
> How can I send variable from my view function(which renders my
> template) to a template tag library(which is {% load blah %} in this
> template? I want to make my tag cloud independent from model:

Your template tag has access to any variable defined in the template
context (that is anything you pass from your view).

So, for example if you passed it from your view as "tag_model":

> register = Library()
>
> @register.inclusion_tag("tags/cloud.html", takes_context=True)
> def tag_cloud(context):
>     """Takes model and tag from context and returns cloud as a
> response."""
>     tag_list = Tag.objects.cloud_for_model(context['tag_model'], steps=9,
> distribution =
> tagging.utils.LOGARITHMIC,filters={'removed':False})
>     return {'tags' : tag_list}
(note that is completely untested).

Another way to do it would be to write your template tag to accept an
argument which is the model you are after (as a string), and use
"django.db.models.get_model" to get the model.

Peter

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



upgrade to released version 1.1.1 problems

2010-03-03 Thread mendes.rich...@gmail.com
Hello Django Users,

I just tried to upgrade my django version towards the last official
release Django 1.1.1 and ran into some trouble after the install.
When i do a runserver first it complained about an AttributeError:
'Settings' that didn't have certain attributes.

To solve this is added the following settings:
LOCALE_PATHS = tuple()
DEFAULT_INDEX_TABLESPACE = ''
DEFAULT_TABLESPACE = ''

This solved this issue but i immediately ran into another one when i
actually wanted to access the admin page.
The message i get is:

File "/Library/Python/2.5/site-packages/django/core/handlers/base.py",
line 42, in load_middleware
raise exceptions.ImproperlyConfigured, 'Error importing middleware
%s: "%s"' % (mw_module, e)
ImproperlyConfigured: Error importing middleware
django.contrib.sessions.middleware: "No module named simple"

Did anyone experience something similar and know how to solve this ?

best regards,

Richard


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



Django GeoRSS syndication feed

2010-03-03 Thread Wayne Dyck
Has anyone created an example of how to incorporate a GeoRSS feed they
would be willing to share? I have seen this link, 
http://code.djangoproject.com/ticket/6547
and understand that "feed_extra_kwargs" and "item_extra_kwargs" were
added to allow this but I am drawing a blank on exactly how to
subclass the base class in order to add a lat and lon point.

Wayne

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



cursor.execute '... field IN %s' problem

2010-03-03 Thread chumphries
I'm trying to pass a list of values as the args to a 'IN' statment in
cursor.execute. When I pass integers, everything works fine, but when
I pass strings, I get nothing:


# should return same results
# env is Py 2.6 / Django 1.1.1 / MySQL 5.

# works
ids = [1, 2, 3]
id_sql = "select * from auth_user where id in %s"
cursor.execute(id_sql, [ids])

# doesn't work
users = ['qwer', 'asdf', 'zxcv']
user_sql = "select * from auth_user where username in %s"
cursor.execute(user_sql, [users])


Am I supposed to be doing something different here?

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



"ImportError: No module named django" with MacPorts

2010-03-03 Thread Tones
Hi --

I'm attempting to run Django on OSX 10.6. I've installed Python2.5 and
Py25-Django (Django v1.1) via MacPorts. But I am receiving the famed
"ImportError: No module named django" error.

Django is installed in this directory:
/opt/local/lib/python2.5/site-packages/django/

To check my $PYTHONPATH, I went to the Python shell and tried "print
sys.path". The site-packages path is indeed included in my PYTHONPATH.

However, when I try "print sys.modules" in the same Python shell,
Django is not included.

I can't figure out what's going on. Django's INSTALL.TXT says all
that's needed to install Django is to copy it into the site-packages
directory. But in this case that hasn't worked. Is something else
needed to give Python access to Django?

I suppose I could forget MacPorts and attempt to install from SVN or a
tarball. But I would really prefer to work through the package
manager, especially since it's so unclear what has gone wrong.

Any thoughts appreciated. Thanks.

=Tim=

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



Re: Struggling with Apache deployment

2010-03-03 Thread Karen Tracey
The traceback in the Apache log includes:

# You need to create a 500.html template.

You really need to do that. Django is trying to handle a server error but
running into another exception along the way, because you have no 500.html
template. When you fix that problem, and assuming you have appropriate
settings for ADMINS and sending mail, part of handling the server error will
include emailing details of the failure to your ADMINS.

You can also just turn on DEBUG and get a pretty debug page that will likely
make it a lot clearer what's going wrong. Long term for your production
server you'll want DEBUG off, though, and you'll want things set up properly
(500.html, etc.) so that any unexpected errors get reported and not buried
in the Apache log.

Karen

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



Struggling with Apache deployment

2010-03-03 Thread WBDenne
Dear All

I have just deployed my django app (Django version 1.1) on Apache 2.2
using mod-wsgi. The App is running OK but i am having problems with
the admin interface. The links into the admin interface work ok and my
models show up correctly BUT I am unable to edit or modify or access
the model data in list or detail view instead i get an a 500 error. In
addition I am also unable to access/change any other data such as
users/groups etc.

The database i am using is sqlite3. Is it possible this is a
permissioning issue on Apache ?  Apache is running on a Windows OS.

Thanks for any help or suggestions as I am tearing my hair out !!
Incidentally the Apache error log (i have copied an extract below is
reporting that a template isn't being found).

Bill


Here are extracts from relevant config files/logs (settings.py /Apache
config/ urls/  Apache Error log)


-- settings.py
--
#
import os

DEBUG = False
TEMPLATE_DEBUG = True

ADMINS = (
# ('Your Name', 'your_em...@domain.com'),
)

MANAGERS = ADMINS

DATABASE_ENGINE = 'sqlite3'
DATABASE_USER = ''
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_PORT = ''



# Absolute path to the project directory
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
MEDIA_ROOT = '%s/mediaroot/stylesheets' % BASE_PATH
MEDIA_URL = ''
ADMIN_MEDIA_PREFIX = '/media/'
# List of callables that know how to import templates from various
sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
# 'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)

ROOT_URLCONF = 'mainsite.urls'

TEMPLATE_DIRS = (

os.path.join(os.path.dirname(__file__), 'templates'),
"C:\djangosite\_dango_live_\mainsite\templates", # Change this to
your own directory.

)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.databrowse',
'mainsite.tmm',
'django.contrib.admin',
)

-- Apache config
---

#WBD django site_media
Alias /site_media "C:/djangosite/_django_live/mainsite/mediaroot/
stylesheets"


Order deny,allow
Allow from all


# django media
Alias /media "C:/Python26/Lib/site-packages/django-1.1.1-py2.6.egg/
django/contrib/admin/media"


Order deny,allow
Allow from all



#  Django WSGI (servered from /dj )
WSGIScriptAlias /dj "C:/Apache2.2/wsgi-scripts/django.wsgi"


AllowOverride None
Options None
Order allow,deny
Allow from all


 urls
--

from django.conf.urls.defaults import *
from django.contrib import databrowse

from mainsite.tmm.models import mmerge_recipient
from django.contrib.auth.decorators import login_required
from django.conf import settings




# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

(r'^tmm/', include('mainsite.tmm.urls')),
(r'^start/$', 'mainsite.views.start'),
(r'^$', 'mainsite.views.start'),


(r'^accounts/login/$', 'django.contrib.auth.views.login'),


# Uncomment the next line to enable the admin:
(r'^admin/$', include(admin.site.urls)),


)


if settings.DEBUG:
urlpatterns += patterns('',
(r'^site_media/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
)

- Apache error log
---

[Wed Mar 03 18:33:31 2010] [error] [client 10.10.10.107] mod_wsgi
(pid=2440): Exception occurred processing WSGI script 'C:/Apache2.2/
wsgi-scripts/django.wsgi'., referer: http://cdcweb/dj/admin/
[Wed Mar 03 18:33:31 2010] [error] [client 10.10.10.107] Traceback
(most recent call last):, referer: http://cdcweb/dj/admin/
[Wed Mar 03 18:33:31 2010] [error] [client 10.10.10.107]   File "C:\
\Python26\\lib\\site-packages\\django-1.1.1-py2.6.egg\\django\\core\
\handlers\\wsgi.py", line 241, in __call__, referer: http://cdcweb/dj/admin/
[Wed Mar 03 18:33:31 2010] [error] [client 10.10.10.107] response
= self.get_response(request), referer: http://cdcweb/dj/admin/
[Wed Mar 03 18:33:31 2010] [error] [client 10.10.10.107]   File "C:\
\Python26\\lib\\site-packages\\django-1.1.1-py2.6.egg\\django\\core\
\handlers\\base.py", line 122, in get_response, referer: http://cdcweb/dj/admin/
[Wed Mar 03 18:33:31 2010] [error] [client 10.10.10.107] return
self.handle_uncaught_exception(request, resolver, sys.exc_info()),
referer: http://cdcweb/dj/admin/
[Wed Mar 03 18:33:31 

Cassandra back end for Django

2010-03-03 Thread Oshadha
Hia fellas,

I'm kind of new to Django framework.as far as I know Django only
supports four major database engines.I have a requirement to use
Cassandra(http://incubator.apache.org(/cassandra/) as the database
backend,but I couldn't find any good resources on the net that give a
helping hand.So I need a help form you guys.If anyone know a good
resources for implementing Cassandra with Django framwork please post
it here and share your experience on these technologies if you have
any.

Thanks.

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



Re: Serializing objects with a many-to-many reference

2010-03-03 Thread Jim N
I just came across manager methods in the docs:

http://docs.djangoproject.com/en/dev/topics/db/managers/#adding-extra-manager-methods

Could I have used these to create a seriallizable QuerySet, by
defining, say, a with_user() method inside the Questions model?

-Jim

On Mar 3, 10:21 am, Jim N  wrote:
> Thanks Russell,
>
> I ended up writing it myself - breaking the QuerySet into a
> dictionary, grabbing and plugging in the information from the other
> model, and then re-serializing it not using the serializer.serialize,
> but the simplejson.dumps.
>
> I'll check out DjangoFullSerializers for future reference though.  It
> seems like this kind of thing must come up all the time.
>
> -Jim
>
> On Mar 2, 6:45 pm, Russell Keith-Magee  wrote:
>
> > On Wed, Mar 3, 2010 at 12:46 AM, Jim N  wrote:
> > > Hi,
>
> > > I am writing a question-and-answer app which serializes data in JSON.
> > > I have Question, User, and Asking models.  Asking is the many-to-many
> > > relationship table for Question and User, because the Asking
> > > relationship may be more complicated than it seems.  (Several users
> > > may ask, and re-ask the same question, and I need to store when the
> > > question was asked, whether the asker is primary or secondary, publish
> > > date for the question, etc.)
>
> > > The problem comes when I serialize a Question.  I want to get the User
> > > information in the serialized object.
>
> > > Models:
>
> > > class User(models.Model):
> > >    alternate_id = models.CharField(max_length=200, null=True)
> > >    identifier = models.CharField(max_length=200, null=True)
>
> > > class Asking(models.Model):
> > >    user = models.ForeignKey(User)
> > >    question = models.ForeignKey(Question)
> > >    is_primary_asker = models.BooleanField()
>
> > > class Question(models.Model):
> > >    text = models.TextField()
> > >    user = models.ManyToManyField('User', through='Asking', null=True)
>
> > > In the view:
>
> > > questions = Question.objects.filter(**filters)
> > > return serializers.serialize("json", questions)
>
> > > That's not giving me anything but a user Id.
>
> > > I looked at natural keys, but I'm using Django 1.1.1.
>
> > > Thanks for any suggestions.
>
> > The short answer is you can't - at least, not out of the box. This is
> > a feature that has been proposed several times [1] in the past.
> > Django's serializers are primarily designed for use in the testing
> > system, where the exact structure of the serialized output isn't as
> > important.
>
> > At some point, I'm hoping to be able to do a full teardown of the
> > serialization infrastructure to make it completely configurable. This
> > would enable features like [1], along with many others.
>
> > In the interim, there is a third-party project called "Django Full
> > Serializers" [2] that includes this sort of functionality.
>
> > [1]http://code.djangoproject.com/ticket/4656
> > [2]http://code.google.com/p/wadofstuff/wiki/DjangoFullSerializers
>
> > Yours,
> > Russ Magee %-)

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



Re: how to check size of a dict or list in template

2010-03-03 Thread raj

To find whether a list/dict, say dd, is empty or not {% if dd %} is
enough. It'll return False when there is no dd defined or if it's
value can be False. Empty lists/dicts are evaluated to be False.

Check built-in filters like length, length_is etc also.



Rajeesh.

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



Re: SQL Server 2008

2010-03-03 Thread David
Steven,

I am involved in just such a project. We are Linux shop, but a lot of
the data for one of our applications is stored in SQL Server 2008. In
general, there are a couple OSS projects to support connecting Django
with SQL Server 2008.

1. django-mssql is probably the best bet but unfortunately, it only
runs on Windows
2. django-pyodbc works on Linux (with unixODBC and FreeTDS) but does
not currently support Django's new multi-database support. The
documentation could also be better.

Because our application needs to connect with multiple databases, we
are likely going to end up using SQLAlchemy/Elixir with pyodbc.

-David

On Mar 3, 6:52 am, "Steven R. Elliott Jr" 
wrote:
> Hello,
>
> I have been asked to write a front-end for an accounting system that will
> allow business participating in certain benefits plans the ability to
> receive and pay their bill online, reconcile bills, and add/delete members.
> The problem is that the database is an existing SQL Server 2008 system and I
> have not found any decent ways to connect to this database. The db itself
> contains over 200 tables but I am only interested in 7 of them. I would love
> to be able to use Django to develop the front end rather than ASP.NET but I
> don't see a great deal of support out there for SQL Server '08 (I am using a
> Mac right now... not real keen on having to bootcamp windows onto my Mac).
> Has anyone had this type of project before? If so, I'd love to hear how you
> got started.
>
> Thanks in advance,
>
> Steven Elliott

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



Send variable from view function to a templatetag

2010-03-03 Thread alecs
How can I send variable from my view function(which renders my
template) to a template tag library(which is {% load blah %} in this
template? I want to make my tag cloud independent from model:

register = Library()

@register.inclusion_tag("tags/cloud.html")
def tag_cloud(request):
"""Takes model and tag from context and returns cloud as a
response."""
tag_list = Tag.objects.cloud_for_model(HARD_CODED_MODEL, steps=9,
distribution =
tagging.utils.LOGARITHMIC,filters={'removed':False})
return {'tags' : tag_list}

Thanks :)

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



Re: verbose field names in admin

2010-03-03 Thread Adam Yee
Ok, take a look at this link...
http://docs.djangoproject.com/en/dev/topics/db/models/#verbose-field-names

If that isn't what you're looking for, then you can change it at the
form level...
http://docs.djangoproject.com/en/1.1/ref/forms/fields/#label

Again, the more detail you give will help (ie. some example code of
how you are actually doing this), and the more likely you are to get
help.

Adam

On Mar 1, 4:12 pm, pixelcowboy  wrote:
> Im not trying to change the verbose name for the model class, but for
> individual fields in the model, by the way.
>
> On Mar 1, 2:45 pm, Adam Yee  wrote:
>
>
>
> > When in doubt, always refer to the docs 
> > -http://docs.djangoproject.com/en/dev/ref/models/options/
> > There may be something small overlooked.
>
> > You shouldn't have to re-sync the database to use verbose_name.  It's
> > just a hook to be used for example, in the model's meta options.  Give
> > us more detail about your model for further help.
>
> > On Mar 1, 7:20 am, pixelcowboy  wrote:
>
> > > Hi, I have added verbose names for each of my field names, with the
> > > purpose of getting a pretty admin display. However, I have reset my
> > > database and the admin still shows the field name only, not the
> > > verbose name. Do I need to do anything else?

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



Re: how to check size of a dict or list in template

2010-03-03 Thread Jirka Vejrazka
> In the template I want to show something like
>
> {%if not  len(objects_tatus ) %} # just to clarify the purpose..I know



> But how can I check the size of the dictionary? If it was a Queryset I
> could have used qset.count  ..but here it would not work.
> Can somebody help?

 Hi there,

  there is probably more than one way to do it, but the one that comes
to mind is to write a simple custom filter, see
http://dpaste.com/167380/  (not tested)

  then you could use:

{% if object_status|generic_length > 0 %}  (or the pre-1.2 equivalent
using ifequal).

  See 
http://docs.djangoproject.com/en/1.1/howto/custom-template-tags/#howto-custom-template-tags
if you are not familiar with custom tags.

  Please note that I have tested the code, so use it as a guidance only.

  Cheers

Jirka

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



Re: what has to be changed after project.db deletion and new empty project.db file creation manually

2010-03-03 Thread Matt McCants
For sqlite3, you don't even need to create an empty db. Just put the desired
filename in your settings.py for the database name and run

python manage.py syncdb

and the database will be created along with all the tables based on the
models for all the installed apps. You don't actually need to run the sql
command unless you're just interested in what Django is going to do when you
run syncdb. Or you're going to manually run the SQL or modify it to alter
existing structure.

I'm not sure if I'm misunderstanding, but it sounds like you made the
changes in the database without making the changes to your models. It's all
about the models! Make the changes there then re-run syncdb. Hope this helps
some. There really aren't any lines to change, just a process to follow.

On Wed, Mar 3, 2010 at 1:47 AM, gintare  wrote:

> Hello.
>
> to summarize the question is
>
> which lines has to be changed when the database file i.e, referenc.db
> is deleted and later created manually as empty database?
>
> The problem is that i created whole project a week before.
>  Later i modified modules, added new tables and new fields (Rrest
> column was added for sure in table Areferenc_aref).
>  I deleted empty database file referenc.db, created new database file
> referenc.db manually expecting that new tables will be generated with
> additional fields for hem.
>
> Nevertheless the django finds only old columns.
>
> besides i made one check:
>
> 1) first of all i totally deleted referenc.db again. For big surprise
> command manage.py syncdb runs without mistakes.
>
> Besides python manage.py sql Areferenc  generates tables for non
> existing database.
>
> ^Cworking:/opt/pages/referenc# python manage.py sql Areferenc
>
> BEGIN;
> CREATE TABLE "Areferenc_aref" (
>"id" integer NOT NULL PRIMARY KEY,
>"Rfirstauthor" varchar(500) NOT NULL,
> "Rauthors" varchar(500) NOT NULL,
>"Rjournal" varchar(500) NOT NULL,
>"Rrest" varchar(500) NOT NULL,
>"Rpage" varchar(500) NOT NULL,
>"Rissue" integer NOT NULL,
> "Rvolume" integer NOT NULL,
>"Ryear" integer NOT NULL,
>"Rtitle" varchar(500) NOT NULL,
>"Rkeyw" varchar(500) NOT NULL,
>"Rurl" varchar(200) NOT NULL,
> "Rindex" varchar(500) NOT NULL,
>"Rname" varchar(500) NOT NULL,
>"Rdoi" varchar(500) NOT NULL,
>"Rlink" varchar(100) NOT NULL,
>"Rmail" varchar(75) NOT NULL,
> "Rconcl" text NOT NULL,
>"Rexists" bool NOT NULL,
>"Rinst" varchar(500) NOT NULL
> )
> ;
> CREATE TABLE "Areferenc_experimental" (
>"id" integer NOT NULL PRIMARY KEY,
> "Rexp" varchar(500) NOT NULL
> )
> ;
> CREATE TABLE "Areferenc_characterization" (
>"id" integer NOT NULL PRIMARY KEY,
>"Rchar" varchar(500) NOT NULL
> )
> ;
>  CREATE TABLE "Areferenc_devices" (
>"id" integer NOT NULL PRIMARY KEY,
>"Rdev" varchar(500) NOT NULL
> )
> ;
> CREATE TABLE "Areferenc_calculations" (
>"id" integer NOT NULL PRIMARY KEY,
> "Rcal" varchar(500) NOT NULL
> )
> ;
> CREATE TABLE "Areferenc_afieldorder" (
>"id" integer NOT NULL PRIMARY KEY,
>"Rorder" varchar(500) NOT NULL
> )
> ;
> CREATE TABLE "Areferenc_aref_Rexperimental" (
> "id" integer NOT NULL PRIMARY KEY,
>"aref_id" integer NOT NULL REFERENCES "Areferenc_aref" ("id"),
>"experimental_id" integer NOT NULL REFERENCES
> "Areferenc_experimental" ("id"),
> UNIQUE ("aref_id", "experimental_id")
> )
> ;
> CREATE TABLE "Areferenc_aref_Rcharacterization" (
>"id" integer NOT NULL PRIMARY KEY,
>"aref_id" integer NOT NULL REFERENCES "Areferenc_aref" ("id"),
> "characterization_id" integer NOT NULL REFERENCES
> "Areferenc_characterization" ("id"),
>UNIQUE ("aref_id", "characterization_id")
> )
> ;
> CREATE TABLE "Areferenc_aref_Rdevice" (
> "id" integer NOT NULL PRIMARY KEY,
>"aref_id" integer NOT NULL REFERENCES "Areferenc_aref" ("id"),
>"devices_id" integer NOT NULL REFERENCES
> "Areferenc_devices" ("id"),
> UNIQUE ("aref_id", "devices_id")
> )
> ;
> CREATE TABLE "Areferenc_aref_Rcalculation" (
>"id" integer NOT NULL PRIMARY KEY,
>"aref_id" integer NOT NULL REFERENCES "Areferenc_aref" ("id"),
> "calculations_id" integer NOT NULL REFERENCES
> "Areferenc_calculations" ("id"),
>UNIQUE ("aref_id", "calculations_id")
> )
> ;
> COMMIT
>
> 2) Secondly I created referenc.db in  ./referenc manually again.
>
> generated tables with command mentioned in step1 with the same output
> (table Areferenc_aref contains column Rrest )
>
> performed manage.py syncdb, which went fluently without mistakes.
>
> executing view i am getting error:
>
> Exception Type:
> OperationalError
>  Exception Value:
> table Areferenc_aref has no column named Rrest
>  Exception Location:
> /usr/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py in
> execute, line 193
>
>  :
>
>
> :
>
>
>  regards,
> gintare
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post 

Re: Django custom types / DjangoUnicodeDecodeError:

2010-03-03 Thread Brandon
Thanks for the pointers, Karen. That change prevents the exception
with Debug enabled, and lets us at least see the general queries that
were run, though the Id's are mangled, as you'd expect.  This should
at least get me over the hump for now.

Thanks again!

On Mar 2, 9:02 pm, Karen Tracey  wrote:
> On Tue, Mar 2, 2010 at 7:05 PM, Brandon  wrote:
> > No error.  I'm guessing Django doesn't populate connection.queries
> > when it isn't in debug mode?
>
> Right.
>
> > This would definitely work for production, but what other options do I
> > have for development? It would be a huge step up for us to be able to
> > work in an interactive shell and see what queries were run during
> > those actions.
>
> Try changing this line:
>
>      File
> "/usr/local/lib/python2.5/site-packages/django/db/backends/__init__.py",
> line 209, in 
>        to_unicode = lambda s: force_unicode(s, strings_only=True)
>
> to:
>        to_unicode = lambda s: force_unicode(s, strings_only=True,
> errors='replace')
>
> (You might want to switch to running from a copy of Django not installed in
> site-packages rather than start changing the official installed version.)
>
> That might avoid the problem, though the params data stored in connection
> queries won't necessarily be too helpful.
>
> I think there's an argument to be made that errors='replace' ought to be
> what is specified there, just because the gathering of debug data should not
> cause an exception to be raised. So that might be a relatively simple fix
> that could be put in easily, if it is actually helpful for your case.
>
> Karen

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



Re: Serializing objects with a many-to-many reference

2010-03-03 Thread Jim N
Thanks Russell,

I ended up writing it myself - breaking the QuerySet into a
dictionary, grabbing and plugging in the information from the other
model, and then re-serializing it not using the serializer.serialize,
but the simplejson.dumps.

I'll check out DjangoFullSerializers for future reference though.  It
seems like this kind of thing must come up all the time.

-Jim

On Mar 2, 6:45 pm, Russell Keith-Magee  wrote:
> On Wed, Mar 3, 2010 at 12:46 AM, Jim N  wrote:
> > Hi,
>
> > I am writing a question-and-answer app which serializes data in JSON.
> > I have Question, User, and Asking models.  Asking is the many-to-many
> > relationship table for Question and User, because the Asking
> > relationship may be more complicated than it seems.  (Several users
> > may ask, and re-ask the same question, and I need to store when the
> > question was asked, whether the asker is primary or secondary, publish
> > date for the question, etc.)
>
> > The problem comes when I serialize a Question.  I want to get the User
> > information in the serialized object.
>
> > Models:
>
> > class User(models.Model):
> >    alternate_id = models.CharField(max_length=200, null=True)
> >    identifier = models.CharField(max_length=200, null=True)
>
> > class Asking(models.Model):
> >    user = models.ForeignKey(User)
> >    question = models.ForeignKey(Question)
> >    is_primary_asker = models.BooleanField()
>
> > class Question(models.Model):
> >    text = models.TextField()
> >    user = models.ManyToManyField('User', through='Asking', null=True)
>
> > In the view:
>
> > questions = Question.objects.filter(**filters)
> > return serializers.serialize("json", questions)
>
> > That's not giving me anything but a user Id.
>
> > I looked at natural keys, but I'm using Django 1.1.1.
>
> > Thanks for any suggestions.
>
> The short answer is you can't - at least, not out of the box. This is
> a feature that has been proposed several times [1] in the past.
> Django's serializers are primarily designed for use in the testing
> system, where the exact structure of the serialized output isn't as
> important.
>
> At some point, I'm hoping to be able to do a full teardown of the
> serialization infrastructure to make it completely configurable. This
> would enable features like [1], along with many others.
>
> In the interim, there is a third-party project called "Django Full
> Serializers" [2] that includes this sort of functionality.
>
> [1]http://code.djangoproject.com/ticket/4656
> [2]http://code.google.com/p/wadofstuff/wiki/DjangoFullSerializers
>
> Yours,
> Russ Magee %-)

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



SQL Server 2008

2010-03-03 Thread Steven R. Elliott Jr
Hello,

I have been asked to write a front-end for an accounting system that will
allow business participating in certain benefits plans the ability to
receive and pay their bill online, reconcile bills, and add/delete members.
The problem is that the database is an existing SQL Server 2008 system and I
have not found any decent ways to connect to this database. The db itself
contains over 200 tables but I am only interested in 7 of them. I would love
to be able to use Django to develop the front end rather than ASP.NET but I
don't see a great deal of support out there for SQL Server '08 (I am using a
Mac right now... not real keen on having to bootcamp windows onto my Mac).
Has anyone had this type of project before? If so, I'd love to hear how you
got started.

Thanks in advance,

Steven Elliott

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



Re: ViewDoesNotExist

2010-03-03 Thread Ayush Sharma
Thanks..sometimes v just don't see small things..thanks..

On Mar 2, 5:10 am, Karen Tracey  wrote:
> On Tue, Mar 2, 2010 at 3:32 AM, Ayush Sharma 
> wrote:
>
> > i am getting the following error on the url
> >http://127.0.0.1:8000/addartist/
>
> > ViewDoesNotExist at /uploadalbum/
>
> > Tried upload in module mysite.MusicFun.views. Error was: 'module'
> > object has no attribute 'Charfield'
>
> Wherever in your code you have spelt Charfield with a lowercase f, you need
> to fix it to use the correct capitalization.
>
> Karen

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



Problems with js and http server's django

2010-03-03 Thread Servais Nabil
Hello, I use an Openlayers and jquery js application on an apache
serveur. When I try to make a request from openlayers to django and
I've got this damn error :

Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/servers/basehttp.py",
line 280, in run
self.finish_response()
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/servers/basehttp.py",
line 320, in finish_response
self.write(data)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/servers/basehttp.py",
line 416, in write
self._write(data)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.py",
line 300, in write
self.flush()
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.py",
line 286, in flush
self._sock.sendall(buffer)
error: [Errno 32] Broken pipe

The request works in the browser.

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



Re: open()

2010-03-03 Thread andreas schmid
zubin71 wrote:
> >From a method defined in a view i need to get the source of an html
> file in the templates directory. This is how i tried it out. An error
> occurs at the line,
>
> f = open(os.path.join(os.getcwd(), '../templates/test.html'), 'r') ;
>   
the output of your os.path.join is something like
'/your/current/workingdir/../templates/test.html'
> However, this causes an error, "File or directory not found".
>
> What do i do? Please help.
>   
if you want to get a dir a level over your actual workingdir you should
maybe slice the output of os.getcwd() and add the right from there on..

> thankx in advance,
> zubin71
>   

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



Re: open()

2010-03-03 Thread Gonzalo Delgado
El 03/03/10 10:45, zubin71 escribió:
> >From a method defined in a view i need to get the source of an html
> file in the templates directory. This is how i tried it out. An error
> occurs at the line,
>
> f = open(os.path.join(os.getcwd(), '../templates/test.html'), 'r') ;
>
> However, this causes an error, "File or directory not found".
>
> What do i do? Please help.
>   

Obviously the path returned by os.path.join(os.getcwd(),
'../templates/test.html') is wrong, but if the file is in the templates
directory you can fetch its contents using Django's template module
render_to_string function:

from django.template.loader import render_to_string
contents = render_to_string('test.html', {})

-- 
Gonzalo Delgado 

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



open()

2010-03-03 Thread zubin71
>From a method defined in a view i need to get the source of an html
file in the templates directory. This is how i tried it out. An error
occurs at the line,

f = open(os.path.join(os.getcwd(), '../templates/test.html'), 'r') ;

However, this causes an error, "File or directory not found".

What do i do? Please help.

thankx in advance,
zubin71

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



editing a ModelForm with extra fields

2010-03-03 Thread Kenneth Gonsalves
hi,

I have a modelform to which I have added a bunch of extra fields by overriding 
__init__(). Adding a new instance works fine, I use fm=Myform(request.POST) and 
fm.save() saves the Model, and then I can access request.POST directly for the 
information in the extra fields and save them to their own model. But when 
editing an existing model instance, I am unable to succeed. I create a dic for 
the data in the extra fields, and do form=Myform(data=data,instance=instance). 
This correctly displays the data in the extra fields, but only some of the data 
in the the Model. I tried passing the data as initial data to the overridden 
__init__. The data displays properly, but the line 
Myform(request.POST,instance=instance) crashes with a key error - the keys in 
request.POST that are not found in instance. Question is: can this be done, or 
should I go back to using normal forms?
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS
http://certificate.nrcfoss.au-kbc.org.in

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



Re: how to check size of a dict or list in template

2010-03-03 Thread Alessandro Pasotti
2010/3/3 harryos 

> > I would try with
> >
> >  {%if not  object_status.0 %}
> >
>
>
> hi
> thanks.That was quite new to me..can you tell me how  that works?
>
> I also tried
> {% if not objects_status.items|length_is:"0" %}
>
>

Oops sorry, I just realize now that your dictionary has booleans as values,
so my method will probably fail.

I use it to test if a dictionary has at least a given number of elements, so
that I can format the page differently, for example you can output text in
two columns if the elements are more than 2 etc. etc.



-- 
Alessandro Pasotti
w3:   www.itopen.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to check size of a dict or list in template

2010-03-03 Thread Alessandro Pasotti
2010/3/3 jimgardener 

> what exactly does object_status.0 mean?  I got an error when I tried
> it in python shell
> jim
>
> On Mar 3, 1:10 pm, Alessandro Pasotti  wrote:
> > 2010/3/3 harryos 
>
> >
> >  {%if not  object_status.0 %}
> >
> >
>
> --
>


Templates are not pure python, object_status.0 is equivalente to python's
object_status[0], returns the value of the first element of the list.

If it is None it will evaluate to boolean false, I'm not sure about blanks
and zeroes though.


It's in the docs  but I cannot recall where exactly.


-- 
Alessandro Pasotti
w3:   www.itopen.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to check size of a dict or list in template

2010-03-03 Thread jimgardener
what exactly does object_status.0 mean?  I got an error when I tried
it in python shell
jim

On Mar 3, 1:10 pm, Alessandro Pasotti  wrote:
> 2010/3/3 harryos 

>
>  {%if not  object_status.0 %}
>
>

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



Re: reverse in settings.py, is it possible?

2010-03-03 Thread rebus_
On 3 March 2010 12:33, Aljosa Mohorovic  wrote:
> i would like to set LOGIN_URL = reverse('custom_url_name') so i'm
> wondering if something like that is possible?
> i've tried with reverse but it fails. any ideas?
>
> Aljosa Mohorovic
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

Quite an old thread but maybe it helps.

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

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



Re: How to create connection pooling in django

2010-03-03 Thread Jirka Vejrazka
>  I am using Django1.1.1(Apache via mod_wsgi deployment) with MSSQL DB. I
> found that the new DB connection is getting created for every request . But
> i want to use connection pooling.
> Can anyone provide me the link to achive connection pooling.
> Thanks and Regards,

vijay,

  first, pelase don't spam the conference with repeated emails The
fact that no-one replied to you in a few hours does not mean that you
need to resend your question. You need to consider timezones across
the globe and the fact that people usually reply in their spare time
and only if they actually know the answer or feel that they can
help/contribute.

  Are you sure that the fact that a new database connection is created
for each request is a problem for you? Most people need to solve other
performance issues first before they find out that connection pooling
would be a problem worth fixing. I'm not doubting your situation, just
asking why you think that connection pooling would significantly help
you. Creating a new DB connection is pretty cheap and quick on MySQL.

  Cheers

   Jirka

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



reverse in settings.py, is it possible?

2010-03-03 Thread Aljosa Mohorovic
i would like to set LOGIN_URL = reverse('custom_url_name') so i'm
wondering if something like that is possible?
i've tried with reverse but it fails. any ideas?

Aljosa Mohorovic

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



Re: checking size of dict or list in template

2010-03-03 Thread Tom Evans
On Wed, Mar 3, 2010 at 7:52 AM, harryos  wrote:
>
> hi
> I am passing a dictionary to the template
> say,
> objects_status={obj1:True,   obj2:False,  obj3:True }
>
> In the template I want to show something like
>
> {%if not  len(objects.status ) %} # just to clarify the purpose..I
> know len will not work
> No objects to show
>
> {% else %}
> Objects are:
> .show the objects and truth values in a table 
>
> {%endif %}
>
>
> But how can I check the size of the dictionary? If it was a Queryset I
> could have used qset.count  ..but here it would not work.
> Can somebody help?
>
> thanks
> harry
>

For this specific example, you could use the for .. empty[1] template
tag, and look at objects.items(), eg:

  {% for obj, status in objects_status.items %}
   {{ obj }}
  {% empty %}
  No objects
  {% endfor %}

If you actually wanted to access the size of the dictionary, you
should use the length[2] template filter, eg:

  There are {{ objects_status.items|length }} object(s).

Cheers

Tom

[1] http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#for-empty
[2] http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#length

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



TransactionMiddleware and 5xx responses

2010-03-03 Thread Dan Fairs
Hi there,

Django's TransactionMiddleware only rolls back the transaction if an exception 
is raised in a view. If a view doesn't raise an exception, but returns (say) a 
500 response directly, the transaction goes ahead and commits.

I noticed this while using Piston, and there's a thread about it here:

  
http://groups.google.com/group/django-piston/browse_thread/thread/2958a12d74a323fa/f4a0192943e7cddd

Is Django's behaviour here a design decision - that views should not return 500 
responses directly, but raise exceptions - or is this an omission in the 
TransactionMiddleware?

Cheers,
Dan
--
Dan Fairs  | http://www.fezconsulting.com/

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



Re: how to check size of a dict or list in template

2010-03-03 Thread harryos
> I would try with
>
>  {%if not  object_status.0 %}
>


hi
thanks.That was quite new to me..can you tell me how  that works?

I also tried
{% if not objects_status.items|length_is:"0" %}

thanks
harry

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



Re: how to check size of a dict or list in template

2010-03-03 Thread Alessandro Pasotti
2010/3/3 harryos 

>
> hi
> I am passing a dictionary to the template
> say,
> objects_status={obj1:True,   obj2:False,  obj3:True }
>
> In the template I want to show something like
>
> {%if not  len(objects_tatus ) %} # just to clarify the purpose..I know
> len will not work
> No objects to show
>
> {% else %}
> Objects are:
> .
>
> {%endif %}
>
>
> But how can I check the size of the dictionary? If it was a Queryset I
> could have used qset.count  ..but here it would not work.
> Can somebody help?
>
> thanks
> harry
>
>

I would try with

 {%if not  object_status.0 %}



-- 
Alessandro Pasotti
w3:   www.itopen.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.