Re: rake routes
> 2. Add 'django.contrib.admindocs' to your INSTALLED_APPS. Tx! But I will rip the innards of that out, because I'm targeting the test side (as usual!), and because we have no admin yet... -- 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: rake routes
On Tue, Oct 19, 2010 at 8:20 PM, Phlipwrote: > A web platform which I will refer to as "Rails" lets you print out all > the equivalents of the matchers and modules in the tree of urls.py > files using "rake routes". One easy way: 1. Install docutils. 2. Add 'django.contrib.admindocs' to your INSTALLED_APPS. 3. Click the 'Documentation' link which will appear in the upper-right of your admin. 4. Notice the nicely-formatted list of all your URL patterns, what they match, and links to the documentation for the views they route to. -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." -- 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.
rake routes
A web platform which I will refer to as "Rails" lets you print out all the equivalents of the matchers and modules in the tree of urls.py files using "rake routes". Does Django have such a command? Or how could one be written? -- Phlip http://bit.ly/ZeekLand -- 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.
change the default widget to a field in a modelform
Hello list. I have a model with a ManyToMany field. For example: -- class Table(models.Model): myField = models.ManyToManyField(OtherTable) -- The modelForm returns a "selectMulttiple" for the field "myField", but I need a normal "select". Finally the modelForm is something like this: -- class MyForm(forms.ModelForm): class Meta: model = Table widgets = { 'myField': forms.Select() } -- This return a form with the normal "select" field. The problem appear when a want to save the model. I can't save because the form is invalid. Django say " Introduce a value list". Somebody have an idea to solve this problem? If I use a selectMultiple the form is valid and I can save the data. Thanks for read and sorry for my poor english. Thanks for read and sorry for my poor english. P.D. I use Django 1.2.1 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Directions on How To Help?
On 19 October 2010 23:50, OldTrollwrote: > I spotted a couple of errors in documentation and after a quick scan > on the docs website I haven't spotted a clear way to help. I can find > directions on helping with code, but I'm not certain if that applies. > Can anyone point me in the right direction? AFAIK, the same rules apply as with code. You create a ticket on http://code.djangoproject.com/simpleticket describing errors you found in a way that it will be easy to find for others. Patches are welcome, but not required. -- Łukasz Rekucki -- 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: jsi18n date and time formating
For example: formats['DATETIME_FORMAT'] = 'N j, Y, P'; On Oct 17, 10:13 pm, timc3wrote: > I am using jsi18n for trying to internationalize some Javascript and > its work fine. > > But I am wondering how to translate the datetime format used (based on > PHP's date) to a format that Javascript can parse? > > 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: "No module named copycompat" error
>From a python prompt can you do: from django.utils import copycompat If not, Django might not be imported properly. Also check your PYTHONPATH. On Oct 18, 10:57 pm, mathphreakwrote: > I just upgraded my computer to Ubuntu 10.10, and now running "python > manage.py runserver" gives me "Error: No module named copycompat". > I've probably also upgraded Django from 1.1.x to 1.2.x, which might be > the problem too. Which upgrade broke manage.py, and how can I fix > this? -- 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: Newbie question: How should I structure my very simple project / app?
Take a look at: http://lincolnloop.com/django-best-practices/projects/layout.html After you have done the tutorials and stuff. Tim. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Passing file to .net web service
Well are you doing that in a page request? Is it timing out? Also if you are doing this with large files its going to eat memory and processing power like you couldn't believe. I would hand this off to another service or daemon, or in my case Celery to do the work. On Oct 19, 10:58 am, Pradnyawrote: > Hello > I am using Django 1.1 and Python 2.6 > > I want to pass file ot file byte array to a web serrvice which is > written in .net, so I am using > > import urllib2 > import urllib2_file > > data = [ ('fileName' , 'test.txt'), ('file', open'/tmp/test.text', > 'r') ] > > data=urllib.urlencode(data) > req=urllib2.Request(URL, data,headers) > u = urllib2.urlopen(req) > > here URL is the .net web service url > > and it is throwing error as "The request was aborted: The request was > canceled." > > If tried without sending file or binary data it works fine. > > Is there any other way I can upload the file or send file to .net web > service? > Please suggest. > > Thanks > Pradnya -- 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.
Directions on How To Help?
I spotted a couple of errors in documentation and after a quick scan on the docs website I haven't spotted a clear way to help. I can find directions on helping with code, but I'm not certain if that applies. Can anyone point me in the right direction? 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.
serving SOAP service with soaplib, consuming with suds
Hi all, I am trying to make a SOAP service in Django via soaplib(1.0.0 - beta 8) and consume the same service for testing purposes with SUDS (0.4). I can consume external SOAP services with SUDS no problem, but am running into problems when trying to consume my own service. My service is as follows: #soap_service.py file import StringIO from soaplib.service import rpc, DefinitionBase from soaplib.serializers import primitive as soap_types class DumbStringIO(StringIO.StringIO): def read(self, n): return self.getvalue() class DjangoSoapService(DefinitionBase): __tns__ = 'http://127.0.0.1:8000' @rpc(soap_types.String, _returns=soap_types.String) def hello_world(self, hello_string): """ Accepts primitive string and returns the same primitive. """ return hello_string Here is my website.views.py class MySOAPService(Application): """ Creates a WSGI application interface to the SOAP service """ def __call__(self, request): django_response = HttpResponse() def start_response(status, headers): status, reason = status.split(' ', 1) django_response.status_code = int(status) for header, value in headers: django_response[header] = value environ = request.META.copy() body = request.raw_post_data environ['CONTENT_LENGTH'] = len(body) environ['wsgi.input'] = DumbStringIO(body) environ['wsgi.multithread'] = False response = super(MySOAPService, self).__call__(environ, start_response) django_response.content = "\n".join(response) return django_response my_soap_service = MySOAPService([DjangoSoapService], DjangoSoapService.__tns__) and here is my urls.py file: urlpatterns += patterns('website.views', (r'^hello_world/', 'my_soap_service'), (r'^hello_world/service.wsdl', 'my_soap_service'), ) I can view the wsdl file no problem, and it correctly shows my method 'hello_world'. However calling the method with suds from the python shell thus: >>>from suds.client import Client client = ('http://127.0.0.1:8000/hello_world/service.wsdl', cache=None) response = client.service.hello_world('hi') gives a stack: Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.5/site-packages/suds-0.4-py2.5.egg/suds/ client.py", line 542, in __call__ return client.invoke(args, kwargs) File "/Library/Python/2.5/site-packages/suds-0.4-py2.5.egg/suds/ client.py", line 602, in invoke result = self.send(soapenv) File "/Library/Python/2.5/site-packages/suds-0.4-py2.5.egg/suds/ client.py", line 649, in send result = self.failed(binding, e) File "/Library/Python/2.5/site-packages/suds-0.4-py2.5.egg/suds/ client.py", line 708, in failed raise Exception((status, reason)) Exception: (403, u'FORBIDDEN') No idea why it's not allowing me to connect, it's all local. Help!! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: Expense of django query
On Tue, Oct 19, 2010 at 3:46 PM, Edwrote: > I have 3 tables: studio, film, images. If film has a foreign key to > studio, and images has a foreign key to film. If I wanted to pull all > of the images for a particular studio, it would be more expensive to > pull: what i do is: in the view, get the images of the studio, ordered by film: images_queryset = image.objects.filter(film__studio_id==studioid).order_by('film') in the template, iterate through the images and show the film whenever it changes: {% for img in images_queryset.all %} {% ifchanged img.film %} ...show the film data {% endifchanged %} show the image... {% endfor %} -- 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.
Export current filtered view in contrib.admin
I'm in the processes of customizing the contrib.admin module to add a few reporting features that we need, specifically the ability to dump the current filtered view to some other format, say CSV. I found a post on django-snippets (http://djangosnippets.org/snippets/ 1792/) that seems like it should work, but when I try to use it I get the "got multiple values for keyword argument" error. I can't figure out where the error is as I know how URLconfs pass parameters to views, but for some reason I can't get this error to go away. I've already modified the admin module to use the local copies rather than pulling from django.contrib.admin so i don't get any cross-config problems. Here's my urlconf line for the export (admin is the local modified copy of django.contrib.admin): (r'^inventory/(.*)/(.*)/export/$', admin.site.admin_view(export), { 'format': 'csv', 'admin_site': admin.site }), Here's the definition of my view: def export(request, app_label, model_name, format, admin_site): Any ideas on what might be happening or perhaps a better solution? I'm on Django 1.2.3 release. Without this URLconf line, the entire admin site works great and has no issues. I already tried creating a custom action but I don't want to only export selected records, but rather all records in the current view including any records on hidden pages if the view is paginated. Thanks! - Russ B. -- 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: Expense of django query
Thanks for the answers. I thought that the view was already pulling the data. I didn't realize it gets pulled when called in the template. I was able to rewrite the view to provide the data more efficiently. I have another related question on the topic of query expense. What is the best practice as far as database table design? I have 3 tables: studio, film, images. If film has a foreign key to studio, and images has a foreign key to film. If I wanted to pull all of the images for a particular studio, it would be more expensive to pull: all films (given studio), and then films.images_set as opposed to: including the studio in the image table and then pulling all images (given studio). But there is some data replication here. Technically, I can discover studio by following the link from image to film to studio. But it I need less queries given this particular need. What is the best practice in a scenario like this? On Oct 19, 4:17 pm, Daniel Rosemanwrote: > On Oct 19, 4:43 pm, Tom Evans wrote: > > > > > > > On Tue, Oct 19, 2010 at 4:16 PM, Daniel Roseman > > wrote: > > > The solution here is to evaluate the queryset in your view first, > > > before passing it to the template. You can do this by simply calling > > > list() on it - eg instead of defining your context as {'actor_list': > > > actor_list}, do {'actor_list': list(actor_list)}. Bear in mind though, > > > if you're doing things like pagination, this will end up being less > > > efficient, as it will evaluate the *whole* queryset rather than just > > > the elements you need for the page you're on. > > > I'm 100% sure Daniel is aware of this, but it is good to explicitly > > point it out: this will also require more memory, as instead of > > iterating through the queryset and producing one object at a time, it > > has to create and store a list of objects. > > > Cheers > > > Tom > > Well, to a certain extent. When iterating through a queryset, Django > populates it in chunks of 100 items. So if the actor_list set is less > than 100 - which is a pretty good bet seeing as it's not paginated - > there'll be very little difference in terms of memory consumption. > -- > 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: login_required and new class based views
Thank you, I didn't know that! -- Best Regards, Valentin Golev Lead Developer r00, http://r00.ru http://valyagolev.net +7 921 789 0895, avaiable 12:00-18:00 MSK 2010/10/19 Łukasz Rekucki: > On 19 October 2010 21:21, Valentin Golev wrote: >> Thank you! >> >> Does python's super really works the way like in the last option? > Yes, it should call dispatch() from the next class in MRO. So if you > place it at the start, like this: > > class MyView(LoginRequiredMixin, TemplateView): > pass > > It should work as expected. > >> >> -- >> Best Regards, >> Valentin Golev >> Lead Developer >> r00, http://r00.ru >> >> http://valyagolev.net >> +7 921 789 0895, avaiable 12:00-18:00 MSK >> >> >> >> 2010/10/19 Łukasz Rekucki : >>> On 19 October 2010 19:06, Valentin Golev wrote: Hello, I'm trying to start using new class based views from the trunk. I need to rewrite a view which is decorated django.contrib.auth.decorators.login_required. How should I go with that? >>> There are couple of options. >>> >>> 1) decorate the final view (for use in urls.py): >>> >>> decorated_view = login_required(MyView.as_view) >>> >>> In this option, you lose the ability to subclass the decorated view. >>> >>> 2) decorate the dispatch method. You need to turn login_required into >>> a method decorator first (Django should probably provide a tool for >>> this). Here[1] is an example how to do this. >>> >>> class MyDecoratedView(MyView): >>> >>> �...@on_method(login_required): >>> def dispatch(self, *args, **kwargs): >>> # do any extra stuff here >>> return super(MyDecoratedView, self).dispatch(*args, **kwargs) >>> >>> 3) Make a class decorator, that does the above, so you could do: >>> >>> @on_dispatch(login_required) >>> class MyDecoratedView(MyView): >>> pass >>> I was going to write something like LoginRequiredMixin, but I have no idea how to do this. I need to run my code before .dispatch(), but I also have to call the old dispatch, but since Mixin aren't inherited from View, I can't just override method and use super(). >>> >>> This is option #4. You can just do: >>> >>> class LoginRequiredMixin(object): >>> >>> def dispatch(self, *args, **kwargs): >>> bound_dispatch = super(LoginRequired, self).dispatch >>> return login_required(bound_dispatch)(*args, **kwargs) >>> >>> >>> [1]: http://www.toddreed.name/content/django-view-class/ >>> >>> -- >>> Łukasz Rekucki >>> >>> -- >>> 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. >> >> > > > > -- > Łukasz Rekucki > > -- > 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: Expense of django query
On Oct 19, 4:43 pm, Tom Evanswrote: > On Tue, Oct 19, 2010 at 4:16 PM, Daniel Roseman wrote: > > The solution here is to evaluate the queryset in your view first, > > before passing it to the template. You can do this by simply calling > > list() on it - eg instead of defining your context as {'actor_list': > > actor_list}, do {'actor_list': list(actor_list)}. Bear in mind though, > > if you're doing things like pagination, this will end up being less > > efficient, as it will evaluate the *whole* queryset rather than just > > the elements you need for the page you're on. > > I'm 100% sure Daniel is aware of this, but it is good to explicitly > point it out: this will also require more memory, as instead of > iterating through the queryset and producing one object at a time, it > has to create and store a list of objects. > > Cheers > > Tom Well, to a certain extent. When iterating through a queryset, Django populates it in chunks of 100 items. So if the actor_list set is less than 100 - which is a pretty good bet seeing as it's not paginated - there'll be very little difference in terms of memory consumption. -- 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: login_required and new class based views
On 19 October 2010 21:21, Valentin Golevwrote: > Thank you! > > Does python's super really works the way like in the last option? Yes, it should call dispatch() from the next class in MRO. So if you place it at the start, like this: class MyView(LoginRequiredMixin, TemplateView): pass It should work as expected. > > -- > Best Regards, > Valentin Golev > Lead Developer > r00, http://r00.ru > > http://valyagolev.net > +7 921 789 0895, avaiable 12:00-18:00 MSK > > > > 2010/10/19 Łukasz Rekucki : >> On 19 October 2010 19:06, Valentin Golev wrote: >>> Hello, >>> >>> I'm trying to start using new class based views from the trunk. >>> >>> I need to rewrite a view which is decorated >>> django.contrib.auth.decorators.login_required. >>> >>> How should I go with that? >> There are couple of options. >> >> 1) decorate the final view (for use in urls.py): >> >> decorated_view = login_required(MyView.as_view) >> >> In this option, you lose the ability to subclass the decorated view. >> >> 2) decorate the dispatch method. You need to turn login_required into >> a method decorator first (Django should probably provide a tool for >> this). Here[1] is an example how to do this. >> >> class MyDecoratedView(MyView): >> >> �...@on_method(login_required): >> def dispatch(self, *args, **kwargs): >> # do any extra stuff here >> return super(MyDecoratedView, self).dispatch(*args, **kwargs) >> >> 3) Make a class decorator, that does the above, so you could do: >> >> @on_dispatch(login_required) >> class MyDecoratedView(MyView): >> pass >> >>> >>> I was going to write something like LoginRequiredMixin, but I have no >>> idea how to do this. I need to run my code before .dispatch(), but I >>> also have to call the old dispatch, but since Mixin aren't inherited >>> from View, I can't just override method and use super(). >> >> This is option #4. You can just do: >> >> class LoginRequiredMixin(object): >> >> def dispatch(self, *args, **kwargs): >> bound_dispatch = super(LoginRequired, self).dispatch >> return login_required(bound_dispatch)(*args, **kwargs) >> >> >> [1]: http://www.toddreed.name/content/django-view-class/ >> >> -- >> Łukasz Rekucki >> >> -- >> 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. > > -- Łukasz Rekucki -- 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: MultiFileInput widget
Okay, I am answering myself. Maybe this info helps someone else. I created a fileupload model with foreignkey relation. # models.py class Item(models.Model): serialnr = models.CharField(max_length=5, blank=True) class Fileupload(models.Model): item = models.ForeignKey(Item) file = models.FileField(upload_to='uploads/%Y/%m/%d', blank=True) ... # views.py def item_create(request): if request.method == 'POST': form = ItemForm(request.POST) fileform = FileuploadForm(request.FILES) ... form.save() id = new_item.id for f in request.FILES.getlist('file[]'): fileform = Fileupload(file=f) fileform.item_id = id fileform.save() # forms.py class FileuploadForm(ModelForm): file = forms.FileField(widget=MultiFileInput, required=False) class Meta: model = Fileupload new_item.save() return HttpResponseRedirect('/tracker/') ... -- 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: login_required and new class based views
Thank you! Does python's super really works the way like in the last option? -- Best Regards, Valentin Golev Lead Developer r00, http://r00.ru http://valyagolev.net +7 921 789 0895, avaiable 12:00-18:00 MSK 2010/10/19 Łukasz Rekucki: > On 19 October 2010 19:06, Valentin Golev wrote: >> Hello, >> >> I'm trying to start using new class based views from the trunk. >> >> I need to rewrite a view which is decorated >> django.contrib.auth.decorators.login_required. >> >> How should I go with that? > There are couple of options. > > 1) decorate the final view (for use in urls.py): > > decorated_view = login_required(MyView.as_view) > > In this option, you lose the ability to subclass the decorated view. > > 2) decorate the dispatch method. You need to turn login_required into > a method decorator first (Django should probably provide a tool for > this). Here[1] is an example how to do this. > > class MyDecoratedView(MyView): > > �...@on_method(login_required): > def dispatch(self, *args, **kwargs): > # do any extra stuff here > return super(MyDecoratedView, self).dispatch(*args, **kwargs) > > 3) Make a class decorator, that does the above, so you could do: > > @on_dispatch(login_required) > class MyDecoratedView(MyView): > pass > >> >> I was going to write something like LoginRequiredMixin, but I have no >> idea how to do this. I need to run my code before .dispatch(), but I >> also have to call the old dispatch, but since Mixin aren't inherited >> from View, I can't just override method and use super(). > > This is option #4. You can just do: > > class LoginRequiredMixin(object): > > def dispatch(self, *args, **kwargs): > bound_dispatch = super(LoginRequired, self).dispatch > return login_required(bound_dispatch)(*args, **kwargs) > > > [1]: http://www.toddreed.name/content/django-view-class/ > > -- > Łukasz Rekucki > > -- > 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: login_required and new class based views
On 19 October 2010 19:06, Valentin Golevwrote: > Hello, > > I'm trying to start using new class based views from the trunk. > > I need to rewrite a view which is decorated > django.contrib.auth.decorators.login_required. > > How should I go with that? There are couple of options. 1) decorate the final view (for use in urls.py): decorated_view = login_required(MyView.as_view) In this option, you lose the ability to subclass the decorated view. 2) decorate the dispatch method. You need to turn login_required into a method decorator first (Django should probably provide a tool for this). Here[1] is an example how to do this. class MyDecoratedView(MyView): @on_method(login_required): def dispatch(self, *args, **kwargs): # do any extra stuff here return super(MyDecoratedView, self).dispatch(*args, **kwargs) 3) Make a class decorator, that does the above, so you could do: @on_dispatch(login_required) class MyDecoratedView(MyView): pass > > I was going to write something like LoginRequiredMixin, but I have no > idea how to do this. I need to run my code before .dispatch(), but I > also have to call the old dispatch, but since Mixin aren't inherited > from View, I can't just override method and use super(). This is option #4. You can just do: class LoginRequiredMixin(object): def dispatch(self, *args, **kwargs): bound_dispatch = super(LoginRequired, self).dispatch return login_required(bound_dispatch)(*args, **kwargs) [1]: http://www.toddreed.name/content/django-view-class/ -- Łukasz Rekucki -- 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-adminfiles and sorl-thumbnail
Hi, I'm trying to install django-adminfiles and therefore I have to install sorl-thumbnails, too. When I now try to create or change am Entry in the admin the adminfiles-widget doesn't render, but just gets me an error-message saying that 'thumbnail' is an invalid block tag. The same happens, when i try to use the thumbnail-tag in one of my templates for testing purposes. In the manage.py shell in my project I can import adminfiles, thumbnails, and PIL (which is another dependency) without any problems. Also when i use print with the repective module, the directories are what they are supposed to be. Any ideas? I mostly need adminfiles as a simple tool to integrate images in Blog- Posts. Does anybody have another recommendation for a good (easy) way to handle this task? Thanks in advance Dominic -- 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.
login_required and new class based views
Hello, I'm trying to start using new class based views from the trunk. I need to rewrite a view which is decorated django.contrib.auth.decorators.login_required. How should I go with that? I was going to write something like LoginRequiredMixin, but I have no idea how to do this. I need to run my code before .dispatch(), but I also have to call the old dispatch, but since Mixin aren't inherited from View, I can't just override method and use super(). Decorating the whole View class doesn't seem like a good idea, either. Am I missing something? Thank you very much! -- 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.
customizing inherited field attributes
Hi, I have the need for the following inheritance customization: class abstract(models.Model): field=models.Charfield() class Meta: abstract=True class A(abstract): I want the field 'field' to be required here. class B(abstract): I want the field 'field' to have a blank=True value here, that is, to not be required Any ideas how to accomplish this? I was trying to use something like self.__name__ with an expression, but self. does not seem to be available to model fields.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: Comments and cascade delete
On 19/10/10 17:16, shacker wrote: > If Django comments are attached to a record (like a news item) and > that item is deleted, the comment remains in the database. In other > words, comments don't get cascade delete treatment like foreign key > relationships do. The django comments contrib uses the generic relation approach (part of the contenttypes contrib). So to get deletion behaviour you want, you need to define a reverse generic relation back to comment on your model for django's deletion cascade to follow the deletion in the generic case. On your own models, this is of course straightforward, but you may be stuck patching if you're commenting on models in third party apps. http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#reverse-generic-relations """ `comments = generic.GenericRelation(Comment, object_id_field="object_pk")` Note also, that if you delete an object that has a GenericRelation, any objects which have a GenericForeignKey pointing at it will be deleted as well. """ -- 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: Comments and cascade delete
One possibility is to add a post-delete signal which listens for instances of news items and uses the content type to clean up comments with that content type and primary key. I'm pretty sure this isn't considered a bug, but I couldn't address the issue of whether it was a planned part of the design or a necessary result of the implementation of generic foreign keys. 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: Different logins in same browser session and login_required
On 19/10/10 17:03, Bill Freeman wrote: > This is a limitation of the browser. It does not keep separate credentials > for separate windows. This is usually desirable because you may choose > to open a link in a new window (or tab) and you still expect to be logged in. > IE8 (and probably other browsers) are growing more flexible in that area: http://blogs.msdn.com/b/ie/archive/2009/05/06/session-cookies-sessionstorage-and-ie8.aspx > The only solution I know is to run separate browsers. You can install, say, > both firefox and chrome, for example. If you truly need to have them be the > same browser version, then the easiest thing is to run one in a virtual > machine. Firefox has long had its "profile" functionality. firefox -no-remote -ProfileManager You can create multiple firefox profiles, then run multiple instances of firefox at once - so long as you use different profiles for them. A bit fiddly, but obviously useful for development/testing. -- 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: Newbie question: How should I structure my very simple project / app?
Waza - Django should be ideal for your project. It should be a snap once you figure out how Django's put together. *Skip Do as others have suggested and do the tutorial. It will help you better understand MVC. * Skip the AJAX stuff unitl you have the above figured out. The magic ponies sometimes get in the way of more important details while you are learning. On Tuesday, October 19, 2010 07:52:34 am wawa wawawa wrote: > Hi All, > > I'm new to Django (and to be honest, a little bit hazy on the subtleties of > MVC, but if you don't try, you don't learn). > > I want to create a simple web frontend for a Python program I have already > (mostly) written and I'd like to use Django (which may be overkill... not > sure). > > - Users have a bunch of externally generated XML files. (Could be one, > could be many (max of 20?). Possibly in an zip or tar.gz archive). > - Users access the Django app and can upload via a simple form (with funky > Ajax uploadiness - including as many ponies and rainbows as might be > necessary) > - A backend script will process this XML, performing all manner of > fantastical space/time-bending magic (which will not take longer than 5 to > 10 secs... Max tested with many, many input files is about 40seconds). > - The output will be produced and the user will have the option to download > as CSV or possibly PDF. Possibly with functionality to allow the report to > be mailed to them when complete (so user identity needs to be built in). > > Very vague I know. But a very simple web app I think. Essentially, the > backend script summarizes the input files into a summary per file and a > total summary of the presence and count of certain keys / values or > combinations of data. There's a set of logical rules that I have yet to > invent which will be used when parsing the input XML (for example: if value > "B" exists in "A" with attribute "Z" but not attribute "X" then count, > otherwise do not). > > The reason I want to use Django is: > - I know I will be asked to add all sorts of functionality to this. Django > is extensible, powerful. > - I don't want to be responsible for maintaing the "rules" and would love > to be able to expose this via an admin interface so anyone (with > authorization) can add or edit rules logic. > - I've already got the bulk of the parsing script written in Python. > > I guess I need: > - a handler for the input files. > - a way to pass these file serially to my backend script (I presume I would > use the filesystem for this? The input files can be anywhere from 2K to 1MB > in very extreme cases.) > - a mechanism to separate different user sessions. > - a way to accumulate the results of each file parse and then report on the > total (store the results in the DB?) > - a mechanism to present and archive the reports (and then this leads to a > way to look up old reports). > > So, given this paucity of requirements and the horrendously unclear > explanation above, what suggestions might you lot have? (Apart from "RTFM", > of course!) > > - Do / Don't use Django? > - Structure of projects / Apps? > - Any key external apps / modules that might be useful (e.g. for handling > for uploads) > - Any gotchas when invoking backend scripts? > ... > > I'm really just looking for a nudge in the right direction. > > Thanks in advance for any tips, pointers or help you can give. > > Thanks > > Waza -- -- 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: Session issues in Internet Explorer
On Oct 19, 3:13 pm, Quiet Light Developmentwrote: > Hello, > > I am having trouble getting sessions to work with my production > server. When I move from one page to the next and try to call > request.session["app"] it is giving me a key error even though I know > I had set it in the previous page. This error is only occurring in IE. > Firefox and Chrome work properly. A little about the server: > > Django version 1.2.1 > Session engine 'django.contrib.sessions.backend.db' > > I'm not using cookies at all presently, but trying to track sessions > through the database. > > Does anyone have experience with this issue? > > Thanks, > Ben Unfortunately the advice you've been getting in this thread has not been very reliable. This has nothing to do with threaded Apache environments, or anything like that. Although you're not using cookies explicitly, Django does automatically use a cookie to identify a user, so that their session data is preserved across requests. This is non-configurable - see the explanation here: http://docs.djangoproject.com/en/1.2/topics/http/sessions/#session-ids-in-urls The cookie is just used to identify a session - all the data is actually stored in the sessions backend: the db table, in your case. There are two places you should check to see what's going wrong. Firstly, check that the value of the 'sessionid' cookie persists across requests. In IE, you can use the venerable Developer Toolbar to examine cookies. For example, IE is very particular about using `expires` rather than `max_age` to determine the lifetime of a cookie. Secondly, you might want to monitor the django_session table to check that the value of app is being saved by the first request. See the page I've linked to above for details on how to decode the data in the session hash. -- 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.
Comments and cascade delete
If Django comments are attached to a record (like a news item) and that item is deleted, the comment remains in the database. In other words, comments don't get cascade delete treatment like foreign key relationships do. This leads to A) database clutter and B) breakage when you do things like loop through comments, linking to the associated content object (which no longer exists). Is this expected behavior, or a bug? It seems out of keeping with the "usual way" of doing things in Django. Anyone have recommended techniques for dealing with this? Thanks, Scot -- 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: Different logins in same browser session and login_required
This is a limitation of the browser. It does not keep separate credentials for separate windows. This is usually desirable because you may choose to open a link in a new window (or tab) and you still expect to be logged in. The only solution I know is to run separate browsers. You can install, say, both firefox and chrome, for example. If you truly need to have them be the same browser version, then the easiest thing is to run one in a virtual machine. On linux you can, if you are sharp, run two X servers on two separate virtual terminals, and log in as different users on the two of them. Browsers run by separate users are separate. On windows you might do this with the switch user without logging out functionality. I don't know about Macs. Bill On Tue, Oct 19, 2010 at 10:55 AM, PyManwrote: > Hi guys, > I need some help about logins and session and any help would be much > appreciated :) > > This is the scenario: > * Django 1.2.0 > * Firefox (but I think any browser too) > > This the steps: > 1) In the same computer (so in the same browser session) I have two > browser windows "W1" and "W2" where the user "U1" is already logged in > in both windows. > 2) In the browser window "W1" the user logs out > 3) In the browser window "W1" the user "U2" logins in and gets > redirect to the main web page > 4) In the browser window "W2" any call to the views (all using the > "login_required" decorator) is done with request.user set to "U2" > instead the old "U1" --> here the human user could still think to be > "U1" in this window (indeed he can see "U1" printed in the web page > previously rendered), but he's surfing like "U2" > > Since you can't keep to more logged users in the same session, I'd > like to catch this situation and redirect the user to the log in page. > > Of course I don't want to rewrite all the ajax and not ajax calls to > pass the "current" (means "old") user as parameter to match with > request.user for a change. It's ugly and expensive. > > Any idea? > > 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. > > -- 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: Session issues in Internet Explorer
On 19 ?.?. 2010, at 22:25, Tom Evans wrote: The server is running Apache 2.2.12 on Ubuntu. >>> >>> You are running in a threaded environment then, your sessions can't persist >>> without cookies or equivalent external storage because the HTTP exchange is >>> not all contained within the same server process... >> >> Whoops, I couldn't cancel that e-mail fast enough, but I'm clearly wrong - >> cause you mentioned that it's only a problem in IE, but that it's working in >> Chrome and Firefox. So maybe you're not using a threaded Apache. Sorry for >> jumping to conclusions! >> >> Jonathan >> > > What has that got to do with the price of cheese? You're absolutely right, it's got nothing to do with it at all, HTTP is stateless, even if I were reaching, thinking of persistent TCP connections, they're on the layer below so it couldn't matter. Sorry about that, it's 11:30pm my time and I didn't get to sleep last night, so I have to beg your forgiveness for having spread nonsense. > All web servers are > stateless, threaded or otherwise. Yeah, of course, I was confusing myself with a problem I just encountered trying to persist non-serializable objects (socket connections) that I couldn't find a work around for under MPM Apache. Ended up with an ugly kludge involving a hidden iframe - almost as shameful as the incorrect responses I offered in this thread... > Sessions are a layer added above > HTTP by your framework. To be frank, none of your replies have made > sense to me - It's good you're frank, I won't feel my mistake is perpetuating itself into impressionable minds. I hope I've helped people with their problems slightly more often than I've mis-lead them in my short time on this list to date, but perhaps I've been too eager to spread my newbie enthusiasm. On the other hand, I'm personally very grateful for the consistently high-quality information and advice you share on this list, I've learned quite a lot about Django from reading your posts every day. Thanks! > django does not use client side sessions, and doesn't > hash the data in a session.. I didn't mean to say that it included any session data in the cookie, just that it hashed the session ID that's stored there, per http://www.djangobook.com/en/2.0/chapter14 : "Cookies use only a hashed session ID -- not the data itself -- thus protecting you from most of the common cookie problems." But I mis-spoke... Anyway, you've set Ben down the right path to understanding, so I'll just go finish debugging so I can finally get some sleep... Yours apologetically, 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-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: Expense of django query
On Tue, Oct 19, 2010 at 4:16 PM, Daniel Rosemanwrote: > The solution here is to evaluate the queryset in your view first, > before passing it to the template. You can do this by simply calling > list() on it - eg instead of defining your context as {'actor_list': > actor_list}, do {'actor_list': list(actor_list)}. Bear in mind though, > if you're doing things like pagination, this will end up being less > efficient, as it will evaluate the *whole* queryset rather than just > the elements you need for the page you're on. I'm 100% sure Daniel is aware of this, but it is good to explicitly point it out: this will also require more memory, as instead of iterating through the queryset and producing one object at a time, it has to create and store a list of objects. Cheers Tom -- 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: Newbie question: How should I structure my very simple project / app?
Hi Javier, Many thanks for your comments. On 19 October 2010 15:57, Javier Guerra Giraldezwrote: > first and foremost, yes, you have to read the manual, and do the > tutorial. ideally, you should forget about your specific project > while doing it. it's not too long, should take a few hours to do > completely. the fact is, if you skip this step, you won't get useful > answers here. > Understood. I'm working my way through them now. [...comment ref: message queueing...] I appreciate your insight into the queuing side. The one thing that I cannot seem to parse is how to structure the App so it fits with the Django approach. Is this one project and one app or is it an app per functional element of the system? Essentially this is a glorified form 'that does stuff in the backend'. I'm struggling with how to structure it... good luck, and welcome > Appreciated! Regards W -- 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: Session issues in Internet Explorer
2010/10/19 Jonathan Barratt: > > On 19 ต.ค. 2010, at 21:49, Jonathan Barratt wrote: > >> >> On 19 ต.ค. 2010, at 21:32, Quiet Light Development wrote: >> >>> Thank you Masklinn and Jonathan for your responses. I don't know a lot >>> about the physical set-up of the system, I can ask the server >>> administrators that question. >>> >>> The server is running Apache 2.2.12 on Ubuntu. >> >> You are running in a threaded environment then, your sessions can't persist >> without cookies or equivalent external storage because the HTTP exchange is >> not all contained within the same server process... > > Whoops, I couldn't cancel that e-mail fast enough, but I'm clearly wrong - > cause you mentioned that it's only a problem in IE, but that it's working in > Chrome and Firefox. So maybe you're not using a threaded Apache. Sorry for > jumping to conclusions! > > Jonathan > What has that got to do with the price of cheese? All web servers are stateless, threaded or otherwise. Sessions are a layer added above HTTP by your framework. To be frank, none of your replies have made sense to me - django does not use client side sessions, and doesn't hash the data in a session.. Django's framework uses cookies (and only cookies) to persist the session identifier in a users browser. The session identifier is retrieved from the session id cookie on subsequent requests and used by the session backend to load the session data for that user. Have you enabled the session middleware? Do you have 'django.contrib.sessions.middleware.SessionMiddleware' in MIDDLEWARE_CLASSES? Is the django session cookie being set? Since your issue seems to be with Internet Explorer, you should install fiddler2 to examine the request/responses being sent/received by your browser. Check that django is setting a session cookie (the response will have a header called Set-Cookie), and that your browser is accepting the cookie and returning it with the next request (the request will have a header called Cookie). A common problem when browsers not not accepting cookies is that the cookie is emitted with an invalid domain. The browser receives the cookie, but seeing the domain is invalid, refuses to store it. Cheers Tom -- 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: Expense of django query
On Oct 19, 3:45 pm, Edwrote: > I have a table for Actor that I query and populate the result in > actor_list to pass to the template. I installed the Django Debug > Toolbar to check the queries hitting the database and found some > strange behavior. If I iterate through the actor_list, only one SQL > query is created, as expected: > > {% for actor in actor_list %} > {{ actor.id }} > {% endfor %} > > But if I call a particular item in the list before the loop, that > additional call generates its own query, meaning the database is hit > twice. > > {{ actor_list.0.id }} > > {% for actor in actor_list %} > {{ actor.id }} > {% endfor %} > > Why is that? Is there a way to do this that doesn't result in two > queries? What's happening here is that calling {{ actor_list.0 }} slices the queryset - it's the same as doing actor_list[0] in Python code. When you slice a queryset, Django always evaluates it, if it hasn't done so already. So in this case Django sends an SQL query with `LIMIT 1` on the end, and returns just that element, from which you then take the id value and throw it away. Then, Django encounters your loop. Now it needs the whole queryset - so it needs to get *that* from the database. Hence your extra query. The solution here is to evaluate the queryset in your view first, before passing it to the template. You can do this by simply calling list() on it - eg instead of defining your context as {'actor_list': actor_list}, do {'actor_list': list(actor_list)}. Bear in mind though, if you're doing things like pagination, this will end up being less efficient, as it will evaluate the *whole* queryset rather than just the elements you need for the page you're on. -- 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: Expense of django query
On Tue, Oct 19, 2010 at 9:45 AM, Edwrote: > Why is that? Is there a way to do this that doesn't result in two > queries? check: http://docs.djangoproject.com/en/1.2/topics/db/optimization/#don-t-overuse-count-and-exists there's a tip about loading the whole query once: use {% with actor_list.all as actors %}. after that, you could use {{actors|first}} to get the first one -- 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.
Re: Session issues in Internet Explorer
Ben, Yes, that is definitely going to be the quickest way to resolve your issue, and I see no reason not to use them - Django hashes the data in them so it's safe from casual prying... Hth, Jonathan ? 19 ?.?. 2553 21:54 Ben Luedtke?: > Thanks Jonathan, > > Either way though, the solution is to set the cookie to allow the > session to persist correct? > > Thanks, > Ben > > On Oct 19, 9:51 am, Jonathan Barratt > wrote: >> On 19 ?.?. 2010, at 21:49, Jonathan Barratt wrote: > >>> You are running in a threaded environment then, your sessions can't persist >>> without cookies or equivalent external storage because the HTTP exchange is >>> not all contained within the same server process... >> >> Whoops, I couldn't cancel that e-mail fast enough, but I'm clearly wrong - >> cause you mentioned that it's only a problem in IE, but that it's working in >> Chrome and Firefox. So maybe you're not using a threaded Apache. Sorry for >> jumping to conclusions! >> >> 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-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.
Different logins in same browser session and login_required
Hi guys, I need some help about logins and session and any help would be much appreciated :) This is the scenario: * Django 1.2.0 * Firefox (but I think any browser too) This the steps: 1) In the same computer (so in the same browser session) I have two browser windows "W1" and "W2" where the user "U1" is already logged in in both windows. 2) In the browser window "W1" the user logs out 3) In the browser window "W1" the user "U2" logins in and gets redirect to the main web page 4) In the browser window "W2" any call to the views (all using the "login_required" decorator) is done with request.user set to "U2" instead the old "U1" --> here the human user could still think to be "U1" in this window (indeed he can see "U1" printed in the web page previously rendered), but he's surfing like "U2" Since you can't keep to more logged users in the same session, I'd like to catch this situation and redirect the user to the log in page. Of course I don't want to rewrite all the ajax and not ajax calls to pass the "current" (means "old") user as parameter to match with request.user for a change. It's ugly and expensive. Any idea? 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: Session issues in Internet Explorer
Thanks Jonathan, Either way though, the solution is to set the cookie to allow the session to persist correct? Thanks, Ben On Oct 19, 9:51 am, Jonathan Barrattwrote: > On 19 ต.ค. 2010, at 21:49, Jonathan Barratt wrote: > > You are running in a threaded environment then, your sessions can't persist > > without cookies or equivalent external storage because the HTTP exchange is > > not all contained within the same server process... > > Whoops, I couldn't cancel that e-mail fast enough, but I'm clearly wrong - > cause you mentioned that it's only a problem in IE, but that it's working in > Chrome and Firefox. So maybe you're not using a threaded Apache. Sorry for > jumping to conclusions! > > 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-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: Session issues in Internet Explorer
On 19 ?.?. 2010, at 21:49, Jonathan Barratt wrote: > > On 19 ?.?. 2010, at 21:32, Quiet Light Development wrote: > >> Thank you Masklinn and Jonathan for your responses. I don't know a lot >> about the physical set-up of the system, I can ask the server >> administrators that question. >> >> The server is running Apache 2.2.12 on Ubuntu. > > You are running in a threaded environment then, your sessions can't persist > without cookies or equivalent external storage because the HTTP exchange is > not all contained within the same server process... Whoops, I couldn't cancel that e-mail fast enough, but I'm clearly wrong - cause you mentioned that it's only a problem in IE, but that it's working in Chrome and Firefox. So maybe you're not using a threaded Apache. Sorry for jumping to conclusions! 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-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: Session issues in Internet Explorer
On 19 ต.ค. 2010, at 21:32, Quiet Light Development wrote: > Thank you Masklinn and Jonathan for your responses. I don't know a lot > about the physical set-up of the system, I can ask the server > administrators that question. > > The server is running Apache 2.2.12 on Ubuntu. You are running in a threaded environment then, your sessions can't persist without cookies or equivalent external storage because the HTTP exchange is not all contained within the same server process... FYI, 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-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.
Expense of django query
I have a table for Actor that I query and populate the result in actor_list to pass to the template. I installed the Django Debug Toolbar to check the queries hitting the database and found some strange behavior. If I iterate through the actor_list, only one SQL query is created, as expected: {% for actor in actor_list %} {{ actor.id }} {% endfor %} But if I call a particular item in the list before the loop, that additional call generates its own query, meaning the database is hit twice. {{ actor_list.0.id }} {% for actor in actor_list %} {{ actor.id }} {% endfor %} Why is that? Is there a way to do this that doesn't result in two queries? -- 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: HTTP load testing tools?
On Oct 13, 10:27 am, Paul Winklerwrote: > On Oct 13, 4:17 am, Chris Withers wrote: > > > Hey all, > > > I hope this is still on topic, but what tool sets do people around here > > use for doingloadtestingof Django projects? > > Same stuff as for any web project. Last time I needed something more > than ab, I used funkload (it's on pypi). A bit of work to set it up, > but being able to record browser sessions as test cases is handy, and > the report documents it produces are pretty nice ... if a bit overly > verbose for my taste. Relatedly, I just came across Benchmaster, which wraps Funkload so you can run it in parallel on lots of clients. http://pypi.python.org/pypi/benchmaster - PW -- 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: Session issues in Internet Explorer
Thank you Masklinn and Jonathan for your responses. I don't know a lot about the physical set-up of the system, I can ask the server administrators that question. The server is running Apache 2.2.12 on Ubuntu. Thanks, Ben On Oct 19, 9:20?am, Jonathan Barrattwrote: > ?On 19 ?.?. 2010, at 21:13, Quiet Light Development wrote: > > > Hello, > > > I am having trouble getting sessions to work with my production > > server. When I move from one page to the next and try to call > > request.session["app"] it is giving me a key error even though I know > > I had set it in the previous page. This error is only occurring in IE. > > Firefox and Chrome work properly. ?A little about the server: > > > Django version 1.2.1 > > Session engine 'django.contrib.sessions.backend.db' > > > I'm not using cookies at all presently, but trying to track sessions > > through the database. > > What web server are you running? > > Best wishes, > 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-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 django admin knows about related objects on delete?
On Tue, Oct 19, 2010 at 4:03 PM, Shawn Milochikwrote: > Check out your model's _meta.get_all_related_objects(). > > Explore that through the interactive interpreter and you'll find > everything you need. > Shawn, _meta.get_all_related_objects() is great :) Thank you very much for sharing this !! br Marc -- Marc -- 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: Session issues in Internet Explorer
On 19 ต.ค. 2010, at 21:13, Quiet Light Development wrote: > Hello, > > I am having trouble getting sessions to work with my production > server. When I move from one page to the next and try to call > request.session["app"] it is giving me a key error even though I know > I had set it in the previous page. This error is only occurring in IE. > Firefox and Chrome work properly. A little about the server: > > Django version 1.2.1 > Session engine 'django.contrib.sessions.backend.db' > > I'm not using cookies at all presently, but trying to track sessions > through the database. What web server are you running? Best wishes, 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-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: Session issues in Internet Explorer
On 2010-10-19, at 16:13 , Quiet Light Development wrote: > I'm not using cookies at all presently, but trying to track sessions > through the database. This is only the server-side storage of the session, you still need a way to match a given client and its session, and that's generally done via a cookie. Either that or some kind of sessionid provided in each and every request, which is even less secure, and as far as I know has been rejected. Would you have some more informations about the physical setup of the system? Multiple load-balanced web frontends, things like that? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Session issues in Internet Explorer
Hello, I am having trouble getting sessions to work with my production server. When I move from one page to the next and try to call request.session["app"] it is giving me a key error even though I know I had set it in the previous page. This error is only occurring in IE. Firefox and Chrome work properly. A little about the server: Django version 1.2.1 Session engine 'django.contrib.sessions.backend.db' I'm not using cookies at all presently, but trying to track sessions through the database. Does anyone have experience with this issue? Thanks, Ben -- 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 django admin knows about related objects on delete?
Check out your model's _meta.get_all_related_objects(). Explore that through the interactive interpreter and you'll find everything you need. 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: Newbie question: How should I structure my very simple project / app?
On Tue, Oct 19, 2010 at 6:52 AM, wawa wawawawrote: > So, given this paucity of requirements and the horrendously unclear > explanation above, what suggestions might you lot have? (Apart from "RTFM", > of course!) first and foremost, yes, you have to read the manual, and do the tutorial. ideally, you should forget about your specific project while doing it. it's not too long, should take a few hours to do completely. the fact is, if you skip this step, you won't get useful answers here. then, you'll see that it's easy to read the rest of the documentation to find anything you need for your project. if at any point you need some pointers, just ask here, in most cases you'll get a quick answer about where to find the relevant docs, together with some extra tips. and lastly, you'll find that your Django code shouldn't wait until your backend process finishes, so you'll have to spin the task out of the request/response cycle. the ideal answer is a queue manager, like RabbitMQ + celery. but if you don't foresee hundreds of files processed daily, a ghetto queue should be enough. for that, simply save the uploaded file somewhere, and note in the database any other parameters, meanwhile your background process checks the DB for tasks ready to be processed, takes them, and updates the status in the DB record. the user would check his task in some status page, and when it reaches the 'done' state, presents the result. good luck, and welcome -- 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.
Re: multiple views function in a single URL specification
seems like you're over thinking... you want a single url to handle multiple pieces of information? you can assign a single view function to a url. but you can define multiple functions within that view and merely pass them through to the template as part of the response. Or take a look at template tags, as that appears to be more suitable On Oct 17, 1:16 pm, John Yeukhon Wongwrote: > I asked this somewhere else but it seems like the responder hasn't > reply the latest comment I > made.http://stackoverflow.com/questions/3951758/how-do-you-iterate-over-a-... > > Nevertheless, I think I should be welcome to make one here. > > Let's keep thing short. > > Say I have a very simple list to iterate > > [--code--] > def link(request): > c = Context() > c['title'] = ['Home Page', 'Current Time', '10 hours later'] > return render_to_response('time.html', c) > [--code--] > > Now say I also have another view called current_time > > In my html I had, for example > [--code--] > {% for item in title %} > {{item}} > {% if not forloop.last %} | {% endif %} > {% endfor %} > > {% if hour <= 1 %} > do something... > {% endif %} > > [--code--] > > For the template, I tried loop through "in c.title, in c, in title" > and still doesn't work > > As you can guess, I use two view functions in a single html file. > > The problem is that I received 'function' object is not iterable > > So the guy said I probably had a problem with the URL > my URL --> (r'^now/$', current_time, link), > > So he recommended me doing this > (r'^articles/(?P\(?P)/$', > 'project_name.views.link'), #the second tuple element is the view > function > > Something similar to Django URL Dispatcher (from the dispatcher > chapter).. I think... > I think he meant to capture then. But what I want to do is really > just, say, localhost/now/ and load the page > > I can definitely integrate two views functions into one single > function, which works fine. > > The question is, how can I assign multiple views function in a single > URL??? > > Thank you for any input 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-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.
Newbie question: How should I structure my very simple project / app?
Hi All, I'm new to Django (and to be honest, a little bit hazy on the subtleties of MVC, but if you don't try, you don't learn). I want to create a simple web frontend for a Python program I have already (mostly) written and I'd like to use Django (which may be overkill... not sure). - Users have a bunch of externally generated XML files. (Could be one, could be many (max of 20?). Possibly in an zip or tar.gz archive). - Users access the Django app and can upload via a simple form (with funky Ajax uploadiness - including as many ponies and rainbows as might be necessary) - A backend script will process this XML, performing all manner of fantastical space/time-bending magic (which will not take longer than 5 to 10 secs... Max tested with many, many input files is about 40seconds). - The output will be produced and the user will have the option to download as CSV or possibly PDF. Possibly with functionality to allow the report to be mailed to them when complete (so user identity needs to be built in). Very vague I know. But a very simple web app I think. Essentially, the backend script summarizes the input files into a summary per file and a total summary of the presence and count of certain keys / values or combinations of data. There's a set of logical rules that I have yet to invent which will be used when parsing the input XML (for example: if value "B" exists in "A" with attribute "Z" but not attribute "X" then count, otherwise do not). The reason I want to use Django is: - I know I will be asked to add all sorts of functionality to this. Django is extensible, powerful. - I don't want to be responsible for maintaing the "rules" and would love to be able to expose this via an admin interface so anyone (with authorization) can add or edit rules logic. - I've already got the bulk of the parsing script written in Python. I guess I need: - a handler for the input files. - a way to pass these file serially to my backend script (I presume I would use the filesystem for this? The input files can be anywhere from 2K to 1MB in very extreme cases.) - a mechanism to separate different user sessions. - a way to accumulate the results of each file parse and then report on the total (store the results in the DB?) - a mechanism to present and archive the reports (and then this leads to a way to look up old reports). So, given this paucity of requirements and the horrendously unclear explanation above, what suggestions might you lot have? (Apart from "RTFM", of course!) - Do / Don't use Django? - Structure of projects / Apps? - Any key external apps / modules that might be useful (e.g. for handling for uploads) - Any gotchas when invoking backend scripts? ... I'm really just looking for a nudge in the right direction. Thanks in advance for any tips, pointers or help you can give. Thanks Waza -- 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-ckeditor causes an unhandled exception
replying to myself... this was fixed 5 days ago on github. updating to latest django-ckeditor solved it. _y On Oct 19, 12:49 pm, jean polowrote: > hallo ! > > I installed django-ckeditor-0.0.7, run it smoothly locally but now I'm > trying to commit the changes on my server, I get an Unhandled > Exception: > [SNIP] > File "/usr/local/alwaysdata/python/django/1.2.1/django/core/ > urlresolvers.py", line 247, in _get_url_patterns > raise ImproperlyConfigured("The included urlconf %s doesn't have > any patterns in it" % self.urlconf_name) > > ImproperlyConfigured: The included urlconf xxx.urls doesn't have any > patterns in it > > I followed all infos from django-ckeditor README, i.e. installed it > (fine), added 'ckeditor' to my installed apps, added: > (r'^ckeditor/', include('ckeditor.urls')), > to my urls.py. > > The weird thing is that it runs fine via the runserver on ssh. > > Any help is greatly appreciated. > > _y -- 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-ckeditor causes an unhandled exception
hallo ! I installed django-ckeditor-0.0.7, run it smoothly locally but now I'm trying to commit the changes on my server, I get an Unhandled Exception: [SNIP] File "/usr/local/alwaysdata/python/django/1.2.1/django/core/ urlresolvers.py", line 247, in _get_url_patterns raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it" % self.urlconf_name) ImproperlyConfigured: The included urlconf xxx.urls doesn't have any patterns in it I followed all infos from django-ckeditor README, i.e. installed it (fine), added 'ckeditor' to my installed apps, added: (r'^ckeditor/', include('ckeditor.urls')), to my urls.py. The weird thing is that it runs fine via the runserver on ssh. Any help is greatly appreciated. _y -- 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: XMPP based apps
thats good work eric On Tue, Oct 19, 2010 at 2:32 AM, Eric Chamberlainwrote: > We've done django based xmpp services and created middleware to enable > django to manage and authenticate ejabberd users. > > On Oct 18, 2010, at 6:10 AM, Venkatraman S wrote: > > Well, I havent Googled, but was wondering whether how one can integrated > XMPP based communications(PUNJAB?) etc with Django? > Has anyone tried this? Any good reads or pointers? > > -V- > http://twitter.com/venkasub > > -- > 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. > -- 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 django admin knows about related objects on delete?
Hi! When we delete an object through admin bulk deletion, django deletes all related objects too. Now imagine that we have these models: class ModelBase(models.Model): pass class ModelA(models.Model): base = models.ForeignKey(ModelBase) class ModelB(models.Model): base = models.ForeignKey(ModelBase) When we deletes an instance of ModelBase django also deletes related instances of ModelA and ModelB. And my question is, given an instance of ModelBase how can we know what model have a relation with it? We need to query all models of all apps that we have installed? or there are another approach more 'elegant' in order to achieve this? thanks! -- Marc -- 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: Path issue on Linux
Thanks Ken. On Mon, Oct 18, 2010 at 2:44 PM, Kenneth Gonsalveswrote: > On Mon, 2010-10-18 at 14:34 +0200, Sithembewena Lloyd Dube wrote: > > Just manage.py , instead of always having to specify the > > program to > > run the command with (python). > > anyway you got the answer - chmod > -- > regards > Kenneth Gonsalves > > -- > 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. > > -- Regards, Sithembewena Lloyd Dube http://www.lloyddube.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.
Passing file to .net web service
Hello I am using Django 1.1 and Python 2.6 I want to pass file ot file byte array to a web serrvice which is written in .net, so I am using import urllib2 import urllib2_file data = [ ('fileName' , 'test.txt'), ('file', open'/tmp/test.text', 'r') ] data=urllib.urlencode(data) req=urllib2.Request(URL, data,headers) u = urllib2.urlopen(req) here URL is the .net web service url and it is throwing error as "The request was aborted: The request was canceled." If tried without sending file or binary data it works fine. Is there any other way I can upload the file or send file to .net web service? Please suggest. Thanks Pradnya -- 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.