How do I get a field value instead of in an admin selectbox?

2009-06-16 Thread DaveB

I have what must be a common problem: there are three master files,
and a transaction in my admin site involves selecting an item from
each of these files. The field in the Transaction table is a foreign
key pointer to the master file's record. The default admin display
condition in the add/change form is that the dropdown boxes for
selecting the master file items only show an ugly " object"
label that is the same for all the choices so the user doesn't know
which to select. The field in the Transaction table is a foreign key
pointing to Person, for example, so the admin is not displaying data
from the Person record referenced by the choice in the dropdown
selection, it only shows that the choice is a Person object. I want a
master table field value for each of the choices to be displayed, e.g.
the value for Person.name, instead of "Person object". What's the way
to make this happen? I've tracked the code that generates the drop-
down html  tag to mysite/templates/admin/edit_inline/
fieldset.html, line 12:  ...  {{ field.label_tag }}{{ field.field }}
where field is an item in "line" which is an item in "fieldset" . I've
tried a bunch of different ways to use fieldsets = [...] in
TransactionAdmin(admin.ModelAdmin)  but I keep getting errors that
claim my fields are not valid fields, although they are clearly
defined in models.py and work fine otherwise when I remove the
"fieldset=  line[]". I have tried using raw_id_fields but this has no
apparent effect, presumably because it's for list_displays not add/
change forms.
So, what's the right way to do this?
Thanks for helping me!
-Dave

Showing the problem:
One of the master tables is called "unit", so here is the code django
is generating (note the "unit object" text that is the displayed
choices.)

UnitID:

-
unit object
unit object
 

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



How do I get a field value instead of in an admin selectbox?

2009-06-16 Thread DaveB

I have what must be a common problem: there are three master files,
and a transaction in my admin site involves selecting an item from
each of these files. The field in the Transaction table is a foreign
key pointer to the master file's record. The default admin display
condition in the add/change form is that the dropdown boxes for
selecting the master file items only show an ugly " object"
label that is the same for all the choices so the user doesn't know
which to select. The field in the Transaction table is a foreign key
pointing to Person, for example, so the admin is not displaying data
from the Person record referenced by the choice in the dropdown
selection, it only shows that the choice is a Person object. I want a
master table field value for each of the choices to be displayed, e.g.
the value for Person.name, instead of "Person object". What's the way
to make this happen? I've tracked the code that generates the drop-
down html  tag to mysite/templates/admin/edit_inline/
fieldset.html, line 12:  ...  {{ field.label_tag }}{{ field.field }}
where field is an item in "line" which is an item in "fieldset" . I've
tried a bunch of different ways to use fieldsets = [...] in
TransactionAdmin(admin.ModelAdmin)  but I keep getting errors that
claim my fields are not valid fields, although they are clearly
defined in models.py and work fine otherwise when I remove the
"fieldset=  line[]". I have tried using raw_id_fields but this has no
apparent effect, presumably because it's for list_displays not add/
change forms.
So, what's the right way to do this?
Thanks for helping me!
-Dave

Showing the problem:
One of the master tables is called "unit", so here is the code django
is generating (note the "unit object" text that is the displayed
choices.)

UnitID:

-
unit object
unit object
 

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



Re: Two views, Two models, Two forms, one template

2009-06-16 Thread Jonathan

Nevermind, I was missing something terribly basic and just needed to
stop looking at it for a bit to realize how to combine it.


On May 22, 5:08 pm, Jonathan  wrote:
> I am sure this is some very easy and simple concept I am just not
> grasping.  I have two views which are very similar.  Both take the
> same variable and iterate the applicable data.  I am trying to get
> them to render on the same template.  However, when I create one as a
> template tag and try to pass the common variable, I get variable is
> not defined errors.
>
> def projectfilesindex(request, object_id):
>         def store()
>             ...
>         files = ProjectFileUrl.objects.filter
> (project_number=object_id).order_by('-uploaded')
>         if not request.method == "POST":
>                 form = UploadForm()
>                 return render_to_response(
>                         'projects/files.html',
>                         {"form": form, "files": files},
>                         context_instance = RequestContext(request, object_id)
>                 )
>
>         form = UploadForm(request.POST, request.FILES)
>         if not form.is_valid():
>                 return render_to_response(
>                         'projects/files.html',
>                         {"form": form, "files": files},
>                         context_instance = RequestContext(request, object_id)
>                 )
>
>         file = request.FILES["file"]
>         filename = file.name
>         content = file.read()
>         store(...)
>         p = Project.objects.get(pk=object_id)
>         f = ProjectFileUrl(url="http://someurl.com/"; + object_id + "_" +
> filename,
>                 name=object_id + "_" + filename, project_number=p)
>         f.save()
>         files = ProjectFileUrl.objects.filter
> (project_number=object_id).order_by('-uploaded')
>         return render_to_response(
>                 'projects/files.html',
>                 {"form": form, "files": files},
>                 context_instance = RequestContext(request, object_id)
>         )
>
> def announce(request, object_id):
>         announcements = ProjectAnnouncement.objects.filter
> (project=object_id).order_by('-date_posted')
>         if not request.method == "POST":
>                 form = ProjectAnnouncementForm()
>                 return render_to_response(
>                         'projects/announcement.html',
>                         {"form": form, "announcements": announcements},
>                         context_instance = RequestContext(request)
>                 )
>         form = ProjectAnnouncementForm(request.POST)
>         if not form.is_valid():
>                 return render_to_response(
>                         'projects/files.html',
>                         {"form": form, "announcements": announcements},
>                         context_instance = RequestContext(request)
>                 )
>         title = request.POST['title']
>         body = request.POST['body']
>         d = datetime.now()
>         p = Project.objects.get(pk=object_id)
>         a = ProjectAnnouncement(author_user=request.user, date_posted=d,
> project=p, title=title, body=body)
>         a.save()
>         announcements = ProjectAnnouncement.objects.filter
> (project=object_id).order_by('-date_posted')
>         return render_to_response(
>                 'projects/announcement.html',
>                 {"form": form, "announcements": announcements},
>                 context_instance = RequestContext(request)
>         )
>
> As they both stand, they work separately.  Every time I try and
> combine them, or make one a template tag, I end up with an error, or
> only getting one to work and the other fails silently.  When I try and
> make one into a template tag, I end up with the "object_id" is not
> globally defined error.
>
> I'm sure I am missing something really basic.  Does anyone have a
> pointer to get me going in the right direction?
>
> Jonathan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Is there a way to calling a model field method on model save

