making RequestContext the default context_instance

2009-12-10 Thread Preston Holmes

Is there a way to make this the default at the project level?

I see a number of tricks out there for making it easier to do within
your own views, but I'm using an auth check in django-navbar, so I
need the full context on every page, and not all reusable apps I'm
using are passing the RequestContext from their views.

As a corollary:

Should all reusable apps default to using RequestContext
context_instance in their views? If not - why not?

-Preston

--

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: Raise error based on both form and inline_formset

2009-12-10 Thread andreas schmid
this is my form+formset and the validation/error display works for both
at the same time.
maybe you can get yours working by comparing it


def myform(request):
idea_form =  ProjectideaForm
activity_formset = inlineformset_factory(Projectidea, Activity,
extra=5)
if request.method == 'POST': # If the form has been submitted...
form= idea_form(request.POST)
formset = activity_formset(request.POST,
instance=Projectidea()) # A form bound to the POST data
if form.is_valid() and formset.is_valid(): # All validation
rules pass
new_idea = form.save()
formset_models = formset.save(commit=False)
for f in formset_models:
f.projectidea = new_idea
f.save()
return HttpResponseRedirect(new_idea.get_absolute_url())
# Redirect after POST
else:
   form= idea_form()
   formset = activity_formset()
return render_to_response('fslform/fslform.html',
  {'form'   : form, 'formset': formset,},
  context_instance=RequestContext(request))





cerberos wrote:
> I'm building a library system and have models Member, Loan and
> LoanItem (relationships as you'd expect), and an inline formset to
> enter a new loan (Loan and LoanItems).
>
> A member can borrow up to 6 books at a time, so my form contains 7
> individual forms (1 loan and 6 loan items), I need to get the member
> from the loan and the number of loan items from the loan items forms
> then raise an error if the items already loaned + the number of new
> loan items entered is greater than 6.
>
> I can raise errors based on the form or the formset but not both
> together, is this possible? What do I subclass to add the custom clean
> method?
>
>
> Here's my unfinished view
>
>
> def loan_add_form(request,template_name='resources/
> loan_add_form.html'):
>
> loan = Loan()
> LoanItemFormset = inlineformset_factory
> (Loan,LoanItem,formset=LoanItemBaseModelFormSet,can_delete=False,extra=6,exclude='date_returned')
>
> if request.method == 'POST':
>
> loan_form = forms.LoanForm(request.POST,instance=loan)
> loan_item_formset = LoanItemFormset
> (request.POST,request.FILES,instance=loan)
>
> if loan_form.is_valid() and loan_item_formset.is_valid():
> loan_form.save()
> loan_item_formset.save()
>
> #request.user.message_set.create(message="Confirmation
> message.")
> #return HttpResponseRedirect('/somepath')
>
> else:
> loan_form = forms.LoanForm(instance=loan)
> loan_item_formset = LoanItemFormset(instance=loan)
>
> context = {
> 'loan_form': loan_form,
> 'loan_item_formset': loan_item_formset,
> }
>
> return render_to_response(template_name, context,
> context_instance=RequestContext(request))
>
> --
>
> 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: how to not delete Image files

2009-12-10 Thread PanFei
hi all,I have solve the problem ,I custom a Storage class and assign it to
the ImageField , then OK!

On Fri, Dec 11, 2009 at 3:16 PM, Xia Kai(夏恺)  wrote:

> Hope this link would be of use to you:
>
>
> http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods
>
>
> Xia Kai(夏恺)
> xia...@gmail.com
> http://blog.xiaket.org
>
> --
> From: "PanFei" 
> Sent: Friday, December 11, 2009 3:02 PM
> To: "Django users" 
> Subject: how to not delete Image files
>
> > Hi all, I have a model that use ImageField , now i want to delete a
> > recorder from the database,but after call delete() my the file is also
> > deleted ! i think i should override some method ,but where it
> > is ,looking forward for you reply ,thank you .
> >
>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-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: how to not delete Image files

2009-12-10 Thread 夏恺
Hope this link would be of use to you:

http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods


Xia Kai(夏恺)
xia...@gmail.com
http://blog.xiaket.org

--
From: "PanFei" 
Sent: Friday, December 11, 2009 3:02 PM
To: "Django users" 
Subject: how to not delete Image files

> Hi all, I have a model that use ImageField , now i want to delete a
> recorder from the database,but after call delete() my the file is also
> deleted ! i think i should override some method ,but where it
> is ,looking forward for you reply ,thank you .
>
 

--

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

2009-12-10 Thread PanFei
Ps : I use the model in django admin .

On Dec 11, 3:02 pm, PanFei  wrote:
> Hi all, I have a model that use ImageField , now i want to delete a
> recorder from the database,but after call delete() my the file is also
> deleted ! i think i should override some method ,but where it
> is ,looking forward for you reply ,thank you .

--

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




how to not delete Image files

2009-12-10 Thread PanFei
Hi all, I have a model that use ImageField , now i want to delete a
recorder from the database,but after call delete() my the file is also
deleted ! i think i should override some method ,but where it
is ,looking forward for you reply ,thank you .

--

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




Break statement in Djnago template

2009-12-10 Thread guptha
Hi group,
Is there any break statement in Django template like one in java to
break for loop as an element if found .

{% for enqhasparent in enqhasparentobjs %}
 {% ifequal enobj.id enqhasparent.enquiry.id %}
{{enobj.student_name|capfirst}}
 
  {% endifequal %}
{% endfor %}


Thanks
Ganesh

--

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: Queryset filter on foreign key

2009-12-10 Thread Mark Schuuring
Hey Daniel,
First of all thanks a lot for your response. You understood it right
that i just want to split up the columns by the blog id so the
defintion of blogs_one and blogs_two was really helpful, thanks. So in
the shell i found out the blogs_x sort the posts. But unfortunately i
can't get it straight to let this work in the template. I worked
through the http://docs.djangoproject.com/en/dev/ref/templates/builtins/
page and used several conditioners (for / if ) which all don't work or
I applied them wrong. For now I have this

** views.py *
def blogs(request, username=None, template_name="blog/blogs.html"):
blogs_one = Post.objects.filter(blog__id=1)
global blogs_one

blogs_two = Post.objects.filter(blog__id=2)
global blogs_two

if username is not None:

user = get_object_or_404(User, username=username.lower())
blogs_one = Post.objects.filter(author=user, blog__id=1)
blogs_two = Post.objects.filter(author=user, blog__id=2)
return render_to_response(template_name, {
"blogs_one": blogs_one,
"blogs_two": blogs_two,
}, context_instance=RequestContext(request))

** Template ***

{% if blogs %}
{% trans "These are blog posts from everyone:" %}




  {% autopaginate blogs_one %}

{% for blog_post in blogs %}
{% show_blog_post blog_post %}
{% endfor %}
{% paginate %}


  {% autopaginate blogs_two %}

{% for blog_post in blogs %}
{% show_blog_post blog_post %}
{% endfor %}
{% paginate %}




{% else %}
{% trans "No blog posts yet." %}
{% endif %}



2009/12/8 Daniel Roseman :
> On Dec 8, 2:47 am, GoSantoni  wrote:
>> Guys, i'm struggling with this problem for more than a week now. My
>> goal is to use a queryset filter with a foreign key>> Issues are
>> 1) column generates a list, what is the right way to get the blog id
>> for a post? So whether the post belongs to blog  1 question or blog 2
>> answer? Tried  Post.objects.get which fails...
>> 2) howto define this in the template
>>
>> Any help/ directions are appreciated!
>>
>> ** First I created this model  with a foreign key
>> **
>> class blog(models.Model):
>>     function_CHOICES = (
>>         (1, _('question')),
>>         (2, _('answer')),
>>         )
>>     function          = models.IntegerField(_('function'),
>> choices=function_CHOICES, default=2)
>>
>>     def __unicode__(self):
>>         return self.get_function_display()
>>
>> class Post(models.Model):
>>     blog = models.ForeignKey(blog)
>>
>> * This is the view with the 'column definition'
>> **
>> def blogs(request, username=None, template_name="blog/blogs.html"):
>>     blogs = Post.objects.filter(status=2).select_related
>> (depth=1).order_by("-publish")
>>     column = Post.objects.values(blog__id).select_related('blog')
>>
>>    if column == 1:
>>      blogs = blogs.filter(author=user).exclude(column==2)
>>
>>    pass
>>      blogs = blogs.filter(author=user).exclude(column==1)
>>
>>    return render_to_response(template_name, {
>>        "blogs": blogs,
>>    }, context_instance=RequestContext(request))
>>
>> * Template. Goal: create 2 columns filtered by whether column
>> =1 or 2 
>>
>> 
>> 
>> 
>>     {% if blogs %}
>>         {% trans "These are blog posts from everyone:" %}
>>       {% autopaginate blogs %}
>>
>>                             ** if column == 1 **
>>             {% for blog_post in blogs %}
>>             {% show_blog_post blog_post %}
>>             {% endfor %}
>>
>>         {% paginate %}
>>     {% else %}
>>         {% trans "No blog posts yet." %}
>>     {% endif %}
>> 
>> 
>>     {% if blogs %}
>>         {% trans "These are blog posts from everyone:" %}
>>
>>                            ** condition for passed data
>> **
>>       {% autopaginate blogs %}
>>             {% for blog_post in blogs %}
>>                 {% show_blog_post blog_post %}
>>             {% endfor %}
>>         {% paginate %}
>>
>>     {% else %}
>>         {% trans "No blog posts yet." %}
>>     {% endif %}
>> 
>> 
>> 
>
> It's really unclear what you are trying to do here. You haven't
> allowed for any way to pass in a parameter to filter on, so you will
> always get all blogs to start with (with posts filtered by user).
> 'Column' - ie blog id - is a property of *each post* in the queryset,
> and will be different for different posts.
>
> Is it just that you want to split them up into two columns depending
> on the blog id? In which case, you could do it like this:
>
> blogs_one = Post.objects.filter(author=user, blog__id=1)
> blogs_two = Post.objects.filter(author=user, blog__id=2)
>
> and then iterate through blogs_one and 

Re: Django HTTPS and HTTP Sessions

2009-12-10 Thread Carlos Ricardo Santos
Is is possible to change the uploaded filename like:

request.FILES['file']['filename']=current.user.username+'_'+str(
current.user.id)

It says 'InMemoryUploadedFile' object does not support item assignment.

Anyway to override 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.




Django HTTPS and HTTP Sessions

2009-12-10 Thread Tony Thomas
Hi,

I'm using Django 1.1.1 with the ssl redirect middleware.

Sessions data (authentication etc.) created via HTTPS are not
available in the HTTP portions of the site.

What is the best way to make it available without having to make the
entire site HTTPS?

--

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.




GenericStackedInline max_num late binding before assigning ModelAdmin.inlines a value

2009-12-10 Thread Silvano
Hi All

I'm stuck with a seemingly simple problem. I have MyInline inherited
from GenericStackedInline that I use in several other ModelAdmins. In
some of these ModelAdmins I want to have MyInline.max_num=1 in others
I need MyInline.max_num=3.

Apparently binding locally to the class MyInline does not work (please
see simplified code below). This will make the first setting
persistent throughout all the code. Would admin.ModelAdmin.inlines
accept a list of objects of type MyInline to which I could bind to?

Any ideas on how to do this differently are much appreciated.

Thanks in advance
Silvano




file: app1.admin.py

class MyInline(generic.GenericStackedInline):
extra = 3
model = MyModel1


file: app2.admin.py

class MyAdmin2(admin.ModelAdmin):
MyInline.max_num = 1 # Obviously this will be persistent
throughout all the code
inlines = [MyInline, ]



file: app3.admin.py

