Re: 'ascii' codec can't encode character u'\xe4'

2012-06-14 Thread Paulo Almeida
Hi, Have you tried using SetEnv directives in .htaccess to change the locale? I'm not sure how that would interact with wsgi, but maybe something like this: http://drumcoder.co.uk/blog/2010/nov/12/apache-environment-variables-and-mod_wsgi/ Of course you'd have to do it in .htaccess instead of

Re: Accessing request.user in a ModelAdmin function

2012-06-14 Thread Paulo Almeida
Hi Alireza, Yes, that did the trick! Thank you, Paulo On Thursday, June 14, 2012 2:26:46 PM UTC+1, Alireza Savand wrote: > > > > On Thursday, June 14, 2012 3:04:54 PM UTC+4, Paulo Almeida wrote: >> >> Hi, >> >> I would like to access the request.user in

Re: Accessing request.user in a ModelAdmin function

2012-06-14 Thread Paulo Almeida
ocs, and it's not obvious to me how to do it. Thanks, Paulo On Thursday, June 14, 2012 1:09:58 PM UTC+1, Paulo Almeida wrote: > > Hi Melvyn, > > I've only been reading the Django 1.2 docs, because it's what's > immediately available in my Linux distribution, but that would be an > excell

Re: Accessing request.user in a ModelAdmin function

2012-06-14 Thread Paulo Almeida
n 14-6-2012 13:04, Paulo Almeida wrote: > > > So then I could just add "is_endorsed" to the list_display variable to > have > > the endorsement status for that user in the Speaker list, in the Admin > > site. Of course, this doesn't work because request is

Accessing request.user in a ModelAdmin function

2012-06-14 Thread Paulo Almeida
in the is_endorsed function. I googled around and saw solutions for similar problems involving overrides of save_model, queryset or formfield_for_manytomany, but I couldn't adapt them to list_display, because I'm creating a function in the ModelAdmin, where I only know how to pass self and

Re: confusing query involving time ranges

2010-08-13 Thread Paulo Almeida
I see. What about Alec Shaner's suggestion? If you replace 'order_by' with 'latest' it will be similar to my suggestion with just two queries. - Paulo On Fri, Aug 13, 2010 at 8:28 AM, Emily Rodgers <emily.kate.rodg...@gmail.com > wrote: > On Aug 12, 10:00 pm, Paulo Almeida <ig

Re: confusing query involving time ranges

2010-08-12 Thread Paulo Almeida
Can you sequentially add the states for each foo? I'm thinking of something like: states = [] for foo in foos: foo_state = State.objects.filter(foo=foo, first_dt__lte=dt, last_dt__gte=dt) if foo_state: states.append(foo_state) else: states =

Re: Newbie Mistake Question

2010-08-07 Thread Paulo Almeida
Is your project named mysite? (That is, is the parent directory of 'polls' named 'mysite'?) -Paulo On Sat, Aug 7, 2010 at 3:20 AM, HawaiiMikeD wrote: > Hi all, > > Just starting out with the tutorial 1 and ran into what I hope is a > minor mistake. I've got my site

Re: Interpolation and comparation between 2 dates: easy and difficult at the same time

2010-08-07 Thread Paulo Almeida
17000s > > What do you think about? Perhaps I'm mading mistakes and can't understand > your reply. Anyway, thanks for reply :) > > Bye! > Álex González > > > On Fri, Aug 6, 2010 at 02:09, Paulo Almeida > <igcbioinformat...@gmail.com>wrote: > >> In the

Re: Finding Duration: Creating a context variable from two DateField model fields

2010-08-05 Thread Paulo Almeida
A function or property in the model would do nicely. You can check this page for more information: http://www.b-list.org/weblog/2006/aug/18/django-tips-using-properties-models-and-managers/ - Paulo On

Re: Interpolation and comparation between 2 dates: easy and difficult at the same time

2010-08-05 Thread Paulo Almeida
In the third case, I didn't understand why you didn't divide (his_to - his_from) / (my_to - my_from). Bearing that in mind, this made sense in my head, but analyze it carefully: def match(mf,mt,hf,ht): mydiff = diff_in_seconds(mf,mt) if (mf >= hf and mt <= ht) or (mf < hf and mt > ht):

Re: overriding model.save()

2010-08-05 Thread Paulo Almeida
I never tried this, but I think you could just delete the value from the form.cleaned_data dictionary, if you don't want it: if instance.my_field == some_value: del form.cleaned_data['my_field'] This would be in the view, before saving, so you wouldn't need to override anything. - Paulo On

