Re: Composite Primary Key Support
What are the downsides of just importing & using SQLAlchemy (which supports composite PK) in a Django program? On Sep 3, 10:43 pm, Russell Keith-Magee wrote: > On Sat, Sep 4, 2010 at 7:17 AM, Brendon wrote: > > I have a project where we have an existing database which uses > > composite (multiple) primary keys for some of the tables. I want to > > move everything over from PHP into DJango without changing the DB. > > Reading the DJango docs though, it seems composite primary keys are > > not supported. I looked online and found that someone was working on > > this, but just noticed then that the ticket was closed and marked as > > "wontfix". > > >http://code.djangoproject.com/ticket/373 > > You must be looking at a different page to me, because this ticket is > open and marked "accepted and assigned" when i look at it. > > > Can anyone tell me for sure if this support has been abandoned or at > > least any information on the status of this? > > > I wasn't sure if this was the best place to ask or django-developers. > > Please let me know i should move this question over. > > Mutli-column composite keys are not currently supported by Django. > Adding support for multi-column keys (primary or otherwise) is > something that has been long discussed, and there is agreement that it > is a desirable feature -- which is why the ticket is marked accepted. > > What is missing is someone to actually do the work. It's easy to get a > basic implementation working, but there are a lot of nasty edge cases > in admin and general usage that need to be resolved. Nothing is going > to get committed to trunk until these issues have been sorted out. > > To the best of my knowledge, nobody is actively working on this at the > moment. If you're interested in contributing, django-developers is the > place to put forward your ideas and plans. > > 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Composite Primary Key Support
On Sat, Sep 4, 2010 at 4:45 PM, Andy wrote: > What are the downsides of just importing & using SQLAlchemy (which > supports composite PK) in a Django program? Essentially you lose integration of models with the rest of Django. Most importantly, this means ModelForms and Admin. It may also limit your ability to use existing reusable applications. However, basic view processing, URL dispatch, non-model forms and most other parts of Django that don't have model interactions will all work as is. You may also be able to implement some form of hybrid; using Django models for the models that don't require composite primary keys, but SQLAlchemy for the models that do. In this setup, you would only lose admin and forms for the models that don't have a Django representation. You may also need to jump through some interesting hoops in order to get foreign keys working between models represented in the two systems. Ultimately, you have to make a value call based on your own needs. 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-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: windows7, django-admin.py, system variables, no module named django.core
On 3 September 2010 19:42, gintare wrote: > Hello, > > I mean the correct way of running django seems to be to add to windows > environmental variable PATH c:/first/Python26/Lib/site-packages/ > Django-1.2.1/django/bin > and when run > $ cmd > $ django-admin.py startproject mysite > > the question, why importing management from django.core do not work? > from django.core import management > Error: No module django.core > > the module is under c:/first/Python26/Lib/site-packages/Django-1.2.1/ > django > I mean it seems cmd must know where are all django modules. How? How did you install Django? In c:/first/Python26/Lib/site-packages, is there a .pth file? If so, what is in it? It sounds like you did not install Django properly - you just unpacked it inside c:/first/Python26/Lib/site-packages. There's a bit more to it. The best way to do it is to use the setup script provided with Django (if you're doing this, do NOT unpack the archive inside site-packages; the setup script will do the copying for you), or use easy_install or pip (which you may have to install separately). To use the provided setup script, simply unpack the Django tarball to somewhere temporary. The open the command prompt at that location, and type - python setup.py install And Python should do the rest. You should have a working Django setup by the end. Also, C:\first\Python26\Scripts should be in your Windows PATH, but none of the other Python related paths. Python already knows about its site-packages directory. And inside C:\first\Python26\Scripts, there should be a file named django-admin.py once the above setup script has finished. > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Regrouping forms in formsets
Hi! I just figured this one out and would like to share my solution for posterity: Since the formset in question is a ModelFormSet (which I forgot to mention in the above message, sorry!), the data for each form can be accessed using "form.instance". Thus, the regroup tag should read: {% regroup formset.forms by instance.attribute as forms_by_attribute %} {# ... looping over the regrouped list, as usual ... #} With this, the regrouping of forms works wonderfully. I hope this helps someone, someday :-) -Felix -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Chat application in Django
Dear Shamail It depends on your host. Serving real-time content over the web requires a web server that can do server push (e.g., Twisted, Tornado, ejabberd, etc.). If your host will let you install your own web server, you're fine. If your host insists on apache, ... I think server push is possible with apache, ... If you're sharing web server resources, your hosts might not be too friendly about your doing server push. If you can't run these systems with your current host, try them out on your own machine while you're looking for a new host;) Best wishes Ivan On Sep 3, 3:02 pm, Shamail Tayyab wrote: > Hi Ivan, > > This looks promising, could you also throw some light on how hosting > friendly this set up will be? > > Thanks > > On Fri, Sep 3, 2010 at 7:13 PM, Salman (shaq) Haq > wrote: > > > > > Hi guys, > > > I am the author of a 'A simple experiment with Hookbox' (see below). > > > Just wanted chime in and say that Hookbox is under development right > > now > > but it is looking very promising. A few people have deployed chat > > applications > > for high traffic websites using it already. The simplicity of Hookbox > > is a major strength. > > > Hotdot is based on Orbited, which is also a framework by the author of > > Hookbox. > > > A new feature coming up in Hookbox is the 'private message api' which > > allows > > messages to be passed from one client to another client rather simply. > > I've been following > > the mailing and people have already started posting demo code using > > this feature. > > > Hope this helps. > > > Best, > > Shaq > > > On Sep 1, 10:05 am, yves_s wrote: > >> I also looking for realtime messaging for django and found this two > >> links. > > >>http://www.clemesha.org/blog/realtime-web-apps-python-django-orbited-... > > >>http://bitshaq.com/2010/07/30/a-simple-experiment-with-hookbox/ > > >> yves > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- > Shamail Tayyab > Blog:http://shamail.in/blog -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Urlencode vs. iriencode
What's the difference between the template filters urlencode and iriencode? When should I use one over the other (or use both)? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Chat application in Django
On Aug 31, 4:31 am, Shamail Tayyab wrote: > Hi, > > I am working on a chat application in Django, how can I ensure that I > do not have to poll the server for any chat data. > > Possible approaches that I've been to: > > 1. BAD - use polling. > > 2. Use long polling - bad approach afa browser support is concerned. > > 3. Using sockets in flash - makes the application flash dependent. > > Is there some good way to do this? Or if there is something Django > specific? Something like HTTPBinding or any 3rd party tested libraries? > I am expected to provide support till IE6. :-( You might want to check out: http://hookbox.org/ -Preston > > Correct me if I am wrong, flash is available on 95% of the systems, this > approach looks like safest bet, is it good to go? > > Btw, how does Gmail and FB chat works? > > Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Problem with ModelForm
I try to Create forms from models I am facing error message with 'is_valid()' error is : { AttributeError at /add_db/ 'Input' object has no attribute 'is_valid' Request Method: POST Request URL:http://localhost/django/add_db/ Django Version: 1.2.1 Exception Type: AttributeError Exception Value: 'Input' object has no attribute 'is_valid' Exception Location: /home/jagdeep/mysite/add_db/views.py in add_db, line 11 Python Executable: /usr/bin/python Python Version: 2.6.5 } Coded file are given below: model.py : from django.db import models from django.forms import ModelForm class Input(models.Model): input1 = models.FloatField() input2 = models.FloatField() class Output(models.Model): out = models.ForeignKey(Input) output = models.FloatField() class InputForm(ModelForm): class Meta : model = Input class OutputForm(ModelForm): class Meta : model = Output View.py : from django.http import HttpResponseRedirect from django.shortcuts import render_to_response from mysite.add_db.models import * from django.template import RequestContext from django.core.urlresolvers import reverse def add_db(request): if request.method == 'POST': form = Input(request.POST) if form.is_valid(): cd = form.cleaned_data input1 = cd['input1'] input2 = cd['input2'] form.save() output = input1 + input2 return render_to_response('add_db/output.html', {'form': form, 'input1':input1, 'input2':input2, 'output':output}, context_instance=RequestContext(request)) else: form = Input() return render_to_response('add_db/add.html', {'form': form}, context_instance=RequestContext(request)) Please help. Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Problem with ModelForm
On Sep 4, 5:19 pm, Jagdeep Singh Malhi wrote: > I try to Create forms from models > I am facing error message with 'is_valid()' > > error is : > { > AttributeError at /add_db/ > > 'Input' object has no attribute 'is_valid' > > Request Method: POST > Request URL: http://localhost/django/add_db/ > Django Version: 1.2.1 > Exception Type: AttributeError > Exception Value: > > 'Input' object has no attribute 'is_valid' > > Exception Location: /home/jagdeep/mysite/add_db/views.py in add_db, > line 11 > Python Executable: /usr/bin/python > Python Version: 2.6.5 > > } > > Coded file are given below: > model.py : > from django.db import models > from django.forms import ModelForm > > class Input(models.Model): > input1 = models.FloatField() > input2 = models.FloatField() > > class Output(models.Model): > out = models.ForeignKey(Input) > output = models.FloatField() > > class InputForm(ModelForm): > class Meta : > model = Input > > class OutputForm(ModelForm): > class Meta : > model = Output > > View.py : > from django.http import HttpResponseRedirect > from django.shortcuts import render_to_response > from mysite.add_db.models import * > from django.template import RequestContext > from django.core.urlresolvers import reverse > > def add_db(request): > if request.method == 'POST': > form = Input(request.POST) > if form.is_valid(): > cd = form.cleaned_data > input1 = cd['input1'] > input2 = cd['input2'] > form.save() > output = input1 + input2 > > return render_to_response('add_db/output.html', {'form': > form, 'input1':input1, 'input2':input2, 'output':output}, > context_instance=RequestContext(request)) > else: > form = Input() > return render_to_response('add_db/add.html', {'form': form}, > context_instance=RequestContext(request)) > > Please help. > > Thanks Fairly obviously, you've instantiated the model - Input() - rather than the form - InputForm() - in both branches of the if statement of your view. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Spam filters for Django?
What about leveraging (google "askimet django") for all users and forcing non-logged in users (eg, anonymous, guests) to also solve a reCAPTCHA? -- Federico On 04/set/2010, at 08:31, Kenneth Gonsalves wrote: > On Fri, 2010-09-03 at 22:25 -0700, Andy wrote: >> Only logged in users will be allowed to post. But that wouldn't stop >> spammers from logging in and posting spam. > > depends on how the registration works. What I do is: > > 1. person fills in his username and email address > 2. he gets a mail with a link > 3. clicks on the link and has to fill in his username, and password > twice > > that extra step seems to baffle the spammers. > -- > regards > Kenneth Gonsalves > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
LIMITATIONS of django
sir what are the shortcomings and limitations of Django. i am newbie and got to develop my own cms using python. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: LIMITATIONS of django
On 09/04/10 11:45, samie wrote: sir what are the shortcomings and limitations of Django. i am newbie and got to develop my own cms using python. Some of the limitations I know of: - composite keys (long-range plans; alternatively, nothing prevents you from using SQLAlchemy or the like) - support for NoSQL databases (in the works for some DBs) - deployment (no $3/mo hosting service offers pure-Django support that I've found; though there is Google AppEngine which is Django-ish) - Py3k support Most folks here haven't found most of those dire impediments. -tkc -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: LIMITATIONS of django
This is not really an appropriate question. Django, like many frameworks is a collection of libraries written in some language. Django happens to be written in Python; as such, your proficiency with Python will have an effect on what you can and can't do with Django. Django provides a lot of useful tools to assist you along the way but it doesn't replace the need for solid coding skills in Python, HTML, JavaScript, and (at least some) knowledge of databases. So in short, you're limited only by your own knowledge. I'm sure a ruby or perl developer would say the same of their respective frameworks. Good luck Steve Sent from my iPhone On Sep 4, 2010, at 12:45 PM, samie wrote: > sir what are the shortcomings and limitations of Django. i am newbie > and got to develop my own cms using python. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Problem with ModelForm
> Fairly obviously, you've instantiated the model - Input() - rather > than the form - InputForm() - in both branches of the if statement of > your view. it works. Thanks Sir. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
DjangoCon Jobs Board
Looking to hire someone? Looking to get hired on? DjangoCon wants to help. If you are an employer looking for staff (and whether or not you will be at the conference), please sent a letter- or A4-sized original (PDFs preferred) document that we can print out and attach to the jobs board for display. If you are looking for a job (and whether you will be at the conference or not) please send an 8.5" x 5.5" or A5-sized original (PDFs preferred) document that we can print our and attach to the jobs board. We do not guarantee to display anything. This is a best-efforts attempt to provide a service to the Django community. regards Steve -- DjangoCon US 2010 September 7-9 http://djangocon.us/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Query Set Problem
In case anyone wants the solution, CSBuySell.objects.extra(select={'open_price':"open_price", 'close_price':"close_price",'low_price':"low_price",'high_price':"high_price", 'profit': "csbuysell_pl(open_price,close_price,low_price,high_price,buy_long,stop_sell,sell_short,stop_buy)"}, tables =['thesheet_dailystats'], where=['thesheet_dailystats.one_pair_id = csbuysell_csbuysell.one_pair_id AND thesheet_dailystats.the_date = csbuysell_csbuysell.the_date']) Notice this is also calling a stored procedure csbuysell_pl(...) On Sep 3, 2:19 pm, tresero wrote: > I want to convert this query: > > SELECT > c.id, > c.buy_long, > c.stop_sell, > c.sell_short, > c.stop_buy, > c.the_date, > p.symbol, > s.open_price, > s.high_price, > s.low_price, > s.close_price > FROM > csbuysell c, > onepair p, > dailystats s > WHERE > c.one_pair_id = p.id AND > s.one_pair_id = c.one_pair_id AND > s.the_date = c.the_date > order by the_date desc > > I can't seem to do it without custom sql, that breaks pagination to > use raw. > > There is no FK relationship between dailystats and csbuysell, hence > the need to do a where join. I figured that out, using > extra(where=['s.one_pair_id = c.one_pair_id. AND s.the_date = > c.the_date'], but > 1. how to add the from clause and then the fields in the query? > > Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django Admin adds trailing 0's
I have some fields that represent recommendations (forex). I modeled them as numeric(8,4) (postgresql). The problem is that the django admin automatically adds trailing 0's. I don't want that because in order to calculate profit/loss, I need to subtract the numbers (as integers, I eliminate the decimal points) and multiply by 10 (the leverage). I want the admin to save the number exactly as input. Postgres does not add trailing 0's, but Django does. Here are some samples and why the trailing 0's are wrong. 76.6000 - 77.3800 -- Converted should be 7660 - 7738 The correct answer should be -78, but eliminating the decimal creates this 766000 - 773800 or -7800, doing the math as floats is wrong as well: -(.78) =-7.8, not -78, so this actually works if I remove the decimal and then * 10. (loss should be 780) 1.3040 - 1.3090 -- Converted should be 13040 - 13090 the correct answer should be -50. Eliminating the decimals creates the correct answer in this case, but doing the math as float and then converting gives: .005 (I then remove the string leaving 5, not 50) (loss should be 500) Basically I need to know if there is a way to have django not add trailing 0's, then I can convert correctly. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ANN: PyMySQL 0.3
Hi Andy - Below is a patch that will let Django use pymysql if MySQLdb is not available. Currently it is not in use in production anywhere but I am hoping to change that soon. Currently its primary use is prototyping applications that are being developed on Mac OSX but deployed on Linux. If you are interested in using it in production please let me know and I will be sure to prioritize any tickets related to production issues. Simply search-replacing MySQLdb with pymysql in django/db/backends/ mysql/base.py and django/db/backends/mysql/introspection.py will get it to work. I will submit a patch soon that tries to import MySQLdb but falls back to pymysql if it is not available. Pete On Sep 3, 5:20 pm, Andy wrote: > Pete, > > Would you recommend PyMySQL for production use? > > Which parts of Django do I need to modify in order to use it with > PyMySQL instead of MySQLdb? > > Thanks. > > On Sep 3, 2:07 pm, Pete Hunt wrote:> I’m proud to > announce the release of PyMySQL 0.3. For those of you > > unfamiliar with PyMySQL, it is a pure-Python drop-in replacement for > > MySQLdb with an emphasis on compatibility with MySQLdb and for various > > Python implementations. I started working on the project due to my > > frustrations stemming from getting MySQLdb working on Snow Leopard. > > PyMySQL has been tested on CPython 2.3+, Jython, IronPython and PyPy, > > and we have an unreleased Python 3.0 branch in Subversion. I encourage > > anyone hoping to connect to MySQL from Python to check it out and > > report any bugs you might find! Our current focus has been bringing it > > up to compatibility with SQLAlchemy and Django, and we have by and > > large achieved that goal with a high level of performance. > > > This is of specific interest to Django users, as one can simply > > replace references to "MySQLdb" with "pymysql" and run their Django > > apps on platforms that are difficult to get working with MySQLdb (like > > Mac OSX Snow Leopard). > > > Check it out athttp://www.pymysql.org/. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Urlencode vs. iriencode
Anyone? I haven't found anything that describes the difference (except that one is for URI's and the other for URLs). On Sep 4, 8:52 am, Jordon Wii wrote: > What's the difference between the template filters urlencode and > iriencode? When should I use one over the other (or use both)? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Where and how should I write translations
Never heard about CLDR before, so your answer doesn't give much sense to me :( Django doesn't have complete implementation of internationalization? makemessages is then useless if I can not add custom strings without overwriting them by Django. Or is there really something I don't know about? Thanks, Martin On Thu, 02 Sep 2010 17:03:01 +0200, Tom Evans wrote: On Thu, Sep 2, 2010 at 2:15 PM, Martin Tiršel wrote: I tried to create second .po file with manual translations, but had no luck either :( `compilemessages` creates the second .mo file, but doesn't use it in the app. Only django.mo is used, but all my translations in django.po file are commented out after I run `makemessages`. In the documentation: "(The caveat with using variables or computed values, as in the previous two examples, is that Django's translation-string-detecting utility, django-admin.py makemessages, won't be able to find these strings. More on makemessages later.)" But there is no "later" :( Thanks, Martin I had to do some clever things to import languages names from the CLDR. I ended up writing a small management command (sorry, can't share the entire thing) which first of all runs makemessages for each language. This generates/updates the django.po files for each language. I then step through each of the languages, load the CLDR xml file, and manually update the generated po file, inserting/updating entries as necessary. Having added all the extra translations, I then run compilemessages, so they are always available. To update the po file, I use polib - which you can get standalone, but is also a part of the amazing django-rosetta. The code to add/update entries using polib is pretty straightforward. First load the po file, look for your key, if it isn't there add it. In code: for (lang, name) in settings.LANGUAGES: lang_po_path = os.path.join(settings.PROJECT_ROOT, '', 'locale', lang, 'LC_MESSAGES', 'django.po') po = polib.pofile(lang_po_path) cldr = self.load_cldr_data(lang, ccodes) for code in ccodes: idx = u'Country code %s' % code try: trans = cldr[code] except KeyError: self.debug("No translation for country code %s" % code) continue entry = po.find(idx) if entry: entry.msgstr = trans entry.obsolete = 0 else: entry = polib.POEntry(msgid=idx, msgstr=trans) entry.occurrences = [ ('Common Locale Data Repository', 1), ] entry.comment = 'Country name, imported from CLDR (Do not manually translate, translation is automatically updated!)' entry.tcomment = entry.comment entry.obsolete = 0 po.append(entry) po.save() Obviously, with your problem, you aren't adding the actual translations, just the msg id, so don't set msgstr. In this example, I'm adding translations for 'Country code AD' -> 'Country code ZW' (which will now translate into 'Andorra' -> 'Zimbabwe' :) Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Spam filters for Django?
the three most common ways are to only allow logged in users to post, captchas or akismet or a combination of the three. Sometimes Honey pot is very effective in combination with captcha. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Urlencode vs. iriencode
Here's the code for the two (the numbers at the start of each line are just line numbers from the file) - iriencode: 128 """ 129 Convert an Internationalized Resource Identifier (IRI) portion to a URI 130 portion that is suitable for inclusion in a URL. 131 132 This is the algorithm from section 3.1 of RFC 3987. However, since we are 133 assuming input is either UTF-8 or unicode already, we can simplify things a 134 little from the full method. 135 136 Returns an ASCII string containing the encoded result. 137 """ 138 # The list of safe characters here is constructed from the "reserved" and 139 # "unreserved" characters specified in sections 2.2 and 2.3 of RFC 3986: 140 # reserved= gen-delims / sub-delims 141 # gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" 142 # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" 143 # / "*" / "+" / "," / ";" / "=" 144 # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" 145 # Of the unreserved characters, urllib.quote already considers all but 146 # the ~ safe. 147 # The % character is also added to the list of safe characters here, as the 148 # end of section 3.1 of RFC 3987 specifically mentions that % must not be 149 # converted. 150 if iri is None: 151 return iri 152 return urllib.quote(smart_str(iri), safe="/#%[]=:;$&()+,!?*@'~") urlencode: 11 """ 12 A version of Python's urllib.quote() function that can operate on unicode 13 strings. The url is first UTF-8 encoded before quoting. The returned string 14 can safely be used as part of an argument to a subsequent iri_to_uri() call 15 without double-quoting occurring. 16 """ 17 return force_unicode(urllib.quote(smart_str(url), safe='/')) So iriencode only encodes the IRI portion (hence the longer list of safe characters), while URL will encode the entire URL, including any GET arguments and anchors. As for usage, I haven't encountered any IRIs, but I believe IRIs need to be encoded before inclusion in HTML (i.e. you can't just include the non-ASCII characters in HTML). As for urlencode, its main purpose is if you're including a URL in a form submission, e.g. the URL to go to after login. urlencode will do everything that iriencode does, but sometimes you might not want it to do that. On 5 September 2010 08:17, Jordon Wii wrote: > Anyone? I haven't found anything that describes the difference > (except that one is for URI's and the other for URLs). > > On Sep 4, 8:52 am, Jordon Wii wrote: >> What's the difference between the template filters urlencode and >> iriencode? When should I use one over the other (or use both)? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: ANN: PyMySQL 0.3
Thanks Pete. I'm definitely interested in using PyMySQL for production. I'm interested in running Django in an async mode using gevent (http:// www.gevent.org/). gevent provides a money patch that turns any Python code into non-blocking. The problem is that MySQLdb is written in C, so it'd still block, which would kinda defeat the whole purpose of having an async Django app if every database access is blocking. PyMySQL looks like could be a great solution for this problem. In fact there's already a thread in the gevent mailing list talking about PyMySQL. You might want to drop by: http://groups.google.com/group/gevent/browse_thread/thread/b5f7bf44b7690ed9 On Sep 4, 4:58 pm, Pete Hunt wrote: > Hi Andy - > > Below is a patch that will let Django use pymysql if MySQLdb is not > available. Currently it is not in use in production anywhere but I am > hoping to change that soon. Currently its primary use is prototyping > applications that are being developed on Mac OSX but deployed on > Linux. If you are interested in using it in production please let me > know and I will be sure to prioritize any tickets related to > production issues. > > Simply search-replacing MySQLdb with pymysql in django/db/backends/ > mysql/base.py and django/db/backends/mysql/introspection.py will get > it to work. I will submit a patch soon that tries to import MySQLdb > but falls back to pymysql if it is not available. > > Pete > > On Sep 3, 5:20 pm, Andy wrote: > > > > > Pete, > > > Would you recommend PyMySQL for production use? > > > Which parts of Django do I need to modify in order to use it with > > PyMySQL instead of MySQLdb? > > > Thanks. > > > On Sep 3, 2:07 pm, Pete Hunt wrote:> I’m proud to > > announce the release of PyMySQL 0.3. For those of you > > > unfamiliar with PyMySQL, it is a pure-Python drop-in replacement for > > > MySQLdb with an emphasis on compatibility with MySQLdb and for various > > > Python implementations. I started working on the project due to my > > > frustrations stemming from getting MySQLdb working on Snow Leopard. > > > PyMySQL has been tested on CPython 2.3+, Jython, IronPython and PyPy, > > > and we have an unreleased Python 3.0 branch in Subversion. I encourage > > > anyone hoping to connect to MySQL from Python to check it out and > > > report any bugs you might find! Our current focus has been bringing it > > > up to compatibility with SQLAlchemy and Django, and we have by and > > > large achieved that goal with a high level of performance. > > > > This is of specific interest to Django users, as one can simply > > > replace references to "MySQLdb" with "pymysql" and run their Django > > > apps on platforms that are difficult to get working with MySQLdb (like > > > Mac OSX Snow Leopard). > > > > Check it out athttp://www.pymysql.org/. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Pylons vs. Django
Hey everyone, I'm a new Python user and I'm looking for a web development framework to build a database-driven website. I've looked at the various Python web frameworks out there and I've settled on either Django or Pylons, but I'm not sure which to choose. Things I've heard about Django that I like: - All the Django documentation is in one place. - The community is larger = more help for newbies. - It has a handy admin interface for adding content quickly. Things I've heard about Pylons that I like: - It's easier to customize and swap components in and out. - It uses SQLAlchemy out of the box. (I've never used it, but I hear that it's better than Django's ORM) - It uses Mako out of the box. (Again, I've never used it, but I hear that it's better than Django's templating system). I'm not sure how important SQLAlchemy and Mako support is, so I'd like to hear opinions from some more experienced Python and Django users. Thanks, Feross -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Problem with ModelForm
On Sat, 2010-09-04 at 09:19 -0700, Jagdeep Singh Malhi wrote: > form = Input(request.POST) form = InputForm(request.POST) -- regards Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Urlencode vs. iriencode
Awesome, thank you. So as far as escaping user-entered data for use in URLs...urlencode is best? On Sep 4, 8:45 pm, Sam Lai wrote: > Here's the code for the two (the numbers at the start of each line are > just line numbers from the file) - > > iriencode: > 128 """ > 129 Convert an Internationalized Resource Identifier (IRI) portion to a > URI > 130 portion that is suitable for inclusion in a URL. > 131 > 132 This is the algorithm from section 3.1 of RFC 3987. However, > since we are > 133 assuming input is either UTF-8 or unicode already, we can > simplify things a > 134 little from the full method. > 135 > 136 Returns an ASCII string containing the encoded result. > 137 """ > 138 # The list of safe characters here is constructed from the > "reserved" and > 139 # "unreserved" characters specified in sections 2.2 and 2.3 of > RFC 3986: > 140 # reserved = gen-delims / sub-delims > 141 # gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" > 142 # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" > 143 # / "*" / "+" / "," / ";" / "=" > 144 # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" > 145 # Of the unreserved characters, urllib.quote already considers all but > 146 # the ~ safe. > 147 # The % character is also added to the list of safe characters > here, as the > 148 # end of section 3.1 of RFC 3987 specifically mentions that % > must not be > 149 # converted. > 150 if iri is None: > 151 return iri > 152 return urllib.quote(smart_str(iri), safe="/#%[]=:;$&()+,!?*@'~") > > urlencode: > 11 """ > 12 A version of Python's urllib.quote() function that can operate > on unicode > 13 strings. The url is first UTF-8 encoded before quoting. The > returned string > 14 can safely be used as part of an argument to a subsequent > iri_to_uri() call > 15 without double-quoting occurring. > 16 """ > 17 return force_unicode(urllib.quote(smart_str(url), safe='/')) > > So iriencode only encodes the IRI portion (hence the longer list of > safe characters), while URL will encode the entire URL, including any > GET arguments and anchors. > > As for usage, I haven't encountered any IRIs, but I believe IRIs need > to be encoded before inclusion in HTML (i.e. you can't just include > the non-ASCII characters in HTML). As for urlencode, its main purpose > is if you're including a URL in a form submission, e.g. the URL to go > to after login. urlencode will do everything that iriencode does, but > sometimes you might not want it to do that. > > On 5 September 2010 08:17, Jordon Wii wrote: > > > > > > > > > Anyone? I haven't found anything that describes the difference > > (except that one is for URI's and the other for URLs). > > > On Sep 4, 8:52 am, Jordon Wii wrote: > >> What's the difference between the template filters urlencode and > >> iriencode? When should I use one over the other (or use both)? > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Urlencode vs. iriencode
On 5 September 2010 16:18, Jordon Wii wrote: > Awesome, thank you. So as far as escaping user-entered data for use > in URLs...urlencode is best? I'd say so. I haven't really found a need for iriencode personally, and from the code, it seems that urlencode does everything iriencode does anyway. > On Sep 4, 8:45 pm, Sam Lai wrote: >> Here's the code for the two (the numbers at the start of each line are >> just line numbers from the file) - >> >> iriencode: >> 128 """ >> 129 Convert an Internationalized Resource Identifier (IRI) portion to a >> URI >> 130 portion that is suitable for inclusion in a URL. >> 131 >> 132 This is the algorithm from section 3.1 of RFC 3987. However, >> since we are >> 133 assuming input is either UTF-8 or unicode already, we can >> simplify things a >> 134 little from the full method. >> 135 >> 136 Returns an ASCII string containing the encoded result. >> 137 """ >> 138 # The list of safe characters here is constructed from the >> "reserved" and >> 139 # "unreserved" characters specified in sections 2.2 and 2.3 of >> RFC 3986: >> 140 # reserved = gen-delims / sub-delims >> 141 # gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" >> 142 # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" >> 143 # / "*" / "+" / "," / ";" / "=" >> 144 # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" >> 145 # Of the unreserved characters, urllib.quote already considers all >> but >> 146 # the ~ safe. >> 147 # The % character is also added to the list of safe characters >> here, as the >> 148 # end of section 3.1 of RFC 3987 specifically mentions that % >> must not be >> 149 # converted. >> 150 if iri is None: >> 151 return iri >> 152 return urllib.quote(smart_str(iri), safe="/#%[]=:;$&()+,!?*@'~") >> >> urlencode: >> 11 """ >> 12 A version of Python's urllib.quote() function that can operate >> on unicode >> 13 strings. The url is first UTF-8 encoded before quoting. The >> returned string >> 14 can safely be used as part of an argument to a subsequent >> iri_to_uri() call >> 15 without double-quoting occurring. >> 16 """ >> 17 return force_unicode(urllib.quote(smart_str(url), safe='/')) >> >> So iriencode only encodes the IRI portion (hence the longer list of >> safe characters), while URL will encode the entire URL, including any >> GET arguments and anchors. >> >> As for usage, I haven't encountered any IRIs, but I believe IRIs need >> to be encoded before inclusion in HTML (i.e. you can't just include >> the non-ASCII characters in HTML). As for urlencode, its main purpose >> is if you're including a URL in a form submission, e.g. the URL to go >> to after login. urlencode will do everything that iriencode does, but >> sometimes you might not want it to do that. >> >> On 5 September 2010 08:17, Jordon Wii wrote: >> >> >> >> >> >> >> >> > Anyone? I haven't found anything that describes the difference >> > (except that one is for URI's and the other for URLs). >> >> > On Sep 4, 8:52 am, Jordon Wii wrote: >> >> What's the difference between the template filters urlencode and >> >> iriencode? When should I use one over the other (or use both)? >> >> > -- >> > You received this message because you are subscribed to the Google Groups >> > "Django users" group. >> > To post to this group, send email to django-us...@googlegroups.com. >> > To unsubscribe from this group, send email to >> > django-users+unsubscr...@googlegroups.com. >> > For more options, visit this group >> > athttp://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.