Re: Processing multiple forms on one page
Oleg, You can set a parameter in your post request that allows you to differentiate between the two POST requests. But a more clean approach would be to just have the different forms POST to different urls(views) and the redirect back to the profile page if there is an error or do whatever. Ian On Wed, Jun 24, 2009 at 2:45 PM, Oleg Oltar wrote: > > Hi! > > I am writing a small application for user profile management. > > I need to display and to process output from 2 form on the page of own > profile. How can I do it? > > 1. Form if to change avatar. (Contains browse and upload buttons) > 2. Form is for changing user details, e.g. info field, or maybe emails > > I want these form to be processed independently. E.g. user can submit > one without filling another. > > I have read a post about similar problem here: > > http://groups.google.com/group/django-users/browse_thread/thread/1ff0909af4e0cdfe > but didn't find a solution for me. > > e.g. if we have following code: >if request.method == 'POST': >form1 = RegistrationForm(request.POST) >form2 = ...(request.POST) > > How to process them? Mean one of them will be empty, and it means I > don't need to return an error in that case. > Actually, I need to understand which of them is in post. But how? > > > Thanks, > Oleg > > > > -- === 株式会社ビープラウド イアン・ルイス 〒150-0012 東京都渋谷区広尾1-11-2アイオス広尾ビル604 email: ianmle...@beproud.jp TEL:03-5795-2707 FAX:03-5795-2708 http://www.beproud.jp/ === --~--~-~--~~~---~--~~ 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: Odd ModelForm problem
I'm not sure why it might work on one server but not on another unless the version of Django was different but as far as I know form.slug is not really guaranteed to exist. Normally it gets added to form.fields or somesuch by the forms metaclass. The actual data from the post request should also not be retrieved this way either. You should probably be doing the slugify() inside the is_valid() if block and accessing whether the slug was passed in the POST data or not by checking "slug" in form.cleaned_data. On Wed, Jun 24, 2009 at 8:40 AM, saxon75 wrote: > form = AddArticleForm(request.POST) >if not form.slug: > form.slug = slugify(form.title) >if form.is_valid(): > -- === 株式会社ビープラウド イアン・ルイス 〒150-0012 東京都渋谷区広尾1-11-2アイオス広尾ビル604 email: ianmle...@beproud.jp TEL:03-5795-2707 FAX:03-5795-2708 http://www.beproud.jp/ === --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to run just ONE test?
On Mon, Jun 22, 2009 at 8:50 PM, patrickk wrote: > > unfortunately, I´m still stuck with it ... > > here´s my tests.py: > > import unittest, os > > class BaseTest(unittest.TestCase): > def setUp(self): > pass > > def tearDown(self): > pass > > def test_fileobject(self): > pass > > even with this stripped-down version, _all_ tests are performed. > btw, models.py is empty (I don´t need that file for my app). I'm afraid I'm completely in the dark here. I've tried to reproduce your problem with your provided test case, but everything works exactly as intended. Here's the setup for a bare-bones test case: 1. Start a new project - django-admin.py startproject mytest 2. Start a new app - ./manage.py startapp myapp 3. Start a second app - ./manage.py startapp otherapp 4. Edit settings.py - add myapp and otherapp to INSTALLED_APPS - set DATABASE_ENGINE to 'sqlite3' 5. Edit myapp/tests.py, add a unit test as described by you. 6. Edit otherapp/tests.py, add a different blank unit test (I used your sample myapp/tests.py, but renamed the test class and test case) Then: a. ./manage.py test -> runs 35 tests. There are 10 failures out of the box, but they are expected due to template problems in the auth app. b. ./manage.py test myapp -> runs 1 test. c. ./manage.py test myapp.BaseTest -> runs 1 test. d. ./manage.py test myapp.BaseTest.test_fileobject -> runs 1 test. This is all exactly as expected (although b,c, and d aren't easy to tell apart; if you change myapp/tests.py to contain: {{{ import unittest, os class BaseTest(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def test_fileobject(self): pass def test_fileobject2(self): pass class BaseTest2(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def test_fileobject3(self): pass def test_fileobject4(self): pass }}} it's easier to tell the difference between the cases: a. ./manage.py test -> runs 38 tests. Again, 10 failures in the auth app. b. ./manage.py test myapp -> runs 4 tests. c. ./manage.py test myapp.BaseTest -> runs 2 tests. d. ./manage.py test myapp.BaseTest.test_fileobject -> runs 1 test. This is all exactly as expected. As for what is happening at your end, all I can suggest at this point is to turn up verbosity (-v 2) and see exactly what is happening. Also, I would suggest trying to reproduce the minimal test case I have just provided; once you have that working, slowly introduce code from your project to the minimal test case until you find out what is causing the problem. Once you have narrowed down the change that causes the problem, we can try and diagnose further. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ 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: Odd ModelForm problem
On Jun 24, 12:40 am, saxon75 wrote: > I'm having a strange problem with my site wherein a ModelForm doesn't > appear to recognize that it has an attribute that it ought to. I > should preface this by saying that I recently moved my codebase to a > new server--everything had been working fine on the old server and I > haven't made any changes to the code since then, so that seems like > the only thing that could have changed, but I have no idea what the > problem is. > > In any case, here are the relevant bits of code: > def add_article(request, sect): > if request.user.is_authenticated(): > if request.user.is_superuser or request.user.groups.filter > (name=sect).count(): > if request.method == 'POST': > form = AddArticleForm(request.POST) > if not form.slug: > form.slug = slugify(form.title) > if form.is_valid(): > article = form.save(commit=False) > article.author = request.user > article.created = datetime.now() > article.section = Section.objects.get(keyword=sect) > article.save() > return render_to_response('thanks.html', > context_instance=RequestContext(request)) > The error comes up in views.py from the add_article() method, the line > "if not form.slug:" The error itself is: 'AddArticleForm' object has > no attribute 'slug' > > This is pretty odd to me, since it seems clear to me from the > declaration that AddArticleForm does have that attribute. Further, > this used to work. > > I am in the HEAD revision of django as of a few minutes ago, and my > Python version is 2.5.4. Actually, now that I think of it, I may have > been using Python 2.4 on the old server. Could that be the problem? You can't access the values of form fields via attribute lookup. Instead, after checking form.is_valid(), you should get the value of slug via form.cleaned_data['slug']. I can't explain why what you were doing used to work, but it shouldn't. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Processing multiple forms on one page
On Jun 24, 6:45 am, Oleg Oltar wrote: > Hi! > > I am writing a small application for user profile management. > > I need to display and to process output from 2 form on the page of own > profile. How can I do it? > > 1. Form if to change avatar. (Contains browse and upload buttons) > 2. Form is for changing user details, e.g. info field, or maybe emails > > I want these form to be processed independently. E.g. user can submit > one without filling another. > > I have read a post about similar problem > here:http://groups.google.com/group/django-users/browse_thread/thread/1ff0... > but didn't find a solution for me. > > e.g. if we have following code: > if request.method == 'POST': > form1 = RegistrationForm(request.POST) > form2 = ...(request.POST) > > How to process them? Mean one of them will be empty, and it means I > don't need to return an error in that case. > Actually, I need to understand which of them is in post. But how? > > Thanks, > Oleg You need to use the 'prefix' parameter when instantiating the form. http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Processing multiple forms on one page
Thanks! I will try the first idea, will create separate views. But in this case, I will have to add user authentification code to all 3 views Now it looks like this: def user_profile(request, profile_name): currentUser = request.user owner = get_object_or_404(User, username = profile_name) try: ownersProfile = owner.get_profile() except Exception, e: ownersProfile = UserProfile(user=owner) ownersProfile.save() # This is my profile if owner.username == currentUser.username: if request.method == 'POST': print request print HHHT uploadForm = ProfileAvatarEdit(request.POST, request.FILES) handleUploadedFile(request.FILES['avatar']) return HttpResponseRedirect('.') else: form = ProfileAvatarEdit() data = RequestContext(request, { 'owner' : owner, 'ownersProfile' : ownersProfile, 'form' : form, } ) return render_to_response('registration/profile.html', data) Should I use this if owner.username == currentUser.username: in all 3 views which I will have? On Wed, Jun 24, 2009 at 11:42 AM, Daniel Roseman wrote: > > On Jun 24, 6:45 am, Oleg Oltar wrote: >> Hi! >> >> I am writing a small application for user profile management. >> >> I need to display and to process output from 2 form on the page of own >> profile. How can I do it? >> >> 1. Form if to change avatar. (Contains browse and upload buttons) >> 2. Form is for changing user details, e.g. info field, or maybe emails >> >> I want these form to be processed independently. E.g. user can submit >> one without filling another. >> >> I have read a post about similar problem >> here:http://groups.google.com/group/django-users/browse_thread/thread/1ff0... >> but didn't find a solution for me. >> >> e.g. if we have following code: >> if request.method == 'POST': >> form1 = RegistrationForm(request.POST) >> form2 = ...(request.POST) >> >> How to process them? Mean one of them will be empty, and it means I >> don't need to return an error in that case. >> Actually, I need to understand which of them is in post. But how? >> >> Thanks, >> Oleg > > You need to use the 'prefix' parameter when instantiating the form. > http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms > -- > DR. > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to run just ONE test?
just to avoid any misunderstanding: when I´m running one test with "... test myapp.BaseTest.test_fileobject" for example, the output is "... runs 1 test" - but before that statement there´s a lot of "create table ...", "installing index ..." stuff. and that´s what I´m confused about. just wanted to make sure that my assumption is right: when I´m running this one (very simplified) test, the "create table ..." and "installing index ..." should NOT be there, right? I´ve just read my first question again and I noticed that I didn´t explain the problem very well. thanks a lot for your effort and patience, patrick On Jun 24, 9:45 am, Russell Keith-Magee wrote: > On Mon, Jun 22, 2009 at 8:50 PM, patrickk wrote: > > > unfortunately, I´m still stuck with it ... > > > here´s my tests.py: > > > import unittest, os > > > class BaseTest(unittest.TestCase): > > def setUp(self): > > pass > > > def tearDown(self): > > pass > > > def test_fileobject(self): > > pass > > > even with this stripped-down version, _all_ tests are performed. > > btw, models.py is empty (I don´t need that file for my app). > > I'm afraid I'm completely in the dark here. I've tried to reproduce > your problem with your provided test case, but everything works > exactly as intended. Here's the setup for a bare-bones test case: > > 1. Start a new project > - django-admin.py startproject mytest > 2. Start a new app > - ./manage.py startapp myapp > 3. Start a second app > - ./manage.py startapp otherapp > 4. Edit settings.py > - add myapp and otherapp to INSTALLED_APPS > - set DATABASE_ENGINE to 'sqlite3' > 5. Edit myapp/tests.py, add a unit test as described by you. > 6. Edit otherapp/tests.py, add a different blank unit test (I used > your sample myapp/tests.py, but renamed the test class and test case) > > Then: > a. ./manage.py test -> runs 35 tests. There are 10 failures out of the > box, but they are expected due to template problems in the auth app. > b. ./manage.py test myapp -> runs 1 test. > c. ./manage.py test myapp.BaseTest -> runs 1 test. > d. ./manage.py test myapp.BaseTest.test_fileobject -> runs 1 test. > > This is all exactly as expected (although b,c, and d aren't easy to > tell apart; if you change myapp/tests.py to contain: > > {{{ > import unittest, os > > class BaseTest(unittest.TestCase): > def setUp(self): > pass > > def tearDown(self): > pass > > def test_fileobject(self): > pass > > def test_fileobject2(self): > pass > > class BaseTest2(unittest.TestCase): > def setUp(self): > pass > > def tearDown(self): > pass > > def test_fileobject3(self): > pass > > def test_fileobject4(self): > pass > > }}} > > it's easier to tell the difference between the cases: > a. ./manage.py test -> runs 38 tests. Again, 10 failures in the auth app. > b. ./manage.py test myapp -> runs 4 tests. > c. ./manage.py test myapp.BaseTest -> runs 2 tests. > d. ./manage.py test myapp.BaseTest.test_fileobject -> runs 1 test. > > This is all exactly as expected. As for what is happening at your end, > all I can suggest at this point is to turn up verbosity (-v 2) and see > exactly what is happening. Also, I would suggest trying to reproduce > the minimal test case I have just provided; once you have that > working, slowly introduce code from your project to the minimal test > case until you find out what is causing the problem. Once you have > narrowed down the change that causes the problem, we can try and > diagnose further. > > Yours, > Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to run just ONE test?
On Wednesday 24 June 2009 14:47:05 patrickk wrote: > just to avoid any misunderstanding: > when I´m running one test with "... test > myapp.BaseTest.test_fileobject" for example, the output is "... runs 1 > test" - but before that statement there´s a lot of "create table ...", > "installing index ..." stuff. and that´s what I´m confused about. > > just wanted to make sure that my assumption is right: when I´m running > this one (very simplified) test, the "create table ..." and > "installing index ..." should NOT be there, right? I´ve just read my > first question again and I noticed that I didn´t explain the problem > very well. regardless of how many tests you run, you have to create the test database - so the 'create table', 'installing indes ...' SHOULD be there, otherwise there is nothing to test against. -- regards kg http://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to run just ONE test?
but the app I´m testing doesn´t require the database - the file models.py is empty. the create table and installing index statements look like this: Creating test database... Creating table auth_permission Creating table auth_group Creating table auth_user Creating table auth_message ... these statements are not related to the app I´m actually testing. thanks, patrick On Jun 24, 11:28 am, Kenneth Gonsalves wrote: > On Wednesday 24 June 2009 14:47:05 patrickk wrote: > > > just to avoid any misunderstanding: > > when I´m running one test with "... test > > myapp.BaseTest.test_fileobject" for example, the output is "... runs 1 > > test" - but before that statement there´s a lot of "create table ...", > > "installing index ..." stuff. and that´s what I´m confused about. > > > just wanted to make sure that my assumption is right: when I´m running > > this one (very simplified) test, the "create table ..." and > > "installing index ..." should NOT be there, right? I´ve just read my > > first question again and I noticed that I didn´t explain the problem > > very well. > > regardless of how many tests you run, you have to create the test database - > so the 'create table', 'installing indes ...' SHOULD be there, otherwise there > is nothing to test against. > -- > regards > kghttp://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Uploading Images
The second message posted by shows that the POST request handler didnt find key 'files' in its Multivalue Dictionary.Its I think the keyword 'file' has been deprecated from later versions of Django.So for uploading the file, just make an instance of the form class like, form = ImageForm(request.POST, request.FILES) Then after checking if its valid save it. Be sure to configure your 'MEDIA_ROOT' directory in 'settings.py' to the path were you want to upload the files. Also enable multipart/form data in your form tag of your templateas mentioned by Roboto. Good Luck! Avinash On Jun 24, 2:53 am, Roboto wrote: > {% if form.is_multipart %} > > {% else %} > > {% endif %} > {{ form }} > > > http://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-... > > On Jun 15, 12:59 am, Oleg Oltar wrote: > > > I made a mistake in view.py. > > Corrected version is > > def handleUploadedFile(file): > > destination = open('usermedia/new.jpg', 'wb+') > > for chunk in file.chunks(): > > destination.write(chunk) > > destination.close() > > return destination > > > def user_profile(request, profile_name): > > owner = get_object_or_404(User, username = profile_name) > > ownersProfile =get_object_or_404(UserProfile, user = owner) > > form = ProfileEdit(request.POST) > > if request.method == 'POST': > > > if form.is_valid(): > > ownersProfile.about = form.cleaned_data['about'] > > ownersProfile.avatar = handleUploadedFile(request.FILES['file']) > > ownersProfile.save() > > return HttpResponseRedirect("/") > > else: > > form = ProfileEdit() > > > Also changed a little bit template: > > > > {{ form.as_p }} > > > > > > > But I am getting: > > MultiValueDictKeyError at /account/profile/test > > > "Key 'file' not found in " > > > :( > > > On Mon, Jun 15, 2009 at 6:54 AM, Oleg Oltar wrote: > > > Hi! > > > > I know that the problem probably was discussed many times already, but > > > I really can't make it working. > > > > I read the documentation and prepared the following code: > > > > model: > > > > class UserProfile(models.Model): > > > """ > > > User profile model, cintains a Foreign Key, which links it to the > > > user profile. > > > """ > > > about = models.TextField(blank=True) > > > user = models.ForeignKey(User, unique=True) > > > ranking = models.IntegerField(default = 1) > > > avatar = models.ImageField(upload_to="usermedia", default = > > > 'images/js.jpg') > > > > def __unicode__(self): > > > return u"%s profile" %self.user > > > > form: > > > > class ProfileEdit(forms.Form): > > > about = forms.CharField(label = 'About', max_length = 1000, > > > required=False) > > > avtar = forms.ImageField() > > > > view: > > > def handleUploadedFile(file): > > > destination = open('usermedia/new.jpg', 'wb+') > > > for chunk in file.chunks(): > > > destination.write(chunk) > > > destination.close() > > > return True > > > > def user_profile(request, profile_name): > > > owner = get_object_or_404(User, username = profile_name) > > > ownersProfile =get_object_or_404(UserProfile, user = owner) > > > form = ProfileEdit(request.POST) > > > if request.method == 'POST': > > > form = ProfileEdit(request.POST, request.FILES) > > > if form.is_valid(): > > > handleUploadedFile(request.FILES['file']) > > > else: > > > form = ProfileEdit() > > > > data = RequestContext(request, > > > { > > > 'owner' : owner, > > > 'ownersProfile' : ownersProfile, > > > 'form' : form > > > } > > > ) > > > return render_to_response('registration/profile.html', data) > > > > And part of template: > > > > > > > {{ form.as_p }} > > > > > > > > > > After trying this code in browser I am getting a text field with > > > browse button, so when I chose file to upload, and finally click > > > upload I am getting 404 Error. > > > Not sure what I might doing wrong. > > > Please 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-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to handle image uploading in a proper way
Hi! I use a following code: def handleUploadedFile(file): destination = open('%s'%(file.name), 'wb+') for chunk in file.chunks(): destination.write(chunk) destination.close() return destination I call it from view using this code. handleUploadedFile(request.FILES['avatar']) Have a question is that OK to do it this way? What if something will happen on client/server side and the close() method will not be called? can it be an issue? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to run just ONE test?
On Wednesday 24 June 2009 15:11:57 patrickk wrote: > but the app I´m testing doesn´t require the database - the file > models.py is empty. > > the create table and installing index statements look like this: > Creating test database... > Creating table auth_permission > Creating table auth_group > Creating table auth_user > Creating table auth_message > ... > > these statements are not related to the app I´m actually testing. I took a look, even if you are testing only one app, it creates the tables for all installed apps - so looks like you have contrib.admin installed, so it is creating those tables. (Whether it should do this is another matter which I do not know enough to talk about). -- regards kg http://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Uploading Images
On Jun 24, 2:50 pm, Avinash wrote: > The second message posted by you shows that the POST request handler didnt > find key 'files' in its Multivalue Dictionary.Its I think the keyword > 'file' has been deprecated from later versions of Django.So for > uploading the file, just make an instance of the form class like, > form = ImageForm(request.POST, request.FILES) > Then after checking if its valid save it. > Be sure to configure your 'MEDIA_ROOT' directory in 'settings.py' to > the path where you want to upload the files. > Also enable multipart/form data in your form tag of your templateas > mentioned by Roboto. > Good Luck! > Avinash > > On Jun 24, 2:53 am, Roboto wrote: > > > {% if form.is_multipart %} > > > > {% else %} > > > > {% endif %} > > {{ form }} > > > > >http://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-... > > > On Jun 15, 12:59 am, Oleg Oltar wrote: > > > > I made a mistake in view.py. > > > Corrected version is > > > def handleUploadedFile(file): > > > destination = open('usermedia/new.jpg', 'wb+') > > > for chunk in file.chunks(): > > > destination.write(chunk) > > > destination.close() > > > return destination > > > > def user_profile(request, profile_name): > > > owner = get_object_or_404(User, username = profile_name) > > > ownersProfile =get_object_or_404(UserProfile, user = owner) > > > form = ProfileEdit(request.POST) > > > if request.method == 'POST': > > > > if form.is_valid(): > > > ownersProfile.about = form.cleaned_data['about'] > > > ownersProfile.avatar = > > > handleUploadedFile(request.FILES['file']) > > > ownersProfile.save() > > > return HttpResponseRedirect("/") > > > else: > > > form = ProfileEdit() > > > > Also changed a little bit template: > > > > > > {{ form.as_p }} > > > > > > > > > > But I am getting: > > > MultiValueDictKeyError at /account/profile/test > > > > "Key 'file' not found in " > > > > :( > > > > On Mon, Jun 15, 2009 at 6:54 AM, Oleg Oltar wrote: > > > > Hi! > > > > > I know that the problem probably was discussed many times already, but > > > > I really can't make it working. > > > > > I read the documentation and prepared the following code: > > > > > model: > > > > > class UserProfile(models.Model): > > > > """ > > > > User profile model, cintains a Foreign Key, which links it to the > > > > user profile. > > > > """ > > > > about = models.TextField(blank=True) > > > > user = models.ForeignKey(User, unique=True) > > > > ranking = models.IntegerField(default = 1) > > > > avatar = models.ImageField(upload_to="usermedia", default = > > > > 'images/js.jpg') > > > > > def __unicode__(self): > > > > return u"%s profile" %self.user > > > > > form: > > > > > class ProfileEdit(forms.Form): > > > > about = forms.CharField(label = 'About', max_length = 1000, > > > > required=False) > > > > avtar = forms.ImageField() > > > > > view: > > > > def handleUploadedFile(file): > > > > destination = open('usermedia/new.jpg', 'wb+') > > > > for chunk in file.chunks(): > > > > destination.write(chunk) > > > > destination.close() > > > > return True > > > > > def user_profile(request, profile_name): > > > > owner = get_object_or_404(User, username = profile_name) > > > > ownersProfile =get_object_or_404(UserProfile, user = owner) > > > > form = ProfileEdit(request.POST) > > > > if request.method == 'POST': > > > > form = ProfileEdit(request.POST, request.FILES) > > > > if form.is_valid(): > > > > handleUploadedFile(request.FILES['file']) > > > > else: > > > > form = ProfileEdit() > > > > > data = RequestContext(request, > > > > { > > > > 'owner' : owner, > > > > 'ownersProfile' : ownersProfile, > > > > 'form' : form > > > > } > > > > ) > > > > return render_to_response('registration/profile.html', data) > > > > > And part of template: > > > > > > > > > {{ form.as_p }} > > > > > > > > > > > > > After trying this code in browser I am getting a text field with > > > > browse button, so when I chose file to upload, and finally click > > > > upload I am getting 404 Error. > > > > Not sure what I might doing wrong. > > > > Please 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-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: Uploading Images
On Jun 15, 4:54 am, Oleg Oltar wrote: > Hi! > > > {{ form.as_p }} > > > > After trying this code in browser I am getting a text field with > browse button, so when I chose file to upload, and finally click > upload I am getting 404 Error. > Not sure what I might doing wrong. > Please help Your problem is in the form tag. You need to put as described here: http://docs.djangoproject.com/en/dev/ref/forms/api/#binding-uploaded-files -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Skipping an item in a loop
I have a template in which I would like to do the following: {% for item in loop %} {% if [previous item].condition %} item.name {% endif %} {% endfor %} In other words, I want to do something with an item in the loop based on whether the *previous* item has some condition set. Is this possible? Thanks, Daniele --~--~-~--~~~---~--~~ 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: Internationalization in django and search engine indexing
You should have a look at: http://code.google.com/p/django-localeurl/ I'm using it on my site and works really well and it's really easy to set up. You can check an example of how your urls will look once is implemented in here: http:\\jaratech.com Cheers, Miguel On Jun 23, 2:42 pm, Olivier wrote: > Thanks yml. > The middleware part interests me a lot but I don't understand how the > code work in your post. > Do you use Django's LocaleMiddleware ? Where do you add the > language_code in the url ? > Finally, does it work with search engine indexing ? Because you still > need to change language with a link, don't you ? > > My concern is really practical, I already have a site > (http://www.spiderchallenge.com) that is localized both in english and french > but google has only index the english content. > > Thanks again, > > Olivier > > On 23 juin, 03:39, yml wrote: > > > This is the motivation for me to write this piece of middleware > > :http://yml-blog.blogspot.com/search/label/Internationalisation > > --yml > > > On Jun 22, 5:52 pm, Olivier wrote: > > > > Hello everyone, > > > > I'm currently using django localization on my site to manage both > > > english and french. I'm using template tags blocktrans and block but > > > both the french & english pages have the same url. I'm wondering if > > > the search engines can work with this configuration and index the two > > > versions or should I use different url ? > > > > I first tried to find if the question was already solved in a > > > different topic but I didn't see it, sorry if I'm wrong. > > >l > > > Thanks in advance, > > > > Olivier --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
File upload over
Hi :) First of all I should say that I am not experienced in Django ;) I have some problem with file Uploading - if the file is large (700Mb) a strange thing happens with RAM&SWAP :( First it tries to cache something and all the 4Gb or Ram are captured, than the cache is purged and it begins to swap - 1 Gb of swap is used and so on ... I'm using Django 1.02 and apache mod_wsgi --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
File Upload : Memory consumption
Hi! I'm trying to upload a large file (700Mb) and something wrong with django happens: First it starts caching enormously (4Gb of ram are used), than it starts to purge caches and starts swapping (1Gb of swap is used). Have you ever faced with such a thing ? Django 1.02, mod_wsgi + Apache 2.2 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: Internationalization in django and search engine indexing
On Wednesday 24 June 2009 13:56:49 Miguel Rodriguez wrote: > You can check an example of how your urls will look once is > implemented in here: http:\\jaratech.com the '\\' did not get converted to '//' ;-) -- regards kg http://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Skipping an item in a loop
On Jun 24, 11:15 am, "Daniele Procida" wrote: > I have a template in which I would like to do the following: > > {% for item in loop %} > {% if [previous item].condition %} > item.name > {% endif %} > {% endfor %} > > In other words, I want to do something with an item in the loop based on > whether the *previous* item has some condition set. > > Is this possible? > > Thanks, > > Daniele Quite possibly someone else will give a better solution, but one solution would be to have this in views.py: class MyClass(): condition = False def make_view_list(original_list): new_list = [] for x in original_list: new_list.append(x) if len(new_list) > 1: new_list[-1].prev_condition = new_list[-2].condition else: new_list[-1].prev_condition = False return new_list def my_view(request): original_list = [MyClass(),MyClass()]MyClass(),MyClass()] view_list = make_view_list(original_list) return render_to_response('index.html', {'list':view_list}) James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django doesn't translate the "timesince" filter.
Hi. :) The problem is that the timesince doesn't get translated in my Django application. All other parts of the site are translated without a problem, but this certain filter cannot be translated. But when I request the page via AJAX this messages get translated without a problem (in Bulgarian). Maybe the cause of this problem is connected with the request and the way it's done. Help! :) Jordan --~--~-~--~~~---~--~~ 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: Skipping an item in a loop
On Jun 24, 11:41 am, James Gregory wrote: > On Jun 24, 11:15 am, "Daniele Procida" > wrote: > > > > > I have a template in which I would like to do the following: > > > {% for item in loop %} > > {% if [previous item].condition %} > > item.name > > {% endif %} > > {% endfor %} > > > In other words, I want to do something with an item in the loop based on > > whether the *previous* item has some condition set. > > > Is this possible? > > > Thanks, > > > Daniele > > Quite possibly someone else will give a better solution, but one > solution would be to have this in views.py: > > class MyClass(): > condition = False > > def make_view_list(original_list): > new_list = [] > for x in original_list: > new_list.append(x) > if len(new_list) > 1: > new_list[-1].prev_condition = new_list[-2].condition > else: > new_list[-1].prev_condition = False > > return new_list > > def my_view(request): > original_list = [MyClass(),MyClass()]MyClass(),MyClass()] > view_list = make_view_list(original_list) > return render_to_response('index.html', {'list':view_list}) > > James Actually I imagine "new_list = list(original_list)" would be more efficient than doing new_list.append(x) in a loop. James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to run just ONE test?
On Wed, Jun 24, 2009 at 5:17 PM, patrickk wrote: > > just to avoid any misunderstanding: > when I´m running one test with "... test > myapp.BaseTest.test_fileobject" for example, the output is "... runs 1 > test" - but before that statement there´s a lot of "create table ...", > "installing index ..." stuff. and that´s what I´m confused about. Ah. That would have been useful to know in the beginning. As noted by Kenneth - that log of info isn't telling you the tests that are running. The final "3 tests run" is the real statistic you need to look at. > just wanted to make sure that my assumption is right: when I´m running > this one (very simplified) test, the "create table ..." and > "installing index ..." should NOT be there, right? I´ve just read my > first question again and I noticed that I didn´t explain the problem > very well. Your assumption is incorrect. It's easy to build a test case to prove why: consider the case where a model in myapp has a foreign key on a model in otherapp. When you run the tests for 'just myapp', you still need the tables for otherapp. We _could_ theoretically prune the sync list - if we parsed the dependency tree, we could probably strip out unnecessary models, but the sync process doesn't actually take that long in the grand scheme of things, and the risk of getting the strip-down process wrong is quite high. So, we've opted not to pursue this option. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: how to run just ONE test?
I see. your foreign key example makes things much clearer to me. sorry for not being clear enough about the issue with my first question. thanks a lot, patrick On Jun 24, 12:47 pm, Russell Keith-Magee wrote: > On Wed, Jun 24, 2009 at 5:17 PM, patrickk wrote: > > > just to avoid any misunderstanding: > > when I´m running one test with "... test > > myapp.BaseTest.test_fileobject" for example, the output is "... runs 1 > > test" - but before that statement there´s a lot of "create table ...", > > "installing index ..." stuff. and that´s what I´m confused about. > > Ah. That would have been useful to know in the beginning. As noted by > Kenneth - that log of info isn't telling you the tests that are > running. The final "3 tests run" is the real statistic you need to > look at. > > > just wanted to make sure that my assumption is right: when I´m running > > this one (very simplified) test, the "create table ..." and > > "installing index ..." should NOT be there, right? I´ve just read my > > first question again and I noticed that I didn´t explain the problem > > very well. > > Your assumption is incorrect. It's easy to build a test case to prove > why: consider the case where a model in myapp has a foreign key on a > model in otherapp. When you run the tests for 'just myapp', you still > need the tables for otherapp. > > We _could_ theoretically prune the sync list - if we parsed the > dependency tree, we could probably strip out unnecessary models, but > the sync process doesn't actually take that long in the grand scheme > of things, and the risk of getting the strip-down process wrong is > quite high. So, we've opted not to pursue this option. > > Yours, > Russ Magee %-) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Using Models for non database obejcts?
Hi- Is it possible to use models for objects that are not supposed to be persisted to the database, or read from it? I would like to use ModelForms, etc for them, but they should not have a table in the db or written to or read from the db. Any help would be appreciated, -markus --~--~-~--~~~---~--~~ 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: Skipping an item in a loop
On 24 Jun 2009, at 12:47 , James Gregory wrote: > On Jun 24, 11:41 am, James Gregory wrote: >> On Jun 24, 11:15 am, "Daniele Procida" >> wrote: >> >> >> >>> I have a template in which I would like to do the following: >> >>> {% for item in loop %} >>> {% if [previous item].condition %} >>> item.name >>> {% endif %} >>> {% endfor %} >> >>> In other words, I want to do something with an item in the loop >>> based on >>> whether the *previous* item has some condition set. >> >>> Is this possible? >> >>> Thanks, >> >>> Daniele >> >> Quite possibly someone else will give a better solution, but one >> solution would be to have this in views.py: >> >> class MyClass(): >> condition = False >> >> def make_view_list(original_list): >> new_list = [] >> for x in original_list: >> new_list.append(x) >> if len(new_list) > 1: >> new_list[-1].prev_condition = new_list[-2].condition >> else: >> new_list[-1].prev_condition = False >> >> return new_list >> >> def my_view(request): >> original_list = [MyClass(),MyClass()]MyClass(),MyClass()] >> view_list = make_view_list(original_list) >> return render_to_response('index.html', {'list':view_list}) >> >> James > > Actually I imagine "new_list = list(original_list)" would be more > efficient than doing new_list.append(x) in a loop. > > James Or zip the list with itself (with offsets where needed) and use that, either for the transformation or for the display. --~--~-~--~~~---~--~~ 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: Using Models for non database obejcts?
On Wed, Jun 24, 2009 at 7:03 PM, Kusako wrote: > > Hi- > > Is it possible to use models for objects that are not supposed to be > persisted to the database, or read from it? I would like to use > ModelForms, etc for them, but they should not have a table in the db > or written to or read from the db. If you just want a form, you don't need to use ModelForms - just use a Form. The core Form framework operates independent of the database layer - it is, quite literally, just a forms framework. ModelForm exists as a convenience for building forms that are closely associated with database objects, but you don't need the database layer, you don't have to use them. For example, if you want a form that will collect a name and age: from django import forms class MyForm(forms.Form): name = forms.CharField(max_length=100) age = forms.IntegerField() You can then instantiate this form and check values. This form won't have a save() method (since there is nothing to save), but it will still have is_valid(), errors, cleaned_data, etc. The form itself will be almost identical to the form produced if you had created a database model: from django.db import models class MyModel(models.Model): name = models.CharField(max_length=100) age = models.IntegerField() and then created a ModelForm: from django import forms class MyForm(forms.ModelForm): class Meta: model = MyModel The parallels between the two syntaxes are very much intentional. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ 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: Skipping an item in a loop
On Jun 24, 12:11 pm, Masklinn wrote: > On 24 Jun 2009, at 12:47 , James Gregory wrote: > > > > > On Jun 24, 11:41 am, James Gregory wrote: > >> On Jun 24, 11:15 am, "Daniele Procida" > >> wrote: > > >>> I have a template in which I would like to do the following: > > >>> {% for item in loop %} > >>> {% if [previous item].condition %} > >>> item.name > >>> {% endif %} > >>> {% endfor %} > > >>> In other words, I want to do something with an item in the loop > >>> based on > >>> whether the *previous* item has some condition set. > > >>> Is this possible? > > >>> Thanks, > > >>> Daniele > > >> Quite possibly someone else will give a better solution, but one > Or zip the list with itself (with offsets where needed) and use that, > either for the transformation or for the display. Yup, that is definitely better. James --~--~-~--~~~---~--~~ 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: File Upload : Memory consumption
I've seen quite a few posts on this, and I think it's documented as well. As I recall, there is a certain way of doing large uploads, search the docs and the forum and I'm sure you'll find it. On Jun 24, 3:20 am, alecs wrote: > Hi! I'm trying to upload a large file (700Mb) and something wrong with > django happens: First it starts caching enormously (4Gb of ram are > used), than it starts to purge caches and starts swapping (1Gb of swap > is used). > Have you ever faced with such a thing ? Django 1.02, mod_wsgi + Apache > 2.2 > 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: File Upload : Memory consumption
On Wed, 2009-06-24 at 03:20 -0700, alecs wrote: > Hi! I'm trying to upload a large file (700Mb) and something wrong with > django happens: First it starts caching enormously (4Gb of ram are > used), than it starts to purge caches and starts swapping (1Gb of swap > is used). > Have you ever faced with such a thing ? Django 1.02, mod_wsgi + Apache > 2.2 > Thanks :) Hi, have you tried to set FILE_UPLOAD_MAX_MEMORY_SIZE ? There are a couple if tips there too: http://docs.djangoproject.com/en/dev/topics/http/file-uploads/ Hopes this will 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-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django admin interface for Web service
django-roa seems to be the way to go if your service is RESTful http://bitbucket.org/david/django-roa/ Goulwen On Jun 23, 6:39 pm, Kusako wrote: > Hi- > > I need to access an XMLRPC web service from the Django admin > interface. Basically what I need is some create forms that will send > data to the web service instead of storing to a database. > As I'm somewhat new to Django I'm wondering about the best way to > accomplish this. Should I just create custom views for the create > forms and link them to the admin site? Or is there a way to use > models, but instead of storing them in the database, send them to the > web service? > > Thanks for any help, > > -markus --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Ifnotequal used with Length filter and a zero value not working
Hey all, I'm having a problem getting ifnotequal logic to work. I have what is basically this layout: {% ifnotequal activeusers|length 0 %} {{ activeusers|length }} Friends Online {% else %} Friends {% endifnotequal %} in one of my templates. Its not quite as simple as that, theres some list elements and CSS classing going on so that the element appears greyed out whenever activeusers|length is 0. Or at least its supposed to, but it doesn't, because this ALWAYS seems to be output the first condition and not the else. So if theres 1 or more, it'll say "n Friends Online", but even when there are 0, it'll say "0 Friends Online" instead of saying simply "Friends". So I know that activeusers|length is output as 0, however for some reason its saying that that output doesn't equal 0. At first I thought maybe the length filter needed to be compared to "0" instead of 0, but that didn't work either. Is there some logical problem I'm missing or does Django just have a problem dealing with zero values in conditional statements? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django-registration not reflecting changes to forms and views
neri...@gmail.com wrote: > I tried adding more form fields to the > registration form and the changes would never show with touch > dispatch.fcgi, Which fcgi implementation are you using? Assuming apache2 web server, note that the common (since it's in debian and derivatives by default) mod_fcgid may not actually discover things need reloading upon touch of the .fcgi . I think it does end server processes after ProcessLifeTime [1] regardless, so the changeover may happen eventually (but that defaults to an hour). You can use consider using "pkill" to slay the '.*dispatch.fcgi' processes... Anyway, if you're on apache, switch to mod_wsgi if you can (yeah, I know it's not in debian/oldstable (why we were using mod_fcgid), but, well, OLDstable), it's generally easier to setup and manage than either of the fastcgis, though does lack mod_fcgid's dynamic process spawning load management strategy which you may or may not care for. [1] http://fastcgi.coremail.cn/doc.htm --~--~-~--~~~---~--~~ 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: Ifnotequal used with Length filter and a zero value not working
Hi Matthew, > I have what is basically this layout: > > {% ifnotequal activeusers|length 0 %} > {{ activeusers|length }} Friends Online > {% else %} > Friends > {% endifnotequal %} Try this: {% if activeusers %} {{ activeusers|length }} Friends Online {% else %} Friends {% endif %} And read this: http://docs.djangoproject.com/en/dev/ref/templates/builtins/#if Best regards, Marcin -- http://www.zenzire.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Internationalization in django and search engine indexing
Thanks Miguel, It seems that it does what I want, I will try it ! I'm using django on Google App Engine (with app engine patch) which use differents data models, do you think it will still work ? Cheers, Olivier On 24 juin, 12:30, Kenneth Gonsalves wrote: > On Wednesday 24 June 2009 13:56:49 Miguel Rodriguez wrote: > > > You can check an example of how your urls will look once is > > implemented in here: http:\\jaratech.com > > the '\\' did not get converted to '//' ;-) > -- > regards > kghttp://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Ifnotequal used with Length filter and a zero value not working
Ah, d'oh - Very obvious, thanks very much! On Jun 24, 1:28 pm, Marcin Mierzejewski wrote: > Hi Matthew, > > > I have what is basically this layout: > > > {% ifnotequal activeusers|length 0 %} > > {{ activeusers|length }} Friends Online > > {% else %} > > Friends > > {% endifnotequal %} > > Try this: > > {% if activeusers %} > {{ activeusers|length }} Friends Online > {% else %} > Friends > {% endif %} > > And read this:http://docs.djangoproject.com/en/dev/ref/templates/builtins/#if > > Best regards, > Marcin > > --http://www.zenzire.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: TinyMCE django admin
On Jun 24, 6:10 am, Dhruv Adhia wrote: > Hello All, > > I have following under models.py > > from django.db import models > from django.contrib import admin > from tinymce import models as tinymce_models > > class BlogPost(models.Model): > > title = models.CharField(max_length=150) > body = models.TextField() #observe, thats how you get big > character field > timestamp = models.DateTimeField() > > class Meta: > ordering = ('-timestamp',) > class Admin: > list_display = ('title', 'timestamp') > js = ['tiny_mce/tiny_mce.js', 'js/textareas.js'] > > class BlogPostAdmin(admin.ModelAdmin): > pass > > class MyModel(models.Model): > my_field = tinymce_models.HTMLField() > > admin.site.register(MyModel) > admin.site.register(BlogPost, BlogPostAdmin) > > As you can see I have followed all the settings. But I dont get the > editor for the textfield and also I HTMLfield does not work. Though I > am able to edit content inside HTML field and then in the front end > side I am not able to view it. It shows me all the tags. I cannot comment about your problem with the BlogPost model, as you are apparently setting up TinyMCE yourself. You may have to use Firebug to debug Javascript. As far as I can see, the MyModel HTMLField does exactly what it is supposed to. You write that the admin site works, and stores HTML in the field. You are seeing tags in your frontend (the raw HTML) because the field content is not marked safe. You may want to use the 'safe' filter. [1] [1] http://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe Regards, Joost --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
encoding question
Hi, I have html page with inline editing. (I have text, that when I click on it, it changes to edit box, and I can change the text) I do it with some java scripts. (http://www.yvoschaap.com/index.php/ weblog/ajax_inline_instant_update_text_20/) The problem is that I should save the text that I change in the database of my django application and what I get after text change is unicode. I mean, something like: %u05D9%u05D2. Maybe someone has an idea how can I save the hebrew letters, for example, correctly in the database? --~--~-~--~~~---~--~~ 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: null values should work here but don't
Thanks so much! A bug: The good news is you're not crazy; the bad news is there's no easy fix. :) But, in fact, I applied one of the patches there and it solved the problem very well. K.C. On Jun 23, 9:28 pm, Karen Tracey wrote: > > Looks like: > > http://code.djangoproject.com/ticket/5622 > > Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 -~--~~~~--~~--~--~---
Applying XSLT to an XML file using Django
Hi everyone in both lists. I created a XSL template and I want to apply it to an XML data (or file) which I get from a django view, I mean, I have this snippet in my views.py http://dpaste.com/59193/ and I have this another snippet to apply an XSL transformation http://dpaste.com/59194/ ( excuse for the commented lines ). I tried this : - sobprocess.popen to execute the script - to use the script inside the view but nothing. My idea is to call transformer function and pick the file and give it to download. Am I missing something?, Am I doing something wrong?... Any kind of help would be appreciate. Thanks in advance and best regards. :D -- Francisco Rivas --~--~-~--~~~---~--~~ 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: why doesn't the "with" template tag transverse blocks?
On Jun 24, 12:16 am, Karen Tracey wrote: > On Tue, Jun 23, 2009 at 11:05 PM, Steve Howell wrote: > > > {% extends "base_form.html" %} > > > {% with form.instance as object %} > > > I understand why tags outside the block would not render anything > > within the parent but it is not as clear to me why the with statement > > would not change the context for template code that it lexically > > encloses. It seems like this code should either dwim or raise an > > exception. > > It doesn't lexically enclose anything if it is inside a child template and > not inside a {% block %}. > > Consider: > > parent.html: > > {% with something as x %} > {% block b1 %} {{ x }} in parent b1{% endblock %} > {% block b2 %} {{ x }} in parent b2{% endblock %} > {% endwith %} > {% with something_else as x %} > {% block b3 %}{{ x }} in parent b3{% endblock %} > {% endwith %} > > child.html: > > {% extends "parent.html" %} > {% with something_else_again as x %} > {% block b3 %}{{ x }} in child b3{% endblock %} > {% block b2 %}{{ x }} in child b2{% endblock %} > {% endwith %} > {% with yet_even_something_else as x %} > {% block b1 %}{{ x }} in child b1{% endblock %} > {% endwith %} > > If those with/endwiths in child.html were to have some effect, what would it > be? Where would you place them in the fully-block-substituted parent > template? something_else_again being x encloses blocks b3 and b2 in > child.html, yet in the parent template these blocks are found in a different > order and have different with's enclosing them...which withs win? I just > don't see any sensible way to make this "work". > > Raising some sort of error for child template content found outside of a {% > block %} seems like a more reasonable idea. I have no idea if it's been > asked for/considered/rejected/etc., nor how hard it would be to do. If you > are really interested in pursuing that idea I'd first search the tracker and > archives of this list to see if it hasn't already been discussed. > > Karen Whats wrong with: {% with something as x %} {% block foo1 %} {{x}} {% endblock %} {% block foo2 %} {{x}} {% endblock%} {% block foo3 %} {{x}} {% endblock%} {% block foo4 %} {{x}} {% endblock %} {% block foo5 %} {{x}} {% endblock %} {% endwith %} just simply being a shortcut for: {% block foo1 %}} {% with something as x %} {{x}} {% endwith %} {% endblock %} {% block foo2 %} {% with something as x %} {{x}} {% endwith %} {%endblock%} {% block foo3 %}} {% with something as x %} {{x}} {% endwith %} {%endblock%} {% block foo4 %}} {% with something as x %} {{x}} {% endwith %} {%endblock%} {% block foo5 %} {% with something as x %} {{x}} {% endwith %} {% endblock%} Seem like it just makes things easier to read and maintain. If the second example works perfectly fine, then why shouldn't the first? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
TinyMCE and Slugfield
hi all - I'm having a weird problem. I've had TinyMCE working with a NewStory model in admin. I just added a new field, a Slugfield, and now the TinyMCE is completely different, and doesn't accept my input?!? Normally, the TinyMCE controls were at the bottom of the textarea, and now they're at the top, with different options (MS Word import, Insert Media, etc) - this doesn't bother me particularly, but it's really bothersome that my input is not accepted - it's just erased and I get the this field in required error?!? To add to the oddness of my problem, in my flatpages admin page, it's the same old TinyMCE that I was used to seeing?!? and it accepts my input In the admin.py file, both classes are configured virtually the same, including the Media class like this: class Media: js = ['/static/js/tiny_mce/tiny_mce.js', '/static/js/tiny_mce/ TinyMCEAdmin.js',] However, in the flatpages admin source, there is no include for TinyMCEAdmin.js, whereas it is in the NewStory admin page source Anyone seen this before or have any ideas? Thanks, Sam --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to load fixtures only once in django unit tests?
Very well explained. Thanks Russell Keith-Magee On Jun 23, 4:58 am, Russell Keith-Magee wrote: > On Tue, Jun 23, 2009 at 1:21 PM, Rama Vadakattu > wrote: > > > In unit tests i need to load few fixtures i have done as below > > > class TestQuestionBankViews(TestCase): > > > #load this fixtures > > fixtures = ['qbank',] > > > def setUp(self): > > login = self.client.login > > (email="m...@gmail.com",password="welcome") > > > def test_starting_an_exam_view(self): > > candidate = Candidate.objects.get(email="m...@gmail.com") > > ...etc > > > def test_review_view(self): > > self.assertTrue(True) > > . > > > def test_review_view2(self): > > self.assertTrue(True) > > > > > Problem: > > > These fixtures are loading for every test (i.e) before > > test_review_view, test_review_view2 etc... as django flushes the > > database after every test > > > How can i prevent that as it is taking lots of time? > > Can't i load in setUp and flush them out while exit but not between > > every test and still inheriting django.test.TestCase ? > > No - this isn't a feature that Django has out of the box. Unit tests > need to be able to guarantee the entry state of the database, and the > only way to easily guarantee this is to ensure that the data is > reloaded at the start of each test, which means flushing out old data > before reloading. > > "Oh", you say. "But my test doesn't modify data! It would be ok if the > database wasn't flushed!". Sure... for the moment. Then you change > your implementation (on purpose or accidentally), and something > strange starts happening to your tests. Tests pass or fail when they > shouldn't because other tests are modifying the base data. Tests pass > or fail depending on which other tests have been executed, or the > order in which tests are executed. > > Django's test suite has repeatedly demonstrated that leaking test > preconditions can be a real headache - Doctests are particularly prone > to exactly this sort of problem. The sort of change you are suggesting > would only serve to introduce these sorts of problems where they don't > exist right now, and to introduce them into the worst possible area of > the code to have surprising and unexpected results. > > For the record, I can think of a few ways this could be accomplished > without needing changes to the Django core. However, I'm not going to > document them here (or anywhere else for that matter). Without wanting > to be rude - if you can't work out how to do this, then you probably > shouldn't be doing it. > > That said, I am sensitive to the fact that Django's unit tests can > take a long time to run, and that this is mostly due to the database > flush. This is why Django v1.1 has modified TestCase to use > transactions to optimize the test running process. This change has > resulted in significantly faster test execution - in some extreme > cases, up to an order of magnitude faster. If you aren't already using > Django trunk, I strongly encourage you to try it out. > > > b.Also there should very good line of separation between > > initialization of object vs initialization before every method > > at present setUp method trying to do both the things > > As I noted earlier, each test case needs to be isolated. Setting up > database data is one of the conditions that needs to be guaranteed. > The distinction you are pointing to only exists in your imagination. > Completely aside from any feature of Django - there is a very good > reason why setUp and tearDown are run before and after each test, but > there is no equivalent method for the start and end of execution for > an entire TestCase. > > Yours, > Russ Magee %-)- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ 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: Applying XSLT to an XML file using Django
On Jun 24, 3:53 pm, Francisco Rivas wrote: > Hi everyone in both lists. > > I created a XSL template and I want to apply it to an XML data (or file) > which I get from a django view, I mean, I have this snippet in my > views.pyhttp://dpaste.com/59193/and I have this another snippet to apply an > XSL > transformationhttp://dpaste.com/59194/( excuse for the commented lines ). > > I tried this : > > - sobprocess.popen to execute the script > - to use the script inside the view but nothing. > > My idea is to call transformer function and pick the file and give it to > download. > > Am I missing something?, Am I doing something wrong?... > > Any kind of help would be appreciate. Thanks in advance and best regards. :D > > -- > Francisco Rivas What do you mean, 'nothing' when you tried to use it inside the view? What happened when you imported it? What happened when you called it? What errors did you get? -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: why doesn't the "with" template tag transverse blocks?
On Wed, Jun 24, 2009 at 11:19 AM, buttman wrote: > Whats wrong with: > > {% with something as x %} > > {% block foo1 %} > {{x}} > {% endblock %} > > {% block foo2 %} > {{x}} > {% endblock%} > > {% block foo3 %} > {{x}} > {% endblock%} > > {% block foo4 %} > {{x}} > {% endblock %} > > {% block foo5 %} > {{x}} > {% endblock %} > > {% endwith %} > > just simply being a shortcut for: > > > > {% block foo1 %}} > {% with something as x %} > {{x}} > {% endwith %} > {% endblock %} > > {% block foo2 %} > {% with something as x %} > {{x}} > {% endwith %} > {%endblock%} > > {% block foo3 %}} > {% with something as x %} > {{x}} > {% endwith %} > {%endblock%} > > {% block foo4 %}} > {% with something as x %} > {{x}} > {% endwith %} > {%endblock%} > > {% block foo5 %} > {% with something as x %} > {{x}} > {% endwith %} > {% endblock%} > > Seem like it just makes things easier to read and maintain. If the > second example works perfectly fine, then why shouldn't the first? > There's nothing wrong with your first example as written, that's perfectly legal. There's no need to repeat the {% with %} inside each block. But note you haven' t made your example a child template -- it doesn't start with {% extends %} -- and that's the key. If this were a child template, you'd have to do it the 2nd way, or place the {% with %}/{% endwith %} in the parent template enclosing all the blocks where you wanted it to have an effect. That's because content in a child template that is outside of any named {% block %} that has been defined in a parent template has no place to go in the ultimately rendered template, so it may as well not be there. I don't know how to restate this to try to make it any clearer than the ways I've already tried to explain it. The title of this thread is not really accurate. {% with %} can span blocks, it just can't do so in a child template since NOTHING outside of {% block %}s (and {% extends %}) in a child template has any effect. If you know the order of the block placement in the parent template I suppose it might work to put the {% with %} within the first block and the {% endwith %} at the end of of the last block, but that's quite ugly. It does lead me to think of another way, though. You could define "start_withs" and "end_withs" blocks and properly place them in the parent tempalte, then define them with overriding content in the child templates, I suppose, if you really need to do this kind of thing. Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: makemessages .. not all translations found or commented out
> when I use this command > ./manage.py makemessages -l nl -e=html,txt,py -- > pythonpath=apps_pinax,templates_pinax > > It finds also text in the txt files.. but it also comments out parts > of translations I found with the first command like > > #~ msgid "Discussion Topics for Tribe" > #~ msgstr "Discussies van groep" That "commenting-out" behavior is normal for strings that aren't in- use anymore. Which means, makemessages didn't find "Discussion Topics for Tribe". Your syntax looks fine, judging by the latest docs, so I can only think of two possible explanations: 1. There's a bug in makemessages' handling of the "-e=" parameter, -OR- 2. You ran makemessages with some of those options missing. #2 seems most likely. If you'd accidentally mis-typed the makemessages command once on a previous attempt, that would've caused some strings to be commented-out. I'm pretty sure that running makemessages again with the CORRECT options won't magically UN-comment those entries. Does your django.po file have a new entry for templates_pinax/tribes/ topics.html:11 "Discussion Topics for Tribe" that ISN'T commented out? (Sorry, I can't attempt to reproduce the behavior myself -- I'm still using 0.97 which predates the integration into manage.py AND the -e option =) --~--~-~--~~~---~--~~ 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: why doesn't the "with" template tag transverse blocks?
On Jun 23, 9:16 pm, Karen Tracey wrote: > > Raising some sort of error for child template content found outside of a {% > block %} seems like a more reasonable idea. I have no idea if it's been > asked for/considered/rejected/etc., nor how hard it would be to do. If you > are really interested in pursuing that idea I'd first search the tracker and > archives of this list to see if it hasn't already been discussed. > A similar ticket regarding enclosing child blocks with "if" statements was closed with the statement that "this is by design." http://code.djangoproject.com/ticket/10975 I don't really agree with the design in either case. I think tags that are truly outside of derived blocks should create syntax errors, and tags that surround derived blocks should somehow satisfy the principle of least astonishment--either apply the conditional or variable assignment when rendering or raise a syntax error, but don't just ignore the tags silently. --~--~-~--~~~---~--~~ 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: TinyMCE django admin
Allright Joost, Second part is working. I am new to those firebug stuff. Can you guide me to docs? Thanks, On Wed, Jun 24, 2009 at 6:34 AM, Joost Cassee wrote: > > On Jun 24, 6:10 am, Dhruv Adhia wrote: > > Hello All, > > > > I have following under models.py > > > > from django.db import models > > from django.contrib import admin > > from tinymce import models as tinymce_models > > > > class BlogPost(models.Model): > > > > title = models.CharField(max_length=150) > > body = models.TextField() #observe, thats how you get big > > character field > > timestamp = models.DateTimeField() > > > > class Meta: > > ordering = ('-timestamp',) > > class Admin: > > list_display = ('title', 'timestamp') > > js = ['tiny_mce/tiny_mce.js', 'js/textareas.js'] > > > > class BlogPostAdmin(admin.ModelAdmin): > > pass > > > > class MyModel(models.Model): > > my_field = tinymce_models.HTMLField() > > > > admin.site.register(MyModel) > > admin.site.register(BlogPost, BlogPostAdmin) > > > > As you can see I have followed all the settings. But I dont get the > > editor for the textfield and also I HTMLfield does not work. Though I > > am able to edit content inside HTML field and then in the front end > > side I am not able to view it. It shows me all the tags. > > I cannot comment about your problem with the BlogPost model, as you > are apparently setting up TinyMCE yourself. You may have to use > Firebug to debug Javascript. > > As far as I can see, the MyModel HTMLField does exactly what it is > supposed to. You write that the admin site works, and stores HTML in > the field. You are seeing tags in your frontend (the raw HTML) because > the field content is not marked safe. You may want to use the 'safe' > filter. [1] > > [1] http://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe > > Regards, > > Joost > > > -- Dhruv Adhia http://thirdimension.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: encoding question
try: from unicodedata import normalize mytext = '%u05D9%u05D2' newtext = normalize('NFKD', mytext).encode('ASCII','ignore') or: import sys reload(sys) sys.setdefaultencoding('latin-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-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 -~--~~~~--~~--~--~---
Can I use django-filebrowser in a form?
Hi- I have a form, not backed by a model and would like to use django- filebrowser for one of its field. Is this possible? I tried someting like my_file = FileBrowseFormField () for my form, but wouldn't work. Thanks for your help, -markus --~--~-~--~~~---~--~~ 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: Using Models for non database obejcts?
Thanks for the rhelp, this clears things up. -markus On Jun 24, 1:21 pm, Russell Keith-Magee wrote: > On Wed, Jun 24, 2009 at 7:03 PM, Kusako > wrote: > > > Hi- > > > Is it possible to use models for objects that are not supposed to be > > persisted to the database, or read from it? I would like to use > > ModelForms, etc for them, but they should not have a table in the db > > or written to or read from the db. > > If you just want a form, you don't need to use ModelForms - just use a > Form. The core Form framework operates independent of the database > layer - it is, quite literally, just a forms framework. ModelForm > exists as a convenience for building forms that are closely associated > with database objects, but you don't need the database layer, you > don't have to use them. > > For example, if you want a form that will collect a name and age: > > from django import forms > class MyForm(forms.Form): > name = forms.CharField(max_length=100) > age = forms.IntegerField() > > You can then instantiate this form and check values. This form won't > have a save() method (since there is nothing to save), but it will > still have is_valid(), errors, cleaned_data, etc. The form itself will > be almost identical to the form produced if you had created a database > model: > > from django.db import models > class MyModel(models.Model): > name = models.CharField(max_length=100) > age = models.IntegerField() > > and then created a ModelForm: > > from django import forms > class MyForm(forms.ModelForm): > class Meta: > model = MyModel > > The parallels between the two syntaxes are very much intentional. > > Yours, > Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django admin interface for Web service
Thanks for the link. This looks pretty interesting. Unfortunately the service I have to access isn't RESTful, so it doesn't look like I can make of roa easily. -markus On Jun 24, 1:33 pm, nautilebleu wrote: > django-roa seems to be the way to go if your service is RESTful > > http://bitbucket.org/david/django-roa/ > > Goulwen > > On Jun 23, 6:39 pm, Kusako wrote: > > > Hi- > > > I need to access an XMLRPC web service from the Django admin > > interface. Basically what I need is some create forms that will send > > data to the web service instead of storing to a database. > > As I'm somewhat new to Django I'm wondering about the best way to > > accomplish this. Should I just create custom views for the create > > forms and link them to the admin site? Or is there a way to use > > models, but instead of storing them in the database, send them to the > > web service? > > > Thanks for any help, > > > -markus --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django installation and the admin
I am going to deploy a django project on a shared host. The server is equipped with apache, mod_python and python. I don't have my own apache instance and I don't have access to python myself. Since Django is effectively a python module and as such will be integrated in python, I wonder what happens with the admin pages in Django. Will they be shared across the server with other users? How can this issue be solved? I wonder, too, if it is necessary to run the setup.py script to install django on the server? Is it perhaps sufficient to upload the django folder to the web server and connect python to django by including django in the python path? Robert --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Entering large chunk of data
Hello All, I have news field in django admin and I would like to enter 2000 news items at once. May I know how to do it in shorter way? Thanks, Dhruv --~--~-~--~~~---~--~~ 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: Applying XSLT to an XML file using Django
Sorry I forgot that important information : What do you mean, 'nothing' when you tried to use it inside the view? The final XML file, that obtained of apply the XSL template to the original XML, is not created. What happened when you imported it? What happened when you called it? When I import the converter.py and call the transformer function I got a parseError in my browser, actually if I run the converter script from my command line it works perfectly, that makes me think, may be, that is another thing. What errors did you get? I got a parseError, I am writing a try and catch exception to get errors. One thing that is strange to me is : I put the following lines in my views.py and every time that I add / xslt to the end of my URL django execute these lines, and it works, so why can not I take that file and apply it an XSL template?... template = loader.get_template("cvsanaly/committers.xml") result_render = render_to_string("cvsanaly/committers.xml", data) xml_file = open("/tmp/committers.xml","w") xml_file.writelines(result_render) xml_file.close() I write a file and I want to apply the XSL template to that file as follow, as you can see I put everything in /tmp, for testing purpouses : styledoc = libxml2.parseFile("cvsanaly/committers.xsl") # get the XSL template style = libxslt.parseStylesheetDoc(styledoc) doc = libxml2.parseFile("/tmp/committers.xml") # file which I want to change result = style.applyStylesheet(doc, {"source":project}) # apply the xsl template style.saveResultToFilename("/tmp/"+xml_name+"_xslt.xml", result, 0) # write the final XML file. Look so trivial but I do not get at all. Thanks in advance again and best regards :D On Jun 24, 6:02 pm, Daniel Roseman wrote: > On Jun 24, 3:53 pm, Francisco Rivas wrote: > > > > > Hi everyone in both lists. > > > I created a XSL template and I want to apply it to an XML data (or file) > > which I get from a django view, I mean, I have this snippet in my > > views.pyhttp://dpaste.com/59193/andI have this another snippet to apply an > > XSL > > transformationhttp://dpaste.com/59194/( excuse for the commented lines ). > > > I tried this : > > > - sobprocess.popen to execute the script > > - to use the script inside the view but nothing. > > > My idea is to call transformer function and pick the file and give it to > > download. > > > Am I missing something?, Am I doing something wrong?... > > > Any kind of help would be appreciate. Thanks in advance and best regards. :D > > > -- > > Francisco Rivas > > What do you mean, 'nothing' when you tried to use it inside the view? > What happened when you imported it? What happened when you called it? > What errors did you get? > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Problem with passing information from related model to a view
As you can see from this I am just learning django. I am trying to list contacts and their related organisations. This does list the contact names. No errors are raised but fields from Organisations do not show with this view and template. I guess I need to be more explicit in referncing the related fields but have not found out how, despite looking through tutorials. Any help appreciated. Paul models.py from django.db import models class Contact(models.Model): fname = models.CharField(max_length=40) sname = models.CharField(max_length=40) email = models.CharField(max_length=60) dir_tel = models.CharField(max_length=25,blank=True) mobile = models.CharField(max_length=25,blank=True) blog = models.URLField(max_length=80,blank=True) linkedin = models.CharField(max_length=40,blank=True) def __str__(self): return '%s %s' %(self.fname,self.sname) class Organisation(models.Model): organisation = models.CharField(max_length=60) addr1 = models.CharField(max_length=40,blank=True) addr2 = models.CharField(max_length=40,blank=True) city = models.CharField(max_length=40,blank=True) county = models.CharField(max_length=40,blank=True) pcode = models.CharField(max_length=12,blank=True) def __str__(self): return '%s' %(self.organisation) views.py from models import Contact def contact_list(request): # where: .filter(fn="value") contact_list=list(Contact.objects.all().select_related()) return render_to_response('contact_list.html',{ 'contact_list': contact_list, }) contact_list.html {% block content %} {% for obj in contact_list %} {{ obj.fname }} {{ obj.sname }} : {{ obj.organisation }} {% endfor %} {% endblock %} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django-registration not reflecting changes to forms and views
I am on Dreamhost using Mod_fastcgi and believe that this is my only option at the moment. I tried pkill python and pkill .*dispatch.fcgi with no change. The only changes that are reflected are changes to the template and the urls i.e., the view and form that are called by the url have been deleted and the app still works as if they were never changed. On Jun 24, 5:10 am, David De La Harpe Golden wrote: > neri...@gmail.com wrote: > > I tried adding more form fields to the > > registration form and the changes would never show with touch > > dispatch.fcgi, > > Which fcgi implementation are you using? Assuming apache2 web server, > note that the common (since it's in debian and derivatives by default) > mod_fcgid may not actually discover things need reloading upon touch of > the .fcgi . I think it does end server processes after ProcessLifeTime > [1] regardless, so the changeover may happen eventually (but that > defaults to an hour). > > You can use consider using "pkill" to slay the '.*dispatch.fcgi' > processes... > > Anyway, if you're on apache, switch to mod_wsgi if you can (yeah, I know > it's not in debian/oldstable (why we were using mod_fcgid), but, well, > OLDstable), it's generally easier to setup and manage than either of the > fastcgis, though does lack mod_fcgid's dynamic process spawning load > management strategy which you may or may not care for. > > [1]http://fastcgi.coremail.cn/doc.htm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with passing information from related model to a view
On Jun 24, 6:26 pm, paultanner wrote: > As you can see from this I am just learning django. > I am trying to list contacts and their related organisations. This > does list the contact names. > No errors are raised but fields from Organisations do not show with > this view and template. > I guess I need to be more explicit in referncing the related fields > but have not found out how, despite looking through tutorials. > Any help appreciated. Paul > > models.py > > from django.db import models > > class Contact(models.Model): > fname = models.CharField(max_length=40) > sname = models.CharField(max_length=40) > email = models.CharField(max_length=60) > dir_tel = models.CharField(max_length=25,blank=True) > mobile = models.CharField(max_length=25,blank=True) > blog = models.URLField(max_length=80,blank=True) > linkedin = models.CharField(max_length=40,blank=True) > def __str__(self): > return '%s %s' %(self.fname,self.sname) > > class Organisation(models.Model): > organisation = models.CharField(max_length=60) > addr1 = models.CharField(max_length=40,blank=True) > addr2 = models.CharField(max_length=40,blank=True) > city = models.CharField(max_length=40,blank=True) > county = models.CharField(max_length=40,blank=True) > pcode = models.CharField(max_length=12,blank=True) > def __str__(self): > return '%s' %(self.organisation) > > views.py > > from models import Contact > > def contact_list(request): > # where: .filter(fn="value") > contact_list=list(Contact.objects.all().select_related()) > return render_to_response('contact_list.html',{ > 'contact_list': contact_list, > }) > > contact_list.html > > {% block content %} > > {% for obj in contact_list %} > > {{ obj.fname }} {{ obj.sname }} : {{ obj.organisation }} > > {% endfor %} > > {% endblock %} The models don't seem to be related in any way. You need a ForeignKey, a OneToOneField or a ManyToManyField from one to the other to identify which organisation(s) are related to which contact(s). The tutorial shows you how to do this with Polls and Choices, you should be able to extrapolate that for your use case. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Entering large chunk of data
Hello Dhruv, Two ways you can do this, that I know. Use your databases' built in data import technique. For example with MySql you can use LOAD DATA. Alternately you could use manage.py shell to run python code to load your data. Read about manage.py shell and dbshell here < http://docs.djangoproject.com/en/dev/ref/django-admin/ >. Toodle-looo... creecode On Jun 24, 10:23 am, Dhruv Adhia wrote: > I have news field in django admin and I would like to enter 2000 news > items at once. May I know how to do it in shorter way? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Flatpages only works when settings.DEBUG = True
What you´ve done? I´m getting this problem and, try all the following steps like you, but still not working ! Can you help me ?? On 5 maio, 04:07, Ronghui Yu wrote: > It works now. That's because a typo error happens in my 404.html page. And > it introduces 500.Thanks all. > > > > On Tue, May 5, 2009 at 9:17 AM, Ronghui Yu wrote: > > Yes, 404.html and 500.html are there. But they extend from base.html, which > > depends on some context variables. I will change them to a simple one and > > see if the problem still there.Thanks > > > On Tue, May 5, 2009 at 12:06 AM, Brian Neal wrote: > > >> On May 4, 10:28 am, Ronghui Yu wrote: > >> > Hi,All, > > >> > I am going to use Flatpages app for those simple pages. And everything > >> > works fine when settings.DEBUG is True, but when it is turned to False, > >> > a URL not configured in urlpatterns will trigger 500, not 404. > > >> Do you have a 404.html error template? You need to have that before > >> flatpages will work when DEBUG is False. See the note titled "Ensure > >> that your 404 template works" in this section: > > >>http://docs.djangoproject.com/en/dev/ref/contrib/flatpages/#module-dj... > > >> Its also a good idea to have a 500.html error template. > > >> Best, > >> BN > > > -- > > === > > Regards > > Ronghui Yu > > -- > === > Regards > Ronghui Yu --~--~-~--~~~---~--~~ 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: File Upload : Memory consumption
The maximum size, in bytes, for files that will be uploaded into memory. Files larger than FILE_UPLOAD_MAX_MEMORY_SIZE will be streamed to disk. Defaults to 2.5 megabytes. My file size is greater than 2.5Mb, so it will be streamed to disk... --~--~-~--~~~---~--~~ 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: Entering large chunk of data
Hey, I would prefer second method as I am using sqlite3. Is this what you mean? django-admin.py loaddata mydata.json , If so I how do I populate json file such large amounts of data? Thanks, On Wed, Jun 24, 2009 at 10:48 AM, creecode wrote: > > Hello Dhruv, > > Two ways you can do this, that I know. Use your databases' built in > data import technique. For example with MySql you can use LOAD DATA. > Alternately you could use manage.py shell to run python code to load > your data. > > Read about manage.py shell and dbshell here < > http://docs.djangoproject.com/en/dev/ref/django-admin/ >. > > Toodle-looo... > creecode > > On Jun 24, 10:23 am, Dhruv Adhia wrote: > > > I have news field in django admin and I would like to enter 2000 news > > items at once. May I know how to do it in shorter way? > > > -- Dhruv Adhia http://thirdimension.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django with mod_wsgi troubles
I've tried a bunch of different approaches going back and forth between mod_python and mod_wsgi. I can't get past this one error: NoSectionError at / No section: 'formatters' Request Method: GET Request URL:http://localhost:1/ Exception Type: NoSectionError Exception Value: No section: 'formatters' Exception Location: C:\Python25\lib\ConfigParser.py in get, line 511 Python Executable: C:\Program Files\Apache Software Foundation \Apache2.2\bin\httpd.exe Python Version: 2.5.4 Python Path:['C:\\Program Files\\Apache Software Foundation\ \Apache2.2', 'C:\\Python25', 'C:\\WINDOWS\\system32\\python25.zip', 'C: \\Python25\\Lib', 'C:\\Python25\\DLLs', 'C:\\Python25\\Lib\\lib-tk', 'C:\\Program Files\\Apache Software Foundation\\Apache2.2\\bin', 'C:\ \Python25\\lib\\site-packages', 'C:\\Python25\\lib\\site-packages\ \wx-2.8-msw-unicode', '/Python25/Lib/site-packages/django', '/Java/ projects/kuali_erd/python', 'C:/Java/projects/kuali_erd/python', '/ Python25/Lib/site-packages', '/Python25/Lib/site-packages/django', '/ Java/projects/kuali_erd/python', 'C:/Java/projects/kuali_erd/python'] Server time:Wed, 24 Jun 2009 13:58:43 -0400 --- I've included the relevant configuration snippets. Can anyone figure out what's causing this error and how to work around it? --- #django.wsgi import os, sys sys.path.append('/Python25/Lib/site-packages') sys.path.append('/Python25/Lib/site-packages/django') import django.core.handlers.wsgi os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' sys.path.append('/Java/projects/kuali_erd/python') apache_configuration= os.path.dirname(__file__) project = os.path.dirname(apache_configuration) workspace = os.path.dirname(project) sys.path.append(workspace) application = django.core.handlers.wsgi.WSGIHandler() #httpd.conf LoadModule wsgi_module modules/mod_wsgi.so Include "/Java/projects/kuali_erd/python/mysite/apache/ apache_django_wsgi.conf" #apache_django_wsgi.conf Listen *:1 DocumentRoot /Java/projects/kuali_erd/python Order allow,deny Allow from all WSGIScriptAlias / "/Java/projects/kuali_erd/python/mysite/apache/ django.wsgi" - 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 -~--~~~~--~~--~--~---
Using two different Comment Instances
I'm familiar with modifying comments to change functionality, that's well documented. But what I want to do is use a modified version of comments on a model and also the standard comments. So I have a model "post" and I want to enable comments, easy enough, and then I want to enable mod_comments on the same "post" model. I don't want to override the regular comments, literally on my page I want it to say "Add a Comment" or "Add a different type of Comment" two links, two different comment types. Also, this would be helpful in the future to know for those instances that I would like to have different types of comments for different types of posts in the same project, so, for example if I have two blogs on in the same project and blog1 has regular comments and then blog2 has mod_comments. Suggestions?? --~--~-~--~~~---~--~~ 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: File Upload : Memory consumption
If to be honest I can't google this posts ... Most of the links are for patches or for old django versions :( Don't know, maybe I should try to set FILE_UPLOAD_MAX_MEMORY_SIZE, but I didn't change it , so the default value is 2.5Mb ... On Jun 24, 2:54 pm, John M wrote: > I've seen quite a few posts on this, and I think it's documented as > well. > > As I recall, there is a certain way of doing large uploads, search the > docs and the forum and I'm sure you'll find it. > > On Jun 24, 3:20 am, alecs wrote: > > > Hi! I'm trying to upload a large file (700Mb) and something wrong with > > django happens: First it starts caching enormously (4Gb of ram are > > used), than it starts to purge caches and starts swapping (1Gb of swap > > is used). > > Have you ever faced with such a thing ? Django 1.02, mod_wsgi + Apache > > 2.2 > > 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: Odd ModelForm problem
I see. Well, I guess I don't know why it worked before either. I made the following change and that seems to have cleared up the problem: This: if not form.slug: form.slug = slugify(form.title) if form.is_valid(): article = form.save(commit=False) is now: if form.is_valid(): article = form.save(commit=False) if not form.cleaned_data['slug']: article.slug = slugify(form.cleaned_data['title']) --~--~-~--~~~---~--~~ 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: Skipping an item in a loop
On Wed, Jun 24, 2009, James Gregory wrote: >> >>> I have a template in which I would like to do the following: >> >> >>> {% for item in loop %} >> >>> {% if [previous item].condition %} >> >>> item.name >> >>> {% endif %} >> >>> {% endfor %} >> >> >>> In other words, I want to do something with an item in the loop >> >>> based on >> >>> whether the *previous* item has some condition set. >> Or zip the list with itself (with offsets where needed) and use that, >> either for the transformation or for the display. Thanks for all the suggestions. We realised that this isn't something that can be handled in a template. What we did was put it in a function in the model: def ancestry_for_address(self): ancestors = [] showparent = self.display_parent for item in self.get_ancestors(ascending = True): if showparent: ancestors.append(item) showparent = item.display_parent That way we get a list of the items, and skip over the ones we don't want. (We need this to construct our institutional addresses. I am in the It Office of the School of Medicine at Cardiff University. If I used the correct names of those, my address would end up being: IT Office Cardiff University School of Medicine Cardiff University which is obviously silly. So, now we can tell the system that "Cardiff University School of Medicine" doesn't need "Cardiff University" to follow it. On the other hand: Human Resources Cardiff University is correct, so "Human Resources" will ask for its parent.) Daniele --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
django-cloudfiles
Hi everyone, I have a young project on github that lets you dump your site's static media to a CloudFiles account (a cloud storage service offered by Mosso / the Rackspace Cloud, which integrates with Limelite's CDN). http://github.com/rossdakin/django-cloudfiles/ And if you like the idea, hows about voting for it? http://bit.ly/ORf2q Cheers, Ross --~--~-~--~~~---~--~~ 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: Entering large chunk of data
Hello Dhruv, On Jun 24, 11:03 am, Dhruv Adhia wrote: > Is this what you mean? > django-admin.py loaddata mydata.json , If so I how do I populate json file > such large amounts of data? The LOAD DATA was in reference too the LOAD DATA INFILE command < http://dev.mysql.com/doc/refman/5.1/en/load-data.html > available for MySql and was just an example. Since you're using sqlite3 that obviously won't be of help. Most databases would have similar methods for importing large amount of data. You'd need to read up on how your database does it if you do decide to go that route. If you don't want to use the command line ( or some kind of client program ) with your database then you're left with using manage.py shell and writing a small python program to load your data. Your program would need to load your Model, open and parse your file, create and save instances of your model. Opening files can be read about in the Python documentation as well as commands that would be useful in parsing your file ( string methods? ). If you've been through the Django documentation then you've seen how to work with Django models. Toodle-looo... creecode --~--~-~--~~~---~--~~ 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: Entering large chunk of data
in sqlite3 (the sqlite3 shell), you can use .import to import data from a text file. It works great. You may need to change the separator. For a one time load, this is probably the easiest method. Dhruv Adhia wrote: > Hey, > > I would prefer second method as I am using sqlite3. > > Is this what you mean? > django-admin.py loaddata mydata.json , If so I how do I populate json file > such large amounts of data? > > Thanks, > > On Wed, Jun 24, 2009 at 10:48 AM, creecode wrote: > >> Hello Dhruv, >> >> Two ways you can do this, that I know. Use your databases' built in >> data import technique. For example with MySql you can use LOAD DATA. >> Alternately you could use manage.py shell to run python code to load >> your data. >> >> Read about manage.py shell and dbshell here < >> http://docs.djangoproject.com/en/dev/ref/django-admin/ >. >> >> Toodle-looo... >> creecode >> >> On Jun 24, 10:23 am, Dhruv Adhia wrote: >> >>> I have news field in django admin and I would like to enter 2000 news >>> items at once. May I know how to do it in shorter way? >>> > > -- Carl Zmola czm...@woti.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Webapp creation: Check box like search to find common ground
Hey Guys, This is my first post on this group. I'm a newbie to Django, Python and mysql, and have recently been asked by my boss to make a web page of a Database. What I have to do: Take the tables from the database(which is in mysql) and create a web application to show which groups belong to which. By that I mean say we have Two groups in a table : X and Y. In X we have numbers 1 - 20. In Y we have letters A - D. Now say 1,5,7 correspond to A and 1,9,15 correspond to B and 2,11,13 correspond to C and so on for D, I want to see what each selection in Y (when checked in a check box) has which numbers? Its an ongoing project, and will post more as I come across it. I hope this benefits other users out there too. Thanks in advance. Best, Divesh A Gidwani --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
PostgreSQL Conference West 2009 Call for Papers
PostgreSQL Conference West 2009 Call for Papers June 24th, 2009, the PostgreSQL Conference U.S. team is pleased to announce the West 2009 venue and call for papers. This year the premiere West Coast PostgreSQL Conference will be leaving its roots at Portland State University and moving north to sunny Seattle, Washington. The event this year is being held at Seattle Central Community College from October 16th through 18th. The move to Seattle opens up a larger metropolitan area for continuing to expose databases users, developers, and administrators to the World's Most Advanced Open Source Database. Following previously successful West Coast conferences, we will be hosting a series of 3-4 hour tutorials, 90 minute mini-tutorials, and 45 minute talks. This year we will be continuing our trend of covering the entire PostgreSQL ecosystem. We would like to see talks and tutorials on the following topics: General PostgreSQL: Administration * Performance * High Availability * Migration * GIS * Integration * Solutions and White Papers * The Stack: Python/Django/Pylons/TurboGears/Custom * Perl5/Catalyst/Bricolage * Potato * Ruby/Rails * Java (PLJava would be great)/Groovy/Grails * Operating System optimization (Linux/FBSD/Solaris/Windows) * Solutions and White Papers * If you are using PostgreSQL as your platform, you need to be presenting at this conference! You may submit your paper here: http://www.postgresqlconference/talksubmission *** The PostgreSQL Conference U.S. series is an autonomous Educational Project used to educate all comers on the use of The World's Most Advanced Open Source Database. Proceeds from the event are donated directly to United States PostgreSQL; the 501c3 non-profit for PostgreSQL education and advocacy in the United States. -- PostgreSQL - XMPP: jdr...@jabber.postgresql.org Consulting, Development, Support, Training 503-667-4564 - http://www.commandprompt.com/ The PostgreSQL Company, serving since 1997 --~--~-~--~~~---~--~~ 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: Entering large chunk of data
Thanks guys, I think Ill go with .import filename tablename I have the table sqlite> .schema promo_new CREATE TABLE "promo_new" ( "id" integer NOT NULL PRIMARY KEY, "title" varchar(200) NOT NULL, "news_content" varchar(200) NOT NULL, "pub_date" datetime NOT NULL ); for news model suppose I want title = 'Some title' , content = 'some content' and pub_date= '2009-06-22 12:33:30' till id 2000 (2000 rows) How would I do that with import statement? On Wed, Jun 24, 2009 at 11:45 AM, Carl Zmola wrote: > > in sqlite3 (the sqlite3 shell), you can use .import to import data from > a text file. It works great. You may need to change the separator. > For a one time load, this is probably the easiest method. > > Dhruv Adhia wrote: > > Hey, > > > > I would prefer second method as I am using sqlite3. > > > > Is this what you mean? > > django-admin.py loaddata mydata.json , If so I how do I populate json > file > > such large amounts of data? > > > > Thanks, > > > > On Wed, Jun 24, 2009 at 10:48 AM, creecode wrote: > > > >> Hello Dhruv, > >> > >> Two ways you can do this, that I know. Use your databases' built in > >> data import technique. For example with MySql you can use LOAD DATA. > >> Alternately you could use manage.py shell to run python code to load > >> your data. > >> > >> Read about manage.py shell and dbshell here < > >> http://docs.djangoproject.com/en/dev/ref/django-admin/ >. > >> > >> Toodle-looo... > >> creecode > >> > >> On Jun 24, 10:23 am, Dhruv Adhia wrote: > >> > >>> I have news field in django admin and I would like to enter 2000 news > >>> items at once. May I know how to do it in shorter way? > >>> > > > > > > -- > Carl Zmola > czm...@woti.com > > > > > -- Dhruv Adhia http://thirdimension.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
TimeField and null
I need a time field that can be None. I define the field so that Null is legal in the DB: time_end = models.TimeField(blank=True, null=True) The form field is: time_end = forms.ChoiceField(required=False, choices=END_TIME_CHOICES) and END_TIME_CHOICES is: END_TIME_CHOICES = ( (None, 'End Time Unknown'), (datetime.time(0,0), '12:00 Midnight'), (datetime.time(0,30), '12:30 AM'), (datetime.time(1,0), '1:00 AM'), (datetime.time(1,30), '1:30 AM'), etc, ) My question is why does this field give a validation error when None is selected, saying: ValidationError at /event/add_event/ Enter a valid time in HH:MM[:ss[.uu]] format. 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: TimeField and null
Hi, On Wed, Jun 24, 2009 at 4:57 PM, adrian wrote: > > > I need a time field that can be None. > > I define the field so that Null is legal in the DB: > > time_end = models.TimeField(blank=True, null=True) > My question is why does this field give a validation error when None > is selected, saying: Because null=True, applies to the database. If you want to allow the user select a null value, you also need to add blank=True -- Kind Regards --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
FileField can't re-display invalid form with File upload widget filled-in?
I've got an app that wants a file upload and some other attributes. If the user fills in the file but has problems with the other attributes, it should re-present the form with the attributes filled with his values, including the name of the file that he selects. In use the example below doesn't re-populate the file upload widget. Is this possible? > class FileDemoForm(forms.Form): > """Require another field so we can show populated file0 not > being bound""" > file0 = forms.FileField() > another = forms.CharField() > > def file_demo(request): > """The bound form is *not* populated with request.FILES info for > file0""" > if request.method == "POST": > form = FileDemoForm(request.POST, request.FILES) > print >> stderr, "### file_demo incoming bound POST form=\n > %s" % (form,) > if form.is_valid(): > return HttpResponseRedirect("/") > else: > form = FileDemoForm() > print >> stderr, "### file_demo returning form=\n%s" % (form,) > return render_to_response('filedrop/file_create.html', {'form': > form}) The incoming form bound with request.FILES and request.POST doesn't show any filename in the widget: > ### file_demo incoming bound POST form= > File0: type="file" name="file0" id="id_file0" /> > Another: class="errorlist">This field is required. type="text" name="another" id="id_another" /> The W3C spec suggests that should be able to take a "defaultValue" or "value" attributes but I can't make that work even with hand-written HTML outside of Django. It also suggests browsers should allow multiple file selection in their input widgets but I've not seen this implemented before. So is it possible to re-populate a 'file' input widget with the user's selection on a failed form? 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: FileField can't re-display invalid form with File upload widget filled-in?
I doubt that this is possible, looks like a security risk if you can select files from the clients pc arbitrary to be uploaded. If that would be possible, a malicious website could embed a in its code, preselect a file from the clients pc, and hide that element with CSS. Most users probably wouldn't notice. Adding to this I doubt you can reconstruct the full path of the uploaded file, all you get is the filename for what I know. On Jun 24, 10:34 pm, Chris Shenton wrote: > I've got an app that wants a file upload and some other attributes. > If the user fills in the file but has problems with the other > attributes, it should re-present the form with the attributes filled > with his values, including the name of the file that he selects. In > use the example below doesn't re-populate the file upload widget. Is > this possible? > > > > > class FileDemoForm(forms.Form): > > """Require another field so we can show populated file0 not > > being bound""" > > file0 = forms.FileField() > > another = forms.CharField() > > > def file_demo(request): > > """The bound form is *not* populated with request.FILES info for > > file0""" > > if request.method == "POST": > > form = FileDemoForm(request.POST, request.FILES) > > print >> stderr, "### file_demo incoming bound POST form=\n > > %s" % (form,) > > if form.is_valid(): > > return HttpResponseRedirect("/") > > else: > > form = FileDemoForm() > > print >> stderr, "### file_demo returning form=\n%s" % (form,) > > return render_to_response('filedrop/file_create.html', {'form': > > form}) > > The incoming form bound with request.FILES and request.POST doesn't > show any filename in the widget: > > > ### file_demo incoming bound POST form= > > File0: > type="file" name="file0" id="id_file0" /> > > Another: > class="errorlist">This field is required. > type="text" name="another" id="id_another" /> > > The W3C spec suggests that should be able to take > a "defaultValue" or "value" attributes but I can't make that work even > with hand-written HTML outside of Django. It also suggests browsers > should allow multiple file selection in their input widgets but I've > not seen this implemented before. > > So is it possible to re-populate a 'file' input widget with the user's > selection on a failed form? > > 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 -~--~~~~--~~--~--~---
modifying or deleting forms and views has no effect on app
I've been trying to figure out why modifications made to forms and views have no effect on the app they belong to. I'm using django- registration and wanted to add some additional fields to the registration form but any changes I make, including deleting forms.py or views.py, has no effect on the app. I've tried pkill on python and dispatch.fcgi as well as touch dispatch.fcgi with no luck. Everything has been working fine up until this point i.e., registering and activating accounts and admin management, but any modification to these files does nothing. Is this a problem with Mod_fastcgi? Thanks, J --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Practical Django Projects or Pro Django Books
For some at intermediate level in Django and basic level in Python ( learned Python thru django) which would be better book for next reading Practical Django Projects by James Bennet or Pro Django by Marty Alchin. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
email for user name in Authentication
I want to use email for user name. How can I increase size of username in django auth from 30 to 50. Also I want two or more accounts to have same user name/ email but different passwords. So username password combination is unique but username is not unique. Can I do this through django auth or would I need to build my own. Do you see any issues with this approach? --~--~-~--~~~---~--~~ 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: TimeField and null
If you look, blank is set to True, and it still returns the validation error. On Jun 24, 3:25 pm, "Gabriel ." wrote: > Hi, > > On Wed, Jun 24, 2009 at 4:57 PM, adrian wrote: > > > I need a time field that can be None. > > > I define the field so that Null is legal in the DB: > > > time_end = models.TimeField(blank=True, null=True) > > My question is why does this field give a validation error when None > > is selected, saying: > > Because null=True, applies to the database. If you want to allow the > user select a null value, you also need to add blank=True > > -- > Kind Regards --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Getting related objects
I have an application, with a model called Entities. I have another, with a model called NewsItem: class NewsItem(models.Model): destined_for = models.ManyToManyField( Entity, ) I can get a list of NewsItems for a particular Entity with something like: Entity.objects.all()[2].newsitem_set.all() My question is: can I get that same list in a template that has only been passed Entity? Thanks, Daniele --~--~-~--~~~---~--~~ 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: email for user name in Authentication
On Wed, Jun 24, 2009 at 5:24 PM, bigme wrote: > > I want to use email for user name. How can I increase size of username > in django auth from 30 to 50. > > Also I want two or more accounts to have same user name/ email but > different passwords. So username password combination is unique but > username is not unique. Can I do this through django auth or would I > need to build my own. Do you see any issues with this approach? > Personally, I find keeping the username a username and exposing the email address for authentication to be a little easier than changing the model and overriding the field. Here are a few snippets to help you: http://www.djangosnippets.org/snippets/74/#c195 http://www.djangosnippets.org/snippets/686/ Hope that helps, Michael --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django admin delete oneToOneField ?
I saw this in the docs: "When Django deletes an object, it emulates the behavior of the SQL constraint ON DELETE CASCADE -- in other words, any objects which had foreign keys pointing at the object to be deleted will be deleted along with it." So it sounds like you don't need to do anything. On Jun 17, 12:41 pm, Dan Sheffner wrote: > ok so I have a list of servers that have a one to one relationship with a > table called cpu. When I delete a server from the server table it should > also delete it one to one relationship with the cpu entry. right? do I > need to pass something extra in the models.py to have this happen? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django with mod_wsgi troubles
On Jun 25, 4:05 am, Laran Evans wrote: > I've tried a bunch of different approaches going back and forth > between mod_python andmod_wsgi. I can't get past this one error: > > NoSectionError at / > > No section: 'formatters' > > Request Method: GET > Request URL: http://localhost:1/ > Exception Type: NoSectionError > Exception Value: > > No section: 'formatters' > > Exception Location: C:\Python25\lib\ConfigParser.py in get, line 511 > Python Executable: C:\Program Files\Apache Software Foundation > \Apache2.2\bin\httpd.exe > Python Version: 2.5.4 > Python Path: ['C:\\Program Files\\Apache Software Foundation\ > \Apache2.2', 'C:\\Python25', 'C:\\WINDOWS\\system32\\python25.zip', 'C: > \\Python25\\Lib', 'C:\\Python25\\DLLs', 'C:\\Python25\\Lib\\lib-tk', > 'C:\\Program Files\\Apache Software Foundation\\Apache2.2\\bin', 'C:\ > \Python25\\lib\\site-packages', 'C:\\Python25\\lib\\site-packages\ > \wx-2.8-msw-unicode', '/Python25/Lib/site-packages/django', '/Java/ > projects/kuali_erd/python', 'C:/Java/projects/kuali_erd/python', '/ > Python25/Lib/site-packages', '/Python25/Lib/site-packages/django', '/ > Java/projects/kuali_erd/python', 'C:/Java/projects/kuali_erd/python'] > Server time: Wed, 24 Jun 2009 13:58:43 -0400 > > --- > > I've included the relevant configuration snippets. Can anyone figure > out what's causing this error and how to work around it? > > --- > > #django.wsgi > import os, sys > sys.path.append('/Python25/Lib/site-packages') > sys.path.append('/Python25/Lib/site-packages/django') > import django.core.handlers.wsgi > > os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' > > sys.path.append('/Java/projects/kuali_erd/python') > > apache_configuration= os.path.dirname(__file__) > project = os.path.dirname(apache_configuration) > workspace = os.path.dirname(project) > sys.path.append(workspace) > > application = django.core.handlers.wsgi.WSGIHandler() > > #httpd.conf > LoadModule wsgi_module modules/mod_wsgi.so > Include "/Java/projects/kuali_erd/python/mysite/apache/ > apache_django_wsgi.conf" > > #apache_django_wsgi.conf > Listen *:1 > > DocumentRoot /Java/projects/kuali_erd/python > > > Order allow,deny > Allow from all > > > WSGIScriptAlias / "/Java/projects/kuali_erd/python/mysite/apache/ > django.wsgi" > > Not that it will help with your problem, but you should never stick your application code anywhere under DocumentRoot. You should also not expose using Allow your Django site directory, only the special directory you created to hold the WSGI script file. These warnings are in the Django integration documentation on the mod_wsgi site. http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: django-registration not reflecting changes to forms and views
On Jun 24, 10:10 pm, David De La Harpe Golden wrote: > neri...@gmail.com wrote: > > I tried adding more form fields to the > > registration form and the changes would never show with touch > > dispatch.fcgi, > > Which fcgi implementation are you using? Assuming apache2 web server, > note that the common (since it's in debian and derivatives by default) > mod_fcgid may not actually discover things need reloading upon touch of > the .fcgi . I think it does end server processes after ProcessLifeTime > [1] regardless, so the changeover may happen eventually (but that > defaults to an hour). > > You can use consider using "pkill" to slay the '.*dispatch.fcgi' > processes... > > Anyway, if you're on apache, switch tomod_wsgiif you can (yeah, I know > it's not in debian/oldstable (why we were using mod_fcgid), but, well, > OLDstable), it's generally easier to setup and manage than either of the > fastcgis, though does lack mod_fcgid's dynamic process spawning load > management strategy which you may or may not care for. Depending on how it is implemented, dynamic process spawning in conjunction with fat Python web applications can be a problem. For a discussion of how it causes issues for mod_python and mod_wsgi when run embedded in Apache see: http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html I still have to sit down and properly look at how mod_fcgid, mod_fastcgi and flup implement their process spawning, but I certainly have concerns that it could also cause problems for certain configurations. Part of the problem with all these mechanisms is their defaults are often biased towards PHP hosting and this sort of configuration doesn't work well for Python web applications. Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: application scope objects? (maybe need cherrypy instead)
sorry to intrude, but the question has come up twice (with 2 different authors) on the list in the last few months with no replies. I'll try again on the user list with some different words --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
objects in memory that don't time out?
This is a re-phrase of a previous email... trying to trigger an answer using terms that might make more sense to this list. I'm more familiar with java frameworks. Is there a way to have objects persist in memory that don't time out? For example, in cherrypy, there's an Application object that persists from when cherrypy starts until it stops. In Java frameworks, there's the ServletContext. .Net apps have something similar. Is this not supported in wsgi? 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: objects in memory that don't time out?
On Jun 25, 9:35 am, qwcode wrote: > This is a re-phrase of a previous email... trying to trigger an answer > using terms that might make more sense to this list. I'm more > familiar with java frameworks. > > Is there a way to have objects persist in memory that don't time out? > > For example, in cherrypy, there's an Application object that persists > from when cherrypy starts until it stops. In Java frameworks, > there's the ServletContext. .Net apps have something similar. > > Is this not supported in wsgi? If you mean a specific object instance which describes the underlying web server attributes, then for WSGI the answer is no. This is because WSGI is meant to be hosted on different web servers and as such how the underlying web server captures such information will be different and isn't standardised. Thus WSGI doesn't attempt to provide a single interface for accessing such information. This doesn't mean that an application which can be hosted on top of WSGI doesn't provide such an object, but it will be application/ framework specific. Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: objects in memory that don't time out?
let me give an example suppose I want to store an XSLT template object to be reused over and over to transform xml where can I put it? I don't want to put in the backend cache, right? that times out? --~--~-~--~~~---~--~~ 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: objects in memory that don't time out?
On Jun 25, 9:58 am, Graham Dumpleton wrote: > On Jun 25, 9:35 am, qwcode wrote: > > > This is a re-phrase of a previous email... trying to trigger an answer > > using terms that might make more sense to this list. I'm more > > familiar with java frameworks. > > > Is there a way to have objects persist in memory that don't time out? > > > For example, in cherrypy, there's an Application object that persists > > from when cherrypy starts until it stops. In Java frameworks, > > there's the ServletContext. .Net apps have something similar. > > > Is this not supported in wsgi? > > If you mean a specific object instance which describes the underlying > web server attributes, then for WSGI the answer is no. This is because > WSGI is meant to be hosted on different web servers and as such how > the underlying web server captures such information will be different > and isn't standardised. Thus WSGI doesn't attempt to provide a single > interface for accessing such information. > > This doesn't mean that an application which can be hosted on top of > WSGI doesn't provide such an object, but it will be application/ > framework specific. Also read: http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading Aspects of sharing data discussed is applicable across different WSGI implementations as far as multiprocess/multithreading issues go. So, as far as question you pose in different thread, look at Python module global variables. If you don't understand how that helps, then you don't understand how Python global variables work. Just be aware of the issues that global variables cause in context of multiprocess web server as described in documentation above. BTW, please don't create separate threads for the same topic like you have. Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Practical Django Projects or Pro Django Books
> For some at intermediate level in Django and basic level in Python > ( learned Python thru django) which would be better book for next > reading Practical Django Projects by James Bennet or Pro Django by > Marty Alchin. I don't think you can say either is better as their approach is quite different. I'd probably put myself in the same skill level as you and I've found both to be useful for different reasons. They're more complimentary than competing, although Practical Django Projects now does have a slight edge in that the recently released second edition is aimed at Django 1.1. In short, if you can afford it, get both. Nick --~--~-~--~~~---~--~~ 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: TimeField and null
On Wed, Jun 24, 2009 at 3:57 PM, adrian wrote: > > > I need a time field that can be None. > > I define the field so that Null is legal in the DB: > > time_end = models.TimeField(blank=True, null=True) > > The form field is: > > time_end = forms.ChoiceField(required=False, choices=END_TIME_CHOICES) > > and END_TIME_CHOICES is: > > END_TIME_CHOICES = ( >(None, 'End Time Unknown'), >(datetime.time(0,0), '12:00 Midnight'), >(datetime.time(0,30), '12:30 AM'), >(datetime.time(1,0), '1:00 AM'), >(datetime.time(1,30), '1:30 AM'), > etc, > ) > > My question is why does this field give a validation error when None > is selected, saying: > > ValidationError at /event/add_event/ > > Enter a valid time in HH:MM[:ss[.uu]] format. > The problem is that your empty choice None becomes the string "None" when it is rendered as an HTML select input element, and comes back in the POST data as a the string "None", not Python's None, so the model TimeField tries to parse the string value "None" as a time and fails. First way that comes to mind to fix it is to change your None to an empty string in END_TIME_CHOICES, and use a TypedChoiceField with empty_value set to None for your form field: time_end = forms.TypedChoiceField(required=False, choices=END_TIME_CHOICES, empty_value=None) Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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: debugging
This does not appear to be the issue, although the indentations are wrong in the posting. The following is what they really are. What am I missing? I am still not sure why unit.save() is not working. def save_unit(request): if request.method == 'POST': form = UnitFormSave(request.POST) if form.is_valid(): unit = Units.objects.create( serial_number = form.cleaned_data['serial_number'], build = form.cleaned_data['build'], model = form.cleaned_data['model'], source = form.cleaned_data['source']) unit.save() return HttpResponseRedirect('/search/') else: form = UnitFormSave() variables = RequestContext(request, { 'form': form }) return render_to_response('unit_save.html', variables) On Jun 23, 6:55 pm, Karen Tracey wrote: > On Tue, Jun 23, 2009 at 9:04 PM, db_333 wrote: > > > Hi I'm trying to figure out why a record I am trying to save from a > > form will not commit. The form seems to be working fine, and I wanted > > to know if there were any specific debugging statements I could use to > > see where this is failing. > > > The following is what I have: > > > 1. model: > > > class Units(models.Model): > > serial_number = models.CharField(max_length=25, primary_key=True) > > build = models.CharField(max_length=50, blank=True) > > model = models.CharField(max_length=20, blank=True) > > create_date = models.DateField(null=True, blank=True) > > source = models.CharField(max_length=20, blank=True) > > class Meta: > > db_table = u'units' > > > 2. form: > > > class UnitFormSave(forms.Form): > > serial_number = forms.CharField(max_length=50) > > build = forms.CharField(max_length=50) > > model = forms.CharField(max_length=10) > > source = forms.CharField(max_length=10) > > > 3. view: > > > def save_unit(request): > > if request.method == 'POST': > > form = UnitFormSave(request.POST) > > if form.is_valid(): > > unit = Units.objects.create( > > serial_number = form.cleaned_data['serial_number'], > > build = form.cleaned_data['build'], > > model = form.cleaned_data['model'], > > source = form.cleaned_data['source']) > > unit.save() > > return HttpResponseRedirect('/search/') > > else: > > form = UnitFormSave() > > > variables = RequestContext(request, { > > 'form': form > > }) > > return render_to_response('unit_save.html', variables) > > Is this actually the way you have the save_unit function indented? You've > got everything indented under "if request.method == 'POST'" with nothing for > the GET case. It rather looks like from the "else" currently paired with > "if form.is_valid():" through the end of the funciton should be out-dented > one level. That way if form is not valid what will happen is that the form > annotated with error messages about what is incorrect will be re-displayed. > What is happening with the code you have posted is that the error-annotated > form is being tossed away and replaced with a new blank form. As it is, > though, I don't see how you are getting anything valid on a GET to begin > with, so I am not even sure this is the code you are actually running. > > Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-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 -~--~~~~--~~--~--~---
Using Signals as hooks
I'm a bit of a noob at Web Devlopment (as you already know if you've read any of my posts on here). I've read that using hooks in key places in a website can help ease future development. Can/Should Django's signals be used for that purpose? If so, to what extent should they be used? For example, on my site where users submit articles for a newsletter, one place to put a hook would be after an article is submitted. Would sending emails to admins about the new submission, as well as emails to the users who subscribe to be notified of new submissions be put in a separate function, as part of the hook, or part of the page? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How can I use database view in Django
I saw the former question in stackoverflow "can i use a database view as a model in django"[http://stackoverflow.com/questions/507795/can-i- use-a-database-view-as-a-model-in-django] and try it in my app,but that's not work.I create a view named "vi_topics" manually and it had "id" column。But I always got the error about "no such column: vi_topics.id",even I add "id" field explicitly. here is my view models : from django.db import models class Vitopic(models.Model): title = models.CharField(max_length=200) content = models.TextField() author_name = models.CharField(max_length=200) author_email = models.CharField(max_length=200) view_count = models.IntegerField(default=0) replay_count = models.IntegerField(default=0) tags = models.CharField(max_length=255) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: db_table = 'vi_topics' btw: I use sqlite3. --~--~-~--~~~---~--~~ 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: objects in memory that don't time out?
> So, as far as question you pose in different thread, look at Python > module global variables. If you don't understand how that helps, then > you don't understand how Python global variables work. Just be aware > of the issues that global variables cause in context of multiprocess > web server as described in documentation above. Ok, my take away is the following. please correct me if I'm wrong. I'm just trying to get my head around it. 1) In django, if you want "application scoped" objects, using module globals (similar to java static variables) is your only recourse. There is no parallel to Java servlet's ServletContext, or cherrypy's Application object 2) Depending on your web server config, you may have multiple instances of these globals, so if you're planning on these being mutable, then you could have problems 3) If your intention is to use non-mutable, thread-safe globals, then you're ok under all configurations, you just might have multiples of the same globals running. --~--~-~--~~~---~--~~ 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: objects in memory that don't time out?
On Jun 25, 3:28 pm, qwcode wrote: > > So, as far as question you pose in different thread, look at Python > > module global variables. If you don't understand how that helps, then > > you don't understand how Python global variables work. Just be aware > > of the issues that global variables cause in context of multiprocess > > web server as described in documentation above. > > Ok, my take away is the following. please correct me if I'm wrong. I'm > just trying to get my head around it. > > 1) In django, if you want "application scoped" objects, using module > globals (similar to java static variables) is your only recourse. > There is no parallel to Java servlet's ServletContext, or cherrypy's > Application object It isn't necessarily the only way, but it is the easiest and since you cannot run multiple Django instances within the one Python (sub) interpreter you don't get an issue of two application instances within same process trying to access the same values. > 2) Depending on your web server config, you may have multiple > instances of these globals, so if you're planning on these being > mutable, then you could have problems If you expect the change made in one process to be reflected in all processes, then yes it is a problem. If you are using them for per process caching where cached information would be same even if generated in different process, then not an issue. > 3) If your intention is to use non-mutable, thread-safe globals, then > you're ok under all configurations, you just might have multiples of > the same globals running. If they are non mutable, is thread safety even an issue? I guess that depends on whether you initialise the global value on module import or not. If done at module import, then no thread locking needed. Only need thread locking if initialisation will be performed from an actual request handler first time it is necessary. Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Problem with passing information from related model to a view
Thx. DR. Duh. I had the foreignkey in an earlier test and then took it out again. Interesting that no error raised. The other thing is that the template needed to call for the related field thus: {{ obj.fname }} {{ obj.sname }} : {{ obj.organisation.organisation }} (seems logical now) With these 2 changes it works fine. BTW. The .select_related() in the above is a red herring - not needed for this purpose but I will doubtless learn its proper uses. As to the tutorial I did read it. Will look again to see why I missed that template syntax detail. I understand why the template process is silent in relation to non- existent data fields. However, with debug on this might not be the ideal policy. Paul On 24 June, 18:44, Daniel Roseman wrote: > On Jun 24, 6:26 pm, paultanner wrote: > > > > > > > As you can see from this I am just learning django. > > I am trying to list contacts and their related organisations. This > > does list the contact names. > > No errors are raised but fields from Organisations do not show with > > this view and template. > > I guess I need to be more explicit in referncing the related fields > > but have not found out how, despite looking through tutorials. > > Any help appreciated. Paul > > > models.py > > > from django.db import models > > > class Contact(models.Model): > > fname = models.CharField(max_length=40) > > sname = models.CharField(max_length=40) > > email = models.CharField(max_length=60) > > dir_tel = models.CharField(max_length=25,blank=True) > > mobile = models.CharField(max_length=25,blank=True) > > blog = models.URLField(max_length=80,blank=True) > > linkedin = models.CharField(max_length=40,blank=True) > > def __str__(self): > > return '%s %s' %(self.fname,self.sname) > > > class Organisation(models.Model): > > organisation = models.CharField(max_length=60) > > addr1 = models.CharField(max_length=40,blank=True) > > addr2 = models.CharField(max_length=40,blank=True) > > city = models.CharField(max_length=40,blank=True) > > county = models.CharField(max_length=40,blank=True) > > pcode = models.CharField(max_length=12,blank=True) > > def __str__(self): > > return '%s' %(self.organisation) > > > views.py > > > from models import Contact > > > def contact_list(request): > > # where: .filter(fn="value") > > contact_list=list(Contact.objects.all().select_related()) > > return render_to_response('contact_list.html',{ > > 'contact_list': contact_list, > > }) > > > contact_list.html > > > {% block content %} > > > > {% for obj in contact_list %} > > > > {{ obj.fname }} {{ obj.sname }} : {{ obj.organisation }} > > > > {% endfor %} > > > > {% endblock %} > > The models don't seem to be related in any way. You need a ForeignKey, > a OneToOneField or a ManyToManyField from one to the other to identify > which organisation(s) are related to which contact(s). > > The tutorial shows you how to do this with Polls and Choices, you > should be able to extrapolate that for your use case. > -- > DR.- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---