Re: Need help with my Form.save() method. Trouble with ForeignKey and ManyToMany Fields.

2010-08-05 Thread Paulo Almeida
Can you check the POST data and see if 'username' is there? You can do it easily with Firefox's Firebug extension. - Paulo On Thu, Aug 5, 2010 at 6:24 AM, strayhand wrote: > So I'm rolling out my own registration form that should update the > following models: > > - User

Re: How to get the model name of an object in template?

2010-08-05 Thread Paulo Almeida
But _meta starts with an underscore, so you can't use it in the template, right? I'm still using Django 1.0.2, so I don't know if that has changed along the way. - Paulo On Thu, Aug 5, 2010 at 8:52 AM, Daniel Roseman wrote: > On Aug 4, 7:27 pm, "David.D"

Re: Saving formsets with multiple databases

2010-08-04 Thread Paulo Almeida
Sorry if this is obvious and you're looking for a more direct way, but If it's only the formset save that fails, I would suggest: instances = formset.save(commit=False) for instance in instances: instance.save(using=database) I have never used multiple databases though, so I don't know if

Re: problem : create form

2010-08-04 Thread Paulo Almeida
If possible, the easiest way would be to create a form based on a model (subclass ModelForm). When you save the form the values will be stores in the appropriate database fields. To answer your final question, the 4 part tutorial I mentioned covers that. - Paulo On Wed, Aug 4, 2010 at 10:09 AM,

Re: problem : create form

2010-08-04 Thread Paulo Almeida
Hi, SQL is created for models, not for forms. Maybe you should try following the tutorial first (it's near the top of the Django documentation page), and then move to other documentation for the specifics. - Paulo On Wed, Aug 4, 2010 at 9:19 AM, Jagdeep Singh Malhi

Re: how to make readonly in change but editable in add?

2010-08-04 Thread Paulo Almeida
Actually, what he wanted was just to override a field, and not the whole form, but he can do it with slight modifications of your code. He would override the form class he wants to modify, instead of creating a generic one, and instead of iterating all the fields he would just set the relevant

Altering object order in formsets with can_order

2010-05-05 Thread Paulo Almeida
can_order). Does that sound reasonable? Thanks for any help, Paulo Almeida -- 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 d

Re: django, reportlab and basedoctemplate | simpledoctemplate

2010-03-30 Thread Paulo Almeida
that is not accessible, cause it does not exist, at > > least i never defined it in any urls.py. > > Maybe thats the problem? Django tries to access a url which doesnt exist? > > > > > > Greetings > > Sven > > > > On Tue, Mar 30, 2010 at 10:55 PM, Sven

Re: django, reportlab and basedoctemplate | simpledoctemplate

2010-03-30 Thread Paulo Almeida
Ok, that is not easy to debug with so little information. Is the IndexError in views.py? Maybe there is a mistake in urls.py, caused by adding the url for the generate_pdf view? - Paulo On Tue, Mar 30, 2010 at 7:57 PM, Sven Richter wrote: > On Tue, Mar 30, 2010 at 8:21

Re: django, reportlab and basedoctemplate | simpledoctemplate

2010-03-30 Thread Paulo Almeida
I'm using Platypus (part of reportlab) to generate pdfs without micromanagement of Canvas elements. reportlab's documentation was very helpful to learn how to work with Paragraph, Table, Image, etc. Some code: # views.py @login_required def view_pdf(request, experiment_id): experiment =

Re: Use admin widgets in inlineformset_factory

2010-03-30 Thread Paulo Almeida
This may point you in the right direction: http://stackoverflow.com/questions/559361/inline-formset-in-django-removing-certain-fields Take home message is that you can pass a ModelForm subclass to the fomset constructor, so you can have a custom form. There is no example in that link though, and

Re: I am having issues with django test

2010-03-29 Thread Paulo Almeida
This doesn't answer your question, but it may help you solve the problem. I have this class in my tests: class LoggedInUser(TestCase): def setUp(self): user = User.objects.create_user(USER, 'm...@nowhere.com', PASS) self.client.login(username=user.username, password=PASS)

Re: change modelform values after POST

2010-03-29 Thread Paulo Almeida
It depends on what you want. You can set 'created_by' to blank=True and null=False, so it doesn't have to be filled but it is still mandatory in the database. Or, if you never want to set it in the form, you can make it 'editable=False' and it doesn't show up in the form, but it can still be NOT

Re: Templates: Looping, ifs and defaults