2009-06-16 Thread Sean Brant

Okay I just came up with this, let me know if this is a really hacky
way to do this. With this it will save the model, then the file and
then the model again, not sure how to do this since we don't get the
filename until after we save the file and we have to set the filename
in the database.

class PostSaveImageField(ImageField):
def pre_save(self, model_instance, add):
return Field.pre_save(self, model_instance, add)

def post_save(self, sender, instance, created, **kwargs):
file = getattr(instance, self.attname)
if file and not file._committed:
file.save(file.name, file, save=False)
setattr(instance, self.attname, file)
instance.save()

def contribute_to_class(self, cls, name):
post_save.connect(self.post_save, sender=cls)
super(PostSaveImageField, self).contribute_to_class(cls, name)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: openid

2009-06-16 Thread Vance Dubberly

thank you.

On Sun, Jun 14, 2009 at 9:10 PM, Rama Vadakattu wrote:
>
> Recently i worked with openid i have used the below package for
> implementing it.
> http://code.google.com/p/django-openid-consumer/
> It is basically a fork of simonwillison  django-openid implementing
> new openid features.
>
> I did not face any problems and successfully implemented openid on my
> site.
>
> --rama
>
>
>
>
>
>
>
>
>
>
> On Jun 14, 9:42 am, Vance Dubberly  wrote:
>> So after looking around a bit it looks like simonwilsons openid
>> package is pretty where it's at for openid in django.
>>
>> Question is: is the package that hasn't been touched 2 years
>> django_openidconsumer the right one to use or has django_openid come
>> along far enough to implement/test.  I note that there was an email
>> further back that said django_openidconsumer doesn't work unless you
>> use the openid2.0 branch so I'm a bit lost.
>>
>> Vance
>>
>> --
>> To pretend, I actually do the thing: I have therefore only pretended to 
>> pretend.
>>   - Jacques Derrida
> >
>



-- 
To pretend, I actually do the thing: I have therefore only pretended to pretend.
  - Jacques Derrida

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



Re: 500 Errors on 404 error?

2009-06-16 Thread Wiiboy

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



Is there a way to calling a model field method on model save

2009-06-16 Thread Sean Brant

I am creating a custom image field, that I would like for it not to
save the image until after the model instance is written to the
database (i want the id for the object to use in the filename). The
ImageField class saves the image to storage via pre_save. Is there any
methods or any other code that fires post save on the Field class? Is
doing some sort of dynamic signal stuff that only way?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Generic views: delete_object and post_delete_redirect

2009-06-16 Thread fgasperino

All,

When creating a pluggable app, I've run across the need to use the
django.views.generic.create_update.delete_object view. Below is a
snippet of my URL patterns.

from django.conf.urls.defaults import *
from django.core.urlresolvers import reverse

