Re: Python-specific question: variable scope

2007-03-30 Thread Rubic
b.py: import a ... def test(): print a.x -- Jeff Bauer Rubicon, Inc. On Mar 30, 6:43 am, "Aidas Bendoraitis" <[EMAIL PROTECTED]> wrote: > Let's say I have the files main.py, a.py and b.py > > main.py: > --- > x="some local value" > import a > ... > > a.py: >

Re: development server

2007-03-29 Thread Rubic
On Mar 29, 4:28 pm, "Adrian Holovaty" <[EMAIL PROTECTED]> wrote: > Strange -- I rarely (if ever) have had the runserver crash on me, and > I use it almost every day. Ditto. I don't think I've crashed it but once in three month's of development. -- Jeff Bauer Rubicon, Inc.

Re: newforms and output of required fields

2007-03-20 Thread Rubic
On Mar 20, 4:27 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I have explained the technique with example code here: > http://code.djangoproject.com/wiki/TemplatedForm Very nice, Alex. You might consider adding this code to the djangosnippets.org site. FWIW, you can replace the first 4

Titus Brown's PyCon '07 talk

2007-03-17 Thread Rubic
My second favorite talk at PyCon 2007 (excepting only the first day's keynote) was Titus Brown's discussion and demo on testing. He demonstrated twill, nose, wsgi_intercept, pinocchio, and scotch -- on both TurboGears and Django frameworks. He's now put together all the source code and demos

Re: newb: newforms and passing an extra parameter: forms.SalesForm(request.POST, p_id)

2007-03-17 Thread Rubic
On Mar 16, 8:17 pm, "johnny" <[EMAIL PROTECTED]> wrote: > >self.data.get('p_id') > > I tried it, getting error: > Exception Type: AttributeError > Exception Value: 'str' object has no attribute 'get' You are calling this as a method from SalesForm? Perhaps you'd better post a minimal

Re: to database or template

2007-03-17 Thread Rubic
On Mar 17, 2:47 pm, enquest <[EMAIL PROTECTED]> wrote: > Would you > A. use the view type1 = article.objects.filter(...) > type2 = article.objects.filter(...) > idem > idem > > OR > B. use the template and use in the template IF condition I think most people here will

Re: newb: newforms and passing an extra parameter: forms.SalesForm(request.POST, p_id)

2007-03-16 Thread Rubic
On Mar 16, 4:49 pm, "johnny" <[EMAIL PROTECTED]> wrote: > Now within SalesForm, how do I get p_id? self.data.get('p_id') -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django

Re: Preventing Multiple Logins

2007-03-16 Thread Rubic
The quick answer would be to check through the session data for a matching user id, but there's one possible wrinkle: How do you know when a user has logged off? In my case (not yet implemented), I'll have a timeout, but that still doesn't address the issue of a user losing a connection and

Re: validating using newforms

2007-03-16 Thread Rubic
I don't work much with form_for_model, but you could probably do something like this: IconForm = forms.models.form_for_model(Icon) if request.method == 'POST': form = IconForm(request.POST) Then perform your own validation, assigning an error to the field and returning: context =

Re: newb: newforms and passing an extra parameter: forms.SalesForm(request.POST, p_id)

2007-03-16 Thread Rubic
johnny, Place p_id as a field in the template (it can be a hidden) so you don't need to pass it as a parameter to SalesForm. If you still need to override the __init__ method in SalesForm, do it in the following manner: class SalesForm(forms.Form): def __init__(self, *args, **kwargs):

Re: Newforms: Is the current method of multiple field comparison the best way?

2007-03-16 Thread Rubic
On Mar 16, 2:18 pm, "James Bennett" <[EMAIL PROTECTED]> wrote: > And that distinction -- between Field-level > validation and Form-level validation -- also > makes intuitive sense to me; it feels right > that a Field only needs to know about itself, I'm not particularly concerned about field

Re: newforms with no pre-set number of fields

2007-03-16 Thread Rubic
Just use a ChoiceField with a radio or checkbox widget. http://www.djangosnippets.org/snippets/26/ -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to

Re: validating using newforms

2007-03-16 Thread Rubic
Benedict, You add a clean_XXX method to your form class, where XXX corresponds to the field name you wish to validate. In your clean_XXX method, you return self.clean_data['XXX'] if your data validates, otherwise raise a ValidationError exception. I just posted a similar response on this

Re: Select filled with data from a table

2007-03-15 Thread Rubic
On Mar 15, 3:13 pm, "Grupo Django" <[EMAIL PROTECTED]> wrote: > Note: I can't use "form_for_model" because it doesn't validate the > date fields all right. Define validation methods for your date fields, e.g.: def clean_fecha_inicio_publicacion(self): dt =

Re: Newforms - Dynamic Fields from a queryset

2007-03-15 Thread Rubic
On Mar 15, 12:30 pm, "Tipan" <[EMAIL PROTECTED]> wrote: > Realised my daft error in creating the dictionary. I've resolved that > now and can happily pass the queryset data to the Form class by > creating the dict. However, I'm still not sure how to pass the number > of records to the Form class.

Re: transactions and unique variables:

2007-03-15 Thread Rubic
Bram, Try removing (commenting out) the transaction decorator and transaction.commit(), then re-run your code. The ProgrammingError exception may be hiding the real exception. At least that's been my experience. -- Jeff Bauer Rubicon, Inc.

Re: Please add to the Django Tutorials list

2007-03-14 Thread Rubic
On Mar 14, 7:27 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I've just added an entire page to the wiki about tutorials > (http://code.djangoproject.com/wiki/Tutorials), with subcategories etc. Very nice, especially the categories. Thanks! -- Jeff Bauer Rubicon, Inc.

Re: Django models, detect whether value comes from db, or has explicitly been supplied.

2007-03-14 Thread Rubic
Assuming you've got a 'mydate' attribute: mydate = models.DateField(null=True) You can conditionally assign it if null: import datetime art = Article.objects.get(pk=1) if not art.mydate: art.mydate = datetime.date.today() art.save() -- Jeff Bauer Rubicon, Inc.

Re: models.ForeignKey problem

2007-03-14 Thread Rubic
Roland, The error message isn't the most helpful. ;-) I had a similar problem back in January and tracked it down to ticket #2536. My workaround was changing the name of the ForeignKey attribute -- in your case 'project' -- to another name. -- Jeff Bauer Rubicon, Inc.

Re: Newforms - Dynamic Fields from a queryset

2007-03-14 Thread Rubic
Tipan, I've posted a code snippet that I think addresses your issue: http://www.djangosnippets.org/snippets/82/ -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To

Re: Model question

2007-03-13 Thread Rubic
Gustav, you're probably going to want a third table: EmployeeDeptHistory = id employee_id department_id transfer_date Add a field attribute in the employee table that references this history. -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~

Re: newforms status

2007-03-13 Thread Rubic
On Mar 13, 10:27 am, "Aljosa Mohorovic" <[EMAIL PROTECTED]> wrote: > what's the status of newforms? http://tinyurl.com/2mtctq -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django

Re: django server: reload and samba share...

2007-03-13 Thread Rubic
On Mar 13, 9:17 am, Jens Diemer <[EMAIL PROTECTED]> wrote: > My sources are on a linux samba share. I used this share under windows > xp and start the django developer server from this share. > > The reload mechanism don't work! > > When i copy the source from the share into my local filesystem,

Re: How much work has been done with newforms?

2007-03-12 Thread Rubic
Grupo Django: > I'm programming a website in django and I'd > like to know more about newfors, since I left > the forms to the end, but now I have to start > with them. I think newforms is almost production-ready and would advise anyone starting a new project to consider using it in favor of

Re: Intializing newforms Form objects

2007-03-08 Thread Rubic
Anders, I think the simple answer is for foreign keys (including ChoiceFields when they're foreign keys), you want to pass it the id/pk of the object. If the ChoiceFields are a list of tuples, just pass it the value. For multiple selection values, pass it a list of the values you want

Re: Marking a DateField event as "repeating"

2007-03-07 Thread Rubic
On Mar 7, 7:33 pm, "Jay Parlar" <[EMAIL PROTECTED]> wrote: > When I render a calendar, I render one month at a time. Any > suggestions on an efficient way to query the db for all the events in > a given month? I don't know enough about your calendar application, but since we're talking about RFC

Re: Manually runing daily_cleanup.py

2007-03-06 Thread Rubic
You can do something like this (all in a single command line), assuming "myproject" is in PYTHONPATH: DJANGO_SETTINGS_MODULE="settings" ./daily_cleanup.py -or- DJANGO_SETTINGS_MODULE="myproject.settings" ./daily_cleanup.py Note: You won't be able to run the above script, unless you can do

Re: iCal like interface in the Admin?

2007-03-06 Thread Rubic
Jay, I would think you'd want to do a custom form for something like this. I'll be doing something similar soon for a scheduling system. You're familiar with the dateutil module? http://labix.org/python-dateutil -- Jeff Bauer Rubicon, Inc.

Re: creating a website log

2007-03-05 Thread Rubic
If the goal is to write the actions to a log file, limodou's recommendation for using signals is easier to implement. I'm more or less duplicating the admin approach in my application. -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~ You received this message

Re: creating a website log

2007-03-05 Thread Rubic
My solution is this: I've ripped out some stuff from the old admin code and written AppLogModel with three methods: def add(self, request): def remove(self, request): def update(self, request): The add/update methods call save() and remove calls delete(). Each method invokes a log

Re: newb: Prevent user Repeating SAME Tags over and over

2007-03-01 Thread Rubic
There's no set data field for models, but if you wanted to store the value as a string you could serialize it: >>> from django.utils import simplejson >>> simplejson.dumps(list(set(('tag1', 'tag2', 'tag1' '["tag1", "tag2"]' Then when you retrieve it, reverse the process: >>>

Re: Limiting choices in a generated form

2007-02-28 Thread Rubic
Choices needs to be a sequence of (id, value) tuples. List comprehensions are probably the most convenient way to do this: http://www.djangosnippets.org/snippets/26/ -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~ You received this message because you are

Re: ChoiceField: where to initialize choices

2007-02-28 Thread Rubic
Can you add 'required=False' to your MultipleChoiceFields? -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: Django snippets

2007-02-28 Thread Rubic
In just the past few days, while djangosnippets.org was under active development (and even down for several hours), the number of submissions has grown to 45. Pretty cool. Anyone care to guess when it will break 100? Kudos to James for setting up this site. -- Jeff Bauer Rubicon, Inc.

Model.add() ?

2007-02-28 Thread Rubic
Responding to Arvind's post on Django developer: http://tinyurl.com/39d4vc In some models, I have add() and update() methods which call save() so I can perform extra operations. Since my app knows whether I want to add vs. update, there's no extra query involved unless I choose to make one by

Re: Unique Id's across several classes/tables

2007-02-27 Thread Rubic
> Is it possible to have the ID field be unique across several classes > or tables? What i would like to do is, given the ID, load the object > of that type out of the database. Does this make sense, and is it > possible? No, it doesn't make sense <0.5 wink>, but here's how you might do it.

Re: newb: date_of_birth field using SelectDateWidget

2007-02-27 Thread Rubic
newsforms doctest demonstrates how to use SelectDateWidget: trunk/tests/regressiontests/forms/tests.py -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post

Re: database table prefix

2007-02-27 Thread Rubic
You could assign DATABASE_PREFIX as an environment variable, then have settings.py get the value (untested): # settings.py import os DATABASE_PREFIX = os.environ['DATABASE_PREFIX'] DATABASE_NAME = "site_%s_foo" % DATABASE_PREFIX Then run manage.py from the command line: $

Re: NOOB: default value in the ChoiceField?

2007-02-27 Thread Rubic
Use the 'initial' keyword arg: http://www.djangoproject.com/documentation/newforms/#initial -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group,

Re: rendering dynamic fields in newforms

2007-02-18 Thread Rubic
On Feb 18, 12:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Looks like you are rendering out the form class itself rather than an > instance of the form. Monster, Thanks, but Honza had the correct reply. I need to access the individual fields in the template, and BoundField is the

rendering dynamic fields in newforms

2007-02-16 Thread Rubic
Hi, I'm the 985th person to attempt dynamic fields in newforms. ;-) Actually I've been able to do lots of dynamic stuff in newforms. It's rendering the forms in templates that sometimes confuses me. For example, given the following code to build a form based on an arbitrary number of

newforms field attributes

2007-02-16 Thread Rubic
I find myself occassionally tripping over how field attributes are handled in newforms because it follows a Python convention of declaration, but doesn't assign them directly to the form instance. >>> from django import newforms as forms >>> class XForm(forms.Form): ... xattr = '42' ...

Re: Deploying multiple sites on one computer using SSL

2007-02-12 Thread Rubic
On Feb 12, 4:46 pm, "oggie rob" <[EMAIL PROTECTED]> wrote: > You can specify the key/passkey files in the virtual > host directive, which would probably be the most > manageable way to do it: > http://www.apache-ssl.org/docs.html#SSLCertificateFile > However, if you use a wildcard you can use the

Re: Radio and Checkbox rendering

2007-02-12 Thread Rubic
Have you looked into passing a widget attribute into your field? You can either subclass a widget or create one from scratch. -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django

Re: Deploying multiple sites on one computer using SSL

2007-02-12 Thread Rubic
On Feb 12, 2:37 pm, "oggie rob" <[EMAIL PROTECTED]> wrote: > For the cons, not true, really. You can use the same IP address. Your advice contradicts my (very limited) understanding of how SSL works, so please inform me of where my ignorance lies ... We're talking about *named* virtual

Re: OT: .pystartup

2007-01-28 Thread Rubic
On Jan 28, 2:50 pm, "Adrian Holovaty" <[EMAIL PROTECTED]> wrote: > The "manage.py shell" command doesn't take into account your > .pystartup file, but that would be a nice improvement if it would. If > you could figure out how to make that happen and provide a patch, > we'll integrate it into

Re: newforms: are FloatField and HiddenField missed yet ?

2007-01-24 Thread Rubic
Since Python 2.3 compatibility is an issue, per ticket #3238, here are a couple possibilities: (a) try/except import decimal and fall back to float if decimal is not available. (b) offer separate FloatField and a DecimalField in newforms. I'm -1 on (a) and +0 on (b). I find the

Re: dynamic form with newforms

2007-01-23 Thread Rubic
You can do something like this (untested): class Survey(models.Model): question = models.CharField(maxlength=100) class SurveyForm(forms.form): def __init__(self, *args, **kwargs): super(SurveyForm, self).__init__(*args, **kwargs) for o in Survey.objects.all():

Re: Test Model under shell

2007-01-23 Thread Rubic
On Jan 23, 9:16 pm, Le Van <[EMAIL PROTECTED]> wrote: > I need to run manage.py sync to reflect the change. > I don't like it at all. Do I need to run mange.py sync or is there > another way to test ? You can call the django.core.management functions from your own code. I do something similar

Re: Splitting models.py into separate modules

2007-01-19 Thread Rubic
Here's another possibility if you're still having problems with __init__.py. Assuming you've got your other modules in the directory: mymodules/ othermodels.py Put a conventional models.py file in your app directory: myapp/ models.py Then import othermodels classes into models: #

Re: subclassing in newforms

2007-01-17 Thread Rubic
Adrian Holovaty wrote: Note that this behavior is up for discussion if many people find it inconvenient. My initial thought is that it's a bit unbalanced to allow for the definition of extra fields in a subclass but not allowing the *removal* of fields in the same way. Building forms is is

Re: How to create a simple PDF

2007-01-17 Thread Rubic
I don't think TinyRML is as powerful as RML, but you can't beat the price! Is TinyRML being actively maintained? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send

Re: subclassing in newforms

2007-01-17 Thread Rubic
Bram - Smartelectronix wrote: I'm trying to do subclassing using newforms, but anything in the subclass just doesn't get passed on to the superclass: Maybe this would work for you? class ExtendedForm(BaseForm): def __init__(self, *args, **kwargs): super(BaseForm,

Re: mod_python/sqlite status

2007-01-16 Thread Rubic
Honza Král wrote: definitely, if you have more that one user, you should definetely run a dedicated db server, preferably one that supports transactions - MySQL with InnoDB engine or postgreSQL (my choice ;) ) You may have already known this, but SQLite does support transactions. I'm

Re: A calendar-like view in Django/Python...

2007-01-16 Thread Rubic
ashwoods wrote: using ical would probably be interesting too... http://www.devoesquared.com/Software/iCal_Module Some additional icalendar modules written in Python: http://codespeak.net/icalendar/ http://vobject.skyhouseconsulting.com -- Jeff Bauer Rubicon, Inc.

Re: Initialize _big_ form

2007-01-16 Thread Rubic
Adrian Holovaty wrote: Disclaimer: It does not yet map all database field types to the correct form field/widget types, but it's a start. FWIW: I've been putting a little helper function in my views.py to conditionally tweak any rough edges ... def model2form(pk): if not pk:

Re: newforms : how to display as_ul from views.py

2007-01-15 Thread Rubic
Ramdas, in your template: {{ form.as_ul }} -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: newforms tip: dynamic ChoiceField

2007-01-14 Thread Rubic
I just read Honza Král's post where he describes handling this in __init__: http://tinyurl.com/ync6y9 -- Jeff Bauer Rubicon, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to

newforms tip: dynamic ChoiceField

2007-01-14 Thread Rubic
I've been using newforms for a few days now and just ran across something in ChoiceField that might be worth sharing. The most common use case for a choice field is to pass a static list of choices. In the example below, it's a list of flavor choices: model.py: class Flavor(models.Model):

Re: dividing up views.py into multiple files

2007-01-10 Thread Rubic
Stefan Foulis wrote: > what I'm trying to do is divide up the views.py file into multiple > files because the single views.py file in some of my apps is getting > very cluttered. > > I tried just making a views subdirectory and then placing multiple > files with groups of views inside Ditto to

post-login processing

2007-01-06 Thread Rubic
When a user logs on, I want to invoke a special method. There doesn't appear to be a way to add a hook/callback to django.contrib.auth.views.login, so my approach is to: 1. Create mysite/login/views.py and copy the login/logout methods from django into it. Add code to invoke post-login

Re: Sharing models between apps

2007-01-02 Thread Rubic
Russell Keith-Magee wrote: You have imported the 'source' model to allow access to referral type as a Python module - but have you added 'source' to INSTALLED_APPS? If you don't do this step, Django doesn't know about the model, so it can't validate the foreign key. Of course. Thanks for the

Sharing models between apps

2007-01-02 Thread Rubic
I'm responding to a thread over 60 days old: http://tinyurl.com/ycmj9l Guillermo implies that a model should be easily shared between Django applications via import. However, if I attempt to move Model class to a shared module, the model won't validate. For example: class