2010-03-24 Thread Paulo Almeida
Sorry, I hadn't understood your original problem, now I see why the nested ifs wouldn't work. Regarding your last question, I think a list of lists would be easier than dictionaries. You can append the product as the first item in each sublist and then iterate the list to get the rows and columns

Re: Templates: Looping, ifs and defaults

2010-03-24 Thread Paulo Almeida
I don't understand why is it obvious that an 'else' won't work. If a single {% else %} is not what you want, you can nest {% if %} clauses. But if you are doing this it can also mean that you should move this logic to the view and just pass the final table to the template. - Paulo On Wed, Mar

Re: More PYTHONPATH issues

2010-03-24 Thread Paulo Almeida
> current directory even with sudo > > On Mar 23, 7:53 pm, Paulo Almeida <igcbioinformat...@gmail.com> wrote: > > Just to clarify: if you run a python shell in > > /Library/Python/2.6/site-packages you can import django, but if you run > > anywhere else you can't? > &g

Re: Overriding admin Media class

2010-03-23 Thread Paulo Almeida
I don't have a working sample (never did this), but you may be looking for something like this: class Media: js = get_path() And in the class where you keep use_editor: def get_path(self) if self.use_editor: return path1 else: return path2 This is just an idea,

Re: More PYTHONPATH issues

2010-03-23 Thread Paulo Almeida
Just to clarify: if you run a python shell in /Library/Python/2.6/site-packages you can import django, but if you run anywhere else you can't? It seems weird that you can't cd into django's directory. - Paulo On Tue, Mar 23, 2010 at 9:13 PM, Riley wrote: > Hey all, > >

Re: Can't perform chmod on django-admin.py

2010-03-23 Thread Paulo Almeida
You should run the command as an administrator, as mentioned. In any case, if you type something like: python /usr/bin/django-admin.py startproject project_name it should work (where /usr/bin/ is the path to the django executable). - Paulo On Tue, Mar 23, 2010 at 10:05 PM, irishsteve

Re: Negate querysets

2010-03-23 Thread Paulo Almeida
Is there some way you can keep track of the queryset? I understand it's dynamic, and maybe complex, for you to be looking for this kind of solution, but if it were possible to have a variable or dictionary keeping track of what you add to the queryset, it might be possible to use it to build the

Re: Remove session on browser close

2010-03-22 Thread Paulo Almeida
Maybe I'm missing something obvious, but can't you pass the user to the template and use: {% if user.is_authenticated %} instead of: {% if form.thanks %} It doesn't solve the problem of logging out, but you don't have to handle the session manually. - Paulo On Mon, Mar 22, 2010 at 9:40 PM,

Re: Event more complicated forms / templates

2010-03-22 Thread Paulo Almeida
You could use inline formsets (have CustomerContactAnswer be a formset of CustomerContactQuestion) and then render the Answer forms as a table in the template. - Paulo On Mon, Mar 22, 2010 at 1:31 PM, ALJ wrote: > Is there any to have a table type form will variable

Re: Tagging - Extending by adding a rating?

2010-03-22 Thread Paulo Almeida
from scratch on this? > > Cheers, > Victor > > On Mar 22, 1:54 pm, Paulo Almeida <igcbioinformat...@gmail.com> wrote: > > A possible solution would be to create a Many To Many relationship > between > > articles and companies, with an intermediary model holding the

Re: Tagging - Extending by adding a rating?

2010-03-21 Thread Paulo Almeida
A possible solution would be to create a Many To Many relationship between articles and companies, with an intermediary model holding the ratings: http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships - Paulo On Mon, Mar 22, 2010 at 2:41 AM, Victor

Re: installation question

2010-03-21 Thread Paulo Almeida
You should run that on the Terminal (not Python, just regular shell), in the folder where you downloaded Django-1.1.1.tar.gz . - Paulo On Sun, Mar 21, 2010 at 10:39 PM, yangyang wrote: > I'm trying to download Django on my Mac OS X 10.4.11. I have download > Python 2.6.4. And

Re: Strings in page in []

2010-03-21 Thread Paulo Almeida
It's not a matter of stripping the brackets, the problem is you are getting a list. I suppose you would get the result you want with the following code: {% if flash %} {% for key, value in flash.items %} {% for v in value %} {{ v }} {% endfor%}

Re: Forms with read only fields

2010-03-20 Thread Paulo Almeida
You can also do that by overriding the form's __init__ : http://stackoverflow.com/questions/324477/in-a-django-form-how-to-make-a-field-readonly-or-disabled-so-that-it-cannot-be You can pass the user to init and disable fields depending on that parameter. - Paulo On Sat, Mar 20, 2010 at 4:02