urlpatterns = patterns("",
url(r"list/", "django.views.generic.list_detail.object_list", dict
(queryset = Note.objects.all(), template_name = "notes/list-notes-
template.html", template_object_name = "note"), name = "list_notes"),

url(r"delete/(?P\d+)",
"django.views.generic.create_update.delete_object", dict(model = Note,
template_name = "notes/delete-note-template.html",
post_delete_redirect = reverse("list_notes")), name = "delete_note"),
)

I'm attempting to use the reverse() shortcut to set
post_delete_redirect to a named URL defined in the same patterns
tuple.

Can this be done? I'm trying to avoid hardcoding the
post_delete_redirect value into the urls.py.

Thanks!

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



changes to views and forms are not reflected in browser

2009-06-16 Thread neri...@gmail.com

Hello,

I'm trying to make changes to views and forms but when I refresh the
browser to view/try the changes nothing seems to have changed. I
normally do "touch dispatch.fcgi" which is working with templates and
urls but with views and forms I get nothing different. I tried other
browsers and cleared my cache as well.

Thanks for any help,

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



Re: Memcached, out of sockets

2009-06-16 Thread Miles

On Jun 16, 3:38 pm, Brian Neal  wrote:
> Wellinstead of ranting about this here, why don't you open a
> ticket and detail your findings. It is in the communities best
> interest to have something like this fixed if it is indeed a problem.
> Thanks.

Because the "fix" will introduce the original problem again - you need
to clean up all socket or they might leak when you do a apache2ctl
graceful, or when you have a high MaxClients count with mod_python
(think large installations with worker mpm).

So, what is less evil? Keep the connection alive, or kill it after
every request? For us, keeping it alive works, but for others, it
might break. You can't really file that as a bug, right? Reopened the
original ticket, if it gets rejected, at least people can find the
solution on google :P

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



django "Unknown column 'inventory_machine.serial_num error

2009-06-16 Thread thesheff

I have cleaned up my model view and I thought for sure that serial_num
field is gone.  I have dropped the db and re-created the db with ./
manage.py syncdb but I still get the below error message. It seems
like it is cached somewhere.  I had this working before I modified the
models.py.  When I do ./manage.py validate I don't any errors with the
new model.  Let me know if you want me to post the model and the code.

management.machineNameCheck()
  File "/home/thesheff17/DigiSoft/django/django1/inventory/
Management.py", line 33, in machineNameCheck
machineList = Machine.objects.get(name=server)
  File "/home/thesheff17/DigiSoft/djtrunk/django/db/models/
manager.py", line 93, in get
return self.get_query_set().get(*args, **kwargs)
  File "/home/thesheff17/DigiSoft/djtrunk/django/db/models/query.py",
line 304, in get
num = len(clone)
  File "/home/thesheff17/DigiSoft/djtrunk/django/db/models/query.py",
line 160, in __len__
self._result_cache = list(self.iterator())
  File "/home/thesheff17/DigiSoft/djtrunk/django/db/models/query.py",
line 275, in iterator
for row in self.query.results_iter():
  File "/home/thesheff17/DigiSoft/djtrunk/django/db/models/sql/
query.py", line 206, in results_iter
for rows in self.execute_sql(MULTI):
  File "/home/thesheff17/DigiSoft/djtrunk/django/db/models/sql/
query.py", line 1734, in execute_sql
cursor.execute(sql, params)
  File "/home/thesheff17/DigiSoft/djtrunk/django/db/backends/util.py",
line 19, in execute
return self.cursor.execute(sql, params)
  File "/home/thesheff17/DigiSoft/djtrunk/django/db/backends/mysql/
base.py", line 83, in execute
return self.cursor.execute(query, args)
  File "/var/lib/python-support/python2.6/MySQLdb/cursors.py", line
166, in execute
self.errorhandler(self, exc, value)
  File "/var/lib/python-support/python2.6/MySQLdb/connections.py",
line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1054, "Unknown column
'inventory_machine.serial_num' in 'field list'")

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



Re: Form Field's required

2009-06-16 Thread Joshua Partogi
Thanks Alex.

On Wed, Jun 17, 2009 at 9:14 AM, Alex Gaynor  wrote:

>
>
> On Tue, Jun 16, 2009 at 6:12 PM, Joshua Partogi wrote:
>
>> Dear all,
>>
>> I want to add an asteriks in the template for required Form Fields. What
>> is the instance attribute for it? I tried reading from
>> http://docs.djangoproject.com/en/dev/topics/forms/#looping-over-the-form-s-fieldsbut
>>  could not find anything like it. I wonder how they do it in the django
>> admin app. Anybody have any idea about this?
>>
>> Thank you very much in advance.
>>
>>

-- 
Join Scrum8.com.

http://scrum8.com/member/jpartogi/
http://scrum8.com/blog/jpartogi/
http://twitter.com/scrum8

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



Re: Form Field's required

2009-06-16 Thread Alex Gaynor
On Tue, Jun 16, 2009 at 6:12 PM, Joshua Partogi wrote:

> Dear all,
>
> I want to add an asteriks in the template for required Form Fields. What is
> the instance attribute for it? I tried reading from
> http://docs.djangoproject.com/en/dev/topics/forms/#looping-over-the-form-s-fieldsbut
>  could not find anything like it. I wonder how they do it in the django
> admin app. Anybody have any idea about this?
>
> Thank you very much in advance.
>
> --
> Join Scrum8.com.
>
> http://scrum8.com/member/jpartogi/
> http://scrum8.com/blog/jpartogi/
> http://twitter.com/scrum8
>
> >
>
{{ field.field.required }} is whether or not the field is required.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Form Field's required

2009-06-16 Thread Joshua Partogi
Dear all,

I want to add an asteriks in the template for required Form Fields. What is
the instance attribute for it? I tried reading from
http://docs.djangoproject.com/en/dev/topics/forms/#looping-over-the-form-s-fieldsbut
could not find anything like it. I wonder how they do it in the django
admin app. Anybody have any idea about this?

Thank you very much in advance.

-- 
Join Scrum8.com.

http://scrum8.com/member/jpartogi/
http://scrum8.com/blog/jpartogi/
http://twitter.com/scrum8

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



Re: subdomain vs. prefix

2009-06-16 Thread Graham Dumpleton



On Jun 17, 12:55 am, "eric.frederich" 
wrote:
> Someone on freenode's  #django mentioned using djblets to accomplish
> this.http://www.chipx86.com/blog/2008/04/03/django-development-with-djblet...
>
> It did not work.
>
> With "WSGIScriptAlias /apps /path/to/django_application/apache/
> django.wsgi" in my apache configuration file, my site was already
> being served up at /apps/.  So following that guide I wound up with my
> site being served at /apps/apps/.  I realize that I could use
> "WSGIScriptAlias / ..." but that is what IT won't allow me to do.
> They want / to just serve static files from a directory.

It can still serve static files but with Django also mounted at root
of web site, they just don't know how to configure it properly. ;-)

Have a look at:

  
http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive

and in particular the example which uses the rewrite rules and the
WSGI script fixups after it.

What that allows is for static files to be served if they exist,
otherwise it delegates the request to the Django application which is
notionally mounted at root of the site, even though served out of a
named .wsgi file executed because of AddHandler.

So, have a read and ask questions if need better explanation than what
documentation gives.

Graham

> So, I'd like to ask one of my questions again... what is the best way
> to detect whether the code is running through Apache (an actual web
> request) or outside (like a cron job that runs "./manage.py runscript"
> from django-extensions)?  There has to be something that gets set that
> I can look at to tell what context the code is running in.
>
> Thanks,
> ~Eric
>
> On Jun 15, 2:45 pm, "eric.frederich"  wrote:
>
>
>
> > Hello,
>
> > I have been running a django site on apache using the following
> > alias...
>
> > WSGIScriptAlias /apps /path/to/django_application/apache/django.wsgi
>
> > In doing this I was pleasantly surprised to see that most of the URLs
> > worked fine.  The only thing I needed to change was LOGIN_URL='/apps/
> > login' in settings.py.  Nowhere else in my code is /apps mentioned
> > because apache sets some script prefix variable that wsgi tells django
> > about and all is well.
>
> > Now I am running into a problem with my cron jobs that run outside the
> > context of apache and my URLs generated with "http://%s%s/"; %
> > (Site.objects.get_current().domain, reverse(*args, **kwargs)) are
> > missing the /apps part.
>
> > I was okay with having one thing my code having /apps hard coded but
> > now I'm looking at having to see what context I'm running in (apache
> > vs. cron) and selectively adding this prefix.  This would introduce
> > another place where I'd need /apps hard coded which I don't like.  I
> > wasn't really happy with having to do it the one time.
>
> > Questions:
>
> > Would running in a subdomain solve all my problems?  For example using
> > apps.example.com rather than example.com/apps/.
>
> > Are there other parts of django that I have not run into yet that
> > expect django to be ran at the root?
>
> > If I can't get IT to give me a subdomain, what is the best way to
> > detect whether the code is running inside Apache or outside so that I
> > can slap /apps into my URLs?
>
> > Thanks in advance,
> > ~Eric
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Developing on Apache w/ mod_python

2009-06-16 Thread Graham Dumpleton



On Jun 17, 4:09 am, "sstein...@gmail.com"  wrote:
> On Jun 16, 2009, at 2:00 PM, gte351s wrote:
>
>
>
> > Gabriel - thanks for the quick response.
> > Sorry for the delay in answering, I was away for a bit :)
>
> > I had some issues with the setup, but I think I'll
> > put it on hold for a bit and use the django built-in
> > dev-server for now.
>
> I tried that once and had a huge headache getting my app re-running  
> under the production server when it had been running fine under the  
> dev server.  I know it's supposed to be the "same" but only for some  
> meanings of "same."
>
> If I were you, I'd take the time now to get the production serving  
> properly now, then test the production server at least at each  
> milestone before you get too far down the road assuming that the  
> production server's going to work the "same" as the dev server.
>
> Just my experience, YMMV.

If you really want to develop under Apache, then I would suggest using
mod_wsgi instead of mod_python because it can be setup to work just
like development server as far as code reloading goes and can be run
multithreaded where development server cannot. See:

  http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.html

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



Re: ModelForm, foreignkey, and hidden fields is null

2009-06-16 Thread Rochak Neupane
ohh, thanks, Daniel! I like your way. and i don't even my to expose the
user_id in a form.I'll try that.

On Mon, Jun 15, 2009 at 10:55 PM, Daniel Roseman wrote:

>
> On Jun 16, 1:12 am, k-dj  wrote:
> > I'm just starting to use django and have run into a problem I have not
> > been able to solve.
> >
> > I have a model Item which stores, among other things, user_id.
> > Then I have a ModelForm. I want user_id to be a hidden field. After
> > searching around the web, I found out how to create a hidden field.
> > The template is rendered as I like it.
> > user_id is a hidden field with a value of 1. The problem is when I
> > submit the form, I get IntegrityError. "Column 'user_id' cannot be
> > null".
> >
> > but from the debug message I get back I can see that POST has all 3
> > things I need. So maybe when a new form is created there is problem.
> >
> > views.py
> > @login_required
> > def newItem(request):
> > if not request.POST:
> > form = ItemForm()
> > return
> render_to_response('manager/newItem.html',{'form':form})
> > newForm = ItemForm(request.POST)
> > if newForm.is_valid():
> > newForm.save() #problem here?
> > return HttpResponsePermanentRedirect('.')
> >
> > models.py
> > class Item(models.Model):
> > user = models.ForeignKey(User)
> > name = models.CharField(max_length=32)
> > description = models.CharField(max_length=128)
> > creation_date = models.DateField(auto_now=True)
> >
> > forms.py
> > class ItemForm(ModelForm):
> > user_id_wid = forms.HiddenInput(attrs={'value': 1})
> > user_id = forms.IntegerField(widget=user_id_wid,required=False)
> > class Meta:
> > model = Item
> > fields = ['name', 'description']
>
>
> You can't set 'value' as an argument to attrs.
>
> If you want to preset the value of a field, pass in an 'initial'
> dictionary on form instatiation:
> form = MyForm(initial={'user_id':1})
>
> However a much better way is not to have the user_id field in the form
> at all, and set the correct value on the object on save.
>
> class itemForm(ModelForm):
>
>class Meta:
> model = Item
> exclude = ('user',)
>
> and in the view:
>if newForm.is_valid():
>item = newForm.save(commit=False)
>item.user_id = 1
>item.save()
>
> --
> DR.
> >
>

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



Alternate authentication

2009-06-16 Thread Daniel Jewett

I have a circumstance that requires me to use an alternative
authentication scenario. The authentication to our school's web site/
services is handled by the the hosting service. (There is some sort of
syncing that occurs with our local Active Directory database.)

I'm installing some Django apps on the school's local webserver which
needs to authenticate against the remote database.

The hosting service sent me this decrypt function in ASP.

Function DeCrypt(strEncrypted, strKey)
   Dim strChar, iKeyChar, iStringChar
   For i = 1 To Len(strEncrypted)
  iKeyChar = (Asc(Mid(strKey, i, 1)))
  iStringChar = Asc(Mid(strEncrypted, i, 1))
  iDeCryptChar = iKeyChar Xor iStringChar
  strDecrypted = strDecrypted & Chr(iDeCryptChar)
   Next
   DeCrypt = strDecrypted
End Function

UserName = Decrypt(request.Cookies("sample")("u"), "Encrypt Key")

I'm assuming this Xor decrypt function can be rewritten in Python but
I could use some help getting started on how to put this all together.

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



Template Question

2009-06-16 Thread CrabbyPete

Is there a way do something like this with the template system
{% if friend in group.members.all %} or simply {% friend in
group.members.all %}
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problem to deploy on production server

2009-06-16 Thread Francis

Is there someone who have more that one instance running on his server
who would like to share how to do it correctly?

And, how can I make my tables data reappear in the admin interface?

Thank you

Francis


On Jun 15, 2:20 pm, Francis  wrote:
> Also, if I set the SITE_ID to be equal in both config, When I save a
> model entry, I got an error from django:
> ERROR:  canceling statement due to statement timeout
>
> Francis
>
> On Jun 15, 10:40 am, Thomas Guettler  wrote:
>
>
>
> > Hi,
>
> > do you use the cache module? Be sure, that both projects use
> > different ones.
>
> > Maybe you need to set SESSION_COOKIE_NAME if the domain name is the
> > same.
>
> > Do you use one database or two? (Is settings.DATABASE_NAME the same?)
>
> >   Thomas
>
> > Francis schrieb:
>
> > > Hi,
>
> > > I have completed one web site and I am now ready to deploy it in
> > > production, but I have serious issues where I can't find any
> > > information/clue on the django web site, in the book or on IRC. I have
> > > no idea how I can solve my problem
>
> > > What I want to achieve is the following:
> > > 1 site under http without admin acces
> > > 1 site under https + admin acces
>
> > > My config
> > > python 2.5
> > > django 1.0.2
> > > postgresql
> > > mod_wsgi (i'm using it because djapian doesn't work with mod_python)
>
> > > So what I did was to create two mod_wsgi on two project repositories.
> > > One configured with the admin apps installed (https) an one without
> > > (http).
> > > Results:
> > > When I save an entry to a model, it saves it and redirects to the non
> > > secure http service instead of the secure one, throwing a 404.
>
> > > So I tried to enable the admin apps on both services.
> > > Results:
> > > Now I get a proxy error on the https service and a timeout on the http
> > > service.
> > > Some tables show no result on the http service but show them all on
> > > the other one.
>
> > > If I shut down the https service, some entries can be saved and others
> > > don't.
> > > The same tables that wrongly display nothing are still empty.
>
> > > I tried to give each site a different site_id, but it doesn't help.
>
> > > Help would be very much appreciated,
>
> > > Thank you
>
> > > Francis
>
> > --
> > Thomas Guettler,http://www.thomas-guettler.de/
> > E-Mail: guettli (*) thomas-guettler + de
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Developing on Apache w/ mod_python

2009-06-16 Thread sstein...@gmail.com


On Jun 16, 2009, at 2:00 PM, gte351s wrote:

>
> Gabriel - thanks for the quick response.
> Sorry for the delay in answering, I was away for a bit :)
>
> I had some issues with the setup, but I think I'll
> put it on hold for a bit and use the django built-in
> dev-server for now.

