Re: Dealing with misc parts of a project
On Thu, Sep 22, 2011 at 7:04 PM, Simon Connah wrote: > This is one of the areas that I think Django could do with improving on. You > might not have enough functionality to justify turning it into a complete > application but you still want to keep it clean and tidy somewhere. > Depends on your definition of 'a complete application'. I have django apps that consist of a few templates, or a single piece of middleware, or a single model. Sometimes things fall like that, an app is not such a heavyweight thing. 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-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.
Workflow for a django based facebook canvas app
Well a very common workflow for writing views in django is to do something like this if request.method == 'POST': do some form related stuff else : do some other stuff But for a facebook canvas app all requests are POST , how can I change my workflow such that my app works for both facebook canvas and as a normal app with out any major change to my code. -- A-M-I-T S|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.
Log file with errors
Hello list. I have a question. To my could be really helpful write a "log file" with the errors, to revise at the next day if something happen. For the moment I have this, a middleware class: -- from django.conf import settings import traceback import sys import logging class TestMiddleware: def getUser(self, request): ... def process_exception(self, request, exception): try: tb = sys.exc_info()[2] ubication = traceback.extract_tb(tb).pop() message = u'Type: %s\nValor: %s\nFile, line, function: %s, %s, %s\nUser: %s' % (type(exception).__name__, exception.__unicode__(), ubication[0], ubication[1], ubicacion[2], self.getUser(request)) logging.basicConfig(filename = settings.LOG_FILE, filemode = 'a', format='Nivel: %(levelname)s\nDate-hour: %(asctime)s\n %(message)s\n', level=logging.ERROR) logging.error(message) except: pass return None -- But something is missing. I only catch exceptions thrown from views. I can't catch FATAL errors like problems in the connection with the database. Errors like that don't go to this code. Somebody have an idea to capture that exceptions, maybe in another function? Cheers , Thanks for read and sorry for my bad english. -- 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.
FieldError on ManyToMany after upgrading to Django 1.3
Just been updating to Django 1.3.1 and come across an odd error. I'm getting the following error from some code which works with version 1.2.7. FieldError: Cannot resolve keyword 'email_config_set' into field. Choices are: id, name, site, type The odd thing being email_config_set is a related name for a ManyToMany field. I'm not sure why django is trying to resolve it into a field. To make it even more odd, this error occurs when DEBUG = TRUE and not when DEBUG = FALSE when testing with runserver. I've been trying to solve this for days now with much googling/pdb/ logging, but since the exception originates deep inside django I'm not familiar enough to find what is going wrong: Traceback (most recent call last): File "./core/driver.py", line 268, in run self.init_norm() File "./driver/emailevent/background.py", line 130, in init_norm self.load_config() File "./driver/emailevent/background.py", line 71, in load_config events = list(config.events.select_related()) File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/ django/db/models/manager.py", line 168, in select_related return self.get_query_set().select_related(*args, **kwargs) File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/ django/db/models/fields/related.py", line 497, in get_query_set return superclass.get_query_set(self).using(db)._next_is_sticky().filter(**(self.core_filters)) File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/ django/db/models/query.py", line 550, in filter return self._filter_or_exclude(False, *args, **kwargs) File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/ django/db/models/query.py", line 568, in _filter_or_exclude clone.query.add_q(Q(*args, **kwargs)) File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/ django/db/models/sql/query.py", line 1194, in add_q can_reuse=used_aliases, force_having=force_having) File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/ django/db/models/sql/query.py", line 1069, in add_filter negate=negate, process_extras=process_extras) File "/usr/local/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/ django/db/models/sql/query.py", line 1260, in setup_joins "Choices are: %s" % (name, ", ".join(names))) FieldError: Cannot resolve keyword 'email_config_set' into field. Choices are: id, name, site, type Any ideas/solutions/pointers/tips would be most welcome. -- 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: Can you trigger a forms style error from a view?
On Thursday, 22 September 2011 21:53:45 UTC+1, John Shaver wrote: > > The only way I could find to do is with 'raise ValidationError'()' in > the clean() function. However, trying to query my User model to see > if that username is already take does not work from the clean() > function. > Why not? That is exactly where you should do it. In fact, look at the code for Django's own signup form - django.contrib.auth.forms, the clean_username method, which does exactly that. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/QVlBbfsphPUJ. 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: Can you trigger a forms style error from a view?
Check out http://groups.google.com/group/django-users/browse_thread/thread/40118d7879bbb228# ... I just asked a very similar question recently. On Sep 22, 4:53 pm, John Shaver wrote: > I'm designing a user registration form for my app. I need to verify > that the username they're using is not already in use before trying to > create the user. If the username already exists, I want to be able to > generate a form style error that says "Sorry that username is already > in use." > > The only way I could find to do is with 'raise ValidationError'()' in > the clean() function. However, trying to query my User model to see > if that username is already take does not work from the clean() > function. On the other hand, I cannot find a way to set the error in > the form object from inside the view. > > I prefer to do this from inside of the view, rather than from the > clean function. I already have several validation rules there that I > created, but I'd prefer to keep the Form class separate from my > models. Any suggestions? > > -John -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.
Handling file uploads in a clustered application server environment
Hey guys, We have an Nginx front-end with a cluster of Django application servers. What are some methods of handling user uploads in this type of an environment? 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.
Re: Handling file uploads in a clustered application server environment
On Fri, Sep 23, 2011 at 4:24 PM, Kurtis wrote: > Hey guys, > > We have an Nginx front-end with a cluster of Django application > servers. What are some methods of handling user uploads in this type > of an environment? > > Thanks! > Very open ended question... Abstract the data: store uploaded media on S3, serve from S3 Replicate the data: store uploaded media on the backend that it is uploaded to, replicate via rsync to the other backends. Centralize the data: push uploaded media to a centralized store (eg CIFS/NFS) that is available to all backends Distribute the data: use a distributed file system (eg Lustre/HDFS) to make the data available to all backends along with many other techniques. 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-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: Handling file uploads in a clustered application server environment
Thanks a lot for the quick response, Tom. I like your idea of using S3 -- or in our case, Rackspace's Cloudfiles. Django-storages was recommended to me in IRC. I think I'm going to try to follow that route as long as I don't have to modify a third party app we're trying to use too heavily. On Fri, Sep 23, 2011 at 11:40 AM, Tom Evans wrote: > On Fri, Sep 23, 2011 at 4:24 PM, Kurtis wrote: > > Hey guys, > > > > We have an Nginx front-end with a cluster of Django application > > servers. What are some methods of handling user uploads in this type > > of an environment? > > > > Thanks! > > > > Very open ended question... > > Abstract the data: store uploaded media on S3, serve from S3 > Replicate the data: store uploaded media on the backend that it is > uploaded to, replicate via rsync to the other backends. > Centralize the data: push uploaded media to a centralized store (eg > CIFS/NFS) that is available to all backends > Distribute the data: use a distributed file system (eg Lustre/HDFS) to > make the data available to all backends > > along with many other techniques. > > 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-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. > > -- 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.
Creating a custom Model Field accessing multiple DB fields
Having read through [1] and experimented with it a bit, I've been unable to determine whether my failure is due to a Django limitation or if it's my own fault. My question comes in two parts: 1) Can a custom model-field interface with more than one DB field? The .db_type() method's return-signature seems to suggest a one-to-one restriction between model fields and database fields. 2) Can one create custom lookups for db_prep_lookup beyond the 21 listed lookup-names under its documentation? Further details: I'm trying to create a custom model-field that jockeys 4 DB fields into and out of a single Python class. The intended interface is something like class MyModel(Model): dob = AmbiguousDate() which would yield a table with fields dob_year_min dob_year_max dob_month dob_day and jockey those into and out of the MyModel.dob class. The intention is that any of those pieces may be null (you might know the day/month of the birthday but not the year; you might have a general age-range to know that a person is between 35-40; you might know a person was born in Feb of 1965, but not the day; etc). For the 2nd item, I'd like to .filter(dob__age_range=(45,50)) in addition to .filter(dob__range=(date1, date2)) using my Model Field code to generate a corresponding SQL query string. Thanks for any pointers/tips, -Tim [1] https://docs.djangoproject.com/en/dev/howto/custom-model-fields/ -- 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.
nob question
Hi, I have a nob question. I want to show data like this: Vegetables: Cucumbers Peas Fruits Tomatoes Bananas My models looks like this: Class Plant_Category (): name - text Class Plant_Name() name - text plant_category – fk how do I go about this? paul -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.
Dynamic formset with FilteredSelectMultiple
Hi ! I have the following models, with a ManyToMany field: class Symptome(TypeMedical): synonyms = models.CharField(u'Synonymes',max_length=160,blank=True) parent = models.ManyToManyField(TypeMedical,related_name='Parent',blank=True) description = models.TextField(u'Description',blank=True) class Ligne(models.Model): weight = models.FloatField(u'Poids') symptoms = models.ManyToManyField(Symptome,verbose_name=u'Symptomes') diagnosis = models.ForeignKey(Symptome,related_name=u'Cause par') required = models.BooleanField(u'Obligatoire') I am writing a form in order to edit 'Symptome' objects. We can have multiple "Ligne" objects refering to a "Symptome" so I am using a formset. I want the user to be able to add or delete rows in the form so I am using the django-dynamic-formset app (http://code.google.com/p/ django-dynamic-formset/). My problem is that I want to use the FilteredSelectMultiple widget provided by the django admin. it works for the first form of the formset, but when I try to add other forms, a basic select widget is displayed. I added the line: SelectFilter.init("id_ligne-"+formCount+"-symptoms", "Sympt\u00F4mes", 0, "/media/") in the javascript "dynamic-formset" file. Now the right widget is displayed for all the new lines I add. However, when I click on "select all" or "delete all" buttons in the second, third (etc) widgets, all the actions are performed only on the first one. Moreover, I can select individually any item in the select widgets except in the first one. Do you have any idea of how I could handle this? I can't find anything! Thank you! Thomas. -- 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.
Creating a WSGI Request for another uWSGI Django App
Hello, You guys are always so helpful so I thought I'd come here with my crazy problem I'm trying to solve. I have a Django Application Cluster. We use subversion for our code. The only type of a post-commit hook we have is an HTTP Request with JSON at a URL we define. Essentially what I want to do is to use this post-commit hook to trigger a cluster-wise reload of the uwsgi service. The problem is that I don't really want to implement a fancy script that uses SSH or anything along those lines. First off, there are security issues. Secondly, I want it to be relatively quick and integrated into our app for easy replication as we add and remove nodes. I started off with some code -- just trying to play around the idea. I want to have two views. The first view is titled "svn_hook". This view is tied to the URL that is called from the post-commit hook by our SVN Hosting Provider. The second view is titled "uwsgi_reload". svn_hook()'s job is to simply open a connection with each of the nodes and call their uwsgi_reload() views. uwsgi_reload()'s job is to simply execute /etc/init.d/uwsgi... reload. Unfortunately, I have *no* idea how to get this thing to work. I tried approaching it with some RPC code in MoinMoin that I was forwarded to by a nice guy in #wsgi. But, as it turns out, I have no idea what I'm doing :) I think if I can get the servers to talk to each other, then I can handle the rest. If you guys have any ideas on either how to fix this code, or a better way of approaching this problem, I would really appreciate the input. By the way, I understand that WSGI is a completely different protocol from HTTP. I tried to understand the code the best I could and had no idea what was going on exactly with the key/value pairs I saw in the MoinMoin code. Hopefully someone can understand what I was trying to accomplish there Thanks again! -Kurtis from django.http import HttpResponse # View for URL Called by SVN on Post-Commit Hook def svn_hook(request): # Resources # import urllib # Used in example code, not here yet... from httplib import HTTPConnection # List of IP Addresses to Reload # hosts = ('192.168.1.1', '192.168.1.2') port = '7999' # Hit the Server """ Note: I was going to do more here ... but I can't even get the thing to work without stalling or throwing errors. I wanted to check for a 200 Status from each host and eventually log if any fail. """ for host in hosts: client = HTTPConnection(host, port, False, 30) client.request("GET", '/reload') response = client.getresponse() body = response.read() body = body.decode('utf-8') # Done return HttpResponse(status = 200) # Temporarily set as /reload for testing purposes. def uwsgi_reload(request): # Execute /etc/init.d/uwsgi reload # and any other logic that may need to be performed # I'll do this later, after I get the actual WSGI call # working. return HttpResponse(status = 200) -- 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: Creating a WSGI Request for another uWSGI Django App
> Hello, > > You guys are always so helpful so I thought I'd come here with my > crazy problem I'm trying to solve. > > I have a Django Application Cluster. We use subversion for our code. > The only type of a post-commit hook we have is an HTTP Request with > JSON at a URL we define. Essentially what I want to do is to use this > post-commit hook to trigger a cluster-wise reload of the uwsgi > service. > > The problem is that I don't really want to implement a fancy script > that uses SSH or anything along those lines. First off, there are > security issues. Secondly, I want it to be relatively quick and > integrated into our app for easy replication as we add and remove > nodes. > > I started off with some code -- just trying to play around the idea. I > want to have two views. The first view is titled "svn_hook". This view > is tied to the URL that is called from the post-commit hook by our SVN > Hosting Provider. The second view is titled "uwsgi_reload". > > svn_hook()'s job is to simply open a connection with each of the nodes > and call their uwsgi_reload() views. uwsgi_reload()'s job is to simply > execute /etc/init.d/uwsgi... reload. > > Unfortunately, I have *no* idea how to get this thing to work. I tried > approaching it with some RPC code in MoinMoin that I was forwarded to > by a nice guy in #wsgi. But, as it turns out, I have no idea what I'm > doing :) > > I think if I can get the servers to talk to each other, then I can > handle the rest. If you guys have any ideas on either how to fix this > code, or a better way of approaching this problem, I would really > appreciate the input. > > By the way, I understand that WSGI is a completely different protocol > from HTTP. I tried to understand the code the best I could and had no > idea what was going on exactly with the key/value pairs I saw in the > MoinMoin code. Hopefully someone can understand what I was trying to > accomplish there > > Thanks again! > -Kurtis > > from django.http import HttpResponse > > # View for URL Called by SVN on Post-Commit Hook > def svn_hook(request): > > # Resources > # import urllib # Used in example code, not here yet... > from httplib import HTTPConnection > > # List of IP Addresses to Reload > # > hosts = ('192.168.1.1', '192.168.1.2') > port = '7999' > > # Hit the Server > """ > > Note: > I was going to do more here ... but I can't > even get the thing to work without stalling or throwing > errors. I wanted to check for a 200 Status from each > host and eventually log if any fail. > > """ > for host in hosts: > client = HTTPConnection(host, port, False, 30) > client.request("GET", '/reload') > response = client.getresponse() > body = response.read() > body = body.decode('utf-8') > > # Done > return HttpResponse(status = 200) > > # Temporarily set as /reload for testing purposes. > def uwsgi_reload(request): > > # Execute /etc/init.d/uwsgi reload > # and any other logic that may need to be performed > # I'll do this later, after I get the actual WSGI call > # working. > > return HttpResponse(status = 200) > > -- > 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. > > Are your servers on a multicast-enabled network ? If they are you can use this http://projects.unbit.it/uwsgi/wiki/Clustering Your svn hook will be only a one-line: os.system("uwsgi --cluster-reload ") -- Roberto De Ioris http://unbit.it -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Dynamic formset with FilteredSelectMultiple
Sorry I mean: "Moreover, I CANNOT select individually items in the select widgets except in the first one. " On Sep 23, 6:05 pm, Thomas49 wrote: > Hi ! > > I have the following models, with a ManyToMany field: > > class Symptome(TypeMedical): > synonyms = > models.CharField(u'Synonymes',max_length=160,blank=True) > parent = > models.ManyToManyField(TypeMedical,related_name='Parent',blank=True) > description = models.TextField(u'Description',blank=True) > > class Ligne(models.Model): > weight = models.FloatField(u'Poids') > symptoms = > models.ManyToManyField(Symptome,verbose_name=u'Symptomes') > diagnosis = models.ForeignKey(Symptome,related_name=u'Cause > par') > required = models.BooleanField(u'Obligatoire') > > I am writing a form in order to edit 'Symptome' objects. We can have > multiple "Ligne" objects refering to a "Symptome" so I am using a > formset. I want the user to be able to add or delete rows in the form > so I am using the django-dynamic-formset app (http://code.google.com/p/ > django-dynamic-formset/). > > My problem is that I want to use the FilteredSelectMultiple widget > provided by the django admin. it works for the first form of the > formset, but when I try to add other forms, a basic select widget is > displayed. I added the line: > SelectFilter.init("id_ligne-"+formCount+"-symptoms", "Sympt\u00F4mes", > 0, "/media/") > in the javascript "dynamic-formset" file. Now the right widget is > displayed for all the new lines I add. > > However, when I click on "select all" or "delete all" buttons in the > second, third (etc) widgets, all the actions are performed only on the > first one. Moreover, I can select individually any item in the select > widgets except in the first one. > > Do you have any idea of how I could handle this? I can't find > anything! > > Thank you! > > Thomas. -- 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: nob question
i got it thanks On Sep 23, 3:59 pm, hawkpaul wrote: > Hi, > > I have a nob question. I want to show data like this: > > Vegetables: > Cucumbers > Peas > Fruits > Tomatoes > Bananas > > My models looks like this: > > Class Plant_Category (): > name - text > Class Plant_Name() > name - text > plant_category – fk > > how do I go about this? > > paul -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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.