class MyAdmin2(admin.ModelAdmin):
MyInline.max_num = 3 # This has no effect
inlines = [MyInline, ]

--

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: problem execute remote commands in views

2009-12-10 Thread victor
same problem with paramiko,i tried paramiko first in fact.
success login and execute commands with paramiko,but got http response
code 499,when got host key invalid with commands.
both success in django shell when fail to get http response in view.

On Dec 10, 5:47 pm, Tom Evans  wrote:
> On Thu, Dec 10, 2009 at 9:36 AM, victor  wrote:
> > i need to execute remote commands through ssh in views,following is my
> > code:
> > @login_required
> > def reposCheck(request):
> >    if request.method == 'POST':
> >        from commands import getoutput
> >        rs = getoutput('ssh t...@192.168.1.2 "[ -d /home/shing3d/
> > shin/ ] && echo 1 || echo 0"')
> >        return HttpResponse(rs)
> >    return HttpResponse('ok')
>
> > the same command success execute in django shell,but got no response
> > from above code when the remote server have detected success login.
> > the http response code is 499.
> > can anyone tell me how to treat it?thx
>
> Probably because you don't have a tty allocated when you run in the
> view. You should be using something like paramiko[1] for this.
>
> Cheers
>
> Tom
>
> [1]http://www.lag.net/paramiko/

--

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.




sitemap how to publish many to many field?

2009-12-10 Thread Michael
Hi there,

I am playing around with Django's sitemap app and I have a question.
When I pass a normal query in a sitemap class like Shop.objects.all()
everything works fine. My problem begins when I try to publish a model
with a many to many field in it.

When I test this code below in the Python shell everything works as I
expected. The query returns two lists. The first is a list of shops
with productgroup 'prepaid' and the second is a list of shops with
productgroup 'tv'. However, when I save the query in my sitemap.py
file and run it only the first group appears in my /sitemap.xml page.

class ShopsInProductGroup(Sitemap):
changefreq = "daily"
priority = 0.7

slug = ['prepaid', 'tv']

def items(self):
for item in self.slug:
navigation = ProductGroup.objects.get(slug=item)
shops = navigation.shop_set.all().order_by('shopname')
return shops

I guess I am doing something wrong but I can't figure out what

--

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: Separate views for form display and handling