I tried that once and had a huge headache getting my app re-running  
under the production server when it had been running fine under the  
dev server.  I know it's supposed to be the "same" but only for some  
meanings of "same."

If I were you, I'd take the time now to get the production serving  
properly now, then test the production server at least at each  
milestone before you get too far down the road assuming that the  
production server's going to work the "same" as the dev server.

Just my experience, YMMV.

S


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



Re: Developing on Apache w/ mod_python

2009-06-16 Thread gte351s

Gabriel - thanks for the quick response.
Sorry for the delay in answering, I was away for a bit :)

I had some issues with the setup, but I think I'll
put it on hold for a bit and use the django built-in
dev-server for now.

Many thanks!
shilo

On Jun 15, 8:47 pm, "Gabriel ."  wrote:
> Hi,
>
> This a test conf with mod_python:
>
> 
>     ServerName py.banshee.lnx
>     DocumentRoot "/home/www/python"
>     ErrorLog /var/log/apache2/cash-error_log
>     CustomLog /var/log/apache2/cash-out_log combined
>
>     
>          SetHandler mod_python
>          PythonHandler django.core.handlers.modpython
>          SetEnv DJANGO_SETTINGS_MODULE pyCash.settings
>          PythonOption django.root /pyCash
>          PythonDebug Off
>          PythonPath "['/home/www/python','/home/www/python/pyCash'] + 
> sys.path"
>          PythonInterpreter pyCash
>     
>
>     Alias /media "/home/www/python/pyCash/pages/media"
>     Alias /admin_media "/home/www/python/pyCash/admin_media"
>
>     
>         SetHandler None
>     
>
>     
>         SetHandler None
>     
>
>     
>         SetHandler None
>     
>
>     
>             Options None
>             AllowOverride FileInfo
>             Order allow,deny
>             Allow from all
>     
>
> 
>
> The project is pyCash an is located at /home/www/python
>
> In my case, I have a symlink call admin_media in my application path
> pointing to the correct crontib path.
>
> Modify it to serve your needs.
>
> --
> Kind Regards
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Queryset._as_sql() is lying to me!

