Re: newforms + multiple sister forms submitted/processed in one user action
On Sat, 11 Aug 2007 14:36:50 +, Patrick Anderson wrote: > On Sat, 11 Aug 2007 14:34:05 +0000, Patrick Anderson wrote: > >> On Fri, 10 Aug 2007 18:46:18 -0700, Doug B wrote: >> >> > --- >>>> >>>> If I have 8 people, how should bind POST data to a form object in the >>>> view? >>> >>> You can use the 'prefix' option when instantiating the forms. Prefix >>> the form with the corresponding form 'number' or other unique >>> identifier. On post pass it the whole post dict. It will pull the >>> data out according to the prefix. >>> >>> >> That's what I thought, too. One problem I have right now is to >> dynamically assign form element id attribute based on count of the for >> loop in the view. > > Which I solved by manipulating Widget attrs in each form.base_field > Now I have the problem with validation and errors, since I'm submitting data in one request to multiple form objects, how can I get to the errors and display them properly next to each field? Perhaps it is better and simpler to deal with each form at a time, even if it means to have a separate submit button for each one. >> >> > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: newforms + multiple sister forms submitted/processed in one user action
On Sat, 11 Aug 2007 14:34:05 +, Patrick Anderson wrote: > On Fri, 10 Aug 2007 18:46:18 -0700, Doug B wrote: > >>> --- >>> >>> If I have 8 people, how should bind POST data to a form object in the >>> view? >> >> You can use the 'prefix' option when instantiating the forms. Prefix >> the form with the corresponding form 'number' or other unique >> identifier. On post pass it the whole post dict. It will pull the >> data out according to the prefix. >> >> > That's what I thought, too. One problem I have right now is to > dynamically assign form element id attribute based on count of the for > loop in the view. Which I solved by manipulating Widget attrs in each form.base_field > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: newforms + multiple sister forms submitted/processed in one user action
On Fri, 10 Aug 2007 18:46:18 -0700, Doug B wrote: >> --- >> >> If I have 8 people, how should bind POST data to a form object in the >> view? > > You can use the 'prefix' option when instantiating the forms. Prefix > the form with the corresponding form 'number' or other unique > identifier. On post pass it the whole post dict. It will pull the data > out according to the prefix. > That's what I thought, too. One problem I have right now is to dynamically assign form element id attribute based on count of the for loop in the view. > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: newforms + multiple sister forms submitted/processed in one user action
On Fri, 10 Aug 2007 13:32:32 -0700, Collin Grady wrote: > One method is to include a hidden input somewhere that indicates the > number of forms present. Then you can just use a for loop from 1 to that > number in the view to build the right number of forms again. > > > This is the raw html form loop (without {{ form }}): -- Name: F. Name: M. Name: L. Name: --- If I have 8 people, how should bind POST data to a form object in the view? Well, here's my view I just started writing: --- def index(request, template): from forms import PersonForm persons = [] if 'total_transfers' in request.session: if request.session['total_transfers']: [persons.append(x) for x in range(1, request.session ['total_transfers']+1)] personnel_form = [] if len(persons): if request.method == 'POST': data = request.POST.copy() for i in persons.values(): f = PersonForm(data) # how should I bind data to form? personnel_form.append(f) ... # to-be done return direct_to_template(request, template, extra_context = { 'persons': persons, 'forms': personnel_forms, }) - --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
newforms + multiple sister forms submitted/processed in one user action
This is a simplified PersonForm I've created with newforms library: class PersonForm(forms.Form): name = forms.CharField() first_name = forms.CharField() middle_name = forms.CharField(required = False) last_name = forms.CharField() The problem I have is that I need to update the Personnel on the same page. How should I go about writing a template and processing the POST request with newforms if the number of PersonForms can vary in each session and the user should submit all forms in one action? By the way, this form is not going to be tied to any existing model. I need to pass submitted data to another server, but that is not the issue here. I'm wondering how newforms library could help me with this task. Has anyone done this before and has any thoughts and tips? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: User model (unique email)
On Tue, 31 Jul 2007 22:40:50 +, Pensee wrote: > Hi, > > On Jul 31, 11:46 pm, Patrick Anderson <[EMAIL PROTECTED]> wrote: >> I'd prefer not to hack the contrib.auth application and change User >> model, > > Adding just unique=true is not so hard and tracking with changes is easy > :). > > You may have a look at the "Django tips: extending the User model" on > The B List [1] > >> so perhaps that constraint should be included in my application code, >> but I'm not sure what the best way to do it should be. > > I think that's a bit of too much overhead. I mean you already have a > bunch of code that can handle this automaticaly. > > -- Amirouche > > > True, that is probably the least complicated method, but it requires me to remember this little hack. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
User model (unique email)
I'd like to create a couple of views that would allow users to retrieve their forgotten username or password by email. It seems to me that the only reliable way to do this would be for my application to require unique email addresses for User objects. However email field in django.contrib.auth.models.User is optional. I'd prefer not to hack the contrib.auth application and change User model, so perhaps that constraint should be included in my application code, but I'm not sure what the best way to do it should be. Any clues? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
HttpResponse error with file downloads
Recently I've encountered the following error: -- Traceback (most recent call last): File "/usr/local/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "/usr/local/lib/python2.5/site-packages/mod_python/importer.py", line 1229, in _process_target result = _execute_target(config, req, object, arg) File "/usr/local/lib/python2.5/site-packages/mod_python/importer.py", line 1128, in _execute_target result = object(arg) File "/usr/local/lib/python2.5/site-packages/django/core/handlers/ modpython.py", line 178, in handler return ModPythonHandler()(req) File "/usr/local/lib/python2.5/site-packages/django/core/handlers/ modpython.py", line 161, in __call__ req.content_type = response['Content-Type'] TypeError: content_type must be a string -- This is my view code that returns the response, which produces this error: - response = HttpResponse(file_data) response['Content-Type'] = u'application/%s' % f response['Content-Disposition'] = u'attachment; filename="%s.%s"' % (t, f) return response - 'f' variable can be: 'zip', 'pdf', 'rtf', 'doc'. And when I print response ['Content-Type'], I see 'application/(f)' so I know that I pass it to Django as I'd expect. Has something changed recently in Django that could affect this code? This was working before. It could be mod_python or Apache error, not specific to Django, but I'm not sure. But perhaps, there's something I'm doing wrong. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: password reset for all cached users?
On Wed, 25 Jul 2007 18:39:03 -0500, James Bennett wrote: > On 7/25/07, Patrick Anderson <[EMAIL PROTECTED]> wrote: >> Anyway, why not reset password for a logged-in user only? Maybe I've >> look at the code too briefly, and there might be a reason for iterating >> through users_cache, but that approach sounds safer to me. > > Since the form accepts an email address as input, it could run into > problems if multiple users share a single email address -- if it just > looked up a single user with get(), for example, it'd end up throwing an > AssertionError. An alternate approach of instead asking for the username > might work, but is probably undesirable from a usability perspective > because people are far more likely to remember their email addresses > than their usernames ;) I see. Yes, that is possible. I guess this issue has many variables. In the worst case scenario, the other user(s) will get an email with a reset password and a link to change 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: password reset for all cached users?
On Wed, 25 Jul 2007 22:47:05 +, Patrick Anderson wrote: > Today when trying to add 'reset password' feature into my project, I > noticed that the PasswordResetForm() 'save' method resets passwords for > all cached users. > > I have been testing the site with various users logged in, and when I > tried to reset my password from within my public site, I received 10 > messages with passwords reset for all users that were in users_cache. > > This might cause problems for people who are using the site from a > shared computer, and I wonder what the reasons for this approach were. > > > This might cause problems if they share the same computer and the same email address, which is rare, but not unconceivable :) Anyway, why not reset password for a logged-in user only? Maybe I've look at the code too briefly, and there might be a reason for iterating through users_cache, but that approach sounds safer to me. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: A convenient way to include images in a blog entry
On Thu, 26 Jul 2007 00:11:59 +0200, Kai Kuehne wrote: > Unfortunately I cannot keep the relation between Entry and Image because > I get an weird error (see #4633) if the m2m field is None. > > So.. is there another way to just show a list of models on an edit page > of another model without having to do a relation between them? > > Thanks in advance. > Kai > > Make the m2m relation optional using (null = True, blank = True) in your model --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
password reset for all cached users?
Today when trying to add 'reset password' feature into my project, I noticed that the PasswordResetForm() 'save' method resets passwords for all cached users. I have been testing the site with various users logged in, and when I tried to reset my password from within my public site, I received 10 messages with passwords reset for all users that were in users_cache. This might cause problems for people who are using the site from a shared computer, and I wonder what the reasons for this approach were. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Edit inline problems
Hi! It's been a while since I posted to this list, but I have a little problem and would like to ask for some help. I have the following 2 models: class Personnel(models.Model): report = models.ForeignKey(Report, unique = True) class Admin: pass def __str__(self): return 'Personnel list from (%s)' % self.report class Person(models.Model): personnel = models.ForeignKey( Personnel, core = True, edit_inline = models.TABULAR, min_num_in_admin = 1, max_num_in_admin = 10, ) first_name = models.CharField('F. Name', maxlength = 25, core = True) middle_name = models.CharField('M. Name', maxlength = 25, blank = True) last_name = models.CharField('L. Name', maxlength = 50) date_born = models.DateField() time_added = models.DateTimeField() def __str__(self): return '%s %s' % (self.first_name, self.last_name) I validate the models and I can see the forms in the Admin, but every time I try to add a Person (while adding a new Personnel list or editing an existing one), none of the Persons get saved. What could be wrong with my model? I'd appreciate your look at it and pointing any errors I might have in my code. Thank you! Patrick --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Empty QuerySet while using dates() method. Is it a bug?
Below is my view function to retrieve month values from a QuerySet: def year_get_months(request, year, template_name): months = Letter.objects.filter( date_published__year = year ).dates('date_published', 'month') return render_to_response( template_name, context_instance = RequestContext( request, { 'months': list(months), }) ) I have just noticed a problem when the result is an empty list when there is only one record in database for a particular year. I have also observed that the first object in a returned list is also missing. Could this be a bug? I'm running the latest development version of Django (#5146) and Python 2.5 Has anyone else noticed it? If there's something wrong in the way I'm doing it here, please let me know. Before I fill out a bug report, I'd like to ask if anyone has been faced with this issue. Patrick Anderson --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How would Django handle a large number of records
Hi! I'm impressed with Django and all the fuss that it removed from my development. Our organisation is considering moving our document management from an old Access db to PostgreSQL and I thought of using django as an admin interface, plus public interface (sometime down the line.) We have about 80,000 records which we will need to migrate. I'm wondering how Django admin interface would deal with such amount of data (they are of the same type, so they might be managed by a single app). I know Django comes from the news publishing world, where databases are huge, but this is a key question for us, and would like to hear comments that will put my concerns to rest, so we can start coding (well, we already have the models and the admin interface:)). Any tips would be appreciated, too. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---