2009-12-10 Thread aa56280
> render_to_response('foo.html', {'form' : form'})

Forgot to add: the form instance in this case will be bound to the
submitted data and will contain the appropriate errors.

--

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: Separate views for form display and handling

2009-12-10 Thread aa56280
First of all, any reason why you're using different views and not the
same view?

Second, yes it's possible to do what you're trying to do. Try this:

if form.is_valid():
  # do something and redirect
else:
  render_to_response('foo.html', {'form' : form'})

--

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: Problems witch Apache - KeyError at / - 'HOME'

2009-12-10 Thread Graham Dumpleton


On Dec 10, 10:01 pm, edward9  wrote:
> Ok. Probably that its. But where can i found proper configuration for
> apache?

What do you mean by proper configuration? That is how Apache/
mod_python works, you can't readily change that behaviour.

If you want your Django instance to run as you rather than special
Apache user and want HOME to still be valid so you can avoid doing the
correct thing of using absolute paths rather than relying on $HOME
being set, then use Apache/mod_wsgi instead. In particular, use
mod_wsgi daemon mode and set up daemon process to run as you.

Do, disable mod_python completely, get mod_wsgi installed and work
through hello world examples in:

  http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide

In the last one with daemon process, change WSGIDaemonProcess line to:

  WSGIDaemonProcess example.com user=your-user-name group=your-primary-
group \
processes=2 threads=15 display-name=%{GROUP}

Replace 'your-user-name' and 'your-primary-group' with what you get
for user/group when you run 'id' command on command line. Eg. if:

  $ id
  uid=501(grahamd) gid=20(staff)

use:

  WSGIDaemonProcess example.com user=grahamd group=staff \
processes=2 threads=15 display-name=%{GROUP}

Modify the hello world program to:

import os

def application(environ, start_response):
status = '200 OK'
output = 'Hello World!\n'
output += 'HOME=%s\n' % os.environ['HOME']

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]

to verify that HOME is actually your home directory.

Once you have confirmed everything working as expect, then you can
instead set up Django.

For that see:

  http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

Graham

> Or can U help me by pasting samples Apache configuration? I have read
> some tutorials about configuration Django with Apache and mod_python
> but nothing works :(
>
> And about quotas i think this is not it. Code without quotas works
> fine on dev server, but stop working on apache.
>
> Regards
> Ed
>
> On Dec 10, 10:14 am, Graham Dumpleton 
> wrote:
>
>
>
> > You do understand that when running under Apache that the code runs as
> > a special Apache user.
>
> > So, not only would the home directory not even be that for your home
> > account, Apache scrubs the HOME user environment variable from the
> > process environment anyway, and so trying to access HOME variable will
> > fail.
>
> > General rule in web programming is, never to rely on user environment
> > variables and secondly never rely on current working directory being a
> > particular location nor use relative paths, always use absolute paths
> > instead.
>
> > Graham
>
> > On Dec 10, 5:19 am, edward9  wrote:
>
> > > Hello everybody
>
> > > I'm new and i want to say Hello to Everybody.
>
> > > I have problem with Apache. I install python, django, apache,
> > > mod_apache and all what is necessary.
>
> > > Apache configuration is:
> > >         
> > >             SetHandler python-program
> > >             PythonHandler django.core.handlers.modpython
> > >             SetEnv DJANGO_SETTINGS_MODULE mysite.settings
> > >             PythonOption django.root /mysite
> > >             PythonDebug Off
> > >             #PythonPath "['/',  '/mysite', '/var/www'] + sys.path"
> > >             PythonPath "['/'] + sys.path"
> > >         
>
> > > I created an application i root folder:
> > > django-admin.py startproject mysite
> > > and i started development(runserver). All works fine. "Configurations
> > > on your first Django-powered page". Running on apache also works fine.
>
> > > But when i create Django app:
> > > manage.py startapp inet
> > > views.py:
> > > # Create your views here.
> > > from django.http import HttpResponse
> > > from django.db import connection
> > > from django.conf import settings
> > > from datetime import datetime
>
> > > def main_page(request):
> > >         output = '''
> > >                 
> > >                         %s
> > >                         
> > >                                 %s%s%s
> > >                         
> > >                 
> > >         ''' % (
> > >                 '1','a','b','c'
> > >         )
> > >         return HttpResponse(output)
>
> > > urls.py
> > > from django.conf.urls.defaults import *
> > > from inet.views import *
>
> > > urlpatterns = patterns('',
> > >         (r'^$',main_page),
> > > )
>
> > > on development server works fine but started on apache i get:
>
> > > KeyError at /
>
> > > 'HOME'
>
> > > Request Method:         GET
> > > Request URL:    http://127.0.0.1/
> > > Exception Type:         KeyError
> > > Exception Value:
>
> > > 'HOME'
>
> > > Exception Location:     /usr/lib/python2.5/UserDict.py in __getitem__,
> > > line 22
> > > Python Executable:      /usr/bin/python
> > > Python Version: 

Re: CSV to JSON snippet

2009-12-10 Thread Zeynel
This worked fine before but now I get the error

C:\...\Django\sw2\wkw2>csv2json.py csvtest1.csv wkw2.Lawyer
Converting C:\...\Django\sw2\wkw2csvtest1.csv from CSV to JSON as C:...
\Django\sw2\wkw2csvtest1.csv.json
Traceback (most recent call last):
  File "C:\...\Django\sw2\wkw2\csv2json.py", line 37, in 
f = open(in_file, 'r' )
IOError: [Errno 2] No such file or directory: 'C:\\...\\Django\\sw2\
\wkw2cvtest1.csv'

>From the snippet http://www.djangosnippets.org/snippets/1680/:

31 in_file = dirname(__file__) + input_file_name
32 out_file = dirname(__file__) + input_file_name + ".json"

34 print "Converting %s from CSV to JSON as %s" % (in_file, out_file)

36 f = open(in_file, 'r' )
37 fo = open(out_file, 'w')


It seems to combine the directory name and file name?

Thanks.

On Nov 14, 7:42 am, Zeynel  wrote:
> Great, thank you. When I ran it in the command prompt it worked fine.
> I noticed that the first column needs to be "pk" with rows starting
> with integers.
>
> On Nov 13, 11:24 pm, Karen Tracey  wrote:
>
>
>
> > On Fri, Nov 13, 2009 at 10:57 PM, Zeynel  wrote:
> > > Thanks, I tried but this did not work either:
>
> > > >>> csv2json.py sw.csvwkw1.Lawyer
>
> > >  File "", line 1
> > >    csv2json.py sw.csvwkw1.Lawyer
> > >                 ^
> > > SyntaxError: invalid syntax
>
> > You need to run the .py script from an OS shell (command prompt), not from
> > within a Python shell.
>
> > 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: how to produce XML output from a test run?

2009-12-10 Thread Phlip
>    python manage.py test --xml

just a note; django-test-extensions broke --verbosity. Google
Codesearch sez the fix is in there, but pip didn't have it. I'm now
patching this up internally.

other than that the package works great!

Oh, except the assertions need embellished diagnostics...

--

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 Sites in Admin Forms

2009-12-10 Thread bfrederi
I got advice from someone in the IRC channel to do this:

from django.contrib.sites.models import Site

def __unicode__(self):
 return self.name

Site.__unicode__ = __unicode__

And it worked.

On Dec 9, 6:02 pm, bfrederi  wrote:
> In one of my models, I have a foreign key to Django's Site model. When
> I view my model in admin, it displays the Site entries by their domain
> (in the __unicode__ method). Is there any way to display the name of
> the Site instead of the domain in admin?

--

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

2009-12-10 Thread Zeynel
I tried to convert my csv file with csv2json.py and it worked before
(see this thread
http://groups.google.com/group/django-users/browse_frm/thread/a00b529ba2147d91/efb82ba2893cc0a7?lnk=gst=csv#efb82ba2893cc0a7)
but now I am trying the same exact thing in a different directory and
I get this error:

C:\...\Django\sw2\wkw2>csv2json.py csvtest1.csv wkw2.Lawyer
Converting C:...\Django\sw2\wkw2csvtest1.csv from CSV to JSON as
C:\...\Django\sw2\wkw2csvtest1.csv.json

Traceback (most recent call last):
  File "C:\...\Django\sw2\wkw2\csv2json.py", line 37, in 
f = open(in_file, 'r' )
IOError: [Errno 2] No such file or directory:
'C:\\...\\Django\\sw2\\wkw2csvtest1.csv'

Below is the link to csv2jason.py and line 37:

http://www.djangosnippets.org/snippets/1680/
...
in_file = dirname(__file__) + input_file_name
out_file = dirname(__file__) + input_file_name + ".json"

print "Converting %s from CSV to JSON as %s" % (in_file, out_file)

[line 37] --> f = open(in_file, 'r' )
fo = open(out_file, 'w')

Do you know an easier way to convert csv to json? (Or how to fix
this?)

On Dec 10, 1:27 pm, John M  wrote:
> You could also use OpenOffice with the SQLIte connector (I think)
>
> I use Access in Windows, works great!
>
> But you might try getting the CSV into a JSON format that the
> manage.py loaddata command could use, that set's you up for the future
> too.
>
> J
>
> On Dec 10, 8:57 am, Zeynel  wrote:
>
>
>
> > Can anyone point me in the right place in documentation for populating
> > my sqlite3 tables with the data in the .csv file? 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.




Issue with Django form when submitted using jQuery form plugin

2009-12-10 Thread jul
hi,

when submitting my form using jQuery form plugin, the request received
by the target view is different than that received when the form is
submitted in the standard way (with no javascript), and my Django
template does not render as expected. When submitted in the standard
way, the template renders the form errors (the "form.
[field_name].errors), while it doesn't when submitted via javascript.
Using the javascript submit, how can I get a request allowing to
render the template as it does using the standard submit?
The code and the diff between the request objects received in both
cases are shown below.

thanks
jul

javascript code:

*
var is_geocoded = false;
var interval;

$(function(){

$("#submit").click(function() {
var options = {
beforeSubmit:  getPosition,  // pre-submit callback
success:   showResponse  // post-submit
callback
};

// bind form using 'ajaxForm'
$('#addresto').ajaxForm(options);
});

});

function getPosition() {

var geocoder =  new GClientGeocoder();
var country = $("#id_country").val();
var city = $("#id_city").val();
var postal_code = $("#id_postal_code").val();
var street_number = $("#id_street_number").val();
var street = $("#id_street").val();
var address = street_number+", "+street+", "+postal_code+", "+city
+", "+country;

geocoder.getLatLng( address, function(point) {

if (point) {

$("#id_latitude").val(point.lat())
$("#id_longitude").val(point.lng())
is_geocoded = true;
} else {
is_geocoded = true;
}
});

interval = setInterval("doSubmit()", 500);

return false;
}

function doSubmit() {

if (is_geocoded) {
$("#addresto").ajaxSubmit();
clearInterval(interval);
}
}
*

Django template code:

*


Name:{{form.name.errors}}
{{ form.name }} 
Country:{{form.country.errors}}
{{ form.country }} 





*

Here's the difference between the request objects received by the view
with standard submit and with javascript submit:

*
x...@xxx:~$ diff javascript_submit standard_submit
7c7
<  'CONTENT_TYPE': 'application/x-www-form-urlencoded; charset=UTF-8',
---
>  'CONTENT_TYPE': 'application/x-www-form-urlencoded',
24c24
<  'HTTP_ACCEPT': '*/*',
---
>  'HTTP_ACCEPT': 
> 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
28d27
<  'HTTP_CACHE_CONTROL': 'no-cache',
33d31
<  'HTTP_PRAGMA': 'no-cache',
36d33
<  'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
70c67
<  'wsgi.input': ,
---
>  'wsgi.input': ,

--

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




Separate views for form display and handling

2009-12-10 Thread Aaron
I have a page with a form on it, and I want to use a separate view
function to handle the form submission and redirect to the page view.
So, the form's action would be "action="{% url views.handleform %}".

This works fine when the form has no errors; it just needs a simple
HttpRedirectResponse. However, I need a way to send the form object
back to the display page if there are any errors found in the form.

I'm actually wondering if this is even possible. Passing form objects
back to the view implies that they'd be optional arguments in the page
view function, where I'd create my own forms if none are provided.
However, it seems the only way a Django view can ever get arguments is
through either its URL string or through its keyword arguments
dictionary in the URLconf.

Is there still hope for me? :/

--

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




Re: How to populate the database

2009-12-10 Thread Zeynel
Thanks, I'll try it now. What does

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'

do? I read the documentation here http://docs.python.org/library/os.html
but I didn't understand.

My app is in

C:.../Documents/PROJECTS/Django/sw2/wkw2.

Do I enter?

os.environ['DJANGO_SETTINGS_MODULE'] = 'sw2.settings'?
from sw2.wkw2.models import School, Lawyer

By INPUT_FILE you mean the file where data I want to upload to sqlite3
is, correct? That file is sw2/csvtest1.csv

What's 'Internal ID'?




This is my models.py:

from django.db import models

class School(models.Model):
school = models.CharField(max_length=300)
def __unicode__(self):
return self.school


class Lawyer(models.Model):
firm_url = models.URLField('Bio', max_length=200)
firm_name = models.CharField('Firm', max_length=100)
first = models.CharField('First Name', max_length=50)
last = models.CharField('Last Name', max_length=50)
year_graduated = models.IntegerField('Year graduated')
school = models.CharField(max_length=300)
school = models.ForeignKey(School)
class Meta:
ordering = ('?',)
def __unicode__(self):
return self.first


Thanks!


On Dec 10, 12:56 pm, Shawn Milochik  wrote:
> Sure, here's a quick & dirty sample I put up on pastebin:
>
> http://pastebin.com/f651cf8de

--

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.




Cross tabulation in template

2009-12-10 Thread John M
I've got data that looks like this from a query

{'status': u'E', 'env__count': 15, 'env': u'dev'}
{'status': u'H', 'env__count': 31, 'env': u'dev'}
{'status': u'I', 'env__count': 164, 'env': u'dev'}
{'status': u'N', 'env__count': 149, 'env': u'dev'}
{'status': u'I', 'env__count': 17, 'env': u'dr'}
{'status': u'H', 'env__count': 2, 'env': u'prod'}
{'status': u'I', 'env__count': 34, 'env': u'prod'}
{'status': u'E', 'env__count': 2, 'env': u'qa'}
{'status': u'H', 'env__count': 1, 'env': u'qa'}
{'status': u'I', 'env__count': 63, 'env': u'qa'}
{'status': u'N', 'env__count': 5, 'env': u'qa'}
{'status': u'E', 'env__count': 1, 'env': u'stage'}
{'status': u'H', 'env__count': 4, 'env': u'stage'}
{'status': u'I', 'env__count': 59, 'env': u'stage'}
{'status': u'N', 'env__count': 2, 'env': u'stage'}
{'status': u'E', 'env__count': 8, 'env': u'xxx'}
{'status': u'H', 'env__count': 1, 'env': u'xxx'}
{'status': u'I', 'env__count': 38, 'env': u'xxx'}
{'status': u'N', 'env__count': 3, 'env': u'xxx'}

is there anyway to make a cross-tab output in a template?

My only solution right now is to pass in several dictionaries with
each of the status's and their counts.  Other ideas would help.

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.




Re: How to populate the database

2009-12-10 Thread John M
You could also use OpenOffice with the SQLIte connector (I think)

I use Access in Windows, works great!

But you might try getting the CSV into a JSON format that the
manage.py loaddata command could use, that set's you up for the future
too.

J

On Dec 10, 8:57 am, Zeynel  wrote:
> Can anyone point me in the right place in documentation for populating
> my sqlite3 tables with the data in the .csv file? 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: Moved server, can't log in

2009-12-10 Thread Oli Warner
I'm afraid this isn't the case for me. My sessions (if these setting does
what they're supposed to) are stored in memcached

CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
SESSION_ENGINE = "django.contrib.sessions.backends.cache"

And memcached is running (there are other sites on the server).
But yes, I am using the sessions framework.


On Thu, Dec 10, 2009 at 2:46 PM, brad  wrote:

>
>
> On Dec 10, 4:57 am, Oli Warner  wrote:
> > A couple of days ago I moved a site from one server to another server and
> > changed the DNS on the domain so it stayed the same. After the DNS had
> > migrated everybody but me could log in. All other users trying to log
> into
> > the admin were getting the "Looks like your browser isn't configured to
> > accept cookies [...]" error. There's also a log in page for non-admins
> and
> > that was also just refusing to log people in.
> >
> > The only way I could fix it was to set the server to redirect the users
> > through to a different subdomain. I would like to go back to the original
> > domain but I can't if it breaks (this is a business-to-business webapp -
> it
> > can't have downtime).
> >
> > I've also got to move a couple more sites in the coming days but I can't
> > until I can figure out what happened here so I can prevent this happening
> > again in the future.
> >
> > I need ideas... Ideally more advanced than "clear the cookies" as there
> are
> > a couple of hundred users on the system - this is vastly impractical.
> >
> > Thanks in advance.
> >
> > This question is also on stackoverflow (if you're a user and you think
> you
> > have the answer, you can get some points):
> http://stackoverflow.com/questions/1872796/changed-django-server-loca...
>
> Are you using Django's session framework? If so, it stores session
> info in the database, which you might want to clear.
>
> See:
> django-admin.py help cleanup
>
> --
>
> 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: question about changing model/table names and attributes ... (still learnin')

2009-12-10 Thread Guy
Thanks, for the advice.  I am checking it out.To clarify, my table
names have changed when I realize styling erros have been
incorporated, (ie. capitalization errors, etc). I wouldn't expect
the table names to change in the operational db.

Thanks again.
Guy

On Dec 10, 12:32 pm, Shawn Milochik  wrote:
> The current best tool for this is South:http://south.aeracode.org/
>
> You can do complicated data and database migrations smoothly, with the 
> ability to roll-back changes.
> I don't know why you mention changing table names, since that should never be 
> necessary. But anything is possible.
>
> If you're doing "major" changes, defined (by me) as creating a new thing 
> (field or table, A.K.A. attribute or model), moving data out of an existing 
> thing into it, then deleting the original thing, you'll want to carefully 
> read and understand South's excellent strategy for doing 
> this;http://south.aeracode.org/wiki/Tutorial3
>
> All your normal stuff, such as adding attributes to models, changing 
> properties (required or not, default values, and so on) are a piece of cake 
> with South.
>
> 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: How to populate the database

2009-12-10 Thread Shawn Milochik
Sure, here's a quick & dirty sample I put up on pastebin:

http://pastebin.com/f651cf8de

--

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 populate the database

2009-12-10 Thread Zeynel
Thanks. I couldn't make the sqlite3 shell work on windows command
prompt, so I cannot use .import.

> read the csv with csv.DictReader, then create instances of my model
> with the values from the resulting dictionary, then calling a .save() on
> the new instance.

Do you have more detailed instructions on this method?

On Dec 10, 12:08 pm, Shawn Milochik  wrote:
> There are different ways to do it, depending on how much data you have and 
> how often you plan to do it.
>
> The fastest way for large files is to use sqlite3's .import command to 
> directly import a file. However, this will bypass any validation done by your 
> models.
>
> The way I do it is to read the csv with csv.DictReader, then create instances 
> of my model with the values from the resulting dictionary, then calling a 
> .save() on the new instance. This is fairly slow, but thorough; you won't 
> realize belatedly that your database is missing required fields or has 
> invalid values, because the script will just blow up if you try.
>
> 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: how to avoid pk collisions at loaddata time

2009-12-10 Thread Phlip
On Dec 9, 4:25 pm, Russell Keith-Magee  wrote:

> > In general, Django "encourages" screwing with the Admin, then
> > extruding sample records, while RoR "encourages" writing very terse,
> > very templated YAML files as test code source.
>
> What rubbish.

Just a netiquette note - I stopped reading 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.




Re: question about changing model/table names and attributes ... (still learnin')

2009-12-10 Thread Shawn Milochik
The current best tool for this is South: http://south.aeracode.org/

You can do complicated data and database migrations smoothly, with the ability 
to roll-back changes.
I don't know why you mention changing table names, since that should never be 
necessary. But anything is possible.

If you're doing "major" changes, defined (by me) as creating a new thing (field 
or table, A.K.A. attribute or model), moving data out of an existing thing into 
it, then deleting the original thing, you'll want to carefully read and 
understand South's excellent strategy for doing this;
http://south.aeracode.org/wiki/Tutorial3

All your normal stuff, such as adding attributes to models, changing properties 
(required or not, default values, and so on) are a piece of cake with South.

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.




question about changing model/table names and attributes ... (still learnin')

2009-12-10 Thread Guy

What is the "best practice" for editing table names or attributes
after they have been established by manage.py syncdb?

Since I am in the very early stages, I either delete the database and
create a new one with syncdb, or manually change the table names (I
generally use the SQLite manager plugin for firefox to assist with the
SQL).

Is there a better way of doing this?  Destroying the database and
building a new one works now when I only have some test entries, but I
am concerned that this would be impractical once my db is fully
populated with real data. Likewise, I want to be careful when editing
tables that contain valuable data.

Can someone point me to a good write-up of this process, or good
software?

Go easy on me, I spent my education in biology and am just getting
started trying to understand silicon rather than carbon based systems.

Thanks.
Guy

--

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: return a dynamically generated image to the user?

2009-12-10 Thread David De La Harpe Golden
Alexander Dutton wrote:
> 
> The alternative would be to stick an Alias in your apache conf (assuming
> you're using apache) to serve the files directly from the filesystem.
> This solution wouldn't let you perform any authorisation, though.
> 

N.B. There is nowadays the X-SendFile thing, should be mentioned a fair
few times in the list archive, you can do authorization in the django
view then hand an order to apache to serve the file from the fs.


--

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 populate the database

2009-12-10 Thread Shawn Milochik
There are different ways to do it, depending on how much data you have and how 
often you plan to do it.

The fastest way for large files is to use sqlite3's .import command to directly 
import a file. However, this will bypass any validation done by your models.

The way I do it is to read the csv with csv.DictReader, then create instances 
of my model with the values from the resulting dictionary, then calling a 
.save() on the new instance. This is fairly slow, but thorough; you won't 
realize belatedly that your database is missing required fields or has invalid 
values, because the script will just blow up if you try.

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.




Raise error based on both form and inline_formset

2009-12-10 Thread cerberos
I'm building a library system and have models Member, Loan and
LoanItem (relationships as you'd expect), and an inline formset to
enter a new loan (Loan and LoanItems).

A member can borrow up to 6 books at a time, so my form contains 7
individual forms (1 loan and 6 loan items), I need to get the member
from the loan and the number of loan items from the loan items forms
then raise an error if the items already loaned + the number of new
loan items entered is greater than 6.

I can raise errors based on the form or the formset but not both
together, is this possible? What do I subclass to add the custom clean
method?


Here's my unfinished view


def loan_add_form(request,template_name='resources/
loan_add_form.html'):

loan = Loan()
LoanItemFormset = inlineformset_factory
(Loan,LoanItem,formset=LoanItemBaseModelFormSet,can_delete=False,extra=6,exclude='date_returned')

if request.method == 'POST':

loan_form = forms.LoanForm(request.POST,instance=loan)
loan_item_formset = LoanItemFormset
(request.POST,request.FILES,instance=loan)

if loan_form.is_valid() and loan_item_formset.is_valid():
loan_form.save()
loan_item_formset.save()

#request.user.message_set.create(message="Confirmation
message.")
#return HttpResponseRedirect('/somepath')

else:
loan_form = forms.LoanForm(instance=loan)
loan_item_formset = LoanItemFormset(instance=loan)

context = {
'loan_form': loan_form,
'loan_item_formset': loan_item_formset,
}

return render_to_response(template_name, context,
context_instance=RequestContext(request))

--

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: return a dynamically generated image to the user?

2009-12-10 Thread Daniel Roseman
On Dec 10, 4:45 pm, Mark Freeman  wrote:
> I have recently created a python module which parses an input string
> and invokes the program lilypond to generate a music score image. All
> of this works fine as a standalone python app. I'm now looking to add
> this to my django site so users can enter the  text on a form, hit
> submit, and have the site return the image of the music score.
>
> The form submission part is no problem, but I am not sure where to
> start with having the view return the image to the page. Anyone have
> suggestions for where to start?

An HttpResponse can contain whatever you like - it doesn't just have
to return HTML. So you can use it quite happily to return raw JPG or
PNG or whatever you want. Just set the mimetype to the correct type
when you initialise it.

Also remember that HttpResponse is a file-like object, so you can pass
it into anything that expects to write to a file.

Here for example is a very old post by Jacob that shows how to use
this to produce dynamic graphical headlines:
http://jacobian.org/writing/improved-text-image-view/
--
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: return a dynamically generated image to the user?

2009-12-10 Thread Alexander Dutton
Hi Mark

On 10/12/09 16:45, Mark Freeman wrote:
> I have recently created a python module which parses an input string
> and invokes the program lilypond to generate a music score image. All
> of this works fine as a standalone python app. I'm now looking to add
> this to my django site so users can enter the  text on a form, hit
> submit, and have the site return the image of the music score.
>
> The form submission part is no problem, but I am not sure where to
> start with having the view return the image to the page. Anyone have
> suggestions for where to start?
>   

We're doing something similar with generating maps.

We have a model to represent the generated map to record a hash of its
creation parameters (e.g. dimensions, points plotted) and when it was
generated. The map is then saved to a cache directory with the hash as a
filename.

We then have a simple view to serve the page:

def generated_map(request, hash):
map = get_object_or_404(Map, hash=hash)
f = open(map.get_filename(), 'r')
return HttpResponse(f, mimetype="image/png")

The alternative would be to stick an Alias in your apache conf (assuming
you're using apache) to serve the files directly from the filesystem.
This solution wouldn't let you perform any authorisation, though.

We remove out old maps when we reach some large number in the cache
directory so as not to fill up the disk.

HTH,

Alex


PS. Sorry Mark for sending this again; my reply-list button seems to
actually be a reply-to-sender button. Silly TB3.04b.

--

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




How to populate the database

2009-12-10 Thread Zeynel
Can anyone point me in the right place in documentation for populating
my sqlite3 tables with the data in the .csv file? 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.




return a dynamically generated image to the user?

2009-12-10 Thread Mark Freeman
I have recently created a python module which parses an input string
and invokes the program lilypond to generate a music score image. All
of this works fine as a standalone python app. I'm now looking to add
this to my django site so users can enter the  text on a form, hit
submit, and have the site return the image of the music score.

The form submission part is no problem, but I am not sure where to
start with having the view return the image to the page. Anyone have
suggestions for where to start?

--

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.




many permission sets for same user

2009-12-10 Thread Adonis
Hi,

I am trying to figure out the best way to do this.
I have built a django application where users are members in projects.
Thus, i need to assign users different permission sets that correspond
to different projects. The django core permission system cannot solve
this by itself. I took a look at django-autority extenion which seems
able enough to solve this but could not figure out how to do this.

{% ifhasperm [permission_label].[check_name] [user] [*objs] %}
lalala
{% else %}
meh
{% endifhasperm %}

in the example above, i can check a permission of a user in an object
(e.g a project in my app).
I would need multiple views of auth_user_user_permissions such as:
project1_user1_permset1, project2_user1_permset3 etc.

Any suggestions will be 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: Tricky Django tables setup

2009-12-10 Thread Superman
Awesome thanks... But then that removes the need for a Category... :
( The projects have to be linked to the Specs which are only linked to
the Category of the Project.

class ProjectSpecs(models.Models):
Project=models.ForeignKey(Project)
Specs=models.ForeignKey(Specs, ##Limit by Category of the
Project## )
Values=models.CharField(max_length=200)

You think I should write a customized function for that? I think that
may be the answer!!!

What do you guys think is it better to have more models, less columns
or less models, more columns??? Which is more efficient in the long
term?


On Dec 10, 11:26 am, GRoby  wrote:
> It sounds like you just need a ProjectSpecs Table:
>
> class ProjectSpecs(models.Models):
>     Project=models.ForeignKey(Project)
>     Specs=models.ForeignKey(Specs)
>     Values=models.CharField(max_length=200)
>
> That would let you assign as many specs to a project that you want,
> with additional fields (basically a many to many relation).
>
> On Dec 10, 10:57 am, Superman  wrote:
>
> > By the way this is what the three models roughly look like.
>
> > Class Projects(model.Models):
> >      title = models.CharField(max_length=200)
> >      category = models.ForeignKey(Category)
>
> > Class Category(model.Models):
> >      title = models.CharField(max_length=200)
> >      specs = models.ManyToManyField(Specs)
>
> > Class Specs(model.Models):
> >      title = models.CharField(max_length=200)
>
> > On Dec 10, 10:53 am, Superman  wrote:
>
> > > Thank you DR for your response.
>
> > > Yes that helps in a way, as that is what I am planning to do. But at
> > > the moment I can store the name of Projects, Categories and Specs in
> > > the three different models. Where can I store the values for the Specs
> > > for each Project? There is no table that contains that information.
> > > How can I set that table up... in a way that it can expand both
> > > sideways and downwards?
>
> > > On Dec 10, 10:38 am, Daniel Roseman  wrote:
>
> > > > On Dec 10, 3:19 pm, Superman  wrote:
>
> > > > > Hi guys, I can't wrap my head around this problem I have... someone
> > > > > please help.
>
> > > > > The Problem: I have a list of various projects, in a Project Model.
> > > > > Each of them has a foreign Key to a Category model. Each Category has
> > > > > a Many to Many Relationship to a Specification model. So it is like
> > > > > this. Project ---> Category --->(m2m) Specifications. All these tables
> > > > > are going to change/increment. I want to set up a table with column 1
> > > > > as Project, column 2 as Category and the rest of the columns as
> > > > > Specification.
>
> > > > > For ex. these are possibly two rows from the column:
> > > > > Colum -> Row1
> > > > > Project -> Skyrise Appartments
> > > > > Category -> Residential Building
> > > > > Specification -> Height - 100m
> > > > >                       -> Floors - 30f
> > > > >                       -> Cost - 50m
> > > > >                        -> Start - Dec 2009
> > > > >                        -> Finish - Dec 2010
> > > > >                         ->Rest of the columns blank
>
> > > > > Colum -> Row 2
> > > > > Project -> GreatHarbour Bridge
> > > > > Category -> Bridge
> > > > > Specification -> Length - 1 km
> > > > >                       -> Type - Cable Stayed
> > > > >                        -> Speed - 80 km/hr
> > > > >                        -> Pillars - 200
> > > > >                        -> Cost - 20m
> > > > >                        -> Start - Feb 2010
> > > > >                        -> Finish - Nov 2010
> > > > >                         >Rest of the columns blank
>
> > > > > I dont want to ceate individal tables for Each Category... coz I may
> > > > > have Hundreds of Categories, Projects and Specs. How do I go about
> > > > > doing this? Please help...
>
> > > > > Thanks
>
> > > > I don't understand what you mean when you say you want to "set up a
> > > > table" with those various columns. The columns all exist in separate
> > > > tables. What would be the benefit of putting them into a single table?
>
> > > > Do you just mean you want to output the columns from various tables at
> > > > once? You can easily do that with Django's ORM, which is capable of
> > > > traversing the relationships between tables. You can then use the
> > > > template language to group the fields into columns for output. Does
> > > > that help?
> > > > --
> > > > 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: Tricky Django tables setup

2009-12-10 Thread GRoby
It sounds like you just need a ProjectSpecs Table:

class ProjectSpecs(models.Models):
Project=models.ForeignKey(Project)
Specs=models.ForeignKey(Specs)
Values=models.CharField(max_length=200)

That would let you assign as many specs to a project that you want,
with additional fields (basically a many to many relation).

On Dec 10, 10:57 am, Superman  wrote:
> By the way this is what the three models roughly look like.
>
> Class Projects(model.Models):
>      title = models.CharField(max_length=200)
>      category = models.ForeignKey(Category)
>
> Class Category(model.Models):
>      title = models.CharField(max_length=200)
>      specs = models.ManyToManyField(Specs)
>
> Class Specs(model.Models):
>      title = models.CharField(max_length=200)
>
> On Dec 10, 10:53 am, Superman  wrote:
>
> > Thank you DR for your response.
>
> > Yes that helps in a way, as that is what I am planning to do. But at
> > the moment I can store the name of Projects, Categories and Specs in
> > the three different models. Where can I store the values for the Specs
> > for each Project? There is no table that contains that information.
> > How can I set that table up... in a way that it can expand both
> > sideways and downwards?
>
> > On Dec 10, 10:38 am, Daniel Roseman  wrote:
>
> > > On Dec 10, 3:19 pm, Superman  wrote:
>
> > > > Hi guys, I can't wrap my head around this problem I have... someone
> > > > please help.
>
> > > > The Problem: I have a list of various projects, in a Project Model.
> > > > Each of them has a foreign Key to a Category model. Each Category has
> > > > a Many to Many Relationship to a Specification model. So it is like
> > > > this. Project ---> Category --->(m2m) Specifications. All these tables
> > > > are going to change/increment. I want to set up a table with column 1
> > > > as Project, column 2 as Category and the rest of the columns as
> > > > Specification.
>
> > > > For ex. these are possibly two rows from the column:
> > > > Colum -> Row1
> > > > Project -> Skyrise Appartments
> > > > Category -> Residential Building
> > > > Specification -> Height - 100m
> > > >                       -> Floors - 30f
> > > >                       -> Cost - 50m
> > > >                        -> Start - Dec 2009
> > > >                        -> Finish - Dec 2010
> > > >                         ->Rest of the columns blank
>
> > > > Colum -> Row 2
> > > > Project -> GreatHarbour Bridge
> > > > Category -> Bridge
> > > > Specification -> Length - 1 km
> > > >                       -> Type - Cable Stayed
> > > >                        -> Speed - 80 km/hr
> > > >                        -> Pillars - 200
> > > >                        -> Cost - 20m
> > > >                        -> Start - Feb 2010
> > > >                        -> Finish - Nov 2010
> > > >                         >Rest of the columns blank
>
> > > > I dont want to ceate individal tables for Each Category... coz I may
> > > > have Hundreds of Categories, Projects and Specs. How do I go about
> > > > doing this? Please help...
>
> > > > Thanks
>
> > > I don't understand what you mean when you say you want to "set up a
> > > table" with those various columns. The columns all exist in separate
> > > tables. What would be the benefit of putting them into a single table?
>
> > > Do you just mean you want to output the columns from various tables at
> > > once? You can easily do that with Django's ORM, which is capable of
> > > traversing the relationships between tables. You can then use the
> > > template language to group the fields into columns for output. Does
> > > that help?
> > > --
> > > 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: Tricky Django tables setup

2009-12-10 Thread Superman
By the way this is what the three models roughly look like.

Class Projects(model.Models):
 title = models.CharField(max_length=200)
 category = models.ForeignKey(Category)

Class Category(model.Models):
 title = models.CharField(max_length=200)
 specs = models.ManyToManyField(Specs)

Class Specs(model.Models):
 title = models.CharField(max_length=200)

On Dec 10, 10:53 am, Superman  wrote:
> Thank you DR for your response.
>
> Yes that helps in a way, as that is what I am planning to do. But at
> the moment I can store the name of Projects, Categories and Specs in
> the three different models. Where can I store the values for the Specs
> for each Project? There is no table that contains that information.
> How can I set that table up... in a way that it can expand both
> sideways and downwards?
>
> On Dec 10, 10:38 am, Daniel Roseman  wrote:
>
> > On Dec 10, 3:19 pm, Superman  wrote:
>
> > > Hi guys, I can't wrap my head around this problem I have... someone
> > > please help.
>
> > > The Problem: I have a list of various projects, in a Project Model.
> > > Each of them has a foreign Key to a Category model. Each Category has
> > > a Many to Many Relationship to a Specification model. So it is like
> > > this. Project ---> Category --->(m2m) Specifications. All these tables
> > > are going to change/increment. I want to set up a table with column 1
> > > as Project, column 2 as Category and the rest of the columns as
> > > Specification.
>
> > > For ex. these are possibly two rows from the column:
> > > Colum -> Row1
> > > Project -> Skyrise Appartments
> > > Category -> Residential Building
> > > Specification -> Height - 100m
> > >                       -> Floors - 30f
> > >                       -> Cost - 50m
> > >                        -> Start - Dec 2009
> > >                        -> Finish - Dec 2010
> > >                         ->Rest of the columns blank
>
> > > Colum -> Row 2
> > > Project -> GreatHarbour Bridge
> > > Category -> Bridge
> > > Specification -> Length - 1 km
> > >                       -> Type - Cable Stayed
> > >                        -> Speed - 80 km/hr
> > >                        -> Pillars - 200
> > >                        -> Cost - 20m
> > >                        -> Start - Feb 2010
> > >                        -> Finish - Nov 2010
> > >                         >Rest of the columns blank
>
> > > I dont want to ceate individal tables for Each Category... coz I may
> > > have Hundreds of Categories, Projects and Specs. How do I go about
> > > doing this? Please help...
>
> > > Thanks
>
> > I don't understand what you mean when you say you want to "set up a
> > table" with those various columns. The columns all exist in separate
> > tables. What would be the benefit of putting them into a single table?
>
> > Do you just mean you want to output the columns from various tables at
> > once? You can easily do that with Django's ORM, which is capable of
> > traversing the relationships between tables. You can then use the
> > template language to group the fields into columns for output. Does
> > that help?
> > --
> > 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: Tricky Django tables setup

2009-12-10 Thread Superman

Thank you DR for your response.

Yes that helps in a way, as that is what I am planning to do. But at
the moment I can store the name of Projects, Categories and Specs in
the three different models. Where can I store the values for the Specs
for each Project? There is no table that contains that information.
How can I set that table up... in a way that it can expand both
sideways and downwards?



On Dec 10, 10:38 am, Daniel Roseman  wrote:
> On Dec 10, 3:19 pm, Superman  wrote:
>
>
>
> > Hi guys, I can't wrap my head around this problem I have... someone
> > please help.
>
> > The Problem: I have a list of various projects, in a Project Model.
> > Each of them has a foreign Key to a Category model. Each Category has
> > a Many to Many Relationship to a Specification model. So it is like
> > this. Project ---> Category --->(m2m) Specifications. All these tables
> > are going to change/increment. I want to set up a table with column 1
> > as Project, column 2 as Category and the rest of the columns as
> > Specification.
>
> > For ex. these are possibly two rows from the column:
> > Colum -> Row1
> > Project -> Skyrise Appartments
> > Category -> Residential Building
> > Specification -> Height - 100m
> >                       -> Floors - 30f
> >                       -> Cost - 50m
> >                        -> Start - Dec 2009
> >                        -> Finish - Dec 2010
> >                         ->Rest of the columns blank
>
> > Colum -> Row 2
> > Project -> GreatHarbour Bridge
> > Category -> Bridge
> > Specification -> Length - 1 km
> >                       -> Type - Cable Stayed
> >                        -> Speed - 80 km/hr
> >                        -> Pillars - 200
> >                        -> Cost - 20m
> >                        -> Start - Feb 2010
> >                        -> Finish - Nov 2010
> >                         >Rest of the columns blank
>
> > I dont want to ceate individal tables for Each Category... coz I may
> > have Hundreds of Categories, Projects and Specs. How do I go about
> > doing this? Please help...
>
> > Thanks
>
> I don't understand what you mean when you say you want to "set up a
> table" with those various columns. The columns all exist in separate
> tables. What would be the benefit of putting them into a single table?
>
> Do you just mean you want to output the columns from various tables at
> once? You can easily do that with Django's ORM, which is capable of
> traversing the relationships between tables. You can then use the
> template language to group the fields into columns for output. Does
> that help?
> --
> 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: Retrieving a subclass instance when all you have is its parent class instance

2009-12-10 Thread bruno desthuilliers
On 28 nov, 03:45, Rodrigo Cea  wrote:
> I have a parent Class "ComponentBase", with abstract=False, that many
> other classes extend.

Same problem here, and I found these two snippets:

http://www.djangosnippets.org/snippets/1037/
http://www.djangosnippets.org/snippets/1034/

HTH

--

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: Tricky Django tables setup

2009-12-10 Thread Daniel Roseman
On Dec 10, 3:19 pm, Superman  wrote:
> Hi guys, I can't wrap my head around this problem I have... someone
> please help.
>
> The Problem: I have a list of various projects, in a Project Model.
> Each of them has a foreign Key to a Category model. Each Category has
> a Many to Many Relationship to a Specification model. So it is like
> this. Project ---> Category --->(m2m) Specifications. All these tables
> are going to change/increment. I want to set up a table with column 1
> as Project, column 2 as Category and the rest of the columns as
> Specification.
>
> For ex. these are possibly two rows from the column:
> Colum -> Row1
> Project -> Skyrise Appartments
> Category -> Residential Building
> Specification -> Height - 100m
>                       -> Floors - 30f
>                       -> Cost - 50m
>                        -> Start - Dec 2009
>                        -> Finish - Dec 2010
>                         ->Rest of the columns blank
>
> Colum -> Row 2
> Project -> GreatHarbour Bridge
> Category -> Bridge
> Specification -> Length - 1 km
>                       -> Type - Cable Stayed
>                        -> Speed - 80 km/hr
>                        -> Pillars - 200
>                        -> Cost - 20m
>                        -> Start - Feb 2010
>                        -> Finish - Nov 2010
>                         >Rest of the columns blank
>
> I dont want to ceate individal tables for Each Category... coz I may
> have Hundreds of Categories, Projects and Specs. How do I go about
> doing this? Please help...
>
> Thanks

I don't understand what you mean when you say you want to "set up a
table" with those various columns. The columns all exist in separate
tables. What would be the benefit of putting them into a single table?

Do you just mean you want to output the columns from various tables at
once? You can easily do that with Django's ORM, which is capable of
traversing the relationships between tables. You can then use the
template language to group the fields into columns for output. Does
that help?
--
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: One to many mixins?

2009-12-10 Thread Superman
Can you not create another Field in SubForm 1 model? Like so:

class SubForm1(models.Model):
  def __unicode__(self):
return "SubForm1"

  Form1 = models.ForeignKey(Form1)
  Form2 = models.ForeignKey(Form2)
  ## some fields here


On Dec 10, 8:53 am, Shai  wrote:
> Hi all,
>
> I'm not sure my title is correct. Here Is my problem: I want to use
> the django admin for data entry into some models. The models are based
> on actual paper forms. There are several forms. and they share some
> fields. I would like to follow the principle of DRY when creating this
> app. As an illustration, consider the following models:
>
> class Form1(models.Model):
>   def __unicode__(self):
>     return "Form1"
>
> class Form2(models.Model):
>   def __unicode__(self):
>     return "Form2"
>
>    ## some fields here
>
> class SubForm1(models.Model):
>   def __unicode__(self):
>     return "SubForm1"
>
>   Form = models.ForeignKey(Form1)
>   ## some fields here
>
> I would like to have Form2 also be linked to a SubForm1 model. How can
> this be done?
>
> Thanks,
> Shai

--

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.




Tricky Django tables setup

2009-12-10 Thread Superman
Hi guys, I can't wrap my head around this problem I have... someone
please help.

The Problem: I have a list of various projects, in a Project Model.
Each of them has a foreign Key to a Category model. Each Category has
a Many to Many Relationship to a Specification model. So it is like
this. Project ---> Category --->(m2m) Specifications. All these tables
are going to change/increment. I want to set up a table with column 1
as Project, column 2 as Category and the rest of the columns as
Specification.

For ex. these are possibly two rows from the column:
Colum -> Row1
Project -> Skyrise Appartments
Category -> Residential Building
Specification -> Height - 100m
  -> Floors - 30f
  -> Cost - 50m
   -> Start - Dec 2009
   -> Finish - Dec 2010
->Rest of the columns blank

Colum -> Row 2
Project -> GreatHarbour Bridge
Category -> Bridge
Specification -> Length - 1 km
  -> Type - Cable Stayed
   -> Speed - 80 km/hr
   -> Pillars - 200
   -> Cost - 20m
   -> Start - Feb 2010
   -> Finish - Nov 2010
>Rest of the columns blank

I dont want to ceate individal tables for Each Category... coz I may
have Hundreds of Categories, Projects and Specs. How do I go about
doing this? Please 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.




Re: Retrieving a subclass instance when all you have is its parent class instance

2009-12-10 Thread trybik
Hi,

you might take a look at this snippet:
http://www.djangosnippets.org/snippets/950/

Basically it's a negative of what you want (i.e. w/o subclasses) but
the idea I guess is there: you want a custom DB manager for which
SuperClass.objects returns in fact the SubClass instances. I bet there
are thousands of complications involving efficiency, filtering or
multi-inheritance but with some simplifying assumptions I guess it's
feasible.

It looks like a fundamental ORM poroblem. I've made some research but
haven't yet found a ready-to-go solution for it in Django. Please
write how it went or maybe someone else already knows how to do it
properly?

Best regards,
Mikołaj

On Nov 28, 3:45 am, Rodrigo Cea  wrote:
> I have a parent Class "ComponentBase", with abstract=False, that many
> other classes extend.
> The parent Class has a ForeignKey relation to another class, "Band".
>
> It is convenient to be able to get a list of all of a band's
> components without having to explicitly list each component class.
>
> I am doing this currently like so:
>
> class ComponentBase(models.Model):
>    band = models.ForeignKey(Band)
>    ...
>     class Meta:
>         abstract = False
>
>     defsubclass(self):
>         try: return self.complogo
>         except: pass
>         try: return self.compnota
>         except: pass
>         try: return self.compalbumfotos
>         except: pass
>         ...
>
> where Complogo, Compnota, etc., are ComponentBase's sublclasses, like
> so:
>
> class CompLogo(ComponentBase):
>     
>
> . With this, I can take an instance of Band and do:
>
> components = ComponentBase.objects.filter(band=band_instance)
>
> which populates "components" with all of the band's ComponentBase
> instances, and then for each one callsubclass() to retrieve the
> actual component, e.g. Complogo().
>
> The thing is the number of components will likely increase in the
> future, and it feels messy to keep extending the try/except list. Is
> there a more compact and less verbose way of retrieving asubclass
> instance when all you have is its parent class instance?

--

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: Moved server, can't log in

2009-12-10 Thread brad


On Dec 10, 4:57 am, Oli Warner  wrote:
> A couple of days ago I moved a site from one server to another server and
> changed the DNS on the domain so it stayed the same. After the DNS had
> migrated everybody but me could log in. All other users trying to log into
> the admin were getting the "Looks like your browser isn't configured to
> accept cookies [...]" error. There's also a log in page for non-admins and
> that was also just refusing to log people in.
>
> The only way I could fix it was to set the server to redirect the users
> through to a different subdomain. I would like to go back to the original
> domain but I can't if it breaks (this is a business-to-business webapp - it
> can't have downtime).
>
> I've also got to move a couple more sites in the coming days but I can't
> until I can figure out what happened here so I can prevent this happening
> again in the future.
>
> I need ideas... Ideally more advanced than "clear the cookies" as there are
> a couple of hundred users on the system - this is vastly impractical.
>
> Thanks in advance.
>
> This question is also on stackoverflow (if you're a user and you think you
> have the answer, you can get some 
> points):http://stackoverflow.com/questions/1872796/changed-django-server-loca...

Are you using Django's session framework? If so, it stores session
info in the database, which you might want to clear.

See:
django-admin.py help cleanup

--

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: distinct related objects [solved]

2009-12-10 Thread andreas
and i solved it in the view. dont know if this is the right way but it
works:

def topic_detail(request, slug):
topic = get_object_or_404(Topic, slug=slug)
t = topic.project_set.all()
techlist = []
for p in t:
for t in  p.technologies.all():
if t in techlist:
pass
else:
techlist.append(t)
return object_list(request,
   queryset=topic.project_set.all(),
   template_name='myapp/topic_detail.html',
   extra_context={'object': topic, 'techlist':
techlist })



On Dec 10, 12:18 pm, andreas schmid  wrote:
> ok im still stucking on this one:
>
> i dont think the regroup tag can help in this case
> but i cant understand how i can query the technologies used within a
> specific topic.
>
> i mean i have alredy the projects assigned to this topic, now i need the
> technologies used by this projects.
>
> any ideas?
>
> Tim Valenta wrote:
> > It looks like the problem is that you're trying to group by
> > Technology, but your queryset is in Projects.  You could experiment
> > with the "regroup" template tag
> > (http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup
> > )
>
> > It's a little hard to understand at first, but I think it's pretty
> > much what you're trying to do.  You would be able to remove the
> > ".distinct" part of your query because dictionary keys are already
> > can't be doubled.
>
> > Hope that helps.
>
> > Tim
>
> > On Nov 26, 7:04 am, andreas schmid  wrote:
>
> >> hi,
>
> >> i have a question about retrieving related objects avoiding double entries.
> >> actually i have 3 models:
> >>     topics
> >>     projects
> >>     technologies
>
> >> the projects model has foreignkeys to topics and technologies. i have a
> >> view for the topic detail like this:
>
> >>     def topic_detail(request, slug):
> >>         topic = get_object_or_404(Topic, slug=slug)
> >>         return object_list(request,
> >>                            queryset=topic.project_set.all(),
> >>                            paginate_by=20,
> >>                            template_name='FSlabs/topic_detail.html',
> >>                            extra_context={ 'topic': topic })
>
> >> in the template i can loop trough the projects and  get those  assigned
> >> to this topic.
> >> but im having problems to retrieve the technologies used by those
> >> projects without having double entries.
>
> >> i tried this in the template with a list for every project
> >> assigned...which of course is not what i want:
>
> >>     {% for project in object_list  %}
> >>             {% for technology in project.technologies.distinct %}
> >>                 {{
> >>     technology.title }}
> >>                 {% if forloop.last %}{% else %}
> >>                 {% ifequal forloop.revcounter0 1 %}and {% else %}, {%
> >>     endifequal %}
> >>                 {% endif %}
> >>             {% endfor %}
> >>         {% endfor %}
>
> >> can somebody point me to the right way to get what i need?
>
> >> thx
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
>

--

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 urlpatterns

2009-12-10 Thread Javier Guerra
On Thu, Dec 10, 2009 at 7:10 AM, Baurzhan Ismagulov  wrote:
> When I try this, I get NoReverseMatch at /apps/: Reverse for 'app-list'
> with arguments '()' and keyword arguments '{}' not found.
>
> I'd like to avoid hard-coding URLs. Is there a way to do that?


the problem is that the call to reverse('app-list') is happening
_before_ the construction of the URL list.

i don't know much about Django internals, but i'd at least try
separating 'app-new' in a different call to patterns() than
'app-list'.

something like:

urlpatterns = patterns('',
   ...
   (r'^apps/$', list_detail.object_list,
{'queryset': App.objects.all()},
'app-list')),
)

urlpatterns += patterns('',
   (r'^app/new/$': create_update.create_object,
{'model': App, 'post_save_redirect': reverse('app-list')},
   'app-new'),
   ...
)


not sure if would work, thought.  it's quite possible that Django
still has work to do after the whole urls.py execution to make
reverse() work.


-- 
Javier

--

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.




One to many mixins?

2009-12-10 Thread Shai
Hi all,

I'm not sure my title is correct. Here Is my problem: I want to use
the django admin for data entry into some models. The models are based
on actual paper forms. There are several forms. and they share some
fields. I would like to follow the principle of DRY when creating this
app. As an illustration, consider the following models:

class Form1(models.Model):
  def __unicode__(self):
return "Form1"

class Form2(models.Model):
  def __unicode__(self):
return "Form2"

   ## some fields here

class SubForm1(models.Model):
  def __unicode__(self):
return "SubForm1"

  Form = models.ForeignKey(Form1)
  ## some fields here


I would like to have Form2 also be linked to a SubForm1 model. How can
this be done?

Thanks,
Shai

--

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 urlpatterns

2009-12-10 Thread Baurzhan Ismagulov
Hello,

Can I use reverse() in urlpatterns, similar to the following?

urlpatterns = patterns('',
...
(r'^apps/$', list_detail.object_list,
 {'queryset': App.objects.all()},
 'app-list'),
(r'^app/new/$': create_update.create_object,
 {'model': App, 'post_save_redirect': reverse('app-list')},
'app-new'),
...
)

When I try this, I get NoReverseMatch at /apps/: Reverse for 'app-list'
with arguments '()' and keyword arguments '{}' not found.

I'd like to avoid hard-coding URLs. Is there a way to do that?

I'm aware that I could probably abuse get_absolute_url for that.
However, I'll need to implement more complex workflows where the same
URL is going to be "called" from different pages on the site and will
have to return back to the "calling" page (not unlike admin's popup
windows, albeit without popups). What is the best way to do that?

I'm using Django 1.0.

Thanks in advance,
-- 
Baurzhan Ismagulov
http://www.kz-easy.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 can child objects inherit data from parents?

2009-12-10 Thread David De La Harpe Golden
bruno desthuilliers wrote:

> First point, you have a tree structure. There are a couple ways to
> handle trees in a relational model, each has pros and cons. The most
> obvious one is the recursive relationship (also known as 'adjacency
> list'):
> 
> create table Person(
>id integer primary key auto increment,
>first_name varchar(50) NULL,
>last_name varchar(50) NULL,
>city varchar(50) NULL,
>ancestor_id integer NULL
>)
> 
> where ancestor_id refers to the Person.id of the 'ancestor'.
> 
> The problem with this solution is that SQL has no way to let you
> retrieve a whole 'branch' in one single query.
> 

True of classical sql, but just to note as an interesting aside - modern
databases support "common table expressions". Maintaining other reps,
materialized path etc. as you mention, still probably better (higher
perf) for many use cases, just sayin'.

CTEs are of course expressed in sql's dire syntax, but anyway in e.g.
recent postgresql this will work:

with recursive x as
(select *, 1 as lev, '.' || id::text as path
   from person where id=3
 union all
 select p.*, x.lev+1 as lev, x.path || '.' || p.id::text as path
   from person p join x on p.ancestor_id = x.id)
  select * from x;

-- there, clear as mud, person 3 and their descendants,
with generated (relative) path and level for each record.  I think.

see
http://wiki.postgresql.org/wiki/CTEReadme#Examples
http://en.wikipedia.org/wiki/Common_table_expressions

ObDjango:  No idea how you'd persuade the ORM to generate CTEs ;-)




--

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: CharField cannot have a "max_length" greater than 255 when using "unique=True"

2009-12-10 Thread germ
for my needs i will patch django/db/backends/mysql/validation.py
producing my own locally used django rpm to allow more than 255. in my
configuration this works fine. thanks all for your time and guidance!

--

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




Re: psycopg2 and "idle in transaction" messages

2009-12-10 Thread Nadae Ivar BADIO
Hi Alexander,

I wanna to ask you how do you configure django debian postgres apache and 
psycopg2
i try it but i could not have i wanan to run it on apache with svn .
Thanks

- Mail Original -
De: "Alexander Dutton" 
À: django-users@googlegroups.com
Envoyé: Jeudi 10 Décembre 2009 12h41:41 Monrovia (GMT)
Objet: psycopg2 and "idle in transaction" messages

Hi all,

As of last Thursday we've been seeing ~100% CPU usage from Apache, which
we believe was caused by Debian Bug #528529[0], whereby psycopg2 was
attempting to double free pointers, resulting in segfaults. This was
then (we think) leaving database connections open, resulting in postgres
saying "no more connections, TYVM" and the whole site 500ing. Not good.

On Monday we worked out what was happening and pulled psycopg2 2.0.12
from PyPI, as the bugfix hasn't been backported to Debian Lenny.
Everything seemed happy, but now we're seeing similar symptoms again and
were wondering if anyone else could help.

Versionwise, we have:
 * Django 1.1
 * Python 2.5.2 (r252:60911, Jan  4 2009, 17:40:26) [GCC 4.3.2]
 * Debian Lenny
 * psycopg2 2.0.12-py2.5-linux-i686
 * postgresql 8.3.8

Here're the outputs of a few things that might be useful:
 * SELECT * FROM pg_stat_activity: http://dpaste.com/131597/
 * SELECT * FROM pg_locks: http://dpaste.com/131598/
 * The top of 'top':   http://dpaste.com/131599/
 * A bit of 'ps -Af':  http://dpaste.com/131600/
 * A screenshot of our CPU usage:  http://users.ox.ac.uk/~kebl2765/cpu.png
 * A screenshot of our load avg:   http://users.ox.ac.uk/~kebl2765/load.png

The short drops in CPU utilisation were due to apache/postgres/system
restarts, and periods of high system CPU usage were generally when it
was 500ing.

The first time round we had tracebacks and memory dumps in our
/var/log/apache2/error.log; now there's nothing useful.

Any help would be greatly appreciated!

Warm regards,

Alex

[0] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=528529

--

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.




psycopg2 and "idle in transaction" messages

2009-12-10 Thread Alexander Dutton
Hi all,

As of last Thursday we've been seeing ~100% CPU usage from Apache, which
we believe was caused by Debian Bug #528529[0], whereby psycopg2 was
attempting to double free pointers, resulting in segfaults. This was
then (we think) leaving database connections open, resulting in postgres
saying "no more connections, TYVM" and the whole site 500ing. Not good.

On Monday we worked out what was happening and pulled psycopg2 2.0.12
from PyPI, as the bugfix hasn't been backported to Debian Lenny.
Everything seemed happy, but now we're seeing similar symptoms again and
were wondering if anyone else could help.

Versionwise, we have:
 * Django 1.1
 * Python 2.5.2 (r252:60911, Jan  4 2009, 17:40:26) [GCC 4.3.2]
 * Debian Lenny
 * psycopg2 2.0.12-py2.5-linux-i686
 * postgresql 8.3.8

Here're the outputs of a few things that might be useful:
 * SELECT * FROM pg_stat_activity: http://dpaste.com/131597/
 * SELECT * FROM pg_locks: http://dpaste.com/131598/
 * The top of 'top':   http://dpaste.com/131599/
 * A bit of 'ps -Af':  http://dpaste.com/131600/
 * A screenshot of our CPU usage:  http://users.ox.ac.uk/~kebl2765/cpu.png
 * A screenshot of our load avg:   http://users.ox.ac.uk/~kebl2765/load.png

The short drops in CPU utilisation were due to apache/postgres/system
restarts, and periods of high system CPU usage were generally when it
was 500ing.

The first time round we had tracebacks and memory dumps in our
/var/log/apache2/error.log; now there's nothing useful.

Any help would be greatly appreciated!

Warm regards,

Alex

[0] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=528529

--

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 1.1 and Jython

2009-12-10 Thread gentlestone
but another error appeared in base.py :(

Caught an exception while rendering: Traceback (most recent call
last):
  File "/Users/iM1/jython2.5.1/Lib/site-packages/doj/backends/zxjdbc/
sqlite3/base.py", line 143, in xFunc
assert self.args() == num_args
AttributeError: 'func' object has no attribute 'args'
 [SQLCode: 0]

has anyone tested django 1.1 SQLITE3 with Jython?

On 10. Dec., 12:38 h., gentlestone  wrote:
> Does anyone using Django 1.1 and Jython?
>
> File "/Users/iM1/Downloads/django-jython-1.0.0/doj/backends/zxjdbc/
> sqlite3/base.py", line 106, in __init__
>     self.client = DatabaseClient()
> TypeError: __init__() takes exactly 2 arguments (1 given)
>
> After a real nightmare installation procedure I finished with this
> exception

--

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 1.1 and Jython

2009-12-10 Thread gentlestone
I found the bug ...

http://code.google.com/p/django-jython/source/detail?r=147

On 10. Dec., 12:38 h., gentlestone  wrote:
> Does anyone using Django 1.1 and Jython?
>
> File "/Users/iM1/Downloads/django-jython-1.0.0/doj/backends/zxjdbc/
> sqlite3/base.py", line 106, in __init__
>     self.client = DatabaseClient()
> TypeError: __init__() takes exactly 2 arguments (1 given)
>
> After a real nightmare installation procedure I finished with this
> exception

--

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 1.1 and Jython

2009-12-10 Thread gentlestone
Does anyone using Django 1.1 and Jython?

File "/Users/iM1/Downloads/django-jython-1.0.0/doj/backends/zxjdbc/
sqlite3/base.py", line 106, in __init__
self.client = DatabaseClient()
TypeError: __init__() takes exactly 2 arguments (1 given)

After a real nightmare installation procedure I finished with this
exception

--

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: distinct related objects

2009-12-10 Thread andreas schmid
ok im still stucking on this one:

i dont think the regroup tag can help in this case
but i cant understand how i can query the technologies used within a
specific topic.

i mean i have alredy the projects assigned to this topic, now i need the
technologies used by this projects.

any ideas?


Tim Valenta wrote:
> It looks like the problem is that you're trying to group by
> Technology, but your queryset is in Projects.  You could experiment
> with the "regroup" template tag
> ( http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup
> )
>
> It's a little hard to understand at first, but I think it's pretty
> much what you're trying to do.  You would be able to remove the
> ".distinct" part of your query because dictionary keys are already
> can't be doubled.
>
> Hope that helps.
>
> Tim
>
> On Nov 26, 7:04 am, andreas schmid  wrote:
>   
>> hi,
>>
>> i have a question about retrieving related objects avoiding double entries.
>> actually i have 3 models:
>> topics
>> projects
>> technologies
>>
>> the projects model has foreignkeys to topics and technologies. i have a
>> view for the topic detail like this:
>>
>> def topic_detail(request, slug):
>> topic = get_object_or_404(Topic, slug=slug)
>> return object_list(request,
>>queryset=topic.project_set.all(),
>>paginate_by=20,
>>template_name='FSlabs/topic_detail.html',
>>extra_context={ 'topic': topic })
>>
>> in the template i can loop trough the projects and  get those  assigned
>> to this topic.
>> but im having problems to retrieve the technologies used by those
>> projects without having double entries.
>>
>> i tried this in the template with a list for every project
>> assigned...which of course is not what i want:
>>
>> {% for project in object_list  %}
>> {% for technology in project.technologies.distinct %}
>> {{
>> technology.title }}
>> {% if forloop.last %}{% else %}
>> {% ifequal forloop.revcounter0 1 %}and {% else %}, {%
>> endifequal %}
>> {% endif %}
>> {% endfor %}
>> {% endfor %}
>>
>> can somebody point me to the right way to get what i need?
>>
>> thx
>> 
>
> --
>
> 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: Django 1.1 - comments - ‘render_comment_ form’ returns TemplateSyntaxError

2009-12-10 Thread Kenny Meyer
On Wed, 9 Dec 2009 21:58:39 -0500
Karen Tracey  wrote:

> On Wed, Dec 9, 2009 at 8:24 PM, Kenny Meyer 
> wrote:
> 
> >
> > /urls.py[shortened]:
> > urlpatterns = patterns('',
> >(r'', include('posts.urls')),
> >(r'^comments/$', include('django.contrib.comments.urls')),
> > )
> >
> >
> Remove the $ from the end of the pattern for the comment urls.
> 
> Karen

Thanks, Karen. It's functioning now perfectly.. I couldn't believe it
was only a typo!

Well, I'll know in the future from now on.

Regards,
Kenny


signature.asc
Description: PGP signature


Re: Problems witch Apache - KeyError at / - 'HOME'

2009-12-10 Thread edward9
Ok. Probably that its. But where can i found proper configuration for
apache?
Or can U help me by pasting samples Apache configuration? I have read
some tutorials about configuration Django with Apache and mod_python
but nothing works :(

And about quotas i think this is not it. Code without quotas works
fine on dev server, but stop working on apache.

Regards
Ed

On Dec 10, 10:14 am, Graham Dumpleton 
wrote:
> You do understand that when running under Apache that the code runs as
> a special Apache user.
>
> So, not only would the home directory not even be that for your home
> account, Apache scrubs the HOME user environment variable from the
> process environment anyway, and so trying to access HOME variable will
> fail.
>
> General rule in web programming is, never to rely on user environment
> variables and secondly never rely on current working directory being a
> particular location nor use relative paths, always use absolute paths
> instead.
>
> Graham
>
> On Dec 10, 5:19 am, edward9  wrote:
>
> > Hello everybody
>
> > I'm new and i want to say Hello to Everybody.
>
> > I have problem with Apache. I install python, django, apache,
> > mod_apache and all what is necessary.
>
> > Apache configuration is:
> >         
> >             SetHandler python-program
> >             PythonHandler django.core.handlers.modpython
> >             SetEnv DJANGO_SETTINGS_MODULE mysite.settings
> >             PythonOption django.root /mysite
> >             PythonDebug Off
> >             #PythonPath "['/',  '/mysite', '/var/www'] + sys.path"
> >             PythonPath "['/'] + sys.path"
> >         
>
> > I created an application i root folder:
> > django-admin.py startproject mysite
> > and i started development(runserver). All works fine. "Configurations
> > on your first Django-powered page". Running on apache also works fine.
>
> > But when i create Django app:
> > manage.py startapp inet
> > views.py:
> > # Create your views here.
> > from django.http import HttpResponse
> > from django.db import connection
> > from django.conf import settings
> > from datetime import datetime
>
> > def main_page(request):
> >         output = '''
> >                 
> >                         %s
> >                         
> >                                 %s%s%s
> >                         
> >                 
> >         ''' % (
> >                 '1','a','b','c'
> >         )
> >         return HttpResponse(output)
>
> > urls.py
> > from django.conf.urls.defaults import *
> > from inet.views import *
>
> > urlpatterns = patterns('',
> >         (r'^$',main_page),
> > )
>
> > on development server works fine but started on apache i get:
>
> > KeyError at /
>
> > 'HOME'
>
> > Request Method:         GET
> > Request URL:    http://127.0.0.1/
> > Exception Type:         KeyError
> > Exception Value:
>
> > 'HOME'
>
> > Exception Location:     /usr/lib/python2.5/UserDict.py in __getitem__,
> > line 22
> > Python Executable:      /usr/bin/python
> > Python Version:         2.5.4
> > Python Path:    ['/', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-
> > linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-
> > dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/
> > python2.5/site-packages', '/usr/lib/python2.5/site-packages/PIL', '/
> > usr/lib/python2.5/site-packages/gst-0.10', '/usr/lib/pymodules/
> > python2.5', '/usr/lib/python2.5/site-packages/gtk-2.0', '/usr/lib/
> > pymodules/python2.5/gtk-2.0']
> > Server time:    Wed, 9 Dec 2009 11:54:14 -0600
> > Traceback Switch to copy-and-paste view
>
> >     * /usr/lib/pymodules/python2.5/django/core/handlers/base.py in
> > get_response
> >         70.
> >         71. # Get urlconf from request object, if available. Otherwise
> > use default.
> >         72. urlconf = getattr(request, "urlconf",
> > settings.ROOT_URLCONF)
> >         73.
> >         74. resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
> >         75. try:
> >         76. callback, callback_args, callback_kwargs = resolver.resolve
> > (
> >         77. request.path_info) ...
> >         78.
> >         79. # Apply view middleware
> >         80. for middleware_method in self._view_middleware:
> >         81. response = middleware_method(request, callback,
> > callback_args, callback_kwargs)
> >         82. if response:
> >         83. return response
> >       ▶ Local vars
> >       Variable  Value
> >       exc_info
> >       (, KeyError('HOME',),  > object at 0x932c57c>)
>
> > Can somebody help me? I dont have any ideas how to solve this problem.
>
> > Thnask for help!
> > Regards
> > Edward9

--

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 

Moved server, can't log in

2009-12-10 Thread Oli Warner
A couple of days ago I moved a site from one server to another server and
changed the DNS on the domain so it stayed the same. After the DNS had
migrated everybody but me could log in. All other users trying to log into
the admin were getting the "Looks like your browser isn't configured to
accept cookies [...]" error. There's also a log in page for non-admins and
that was also just refusing to log people in.

The only way I could fix it was to set the server to redirect the users
through to a different subdomain. I would like to go back to the original
domain but I can't if it breaks (this is a business-to-business webapp - it
can't have downtime).

I've also got to move a couple more sites in the coming days but I can't
until I can figure out what happened here so I can prevent this happening
again in the future.


I need ideas... Ideally more advanced than "clear the cookies" as there are
a couple of hundred users on the system - this is vastly impractical.

Thanks in advance.

This question is also on stackoverflow (if you're a user and you think you
have the answer, you can get some points):
http://stackoverflow.com/questions/1872796/changed-django-server-location-now-logins-dont-work/

--

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

2009-12-10 Thread Gonzalo Delgado
El Wed, 9 Dec 2009 21:23:20 -0600
Kenneth McDonald  escribió:

> Where would one find such beasties? Once I've taught myself Django,  
> I'd like to think I might be able to get some sort of job with it,  
> albeit a very junior one.

If you're an experienced programmer, but a Django newbie, I think there's a
good chance for you on any Django job offering. In that case I suggest you try
DjangoGigs[0].

If you don't have much experience programming you can try starting a tiny
project of your own and/or joining a small free (as in freedom) software
project that uses Django. For that you should go to Google Projects[1],
Bitbucket[2], Launchpad[3], Github[4], etc.

[0] http://djangogigs.com/
[1] http://code.google.com/hosting/search?q=django=Search+projects
[2] http://bitbucket.org/repo/all/?name=django
[3] https://launchpad.net/+search?field.text=django-
[4] http://github.com/search?type=Repositories=python=django
-- 
Gonzalo Delgado 
http://gonzalodelgado.com.ar/


pgpdQBeZVm1Er.pgp
Description: PGP signature


Re: Performance monitoring

2009-12-10 Thread Rory Hart
On Thu, Dec 10, 2009 at 5:23 PM, Mikhail Korobov wrote:

> Performance monitoring doesn't have to be related to django itself.
> There are external projects that cant do performance monitoring (CPU,
> i/o, memory usage over time). You may give munin (http://
> munin.projects.linpro.no/) a chance.
>
> On Dec 10, 7:43 am, Kegan Gan  wrote:
> > Hi,
> >
> > Google App Engine provides a rather extensive set of tools to monitor
> > the performance of your applications running in App Engine. Is there
> > something similar for Django?
> >
> > 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.
>
>
>
Quite so, I would suggest Zabbix (http://www.zabbix.com/) we have used it in
a couple of deployments now to great success.

-- 
Rory Hart
http://www.whatisthescience.com
http://blog.roryhart.net

--

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

2009-12-10 Thread Tom Evans
On Thu, Dec 10, 2009 at 9:36 AM, victor  wrote:
> i need to execute remote commands through ssh in views,following is my
> code:
> @login_required
> def reposCheck(request):
>    if request.method == 'POST':
>        from commands import getoutput
>        rs = getoutput('ssh t...@192.168.1.2 "[ -d /home/shing3d/
> shin/ ] && echo 1 || echo 0"')
>        return HttpResponse(rs)
>    return HttpResponse('ok')
>
> the same command success execute in django shell,but got no response
> from above code when the remote server have detected success login.
> the http response code is 499.
> can anyone tell me how to treat it?thx
>

Probably because you don't have a tty allocated when you run in the
view. You should be using something like paramiko[1] for this.

Cheers

Tom

[1] http://www.lag.net/paramiko/

--

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: Problems witch Apache - KeyError at / - 'HOME'

2009-12-10 Thread kid...@gmail.com
Not sure about your first error, but you are getting this second error
because you forgot to put quotes around main_page in your urls.py

On Dec 10, 12:28 am, edward9  wrote:
> Yes. I restart Apache every configuration change.
>
> Error from text box:
> Environment:
>
> Request Method: GET
> Request URL:http://127.0.0.1/
> Django Version: 1.0.2 final
> Python Version: 2.5.4
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> Traceback:
> File "/usr/lib/pymodules/python2.5/django/core/handlers/base.py" in
> get_response
>   77.                     request.path_info)
> File "/usr/lib/pymodules/python2.5/django/core/urlresolvers.py" in
> resolve
>   179.             for pattern in self.urlconf_module.urlpatterns:
> File "/usr/lib/pymodules/python2.5/django/core/urlresolvers.py" in
> _get_urlconf_module
>   198.             self._urlconf_module = __import__
> (self.urlconf_name, {}, {}, [''])
> File "/mysite/urls.py" in 
>   18.   (r'^$',main_page),
>
> Exception Type: NameError at /
> Exception Value: name 'main_page' is not defined
>
> Apache:
>         
>             SetHandler python-program
>             PythonHandler django.core.handlers.modpython
>             SetEnv DJANGO_SETTINGS_MODULE mysite.settings
>             #PythonOption django.root /mysite
>             PythonDebug Off
>             PythonPath "['/',  '/mysite', '/var/www'] + sys.path"
>             #PythonPath "['/'] + sys.path"
>         
>
> On development server works fine. On Apache not working. I have tried
> to create new project but same situation.
>
> Regards
> Edward9
>
> On Dec 10, 12:41 am, Karen Tracey  wrote:
>
>
>
> > Did you restart Apache after making all your code changes?
>
> > Please click the Switch to copy-and-paste view link and cut and paste the
> > contents of the text box that will appear.  The other version is not good
> > for pasting into email.
>
> > 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.




problem execute remote commands in views

2009-12-10 Thread victor
i need to execute remote commands through ssh in views,following is my
code:
@login_required
def reposCheck(request):
if request.method == 'POST':
from commands import getoutput
rs = getoutput('ssh t...@192.168.1.2 "[ -d /home/shing3d/
shin/ ] && echo 1 || echo 0"')
return HttpResponse(rs)
return HttpResponse('ok')

the same command success execute in django shell,but got no response
from above code when the remote server have detected success login.
the http response code is 499.
can anyone tell me how to treat it?thx

--

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-tagging - how to get current page number in a template

2009-12-10 Thread tezro
Firstly, we have simple template.
---
{% load pagination_tags %}
{% block first_column %}
{% autopaginate object_list %}
{% paginate %}
{% endblock %}
---

Suppose, we have "second_column", so how do I get the current page
number, number of all pages paginated, or even next/previous page
link, if it matters, exactly in other block?

--

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: Problems witch Apache - KeyError at / - 'HOME'

2009-12-10 Thread Graham Dumpleton
You do understand that when running under Apache that the code runs as
a special Apache user.

So, not only would the home directory not even be that for your home
account, Apache scrubs the HOME user environment variable from the
process environment anyway, and so trying to access HOME variable will
fail.

General rule in web programming is, never to rely on user environment
variables and secondly never rely on current working directory being a
particular location nor use relative paths, always use absolute paths
instead.

Graham

On Dec 10, 5:19 am, edward9  wrote:
> Hello everybody
>
> I'm new and i want to say Hello to Everybody.
>
> I have problem with Apache. I install python, django, apache,
> mod_apache and all what is necessary.
>
> Apache configuration is:
>         
>             SetHandler python-program
>             PythonHandler django.core.handlers.modpython
>             SetEnv DJANGO_SETTINGS_MODULE mysite.settings
>             PythonOption django.root /mysite
>             PythonDebug Off
>             #PythonPath "['/',  '/mysite', '/var/www'] + sys.path"
>             PythonPath "['/'] + sys.path"
>         
>
> I created an application i root folder:
> django-admin.py startproject mysite
> and i started development(runserver). All works fine. "Configurations
> on your first Django-powered page". Running on apache also works fine.
>
> But when i create Django app:
> manage.py startapp inet
> views.py:
> # Create your views here.
> from django.http import HttpResponse
> from django.db import connection
> from django.conf import settings
> from datetime import datetime
>
> def main_page(request):
>         output = '''
>                 
>                         %s
>                         
>                                 %s%s%s
>                         
>                 
>         ''' % (
>                 '1','a','b','c'
>         )
>         return HttpResponse(output)
>
> urls.py
> from django.conf.urls.defaults import *
> from inet.views import *
>
> urlpatterns = patterns('',
>         (r'^$',main_page),
> )
>
> on development server works fine but started on apache i get:
>
> KeyError at /
>
> 'HOME'
>
> Request Method:         GET
> Request URL:    http://127.0.0.1/
> Exception Type:         KeyError
> Exception Value:
>
> 'HOME'
>
> Exception Location:     /usr/lib/python2.5/UserDict.py in __getitem__,
> line 22
> Python Executable:      /usr/bin/python
> Python Version:         2.5.4
> Python Path:    ['/', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-
> linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-
> dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/
> python2.5/site-packages', '/usr/lib/python2.5/site-packages/PIL', '/
> usr/lib/python2.5/site-packages/gst-0.10', '/usr/lib/pymodules/
> python2.5', '/usr/lib/python2.5/site-packages/gtk-2.0', '/usr/lib/
> pymodules/python2.5/gtk-2.0']
> Server time:    Wed, 9 Dec 2009 11:54:14 -0600
> Traceback Switch to copy-and-paste view
>
>     * /usr/lib/pymodules/python2.5/django/core/handlers/base.py in
> get_response
>         70.
>         71. # Get urlconf from request object, if available. Otherwise
> use default.
>         72. urlconf = getattr(request, "urlconf",
> settings.ROOT_URLCONF)
>         73.
>         74. resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
>         75. try:
>         76. callback, callback_args, callback_kwargs = resolver.resolve
> (
>         77. request.path_info) ...
>         78.
>         79. # Apply view middleware
>         80. for middleware_method in self._view_middleware:
>         81. response = middleware_method(request, callback,
> callback_args, callback_kwargs)
>         82. if response:
>         83. return response
>       ▶ Local vars
>       Variable  Value
>       exc_info
>       (, KeyError('HOME',),  object at 0x932c57c>)
>
> Can somebody help me? I dont have any ideas how to solve this problem.
>
> Thnask for help!
> Regards
> Edward9

--

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: Format fields in list, but keep sortable?

2009-12-10 Thread philomat
Chris: Sure, there's that possibility – however, I think it would be
very bad practise to insert a redundant field like this, just for
formatting matters. Also, one might want the option of using localised
units, etc.

Shawn: Of course you are generally correct and I know that the core
developers keep reminding everyone of this fact. However, they
themselves have implemented a lot of "niceness" in the admin lists
(boolean icons, date formatting etc), so I think this trivial
formatting matter is not about going beyond the scope of the admin.
Also, rewriting the whole admin application just because you want to
format some fields in a different way would be a bit exaggerated.
Also, I don't think you have to call yourself lazy for making the most
of what's already there.

I suppose there is not a really easy way, then.

--

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.