2009-06-16 Thread Alex Gaynor
On Tue, Jun 16, 2009 at 11:48 AM, Andrew Durdin  wrote:

>
> Today I ran into an issue where using distinct() and values() on a
> queryset where the model had default ordering would return apparently
> non-distinct results.  After searching, I found
> http://code.djangoproject.com/ticket/9186
> which indicates that this is now correct behaviour.  It took me a long
> time to discover what was wrong, however, because the queryset's
> _as_sql() method didn't show the the extra field that the default
> ordering caused to be selected.  For example (expanding on the example
> in that ticket), if I call:
>
> {{{ PbxRecord.objects.values('extension').distinct()._as_sql() }}}
>
> I'd get back this sql:
>
> {{{ ('SELECT DISTINCT `datastore_pbxrecord`.`extension` FROM
> `datastore_pbxrecord`', ()) }}}
>
> And not the actual sql that will be executed when the queryset is
> evaluated:
>
> {{{ SELECT DISTINCT `datastore_pbxrecord`.`extension`,
> `datastore_pbxrecord`.`id` FROM `datastore_pbxrecord` ORDER BY
> `datastore_pbxrecord`.`id` ASC }}}
>
> Why does _as_sql() not return the actual sql that will be executed?
> Is there any way to obtain the real SQL that a queryset will use?
> Although I only use _as_sql() for debugging, it'd be nice to know that
> it is reliable.
>
> Andrew.
> >
>
Use QuerySet.query.as_sql().  QuerySet._as_sql() is exclusively for use with
__in filters so it gets limited to just the primary key.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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



Queryset._as_sql() is lying to me!

2009-06-16 Thread Andrew Durdin

Today I ran into an issue where using distinct() and values() on a
queryset where the model had default ordering would return apparently
non-distinct results.  After searching, I found 
http://code.djangoproject.com/ticket/9186
which indicates that this is now correct behaviour.  It took me a long
time to discover what was wrong, however, because the queryset's
_as_sql() method didn't show the the extra field that the default
ordering caused to be selected.  For example (expanding on the example
in that ticket), if I call:

{{{ PbxRecord.objects.values('extension').distinct()._as_sql() }}}

I'd get back this sql:

{{{ ('SELECT DISTINCT `datastore_pbxrecord`.`extension` FROM
`datastore_pbxrecord`', ()) }}}

And not the actual sql that will be executed when the queryset is
evaluated:

{{{ SELECT DISTINCT `datastore_pbxrecord`.`extension`,
`datastore_pbxrecord`.`id` FROM `datastore_pbxrecord` ORDER BY
`datastore_pbxrecord`.`id` ASC }}}

Why does _as_sql() not return the actual sql that will be executed?
Is there any way to obtain the real SQL that a queryset will use?
Although I only use _as_sql() for debugging, it'd be nice to know that
it is reliable.

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



Re: Newb with some questions ...

2009-06-16 Thread Peter Herndon

For REST in Django, there are a number of options, but django-piston
is a front-runner.

---Peter

On 6/14/09, Gunnar  wrote:
>
> Good Day,
>
> I'm an 'ol VB6/SQL Server client-server programmer who has moved
> into .NET, Silverlight and has done some websites with Joomla. I've
> also done a LOT of Shockwave-Lingo, C++ and C#.
>
> After spending several days researching, I'm settling into Django more
> and more, and am letting go of the near hysteria I'm seeing over Ruby
> on Rails.
>
> ( I'm not keen on a language that is only around because of ROR, I'm
> not keen on Ruby performance)
>
> My goals are ...
>
> (1) Build REST web services incorporating ORM and sending XML results
> to Silverlight
>
> (2) Possibly integrating Django 'apps' into Joomla
>
> and
>
> (3) Building out full-blown websites with Djano - where for me - it
> would compete with Joomla.
>
> (4) It MUST run on GoDaddy - beyond my ability to influence so thanks
> in advance for the flame ;-)
>
>
> QUESTIONS...
>
> Goal (1) - To meet this goal, I just need web services. Is this
> practical in Django and can you point me somewhere to read-up on
> this???
>
> Goal (2) - This is more of a Joomla question - but if anyone has a
> suggestion - I am all ears!
>
> Goal (3) - I need to bone-up on Django so expect questions
>
> Goal (4) - Does anyone have experience with Django hosted at GoDaddy?
> Do they use Fast-CGI for Python?
>  What problems can I expect?   Going to another host is not an option!
>
> Thanks in advance.!
> Gunnar
>
> >
>

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



Building a widget from zero

2009-06-16 Thread MiratCanBayrak

Hi i wrote an application called category. As you guess it an
application to hold categories. Than i wanted to use it on my site. I
wrote a function that builds html code for displaying categories, but
now i want to use that view as widget.

How can i do it? how can i build a widget ?

That is function building that produces html code : http://dpaste.com/56008/,
its output is http://g.imagehost.org/view/0216 , produced html code is
http://dpaste.com/56011/ and my category model is here : 
http://dpaste.com/56009/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: subdomain vs. prefix

2009-06-16 Thread eric.frederich

Someone on freenode's  #django mentioned using djblets to accomplish
this.
http://www.chipx86.com/blog/2008/04/03/django-development-with-djblets-unrooting-your-urls/

It did not work.

With "WSGIScriptAlias /apps /path/to/django_application/apache/
django.wsgi" in my apache configuration file, my site was already
being served up at /apps/.  So following that guide I wound up with my
site being served at /apps/apps/.  I realize that I could use
"WSGIScriptAlias / ..." but that is what IT won't allow me to do.
They want / to just serve static files from a directory.

So, I'd like to ask one of my questions again... what is the best way
to detect whether the code is running through Apache (an actual web
request) or outside (like a cron job that runs "./manage.py runscript"
from django-extensions)?  There has to be something that gets set that
I can look at to tell what context the code is running in.

Thanks,
~Eric


On Jun 15, 2:45 pm, "eric.frederich"  wrote:
> Hello,
>
> I have been running a django site on apache using the following
> alias...
>
> WSGIScriptAlias /apps /path/to/django_application/apache/django.wsgi
>
> In doing this I was pleasantly surprised to see that most of the URLs
> worked fine.  The only thing I needed to change was LOGIN_URL='/apps/
> login' in settings.py.  Nowhere else in my code is /apps mentioned
> because apache sets some script prefix variable that wsgi tells django
> about and all is well.
>
> Now I am running into a problem with my cron jobs that run outside the
> context of apache and my URLs generated with "http://%s%s/"; %
> (Site.objects.get_current().domain, reverse(*args, **kwargs)) are
> missing the /apps part.
>
> I was okay with having one thing my code having /apps hard coded but
> now I'm looking at having to see what context I'm running in (apache
> vs. cron) and selectively adding this prefix.  This would introduce
> another place where I'd need /apps hard coded which I don't like.  I
> wasn't really happy with having to do it the one time.
>
> Questions:
>
> Would running in a subdomain solve all my problems?  For example using
> apps.example.com rather than example.com/apps/.
>
> Are there other parts of django that I have not run into yet that
> expect django to be ran at the root?
>
> If I can't get IT to give me a subdomain, what is the best way to
> detect whether the code is running inside Apache or outside so that I
> can slap /apps into my URLs?
>
> Thanks in advance,
> ~Eric
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Switching the sort order in a table (template) - Can you retrieve variables from the extra_context in a view function?

2009-06-16 Thread DaleB

Ups... sorry. I just solved it myself.
I overlooked the simple fact that i can use an if/else-construct based
on the extra_context in my template
So i don't have to access the context from a view at all.

Sometimes things are too simple ;-)


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



Re: Query Help: "Get Blogs where last Entry.title='foo'"

2009-06-16 Thread Jason

Took me awhile to wrap my head around it, but that got me where I need
to be, thank you.

On Jun 15, 3:41 pm, Streamweaver  wrote:
> A custom method in the model could work fine.
>
> If you set a 'get_latest_by' in the Entry Model 
> ->http://www.djangoproject.com/documentation/models/get_latest/
>
> Then in the Blog Model define something like:
>
> def last_is_foo(self):
>     if Entry.objects.latest().title == 'foo'
>         return True
>     return False
>
> Adding a CustomManager to that would easily give you back sets.
>
> Getting closer?
>
> On Jun 15, 4:11 pm, Jason  wrote:
>
> > Close.  That returns all entrys that have title foo.  I need all blogs
> > *where the last entry* has title foo.  I think I need to
> > leverage .extra(where=something) but not having much luck.
>
> > On Jun 15, 2:36 pm, Streamweaver  wrote:
>
> > > If I understand your question right there is an example that covers
> > > this exact situation that may help at
>
> > >http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-...
>
> > > I believe it could come out to something like this:
>
> > > e = Entry.objects.filter(title__exact='foo')
>
> > > blog = e.blog
>
> > > On Jun 15, 2:41 pm, Jason  wrote:
>
> > > > I'm new to django and attempting to leverage the query functionality.
> > > > I'm not sure if what I'm attempting requires custom sql or if I"m just
> > > > missing something.  I'm spending alot of time with the docs but
> > > > haven't found guidance for this issue.
>
> > > > Just using blogs as an easy example, assume the models below...
>
> > > > class Blog(models.Model):
> > > >     name = models.CharField(max_length=100, unique=True)
>
> > > > class Entry(models.Model):
> > > >     blog = models.ForeignKey(Blog)
> > > >     title = models.CharField(max_length=100)
>
> > > > How can I construct a query that returns all blogs where the last
> > > > entry has a title of 'foo'?
>
> > > > Note:  Using Django 1.1 beta, and thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Developing on Apache w/ mod_python

2009-06-16 Thread kiwi

thanks gabriel, now everything works..

Hello!!


On Jun 15, 7:47 pm, "Gabriel ."  wrote:
> Hi,
>
> This a test conf with mod_python:
>
> 
>     ServerName py.banshee.lnx
>     DocumentRoot "/home/www/python"
>     ErrorLog /var/log/apache2/cash-error_log
>     CustomLog /var/log/apache2/cash-out_log combined
>
>     
>          SetHandler mod_python
>          PythonHandler django.core.handlers.modpython
>          SetEnv DJANGO_SETTINGS_MODULE pyCash.settings
>          PythonOption django.root /pyCash
>          PythonDebug Off
>          PythonPath "['/home/www/python','/home/www/python/pyCash'] + 
> sys.path"
>          PythonInterpreter pyCash
>     
>
>     Alias /media "/home/www/python/pyCash/pages/media"
>     Alias /admin_media "/home/www/python/pyCash/admin_media"
>
>     
>         SetHandler None
>     
>
>     
>         SetHandler None
>     
>
>     
>         SetHandler None
>     
>
>     
>             Options None
>             AllowOverride FileInfo
>             Order allow,deny
>             Allow from all
>     
>
> 
>
> The project is pyCash an is located at /home/www/python
>
> In my case, I have a symlink call admin_media in my application path
> pointing to the correct crontib path.
>
> Modify it to serve your needs.
>
> --
> Kind Regards
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Switching the sort order in a table (template) - Can you retrieve variables from the extra_context in a view function?

2009-06-16 Thread DaleB

Hi all,

i am looking for solution to sort a table in a template:
Basically it's about switching between ascending and descending order.
My idea was to store the current sort order in the template's
extra_context (extra_context={'dir': sortdir,) and retrieve it from
there the next time i call the view.
Based on the set variable i could easily invert the sort-order .

Though this seems rather simple i couldn't find any information on how
to access the context from a view funtion? Is this possible at all?

Are there other good solutions (apart form js) to achieve what i am
trying to do?

Greetings,
Andreas


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



Re: Memcached, out of sockets

2009-06-16 Thread Brian Neal

On Jun 15, 7:28 pm, Miles  wrote:
> I've been running the python memcached connector for a while, without
> much trouble. But just today during a stress test of one of the feeds
> (read: many many requests expected), I've ran into an out of sockets
> situation.
>
> After every single request, the cache backend forces a disconnect from
> all memcached servers. That's no problem if you don't get too many
> hits, but after about ~5k requests in a minute, python just fails to
> connect to memcached and falls back to database access.
>
> Cause:
>
> Fixed #5133 -- Explicitly close memcached connections after each
> request
> (similar to database connection management). We can't effectively
> manage the
> lifecycle by pooling connections and recent versions of python-
> memcache can
> lead to connection exhaustion in some quite reasonable setups.
>
> Memcached is designed to help web apps hit insane throughput, not kill
> the whole server by exhausting all available sockets by forcing them
> all in TIME_WAIT... Without a decent amount of traffic, people
> wouldn't even bother to run memcached.
>
> Oh well, I'll be nooping the fix locally. That it added another 30%
> throughput on windows is just a bonus. If you plan to disable close
> with something like
> django.core.cache.backends.memcached.CacheClass.close = lambda x:
> None, make sure you also set memcache._Host._DEAD_RETRY = 5. Otherwise
> a broken socket can cause 30s of no cache on a thread, or worse, 30s
> of no cache at all when you restart memcached, instead of reconnecting
> on the next request. I thought I hit a bug the first I saw it happen.
>
> With a mod_wsgi deamon mode setup, max-requests=500, I'm not scared of
> leaking some sockets which gets freed after a few minutes at most.

Wellinstead of ranting about this here, why don't you open a
ticket and detail your findings. It is in the communities best
interest to have something like this fixed if it is indeed a problem.
Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



500 Errors on 404 error?

2009-06-16 Thread Wiiboy

I finally got Django to email me about 404 and 500 errors.  To test
it, I typed in a random path, that I knew would be a 404 error.
However, I got an email, and an error page, about a 500 error.  The
email said the following:

 File "/home/schoo37/webapps/schoolgoo/lib/python2.5/django/core/
handlers/base.py", line 118, in get_response
   callback, param_dict = resolver.resolve404()

 File "/home/schoo37/webapps/schoolgoo/lib/python2.5/django/core/
urlresolvers.py", line 226, in resolve404
   return self._resolve_special('404')

 File "/home/schoo37/webapps/schoolgoo/lib/python2.5/django/core/
urlresolvers.py", line 221, in _resolve_special
   return getattr(import_module(mod_name), func_name), {}

 File "/home/schoo37/webapps/schoolgoo/lib/python2.5/django/utils/
importlib.py", line 35, in import_module
   __import__(name)

ValueError: Empty module name


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



Re: django nginx fastcgi and flup

2009-06-16 Thread Adam N

I actually had issues with my most recent installation.  These are the
instructions I wrote/use and am currently maintaining.  Strangely, it
worked on my previous two installations ...

http://wiki.nginx.org/NginxPythonFlup

I'm using nginx version: nginx/0.6.35

Any assistance on those wiki pages is greatly appreciated.

-Adam

On Jun 12, 1:41 pm, Matt Davies  wrote:
> Hello Dhruv
> I've been using this configurement for ages, and we recently updated our
> django code.  The app runs almost %100, but there's a certain part that
> calls a number of tags out of the database and displays the, and this
> section is intermittently failing.
>
> To make it even wierder it works if I set debug to False in the settings
> file.
>
> I'll get into more detail later, I was just checking if there was a known
> problem.
>
> We've also updated Flup, which may be causing problems as well
>
> 2009/6/12 Dhruv Adhia 
>
>
>
> > Hello Matt,
>
> > Couple of days back I tried firing django app on fcgi server through
> > runfcgi command. As indicated I installed flup packages and did python path
> > settings as usual and when I run it I dont get any message that its running
> > on so and so server and neither does it runs the server. Is it something
> > similar?
>
> > On Fri, Jun 12, 2009 at 10:30 AM, Matt Davies  wrote:
>
> >> Hello everyone
> >> I'm going to write down a quite complex problem I'm having that I'm having
> >> trouble debugging, but before I start has anyone noticed any strange
> >> behaviour using django nginx fastcgi and flup recently?
>
> >> If there is an obvious problem that I haven't heard about then any links
> >> I"d be grateful
>
> >> I'll post the problem back to this forum as I work though it, it might
> >> help someone out.
>
> >> Hopefully me :-)
>
> > --
> > Dhruv Adhia
> >http://thirdimension.com
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: AttributeError when implementing Django Tutorial

2009-06-16 Thread ebbnormal

Thanks man!

Ryan.



On Jun 15, 9:12 pm, Alex Gaynor  wrote:
> On Mon, Jun 15, 2009 at 8:34 PM, ebbnormal  wrote:
>
> > Hello,
>
> > I have been following along the Django tutorial, and as I was editing
> > the urlpatterns in my urls module, i got the following error
> > when I tried to run the mysite server:
>
> >    AttributeError at /
> >    'AdminSite' object has no attribute 'urls'
> >    Request Method:     GET
> >    Request URL:        http://127.0.0.1:8000/
> >    Exception Type:     AttributeError
>
> > the line that error references is in my urls.py file, line 13:
>
> > >>>from django.conf.urls.defaults import *
>
> > # Uncomment the next two lines to enable the admin:
> > from django.contrib import admin
> > admin.autodiscover()
>
> > urlpatterns = patterns('',
> >       # (r'^mysite/', include('mysite.foo.urls')),
> >              (r'^polls/$', 'mysite.polls.views.index'),
> >              (r'^polls/(?P\d+)/$',
> > 'mysite.polls.views.detail'),
> >              (r'^polls/(?P\d+)/results/$',
> > 'mysite.polls.views.results'),
> >              (r'^polls/(?P\d+)/vote/$',
> > 'mysite.polls.views.vote'),
> >              (r'^admin/', include(admin.site.urls)),   #FIXME: this
> > is the error.
> > )
>
> > however, line13 is exactly as written in part 3 of the official Django
> > tutorial.
>
> > Any suggestions?
>
> > Thanks
>
> > Ryan.
>
> The problem is you are folloiwng the tutorial for the latest development
> version of Django, but you are using Django 1.0.  Follow the tutorial 
> here:http://docs.djangoproject.com/en/1.0/instead.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to access a form subfield? form design?

2009-06-16 Thread V

AFAIK you can't change your select box's options ordering. You should
do it by changing MONTH_LIST directly.

On Jun 15, 11:38 am, Bastien  wrote:
> Hi,
>
> I have a multi choice field to choose 1 or many months in checkboxes:
>
> in forms.py:
> months_open = forms.MultipleChoiceField(choices = MONTH_LIST,
> widget=forms.CheckboxSelectMultiple)
>
> then in my template I use {{ form.months_open }} to make the list
> appear. Now that works but the list appears as a raw list without
> style so I would like to change the order of the months but don't know
> how to access them. I tried things like {{ form.months_open.1 }} or
> {{ form.months_open[0] }} , I tried a for loop to get what's inside
> but there's nothing I can do.
>
> Anybody can tell me how this works?
> Thanks.
> Bastien
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: reverse url fails on existing url

2009-06-16 Thread Bastien

thanks!! both works.
Bastien

On Jun 16, 11:10 am, Brian May  wrote:
> On Tue, Jun 16, 2009 at 02:07:01AM -0700, Bastien wrote:
> > I don't understand how this works, on my url without arguments I can
> > use the template tag {% url ... %} and it just works but as soon as I
> > have an argument like this one:
>
> >     url(r'^users/(?P.+)/comments/$',
> >         view=public_comments,
> >         name='public_comments'),
>
> > and I call it via:
>
> >     {% url public_comments args=user.username %}
>
> > then I get :
>
> > Caught an exception while rendering: Reverse for public_comments' with
> > arguments '()' and keyword arguments '{'args': u'my_name'}' not found.
>
> I haven't double checked, but I think that should read:
>
> {% url public_comments user.username %}
>
> or
>
> {% url public_comments username=user.username %}
> --
> Brian May 
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form instance to update an object

2009-06-16 Thread Daniel Roseman

On Jun 16, 9:48 am, Genis Pujol Hamelink 
wrote:
> well, if you retrieve an object via GET modify something and then submit the
> new data you will create a POST request and I was wondering if I could test
> wether the object being saved was an existing one or not...
>
> greetings,
>
> Genis
>
OK, so you have the existing object. Now you can pass it in via the
instance parameter when you instantiate the form, as I stated above.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: reverse url fails on existing url

2009-06-16 Thread Brian May

On Tue, Jun 16, 2009 at 02:07:01AM -0700, Bastien wrote:
> I don't understand how this works, on my url without arguments I can
> use the template tag {% url ... %} and it just works but as soon as I
> have an argument like this one:
> 
> url(r'^users/(?P.+)/comments/$',
> view=public_comments,
> name='public_comments'),
> 
> and I call it via:
> 
> {% url public_comments args=user.username %}
> 
> then I get :
> 
> Caught an exception while rendering: Reverse for public_comments' with
> arguments '()' and keyword arguments '{'args': u'my_name'}' not found.

I haven't double checked, but I think that should read:

{% url public_comments user.username %}

or

{% url public_comments username=user.username %}
-- 
Brian May 

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



reverse url fails on existing url

2009-06-16 Thread Bastien

Hello,

I don't understand how this works, on my url without arguments I can
use the template tag {% url ... %} and it just works but as soon as I
have an argument like this one:

url(r'^users/(?P.+)/comments/$',
view=public_comments,
name='public_comments'),

and I call it via:

{% url public_comments args=user.username %}

then I get :

Caught an exception while rendering: Reverse for public_comments' with
arguments '()' and keyword arguments '{'args': u'my_name'}' not found.

anybody has an idea?
thanks,
Bastien

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



Re: form instance to update an object

2009-06-16 Thread Genis Pujol Hamelink
well, if you retrieve an object via GET modify something and then submit the
new data you will create a POST request and I was wondering if I could test
wether the object being saved was an existing one or not...

greetings,

Genis

2009/6/16 Daniel Roseman 

>
> On Jun 15, 4:23 pm, Genis Pujol Hamelink 
> wrote:
> > yes, but what if it's a new object and not an existing one? How do I test
> > this? The request method will be POST, so form will be form =
> > MyForm(request.POST)... so if form.pk exists in the db how do I tell
> it's
> > editing an existing object?
> >
> > if request.method == 'POST':
> >  form = myform(request.POST)
> >  try:
> >instance = myobj.objects.get(id=form.id)
> >form = myform(request.POST, instance=instance)
> >if form.is_valid():
> >  form.save()
> >else:
> >   whatever goes here
> >  except:
> >form = myform(request.POST)
> > if form.is_valid():
> >  form.save()
> >else:
> >   whatever goes here
> >
> > Something like this or do u know a better way?
> >
>
> I don't really understand how a newly-entered item can exist in the
> database already. At the very least, saving the new item would give it
> a new PK, so it wouldn't be a duplicate, surely.
> --
> DR.
> >
>


-- 
Genís

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