Re: what is the best way to capture the subdomain and send it to a view?
Cool. Thanks a lot. I'll try that out when I get home. It is definitely the cleanest solution by far.
making photo gallery
hi i am trying to develop a photogallery application. For this i need four photos per line. To calculate the line breaks, i tried to use forloop.counter - but apparently one cannot do maths on the counter. I was doing {% ifequal (forloop.counter % 4) 0 %} but am getting an error. any clues? -- regards kg http://www.livejournal.com/users/lawgon tally ho! http://avsap.org.in ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!
Re: making photo gallery
On Thursday 05 Jan 2006 2:43 pm, Kenneth Gonsalves wrote: > hi > i am trying to develop a photogallery application. For this i > need four photos per line. To calculate the line breaks, i tried > to use forloop.counter - but apparently one cannot do maths on > the counter. I was doing > {% ifequal (forloop.counter % 4) 0 %} > > but am getting an error. any clues? got it: {% if forloop.counter|add:"-1"|divisibleby:"4" %} -- regards kg http://www.livejournal.com/users/lawgon tally ho! http://avsap.org.in ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!
Suitability, Performance and scalability Info
Hi My company is looking for me to outline there web apps strategy going forward, and of course they want tried and tested which means websphere and J2EE or possibly .NET. I of course want something better and django stands out. Its mostly for interactive apps, as opposed to static content, so my first questions is can I do things like javascript and xmlhttprequest (ie AJAX ) in django easily ? I am sure I can but thought it prudent to ask. We will be adding many small data bases, with simple maintaince, but also adding complex sales forcasts which would be almost spread sheet like, and then the results of that would be graphs, funnells, etc (and yes I know normal apps would be better, but they want web ) The other things were they gonna something to go on for speed and scalability. Is there any info out there ? On scalability can it be clustered easily (as with websphere)? I know this is a really loose question, but any info would be appreciated. Thanks, S
Re: Suitability, Performance and scalability Info
On 5 Jan 2006, at 11:40, ChaosKCW wrote: I of course want something better and django stands out. Its mostly for interactive apps, as opposed to static content, so my first questions is can I do things like javascript and xmlhttprequest (ie AJAX ) in django easily ? I am sure I can but thought it prudent to ask. Absolutely. Django doesn't put any barriers in front of you outputting XML or JSON or JavaScript instead of HTML, making Ajax stuff really easy to do. The other things were they gonna something to go on for speed and scalability. Is there any info out there ? On scalability can it be clustered easily (as with websphere)? Django scales using the "shared nothing" architecture - so you can run multiple web servers talking to a single database server with ease (and concentrate your efforts on scaling that database server). Django performance is excellent - there aren't any official benchmarks but I feel comfortable in stating that a server running Django should be able to handle more requests than a server running Rails or TurboGears (the Python interpreter is faster than Ruby, and Django's template system is significantly faster than the one used by TurboGears). That said, the bottleneck for most apps is the database so these performance differences may not affect you in deployment situations. Django doesn't currently support more advanced scaling architectures but features for supporting replicated databases are currently under discussion - contributions of advice (and code) in this area are welcome. Hope that answers your questions, Simon
Re: Web host for Django, what to ask for?
Hello James Bennett and Joshua D. Drake , Thank you for some ideas about using Django with share webhosting . I have some more questions: 1. Does it mean that I should ask my webhosting provider to install mod_proxy Apache module( my provider uses Apache server)? 2.After enabling proxy, is it possible ( via SSH access) to install my own Apache and mod_Python and configure it for Django? 3. Is there any cookbook how to setup proxy? Thank you for help Regards, Lad.
Numbre formatting in the admin application
Hello! Is there any way to format a number in the admin aplication? For example: Integers: Right align Float: Right aling Currency: Right aling+ format acording to locale. That is 1234.23 -> 1.234.23 € Best regards, -- Antoni Aloy López Binissalem - Mallorca Soci de Bulma
Re: making photo gallery
2006/1/5, Kenneth Gonsalves <[EMAIL PROTECTED]>: > > hi > i am trying to develop a photogallery application. You might be interesting in contributing to hugo's [1] [1] https://simon.bofh.ms/cgi-bin/trac-django-projects.cgi/wiki/DjangoGallery -- Brice Carpentier aka Br|ce
ANN: "Snakes and Rubies" (Django/Rails meetup) video/audio available
Last month, there was a Django/Rails meetup in Chicago, at which I spoke about Django and David H. of Rails spoke about Rails. Last night we made available video and audio of both presentations, plus the Q&A session. Jacob spent a *ton* of time condensing the 13 hours of raw video into nicely edited files for your downloading pleasure. Check them out here: http://www.djangoproject.com/snakesandrubies/ Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org
Re: Suitability, Performance and scalability Info
Yes thats very helpfull. Thanks,
Re: ANN: "Snakes and Rubies" (Django/Rails meetup) video/audio available
Thanks Adrian and Jacob. Nice Job ;) I am downloading the videos right now. I plan to download rails and django presentation on video and for the Q&A session download only the audio. You said in the download page "If at all possible, please use BitTorrent! Our servers thank you..." I suggest you to use more compression on the audio files, file size can be reduced to a fourth (or even less) withouth affecting audio quality. That way your servers will thank you too, and we, the audience will get the files faster. Thanks again. Jorge
Re: ANN: "Snakes and Rubies" (Django/Rails meetup) video/audio available
On 5 Jan 2006, at 15:17, stinger wrote: You said in the download page "If at all possible, please use BitTorrent! Our servers thank you..." It would be useful if there were torrents for just Adrian's talk, just the Q&A etc. Cheers, Simon
Data from multiple engines/data in one Django app (or project)
Here's an issue I've been wondering about. It's something that comes up somewhat frequently in the type of development we do, and I'm wondering what the Django-centric approach to this would be? Here's the situation: We have newly developed Django app that's running beautifully. In fact, it's working so well that a new requirement has popped up to have the application integrate with a legacy data source that lives on a different RDBMS than the one the company has standardized on for web apps. So, how would one typically go about using data from multiple databases and/or database engines in one Django app? At first I thought I'd just separate that model out into another app, but of course apps installed into the same project/site use the same settings. I could create a completely self-contained Python module to pull in that data, but it seems counterproductive to the general idea of using the framework. Is there a way to model data from multiple, separate data sources in the same Django project? Thanks, Morten
Re: making photo gallery
> {% if forloop.counter|add:"-1"|divisibleby:"4" %} Arrggh, my eyes are burning! try {% if forloop.counter0|divisibleby:4 %} -rob
Re: making photo gallery
For this exact use I created the following custom filter. It converts a list into a two-dimensional table: def tabularize(value, cols): """modifies a list to become a list of lists eg [1,2,3,4] becomes [[1,2], [3,4]] with an argument of 2""" try: cols = int(cols) except ValueError: return [value] return map(*([None] + [value[i::cols] for i in range(0, cols)])) so now you just have to: {% for row in photos|tabularize:"4" %} {% for photo in row %} {% if photo %}{{ photo.whatever }}{% endif %} {% endfor %} {% endfor %}
Fwd: customizing appearance of foreign key edited inline
I'm resending this question because I'm still having trouble figuring this out. I'm interested in customizing how a inline-edited foreign key appears in the admin interface. Is there some way to do this? Thanks.-- Forwarded message --From: Colleen Owens <[EMAIL PROTECTED]>Date: Jan 4, 2006 1:17 PM Subject: customizing appearance of foreign key edited inlineTo: django-users@googlegroups.comHi, I'm having trouble figuring out how to customize the appearance of a foreign key that's edited inline in the admin interface. For example, if I wanted to change how the poll choices from the tutorial are displayed, by suppressing the number of votes, or changing the order in which the votes and choices are displayed, is there a way to do this? Thanks. Colleen
Re: what is the best way to capture the subdomain and send it to a view?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Le Roux wrote: > Thanks. I'll do that. It just feels like that type of thing should > happen outside of the view (and come to the view as a parameter). The > other thing is that _all_ my views will need this and to me that just > feels a bit dirty. I guess it is probably the best way, though. I suggested on the devel ml, that the urlresolver should be configurable, which would you allow to write an own which also uses the hostname to match sites. or even write one that uses a database :) hopefully they like the idea. kindly regards daniel -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2 (GNU/Linux) Comment: GnuPT 2.7.2 Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDvXFly/mkIQp7AD0RAqBXAKCq+WoHMqky1DVJyo/QRkcggJ0LTQCePClE DAER0y/KzG32BgKkvFN8yz8= =0RbJ -END PGP SIGNATURE-
Re: making photo gallery
Kevin wrote: return map(*([None] + [value[i::cols] for i in range(0, cols)])) Nice, but why use all of that magic? return [value[i:i+cols] for i in range(0, len(value), 4)] your version actually returns [(1,2), (3,4)], iow a list of tuples.
Re: making photo gallery
Sean Perry wrote: Kevin wrote: return map(*([None] + [value[i::cols] for i in range(0, cols)])) Nice, but why use all of that magic? return [value[i:i+cols] for i in range(0, len(value), 4)] your version actually returns [(1,2), (3,4)], iow a list of tuples. where that last 4 is 'cols'. pasted my test version, doh.
ownership concept?
hi thanks for django, its a real pleasure to work with. I am working on an app where users will need to be able to view, add, edit, delete only their "own" objects. Will I not be able to implement this in Django at this time? thanks.
Re: ownership concept?
you can implement this with custom views. just put a where clause when you retreive the object list, and check the user-id when you retrieve it and error out if it isn't the owner. (or you haven't got the 'admin' flag set on your user) regards Ian. On 1/6/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > hi > > thanks for django, its a real pleasure to work with. > > I am working on an app where users will need to be able to view, add, > edit, delete only their "own" objects. Will I not be able to implement > this in Django at this time? > > thanks. > > -- [EMAIL PROTECTED] -- blog: http://feh.holsman.net/ -- PH: ++61-3-9877-0909 If everything seems under control, you're not going fast enough. - Mario Andretti
Re: Data from multiple engines/data in one Django app (or project)
On 5 Jan 2006, at 17:48, mortenbagai wrote: Is there a way to model data from multiple, separate data sources in the same Django project? Not at the moment, but it's under active discussion: http://code.djangoproject.com/ticket/1142 Please add a brief description of your requirement to that ticket so we can be sure to accommodate you. Cheers, Simon
Re: ANN: "Snakes and Rubies" (Django/Rails meetup) video/audio available
Cool, feels like have been waiting for this video forever. ;-) Special cheers to Jacob's video editing efforts. I know how painful it could be. - Cheng Zhang On Jan 5, 2006, at 10:20 PM, Adrian Holovaty wrote: Last month, there was a Django/Rails meetup in Chicago, at which I spoke about Django and David H. of Rails spoke about Rails. Last night we made available video and audio of both presentations, plus the Q&A session. Jacob spent a *ton* of time condensing the 13 hours of raw video into nicely edited files for your downloading pleasure. Check them out here: http://www.djangoproject.com/snakesandrubies/ Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org
Re: ownership concept?
thanks!
Adding errors into the form?
Folks, I'm working on an application that makes use of Django Captcha. I want to be able to display the captcha validation error along with other errors on the form after post, and here is my view code (please note the story model is the same as django.models.storys so the manipulator is django.models.storys.StoryManipulatorAdd): def create_story(request, captcha_error): manipulator = storys.AddManipulator() if request.POST: new_data = request.POST.copy() new_data['submission_user'] = str(request.user.id) errors = manipulator.get_validation_errors(new_data) if captcha_error: errors['captcha_word'] = captcha_error manipulator.do_html2python(new_data) if not errors: new_story = manipulator.save(new_data) return HttpResponseRedirect('/category/' + new_data['category_id']) else: new_data = manipulator.flatten_data() errors = {} form = formfields.FormWrapper(manipulator, new_data, errors) #debug print form return render_to_response('faxian/create_form', {'form': form}, context_instance=Context(request)) Below is the related template: {% load captcha %} {% captcha %} {% trans "Please enter the word you see in the picture" %} {% if form.captcha_word.errors %}*** {{ form.captcha_word.errors|join:", " }} When I print out the form for debugging, I do see the following: {'error_dict': {'captcha_word': ['Invalid word.']}, 'manipulator': , ...} but it seems from.captcha_word.errors doesn't get the value out of form, as the error message is not displayed on the browser. Any clue would be appreciated! --Feiyu
Re: Adding errors into the form?
Hi Feiyu. the problem is the captcha validation is the manipulator out of scope when the the validation is run. there are 2 choices. 1. the captcha view should throw a validation error (not a 404).. thats my bug, and I will fix it shortly. This will mean you will get the error message on your edit page. 2. the 2nd is to integrate the captcha code into your view itself. in order to do this cleanly I should refactor the code so you have a function to call something like is_valid_captcha( request.POST ) and let you create you own validation error. I'll try to get around to it tomorrow. On 1/6/06, FX <[EMAIL PROTECTED]> wrote: > > Folks, > I'm working on an application that makes use of Django Captcha. I want > to be able to display the captcha validation error along with other > errors on the form after post, and here is my view code (please note > the story model is the same as django.models.storys so the manipulator > is django.models.storys.StoryManipulatorAdd): > > def create_story(request, captcha_error): > manipulator = storys.AddManipulator() > > if request.POST: > new_data = request.POST.copy() > new_data['submission_user'] = str(request.user.id) > errors = manipulator.get_validation_errors(new_data) > if captcha_error: > errors['captcha_word'] = captcha_error > manipulator.do_html2python(new_data) > > if not errors: > new_story = manipulator.save(new_data) > > return HttpResponseRedirect('/category/' + > new_data['category_id']) > else: > new_data = manipulator.flatten_data() > errors = {} > > form = formfields.FormWrapper(manipulator, new_data, errors) > #debug > print form > return render_to_response('faxian/create_form', {'form': form}, > context_instance=Context(request)) > > Below is the related template: > {% load captcha %} > > {% captcha %} > > {% trans "Please enter the word you see in the picture" %} {% if > form.captcha_word.errors %}*** {{ form.captcha_word.errors|join:", " > }} > value="{{captcha_id}}"/> height=60 /> > > > > When I print out the form for debugging, I do see the following: > {'error_dict': {'captcha_word': ['Invalid word.']}, 'manipulator': > , ...} > > but it seems from.captcha_word.errors doesn't get the value out of > form, as the error message is not displayed on the browser. > > Any clue would be appreciated! > > --Feiyu > > -- [EMAIL PROTECTED] -- blog: http://feh.holsman.net/ -- PH: ++61-3-9877-0909 If everything seems under control, you're not going fast enough. - Mario Andretti
Re: ownership concept?
On Friday 06 Jan 2006 7:23 am, [EMAIL PROTECTED] wrote: > hi > > thanks for django, its a real pleasure to work with. hi george - nice to see you on this list ;-) -- regards kg http://www.livejournal.com/users/lawgon tally ho! http://avsap.org.in ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!
Re: Adding errors into the form?
Hi Ian, Thanks for the prompt reply. (which time zone are you in?) I made some modifications to your Django Captcha that might be useful, so I'm attaching the patch (generated by svn) below. The changes are: 1. modified to make use of tempfile.mkdtemp() and tempfile.tempdir instead of "/tmp" to make it OS/platform argnostic. 2. modified the captcha_class to set context variables instead of returning hard coded html code, so the template author can use it with more flexibility 3. added an empty __init.py__ under zilbo/ so I can use the captcha app by refering it as zilbo.common.captcha patch: Index: __init__.py === --- common/captcha/views.py (revision 58) +++ common/captcha/views.py (working copy) @@ -1,3 +1,4 @@ +import tempfile from django.core.exceptions import Http404, ObjectDoesNotExist, ViewDoesNotExist from django.core.extensions import DjangoContext as Context from django.conf.settings import SITE_ID @@ -8,7 +9,7 @@ import Captcha def _getFactory( id ): -return Captcha.PersistentFactory("/tmp/pycaptcha_%d" % id ) +return Captcha.PersistentFactory(tempfile.gettempdir() + "/pycaptcha_%d" % id ) def image( request ): """ @@ -29,21 +30,25 @@ verify the captcha and then forward the request TBD: redirect to the original form with a validation error """ + +captcha_error = [] + if request.POST: id = request.POST["captcha_id"] word = request.POST["captcha_word"] test = _getFactory(SITE_ID).get(id) if not test: -raise Http404("invalid captcha id") +captcha_error.append('Invalid captcha id.') if not test.valid: -raise Http404("Test invalidated, try again") +captcha_error.append('Test invalidated, try again.') elif not test.testSolutions([word]): -raise Http404("try again") +captcha_error.append('Invalid word.') + mod_name, func_name = urlresolvers.get_mod_func(forward_to) try: func, ignore = getattr(__import__(mod_name, '', '', ['']), func_name), {} -return func( request, *arguments, **keywords) +return func(request, captcha_error, *arguments, **keywords) except (ImportError, AttributeError), e: raise ViewDoesNotExist, "Tried %s. Error was: %s" % (forward_to, str(e)) @@ -52,21 +57,26 @@ verify the captcha and then forward the request for anonymous users only TBD: redirect to the original form with a validation error """ +captcha_error = [] + if request.POST and request.user.is_anonymous(): -id = request.POST["captcha_id"] -word = request.POST["captcha_word"] -test = _getFactory(SITE_ID).get(id) -if not test: -raise Http404("invalid captcha id") -if not test.valid: -raise Http404("Test invalidated, try again") -elif not test.testSolutions([word]): -raise Http404("try again") + +if request.POST: +id = request.POST["captcha_id"] +word = request.POST["captcha_word"] +test = _getFactory(SITE_ID).get(id) +if not test: +captcha_error.append('Invalid captcha id.') +if not test.valid: +captcha_error.append('Test invalidated, try again.') +elif not test.testSolutions([word]): +captcha_error.append('Invalid word.') + mod_name, func_name = urlresolvers.get_mod_func(forward_to) try: func, ignore = getattr(__import__(mod_name, '', '', ['']), func_name), {} -return func( request, *arguments, **keywords) +return func( request, captcha_error, *arguments, **keywords) except (ImportError, AttributeError), e: raise ViewDoesNotExist, "Tried %s. Error was: %s" % (forward_to, str(e)) Index: common/captcha/templatetags/captcha.py === --- common/captcha/templatetags/captcha.py (revision 58) +++ common/captcha/templatetags/captcha.py (working copy) @@ -1,3 +1,4 @@ +import tempfile from django.core import template from django.conf.settings import SITE_ID import Captcha @@ -3,9 +4,26 @@ from Captcha.Visual import Tests +tempfile.mkdtemp() + +#TODO change this to be generic def _getFactory(id): -return Captcha.PersistentFactory("/tmp/pycaptcha_%d" % id ) +return Captcha.PersistentFactory(tempfile.gettempdir() + "/pycaptcha_%d" % id ) +#TODO change the tag to be more generic so we can customize the language and the size of the image, etc class captcha_class(template.Node): -""" return a image and a input box """ +""" generate a captcha image and specify the related input box parameters. + +Basically you have the following context variables: +captcha_image: the url to the captcha image +captcha_input_name: the input box name to submit the captcha w