Re: Two user account types and login_required decorator

2010-03-19 Thread Paulo Almeida
Hi, This ticket is pretty old, but if it turns out you need a new decorator you can try the patch: http://code.djangoproject.com/ticket/11770 Regards, Paulo On Fri, Mar 19, 2010 at 9:57 PM, Martin Tiršel wrote: > Hello, > > I am programming an application where one part

Re: Send e-mail with large files from form attached

2010-03-19 Thread Paulo Almeida
zro...@gmail.com> wrote: > Oh. I get it, sorry. Any suggestions on my next question about > file.read() would be thankful. > > On Mar 19, 5:20 pm, Paulo Almeida <igcbioinformat...@gmail.com> wrote: > > Hi, > > > > My suggestion to zip the files was to provide a s

Re: login() and 'unicode' object is not callable error

2010-03-19 Thread Paulo Almeida
I think what's happening is you are assigning a string to the 'login' variable: login = request.POST['login'] So when you get to: login(request, user) login is the text and not the function. HTH, Paulo On Fri, Mar 19, 2010 at 3:15 PM, Martin Tiršel wrote: > Hello, > >

Re: UnicodeDecodeError Solution?

2010-03-19 Thread Paulo Almeida
I had a similar problem and I used two approaches. First I used Django's smart_str: from django.utils.encoding import smart_str text = smart_str(text) Then I had the same problem with fields using the csv module and I used these functions that I found on the web: def

Re: Send e-mail with large files from form attached

2010-03-19 Thread Paulo Almeida
hen a-mailng files are uploaded to RAM anyway, zipping files just > don't really help on binary data. I chosed to save them to a web- > visible location. > > On Mar 18, 7:59 pm, Paulo Almeida <igcbioinformat...@gmail.com> wrote: > > I can't help you with the technical part,

Re: models.TextField --> \r\n in DB

2010-03-18 Thread Paulo Almeida
Hi Thomas, Django's normalize_newlines function should do the trick. You can import it from django.utils.text. See this page for an example: http://www.palewire.com/posts/2009/09/01/django-recipe-remove-newlines-text-block/ Best, Paulo On Thu, Mar 18, 2010 at 4:27 PM, Thomas Guettler

Re: ManagementForm validation error in unit test

2010-03-18 Thread Paulo Almeida
Mystery solved. Thanks for your help, and sorry for the waste of time, but the problem was that I missed a previous form submission in the same test function, that was used just to test validation. I hadn't added the ManagementForm variables there, so that was the problem. Best regards, Paulo On

Re: ManagementForm validation error in unit test

2010-03-18 Thread Paulo Almeida
Hi Rajeesh, Thanks for the reply, but I still didn't manage to make it work. On the one hand, I couldn't find the get_default_prefix function (I'm using Django 1.02, which may explain that), but on the other hand, I do provide a prefix argument when I generate the formset, in my view:

Re: Send e-mail with large files from form attached

2010-03-18 Thread Paulo Almeida
I can't help you with the technical part, but a couple of suggestions: * Sum the size of the images and send two (or more) e-mails if it exceeds a threshold * Forget attachments and just zip the images and make them accessible in an URL that is e-mailed to the site admin - Paulo On Wed, Mar 17,

ManagementForm validation error in unit test

2010-03-18 Thread Paulo Almeida
Hi, I have a function in tests.py that tests the editing of a form, and it worked fine until I added an inline formset to the form. Now it fails with this error: ValidationError: [u'ManagementForm data is missing or has been tampered with'] I added these lines to the test function:

Re: Django TimeField Model without seconds

2009-08-06 Thread Paulo Almeida
Hi, Streamweaver wasn't suggesting assigning 00 to every time, just hiding what you don't want to show using views or templates. For instance: http://docs.djangoproject.com/en/dev/ref/templates/builtins/#time - Paulo On Thu, Aug 6, 2009 at 6:47 PM, Hellnar wrote: > >

Re: Get current user outside a view / without an request object

2009-08-06 Thread Paulo Almeida
kwargs): > self.user= inputUser >super(SendMessageForm, self).__init__(*args, **kwargs) > --- > the 'recipientUser = ShowValidContactList(currentUser=self.user, > label=u'Send to')' raises error because of that 'self.user' ('self' > wouldn't be defined and be out

Re: Get current user outside a view / without an request object

2009-08-06 Thread Paulo Almeida
It doesn't have to be a callable, you can just do something like: recipientUser = ShowValidContactList(currentUser=self.currentUser) I never used that kwargs.pop function (I didn't know you could do that), but I have code like this: class ExperimentForm(ModelForm): """ Generate form to

Re: Application decoupling - project architecture question

2009-08-06 Thread Paulo Almeida
I'm far from being an expert, but maybe you can look at the django-tagging code for inspiration: http://code.google.com/p/django-tagging/ What they do is to provide a TagField in the tagging application, and then you can use that field in the form of the application using tags. You can probably

Re: Select Table or Database based on User

2009-08-05 Thread Paulo Almeida
Yeah, the way I do that is have a foreign key with the user in the table with private data and then filter by user when retrieving data in the view. On Wed, Aug 5, 2009 at 10:11 PM, Maksymus007 wrote: > > > > > Hi everyone, > > > > I'm sure this has come up in the past,

Re: default blank choice on form.Form select widget

2009-08-05 Thread Paulo Almeida
Did you see this ticket? http://code.djangoproject.com/ticket/4092 Maybe you can use the patch code to customize your field. - Paulo On Wed, Aug 5, 2009 at 8:01 PM, JHeasly wrote: > > The doc page "Creating forms from models" >

Re: Unit test failing with 302 instead of 200, using Django's TestCase class

2009-08-05 Thread Paulo Almeida
was not there anymore. I suppose that rollback is the difference that made the test work with unittest. Thanks for all the help, Paulo On Wed, Aug 5, 2009 at 11:11 AM, Paulo Almeida <igcbioinformat...@gmail.com>wrote: > Hi, > > Thanks for the suggestion. I will do that now, but in

Re: Unit test failing with 302 instead of 200, using Django's TestCase class

2009-08-05 Thread Paulo Almeida
to try and narrow down the problem. Thanks, Paulo On Wed, Aug 5, 2009 at 10:57 AM, Malcolm Tredinnick < malc...@pointy-stick.com> wrote: > > On Wed, 2009-08-05 at 10:45 +0100, Paulo Almeida wrote: > > Ok, so with APPEND_SLASH = False , I get a 404 (so no >

Re: Unit test failing with 302 instead of 200, using Django's TestCase class

2009-08-05 Thread Paulo Almeida
at /myflow/experiments response.content I can tell that the fixtures are being loaded, so it should not be a problem of experiment 1 not existing. If you can suggest anything else I may try, please do. Thank you, - Paulo Almeida On Tue, Aug 4, 2009 at 9:27 PM, Paulo Almeida <igcbioinformat...@gmail.com

Re: model upload_to

2009-08-04 Thread Paulo Almeida
For what it's worth, if all you want to do is change the upload folder, you can also do it by overriding the form's __init__. - Paulo On Tue, Aug 4, 2009 at 9:28 PM, Stefan Hjelm wrote: > > ok don't know what typo I made yesterday but it works now, maybe > backslash in

Re: Login screen is always shown, i dont like it :/

2009-08-04 Thread Paulo Almeida
Hi, If you redirect users to your login screen in views that require login (for instance, using the login_required decorator), you don't have to give out your /accounts/login URL to users. Of course they can still go there if they want, but there's no reason why they should. Your login can

Re: Unit test failing with 302 instead of 200, using Django's TestCase class

2009-08-04 Thread Paulo Almeida
at response['location'] with and without APPEND_SLASH to see if that is doing anything. Thanks again, Paulo On Tue, Aug 4, 2009 at 6:45 PM, Karen Tracey <kmtra...@gmail.com> wrote: > On Tue, Aug 4, 2009 at 1:33 PM, Paulo Almeida <igcbioinformat...@gmail.com > > wrote: > >

Re: Unit test failing with 302 instead of 200, using Django's TestCase class

2009-08-04 Thread Paulo Almeida
guess I'll have to figure it out, because it seems to be the key to the problem. Thanks for the reply, Paulo Almeida On Tue, Aug 4, 2009 at 6:18 PM, Karen Tracey <kmtra...@gmail.com> wrote: > On Tue, Aug 4, 2009 at 12:26 PM, palmeida <igcbioinformat...@gmail.com>wrote: > &

Re: Unit test failing with 302 instead of 200, using Django's TestCase class

2009-08-04 Thread Paulo Almeida
>subset_header = True > >else: > >subset_header = False > >return render_to_response('myflow/view_experiment.html', > > {'experiment': exp, > > 'subsets': subsets, > >