Re: Can't make ManyToMany form fields hidden

2015-03-06 Thread Eric Abrahamsen
Collin Anderson <cmawebs...@gmail.com> writes:

> https://code.djangoproject.com/ticket/24453

For posterity: I should have been using a forms.MultipleHiddenInput
widget for the ManyToManyField, rather than a plain old
forms.HiddenInput.

> On Wednesday, March 4, 2015 at 12:40:40 AM UTC-5, Eric Abrahamsen
> wrote:
>
> Hi, 
>
> I'm making some heavily customized model formsets, to encourage my
> users 
> to input data. Mostly that involves cutting down the number of
> huge 
> drop-down menus they have to go surfing through. 
>
> So I have a model like this: 
>
> class Work(models.Model): 
> authors = models.ManyToManyField
> (Author,blank=True,related_name="works") 
>
> I first present them with a pre-query form, to choose an Author,
> then 
> give them a Work modelformset with the "authors" field pre-filled
> with 
> that author. So the initial data sort of looks like: 
>
> init["authors"] = [pre_query.cleaned_data["authors"]] # must be a
> list 
>
> for i in range(0, number_of_additional_forms): 
> initial.append(init) 
>
> formset = WorkFormSet(queryset=Work.objects.none(),
> initial=initial) 
>
> Nothing unusual there. Now I want to make the "authors" field
> hidden. 
> This is both to reassure my users, and to reduce the size of the
> page -- 
> these are really long dropdowns. 
>
> Adding the hidden widget to the "authors" field, however, gives me
> this 
> validation error: 
>
> (Hidden field authors) Enter a list of values. 
>
> The form input field looks like this: 
>
>  value="[37L]" /> 
>
> Looks like a list of values to me, but maybe it's not getting read
> that 
> way. 
>
> In the meantime it's not a disaster if the monster "authors"
> dropdown is 
> visible for each of my Work forms, but it would be really nice to 
> eventually get it hidden. 
>
> In the past I did this by manually *removing* fields from the
> forms, and 
> adding the values in during the POST/save process, but that always
> felt 
> bad to me. 
>
> Thanks! 
> Eric 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87bnk58js3.fsf%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Can't make ManyToMany form fields hidden

2015-03-03 Thread Eric Abrahamsen
Hi,

I'm making some heavily customized model formsets, to encourage my users
to input data. Mostly that involves cutting down the number of huge
drop-down menus they have to go surfing through.

So I have a model like this:

class Work(models.Model):
  authors = models.ManyToManyField(Author,blank=True,related_name="works")

I first present them with a pre-query form, to choose an Author, then
give them a Work modelformset with the "authors" field pre-filled with
that author. So the initial data sort of looks like:

init["authors"] = [pre_query.cleaned_data["authors"]] # must be a list

for i in range(0, number_of_additional_forms):
  initial.append(init)

formset = WorkFormSet(queryset=Work.objects.none(), initial=initial)

Nothing unusual there. Now I want to make the "authors" field hidden.
This is both to reassure my users, and to reduce the size of the page --
these are really long dropdowns.

Adding the hidden widget to the "authors" field, however, gives me this
validation error:

(Hidden field authors) Enter a list of values.

The form input field looks like this:



Looks like a list of values to me, but maybe it's not getting read that
way.

In the meantime it's not a disaster if the monster "authors" dropdown is
visible for each of my Work forms, but it would be really nice to
eventually get it hidden.

In the past I did this by manually *removing* fields from the forms, and
adding the values in during the POST/save process, but that always felt
bad to me.

Thanks!
Eric

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87lhjdjpay.fsf%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: read GET and POST simultaneously?

2015-01-27 Thread Eric Abrahamsen
Tom Christie <christie@gmail.com> writes:

> Absolutely no problem at all doing that. The only thing that's
> confusing here is that `request.GET` is a misleading name. The query
> parameters are available on any request, regardless of the HTTP
> method.
>
>> Is this reliable behavior across browsers?
>
> Yes.
>
>> Is it a dumb idea for reasons I haven't thought of?
>
> No.

Thank you very much!

> Cheers,
>
> Tom
>
> On Tuesday, 27 January 2015 03:26:52 UTC, Eric Abrahamsen wrote:
>
> As far as I can tell (testing with the Conkeror web browser), it's
> possible to read both GET and POST at once: if a user POSTs to a URL
> containing GET parameters, you can get them both in the view.
> 
> Is this reliable behavior across browsers? Is it a dumb idea for
> reasons I haven't thought of?
> 
> A bit of background, in case there's simply a better approach to
> this:
> 
> I'm using GET parameters to create custom model formsets:
> depending on those parameters, I construct different initial data, and
> set some of the form fields to use hidden input -- this makes it much
> easier for users to input bulk model instances without having to mess
> with endless drop-down menus.
> 
> But I need the same initial data when handling the POST request,
> which means I either need to re-read the GET parameters in the POST
> method (I'm not sure that's reliable), or I need to otherwise store
> the values of those parameters (ie in the session), and read them
> again from there during POST.
> 
> URL arguments would be stable, but there are many different
> possible parameters, half of which won't even be present for any given
> formset, and I don't know how to handle that using URL segments.
> 
> I'd be interested in hearing any thoughts on this!
> 
> Thanks, Eric

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87lhkomf0u.fsf%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


read GET and POST simultaneously?

2015-01-26 Thread Eric Abrahamsen
As far as I can tell (testing with the Conkeror web browser), it's
possible to read both GET and POST at once: if a user POSTs to a URL
containing GET parameters, you can get them both in the view.

Is this reliable behavior across browsers? Is it a dumb idea for reasons
I haven't thought of?

A bit of background, in case there's simply a better approach to this:

I'm using GET parameters to create custom model formsets: depending on
those parameters, I construct different initial data, and set some of the
form fields to use hidden input -- this makes it much easier for users
to input bulk model instances without having to mess with endless
drop-down menus.

But I need the same initial data when handling the POST request, which
means I either need to re-read the GET parameters in the POST method
(I'm not sure that's reliable), or I need to otherwise store the values
of those parameters (ie in the session), and read them again from there
during POST.

URL arguments would be stable, but there are many different possible
parameters, half of which won't even be present for any given formset,
and I don't know how to handle that using URL segments.

I'd be interested in hearing any thoughts on this!

Thanks,
Eric

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87d260sxuk.fsf%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Handle multiple modelforms in one html form

2015-01-17 Thread Eric Abrahamsen
Kakar Nyori  writes:

> When doing so, only the last pform is gets saved. And the other two
> pforms are ignored. How do I get to save all the three forms of photo
> (pforms) accordingly?
>
> Or is there any other way around? Your help will be much appreciated!
> Thank you.

James is right that a formset is probably the best solution. If for some
reason you actually need three separate forms, you can use different
"prefix" arguments to the separate forms. See:

http://stackoverflow.com/questions/17421981/django-form-prefix-vs-form-set

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87zj9hpvkn.fsf%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: another CSRF question -- and django hitcount

2014-12-06 Thread Eric Abrahamsen
Eric Abrahamsen <gir...@gmail.com> writes:

Apologies for the very stupid posting below! I did my homework, and
actually used the JQuery ajax function, like I was supposed to.

Incidentally, I also had the "async" keyword on the  tag in the
head that loaded jquery, and that apparently killed the document.ready
function altogether. Learned something new.

> I have a question about the django-hitcount app that I think is likely
> csrf-related.
>
> I recently upgraded a site from Django 1.4 all the way to 1.7. I've got
> most everything working fine, except that the hitcount app I've been
> using[1], stopped recording hits.
>
> Nevermind the actual app, it works by making an ajax call to a certain
> URL when a page is opened. Right now, the rendered javascript looks like
> this:
>
> <script type="text/javascript"><!--
>   $(document).ready(function() {
>   $.post( '/ajax/hit/',
>   { hitcount_pk : '1767', csrfmiddlewaretoken: csrf_token },
>   function(data, status) {
>   if (data.status == 'error') {
>   // do something for error?
>   }
>   },
>   'json');
>   });
> -->
>
> Since I upgraded, no hits have been recorded. I can't say for sure it's
> csrf-related, but I've been looking at the docs[2], and suspect that's
> the problem.
>
> The string "csrf_token" is produced as a hardcoded string, not a
> variable or anything -- that seems awfully wrong to me.
>
> After looking at the docs, and installing the cookie plugin, and
> scratching my head, this is what I've come up with:
>
> var csrftoken = $.cookie('csrftoken');
> function csrfSafeMethod(method) {
> // these HTTP methods do not require CSRF protection
> return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
> }
> $.ajaxSetup({
> beforeSend: function(xhr, settings) {
> if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
> xhr.setRequestHeader("X-CSRFToken", csrftoken);
> }
> }
> });
> $(document).ready(function() {
> $.post( '/ajax/hit/',
>   { hitcount_pk : '{{ object.pk }}'},
>   function(data, status) {
>   if (data.status == 'error') {
>   // do something for error?
>   }
>   },
>   'json');
> });
>
> ("object" is the variable )
>
> Does this seem right? Will the ajaxSetup apply to my post, even though I
> haven't said anything explicitly to that effect?
>
> I apologize for such a brainless set of questions -- I don't know JS
> very well, and don't know how to debug it. How could I even tell if this
> was working?
>
> Eric
>
>
> [1]: https://github.com/scottwrobinson/django-hitcount/
> [2]: https://docs.djangoproject.com/en/1.7/ref/contrib/csrf/#ajax

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87sigs5b7f.fsf%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


another CSRF question -- and django hitcount

2014-12-06 Thread Eric Abrahamsen
I have a question about the django-hitcount app that I think is likely
csrf-related.

I recently upgraded a site from Django 1.4 all the way to 1.7. I've got
most everything working fine, except that the hitcount app I've been
using[1], stopped recording hits.

Nevermind the actual app, it works by making an ajax call to a certain
URL when a page is opened. Right now, the rendered javascript looks like
this:



Since I upgraded, no hits have been recorded. I can't say for sure it's
csrf-related, but I've been looking at the docs[2], and suspect that's
the problem.

The string "csrf_token" is produced as a hardcoded string, not a
variable or anything -- that seems awfully wrong to me.

After looking at the docs, and installing the cookie plugin, and
scratching my head, this is what I've come up with:

var csrftoken = $.cookie('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
$(document).ready(function() {
$.post( '/ajax/hit/',
{ hitcount_pk : '{{ object.pk }}'},
function(data, status) {
if (data.status == 'error') {
// do something for error?
}
},
'json');
});

("object" is the variable )

Does this seem right? Will the ajaxSetup apply to my post, even though I
haven't said anything explicitly to that effect?

I apologize for such a brainless set of questions -- I don't know JS
very well, and don't know how to debug it. How could I even tell if this
was working?

Eric


[1]: https://github.com/scottwrobinson/django-hitcount/
[2]: https://docs.djangoproject.com/en/1.7/ref/contrib/csrf/#ajax

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87oarh5h57.fsf%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: defining an app stub using AppConfig?

2014-11-30 Thread Eric Abrahamsen
Collin Anderson <cmawebs...@gmail.com> writes:

> Hi Eric,
>
> I'm not sure, but is this what you want?
>
> models = apps.get_app_config(setting.NEWSLETTER_APP).models_module
>
> Collin

Thanks Collin. I think that would do what I want, but in the end I
decided the easier way to go would be to fork the app, then experiment
with switching code in the app itself, rather than switching apps in my
Django project. Whether or not that will actually turn out to be simpler...

> On Tuesday, November 25, 2014 1:50:40 AM UTC-5, Eric Abrahamsen wrote:
>
> I'm messing around with testing many Github forks of the emencia 
> newsletter app, looking for one I like. In the meantime (and as
> I'm 
> likely to continue switching around for a while), I'd like not to
> have 
> to commit code that points at the different names of the different
> apps: 
> they all have the same models and database structure, the only
> thing 
> that changes is the top-level name of the module. 
> 
> I looked at the code for contrib/comments, and have some questions
> about 
> using AppConfig. 
> 
> What I'd like to do is have a setting in settings.py that reads: 
> 
> NEWSLETTER_APP='maja_newsletter' 
> 
> Or what have you. This would change semi-regularly as I test. 
> 
> Then I'd have a top-level file called newslettermodule.py, with 
> something like this in it: 
> 
> from django.conf import settings 
> from django.apps import apps 
> 
> module = apps.get_app_config(settings.NEWSLETTER_APP.rpartition
> (".")[2]).module 
> 
> 
> Here's where I'm having trouble. Is there any way that I can
> basically 
> dump all the models from what would be module.models into this
> file? 
> Playing with this in the shell, when I try to import actual models
> from 
> module.models I get an "No module named module.models", even
> though 
> eval'ing "module.models" directly gives me: 
> 
>  
> 
> Clearly this is just a misunderstanding on my part about how
> Python 
> modules work. 
> 
> Is there anything I can do? Looking at the code in
> contrib/comments I 
> suspect not -- if there were, it would have been done there. 
> 
> Anyway, thanks for any light shed on how AppConfig can be used in
> this 
> situation... 
> 
> Eric 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87iohww3i1.fsf%40ericabrahamsen.net.
For more options, visit https://groups.google.com/d/optout.


defining an app stub using AppConfig?

2014-11-24 Thread Eric Abrahamsen
I'm messing around with testing many Github forks of the emencia
newsletter app, looking for one I like. In the meantime (and as I'm
likely to continue switching around for a while), I'd like not to have
to commit code that points at the different names of the different apps:
they all have the same models and database structure, the only thing
that changes is the top-level name of the module.

I looked at the code for contrib/comments, and have some questions about
using AppConfig.

What I'd like to do is have a setting in settings.py that reads:

NEWSLETTER_APP='maja_newsletter'

Or what have you. This would change semi-regularly as I test.

Then I'd have a top-level file called newslettermodule.py, with
something like this in it:

from django.conf import settings
from django.apps import apps

module = apps.get_app_config(settings.NEWSLETTER_APP.rpartition(".")[2]).module


Here's where I'm having trouble. Is there any way that I can basically
dump all the models from what would be module.models into this file?
Playing with this in the shell, when I try to import actual models from
module.models I get an "No module named module.models", even though
eval'ing "module.models" directly gives me:



Clearly this is just a misunderstanding on my part about how Python
modules work.

Is there anything I can do? Looking at the code in contrib/comments I
suspect not -- if there were, it would have been done there.

Anyway, thanks for any light shed on how AppConfig can be used in this
situation...

Eric

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87vbm3ixb5.fsf%40ericabrahamsen.net.
For more options, visit https://groups.google.com/d/optout.


Weird permissions issue

2011-03-12 Thread Eric Abrahamsen
I'm using the emencia newsletter, and things are essentially fine,
except that I've run into a very strange permissions issue in the
admin
backend. I have my regular user login, and the superuser. I've given
my
regular user all permissions for all newsletter models, and yet some
of
the inter-modal relations are not showing up.

The MailingList model has a ManyToMany relationship to Contact, yet
when
I'm logged in as my regular user and look at a MailingList instance,
the
two windows for selecting Contacts from the contact list are blank.
Same
for all the relationship fields on all the models: whether ForeignKey
or
ManyToMany, none of them display the choices for creating a
relationship. I just tried using the admin javascript green "plus
sign"
to both create an instance of a related model and put it into the
list.
The creation comes off okay, and I see the new Contact (in this case)
appear in the list, but when I save the MailingList model, it tells
me:
"Select a valid choice. 594 is not one of the available choices." 594
is
the id of the Contact instance I just created.

This only happens on my production system, not my development system.
Both are running django 1.2.3, and the development version of the
emencia
newsletter. What can have gotten screwed up here? I added the
newsletter
app much later, is there a possibility this is a database-level issue?

I've dumped the data, destroyed and recreated the tables, and loaded
the data again, to no avail…

Any pointers towards further debugging would be much welcome…

Thanks,
Eric

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can't create super user

2011-03-05 Thread Eric Abrahamsen
On Sat, Mar 05 2011, royy wrote:

> Hello.
>
> I can't create a superuser for an admin area,  i type username and e-
> mail, then when I try to type password the keyboard freezes and
> doesn't respond so I need to use the Ctrl + break to quit server (I'm
> following the steps for writing my first Django app).

Are you sure the password simply isn't being echoed to the console? Try
typing it out and hitting return, even if you don't see anything, that
should complete the process.

Eric

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: AW: parameter, but not in the URL

2011-03-04 Thread Eric Abrahamsen
On Fri, Mar 04 2011, Szabo, Patrick (LNG-VIE) wrote:

> Hi, 
>
> Thanks for you fast response !
>
> I've already made sure that users can only edit or delete objects that
> they've created but i thought it might be even better to hide those
> information.

If you put the delete link in a form "action", and have the delete view
redirect to a different url when it's done, that's about as "hidden" as
it gets. A determined user will still be able to figure out the pattern,
but if they can only delete their own resoures, then why hide it?

>
> Kind regards
>
>
> . . . . . . . . . . . . . . . . . . . . . . . . . .
> Patrick Szabo
>  XSLT Developer 
> LexisNexis
> Marxergasse 25, 1030 Wien
>
> mailto:patrick.sz...@lexisnexis.at
> Tel.: +43 (1) 534 52 - 1573 
> Fax: +43 (1) 534 52 - 146 
>
>
> -Ursprüngliche Nachricht-
>
> Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im 
> Auftrag von Eric Abrahamsen
> Gesendet: Freitag, 04. März 2011 10:46
> An: django-users@googlegroups.com
> Betreff: Re: parameter, but not in the URL
>
> On Fri, Mar 04 2011, Szabo, Patrick (LNG-VIE) wrote:
>
>> 127.0.0.1:800/93/1
>>
>>  
>>
>> This would delete an object with the id 93.
>>
>> This is very unsecure and once the user notices how this works he
>> could delete any object he wants.
>>
>>  
>>
>> How can i make this more secure ?!
>
> There's pretty much always a public-facing URL that can be used to
> delete a resource. I believe the best thing is just to require that a
> user be logged in to perform the action. That's most simply done with a
> @login_required decorator on the
>
> If you keep track of which users created which resources, you can
> restrict them to only deleting resources they created with some simple
> logic in the view.
>
> HTH,
> Eric
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: parameter, but not in the URL

2011-03-04 Thread Eric Abrahamsen
On Fri, Mar 04 2011, Szabo, Patrick (LNG-VIE) wrote:

> 127.0.0.1:800/93/1
>
>  
>
> This would delete an object with the id 93.
>
> This is very unsecure and once the user notices how this works he
> could delete any object he wants.
>
>  
>
> How can i make this more secure ?!

There's pretty much always a public-facing URL that can be used to
delete a resource. I believe the best thing is just to require that a
user be logged in to perform the action. That's most simply done with a
@login_required decorator on the

If you keep track of which users created which resources, you can
restrict them to only deleting resources they created with some simple
logic in the view.

HTH,
Eric

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



weird permissions issue

2011-03-02 Thread Eric Abrahamsen
I'm using the emencia newsletter, and things are essentially fine,
except that I've run into a very strange permissions issue in the admin
backend. I have my regular user login, and the superuser. I've given my
regular user all permissions for all newsletter models, and yet some of
the inter-modal relations are not showing up.

The MailingList model has a ManyToMany relationship to Contact, yet when
I'm logged in as my regular user and look at a MailingList instance, the
two windows for selecting Contacts from the contact list are blank. Same
for all the relationship fields on all the models: whether ForeignKey or
ManyToMany, none of them display the choices for creating a
relationship. I just tried using the admin javascript green "plus sign"
to both create an instance of a related model and put it into the list.
The creation comes off okay, and I see the new Contact (in this case)
appear in the list, but when I save the MailingList model, it tells me:
"Select a valid choice. 594 is not one of the available choices." 594 is
the id of the Contact instance I just created.

This only happens on my production system, not my development system.
Both are running django 1.2.3, and version 0.2 of the emencia
newsletter. What can have gotten screwed up here? I added the newsletter
app much later, is there a possibility this is a database-level issue?

Any pointers towards further debugging would be much welcome…

Thanks,
Eric

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



mapping django import tree?

2010-03-28 Thread Eric Abrahamsen
It was only recently that I finally learned how Etags work in Emacs and
made myself a tags file for Django's source code -- now that I'm 4/5 of
the way to pure programming leisure I can't rest until the laziness is
complete.

That means making a programmatic map of django class/function import
paths, so I don't have to keep looking up where the "reverse" function
comes from, etc.

Does anyone know of a plugin like this for any editor? Or does anyone
own a representation of django's import paths in some sort of parseable
format?

Thanks!
Eric

-- 
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: Difference between request.POST.get('foo') and request.POST['foo']?

2010-03-24 Thread Eric Abrahamsen
On Tue, 2010-03-23 at 23:14 -0700, Daniel wrote:
> Hi,
> 
> Are these statements equivalent?  I want to say no, but I can't see
> why.

Nope. If the key 'foo' doesn't exist, request.POST.get('foo') will
return None, while request.POST['foo'] will blow up with a KeyError.
Using the get() method on dictionaries also allows you to provide a
default value as the second argument, to be returned instead of None if
the key doesn't exist.

E


> 
> Thank you
> 


-- 
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: Scope of an app

2010-02-18 Thread Eric Abrahamsen


On Feb 18, 2010, at 9:41 PM, Sander wrote:


Thanks!

Those guidelines are certeinly helpfull.


Hope these helps. If you need more specific answers please expand the
following paragraph:

My main project should have a couple of entities, like for example  
an
'Employee', 'Manager', 'Question'. An employee can ask questions,  
and

a manager can read questions.


let's say the following (pure hypothetical):
- an Manager can read questions at example.com/manager/read
- an Employee can post questions at example.com/employee/add

Let me try myself:
In this case, following your guidelines,  I think I have to create an
app called 'question' whith the functionality of adding and listing
the questions
Also the Employee and Manager should be different apps because they
have functionality of changing their information.
The apps DO depent on eachoter because a question is placed by a
'Employee' but thats fine


As the others have hinted there's a large element of personal  
preference here: I would tend to put all these things in one app. As  
Atamert said, if a particular model is useless by itself, it doesn't  
need its own app. For instance, in your future site, does an Employee  
do anything except pose questions? Does a Manager do anything but  
answer them? Both Employees and Managers are a kind of Person – are  
they differentiated only by the way they interact with each other?  
Then they should probably be part of the same app. Likewise, if the  
Question model is useless without some sort of Employee/Manager model  
to interact with it, it doesn't need to be on its own.


I don't think it will hurt you to err on the side of consolidation…

two cents,
Eric



Am I on the right track?

Thanks


On 18 feb, 14:03, Atamert Ölçgen  wrote:

On Thursday 18 February 2010 14:43:07 Sander wrote:


Hello everybody,



I'm having a little hard time starting a Django project because I'm
not sure where to place my models in the first place.



For example, the Django beginner tutorials put all entities of the
'Poll' application (Question, Answer) in a new app called Polls.  
Thats

pretty clear, but a poll is a pretty independant app.


My main project should have a couple of entities, like for example  
an
'Employee', 'Manager', 'Question'. An employee can ask questions,  
and

a manager can read questions.


Is it conventional to create, lets say a 'main' or 'core' app  
where I
put these models? Or should I create different apps per  
functionality,

or per entity?



I hope you understand my question. Any response is much appriciated.



Thanks in advance!



Sander


I don't know the exact answers. But here is some guidelines:

* An app can depend on another app. But cyclical dependencies  
should be

avoided. (Even though Django allows you to reference models this way)
* Don't think in terms of entities, think in terms of  
**functionality**.
* (Perhaps not applicable to this situation, but) learn register  
pattern of

admin and generic relations.
* If any two models are meaningless seperated, they should be in  
the same app.
* An app shouldn't be too big. Not in terms of bytes, but in  
functionality it
provides. Sometimes it's a good idea to write another app that  
supports the

1st one.

Hope these helps. If you need more specific answers please expand the
following paragraph:

My main project should have a couple of entities, like for example  
an
'Employee', 'Manager', 'Question'. An employee can ask questions,  
and

a manager can read questions.


--
Saygılarımla,
Atamert Ölçgen

 -+-
 --+
 +++

www.muhuk.com
mu...@jabber.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 
.




--
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: Next previous links from a query set / generi views

2010-02-07 Thread Eric Abrahamsen


On Feb 8, 2010, at 7:56 AM, eaman wrote:


I'm up to code those two methods...

If some one is interested in this thread I managed to code
these two methods: get_next | get_prev
in order to get a previous or next item in a set right from my model:
- http://dpaste.com/155961/


Now that you've got a date attribute, why not use that for next and  
previous?


If you don't want to do that, you still might consider returning a  
real object instance, and then giving the model a get_absolute_url()  
method and calling that in the template. That will save you hardcoding  
the links in the template.


But if it's just an id you want, the following might be more efficient:

def get_next(self):
all_ids = Foto.objects.filter(galleria = self.galleria,  
id__gt=self.id).values_list("id",flat=True).order_by("id")

try:
return min(all_ids)
except ValueError:
return None

Then reverse that (id__lt=self.id and use the max python function) for  
get_prev()


Hope that's helpful,
Eric



- Is there a better way to get the highest  'previous' item then
using
   aggregate(Max('id'))?

- I guess the if /else conditional loop that should check the
existence of the prev | next item is suboptimal...

/eaman

--
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: Next previous links from a query set / generi views

2010-02-07 Thread Eric Abrahamsen


On Feb 7, 2010, at 8:54 PM, eaman wrote:




On Feb 7, 3:24 am, Eric Abrahamsen <gir...@gmail.com> wrote:

Yup, if you have non-null date/datetime fields on your model, each
model will automatically get "get_next_by_FOO" and
"get_previous_by_FOO" methods, where FOO is the name of the datetime

Well I guess the 'Lazy' optiond is to add a date field to my model and
get the free pagination. Or code my own view, of course.


The lazy option would probably be to add get_next() and get_previous()  
methods to your model, that return an instance based on whatever  
definition of "next" and "previous" works for you. You might consider  
some kind of timestamp field for your model, though – you'd be  
surprised how often that comes in handy…




Thanks.
/eaman
[CUT]

--
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: Next previous links from a query set / generi views

2010-02-06 Thread Eric Abrahamsen
Yup, if you have non-null date/datetime fields on your model, each  
model will automatically get "get_next_by_FOO" and  
"get_previous_by_FOO" methods, where FOO is the name of the datetime  
field:


http://docs.djangoproject.com/en/1.1/ref/models/instances/#django.db.models.Model.get_next_by_FOO

Eric

On Feb 7, 2010, at 2:34 AM, eaman wrote:


Hello, I have a quite simple query set and a related generic views:
http://dpaste.com/155494/
And template for generating a detail page of a photo.

Is there an easy way to have a link to  previous | next element in the
template
without manualy coding a view ?

Somthing like a:
{% if foto.next_item %}
Next
{% endif}

--
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.



Custom comment app and tables

2010-02-03 Thread Eric Abrahamsen
Over the course of a year or two of manual database twiddling, I've  
fairly well messed up my table indexes and whatnot. In particular, I'm  
getting lots of "duplicate key names" when installing fixtures for  
testing, and generic foreign keys that point at contenttypes that no  
longer exist.


I've started with my custom comment app, and I have some questions  
about how this works:


1. If I'm using BaseCommentAbstractModel only, should I expect syncdb  
to create django_comments and django_comment_flags tables?


2. Is it possible to have a custom comment model that's just called  
Comment?


3. The comments app is one of the ones where indexes can't be created  
because of duplicate key names. I tried the trick of renaming my  
custom comment table in the database, and then running syncdb to  
create an empty "proper" table, planning to move the data into the new  
table after. The syncdb output looks like this (I named the custom  
comment model MyComment):


Creating table django_comments
Creating table django_comment_flags
Creating table comments_mycomment
Installing index for comments.Comment model
Installing index for comments.CommentFlag model
Installing index for comments.MyComment model
Installing index for comments.Comment model
Failed to install index for comments.Comment model: (1061, "Duplicate  
key name 'django_comments_content_type_id'")

Installing index for comments.CommentFlag model
Failed to install index for comments.CommentFlag model: (1061,  
"Duplicate key name 'django_comment_flags_user_id'")

Installing index for comments.MyComment model
Failed to install index for comments.MyComment model: (1061,  
"Duplicate key name 'comments_mycomment_content_type_id'")


So it looks like the python models Comment and CommentFlag are being  
created "inside" my custom app, though the tables are still labeled  
"django_XXX". Presumably that's how it's supposed to work, but how do  
I get rid of my index failures?


Thanks!
Eric


--
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: Using a template variable in the "include" template tag

2010-01-29 Thread Eric Abrahamsen


On Jan 30, 2010, at 2:07 PM, Super McFly wrote:


Thanks for your suggestion, Eric. I actually tried that but for some
reason it didn't work so I assumed it was the same problem. It turns
out it does work so a big thank you to you and everyone else who tried
to help.


Good!

Since you've already got a Content superclass going you could probably  
do some metaclass jiggery-pokery to make this automatic for subclasses  
�C on reflection it wouldn't be as simple as I blithely suggested in my  
last response, but I think it could be done.


E



On Jan 30, 5:59 am, Eric Abrahamsen <gir...@gmail.com> wrote:

I've done this by including a python-only attribute on the models
themselves:

include_template = "content/post/include.html"

and in the template {% include content.include_template %}

Provided that "content" is a model instance.

You could even write a model mixin class that does this  
automatically,

populating the include_template attribute using string formatting and
the class name.

Eric

On Jan 30, 2010, at 1:45 PM, Super McFly wrote:


I guess the only way to do this would be to use an if conditional,
which would be really ugly...



{% if content.model_type == 'post' %}
  {% include "content/post/include.html" %}
{% endif %}



{% if content.model_type == 'review' %}
  {% include "content/review/include.html" %}
{% endif %}



On Jan 30, 5:33 am, Super McFly <martinmal...@gmail.com> wrote:
Thank you for the reply. Do you have any suggestions on how to do  
it

my way?



On Jan 30, 5:23 am, pyleaf <lg.feixi...@gmail.com> wrote:



i think that will not work,because 'include' excutes before the
Variable.



On Sat, Jan 30, 2010 at 12:51 PM, Super McFly
<martinmal...@gmail.com>wrote:


Is it possible to use a template variable in the "include"  
template

tag. My actual problem is below...



{% include "content/{{ content.model_type }}/include.html" %}



{{ content.model_type }} by itself outputs "post" and the full
string
outputs "content/post/include.html" and if that string is hard-
coded
then the template is included.



--
You received this message because you are subscribed to the
Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com 
.

To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@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 
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.



a hook where request is available

2010-01-29 Thread Eric Abrahamsen
I've got a "NewContent" model which is essentially a tumblelog – when  
instances of certain models are created or saved, a NewContent  
instance is created that keeps track of them, and NewContent querysets  
are used to populate the index page, RSS feed, etc.


Up until now I've been doing this in the admin, with a custom save  
button called "Save and Mark and New", and then a subclassed  
ModelAdmin with response_add and response_change overridden, to check  
for this particular save value in request.POST and create a NewContent  
instance if necessary.


I'm slowly moving to front-end admin functionality, using generic  
views, and so far as I can tell, there's no point during the create/ 
update cycle where I'll have access to both the request (for checking  
the custom save value), and the created/updated object itself (which  
gets passed to a NewContent creation manager). I've looked at signals,  
middleware, form save methods, object save methods, and wrapping the  
generic view functions (I guess that's the same as middleware).


The only things left I can think of is, using my own versions of  
create_object and create_object, which I'd rather not do, or else  
doing away with the custom save button, and having post_save_redirect  
point to a page that asks users if they want to add the newly saved  
object to the new content stream.


Option two wouldn't be terrible, but I'd rather do it in one step. Do  
I have any other options here?


Thanks!
Eric

--
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: Using a template variable in the "include" template tag

2010-01-29 Thread Eric Abrahamsen
I've done this by including a python-only attribute on the models  
themselves:


include_template = "content/post/include.html"

and in the template {% include content.include_template %}

Provided that "content" is a model instance.

You could even write a model mixin class that does this automatically,  
populating the include_template attribute using string formatting and  
the class name.


Eric

On Jan 30, 2010, at 1:45 PM, Super McFly wrote:


I guess the only way to do this would be to use an if conditional,
which would be really ugly...

{% if content.model_type == 'post' %}
   {% include "content/post/include.html" %}
{% endif %}

{% if content.model_type == 'review' %}
   {% include "content/review/include.html" %}
{% endif %}



On Jan 30, 5:33 am, Super McFly  wrote:

Thank you for the reply. Do you have any suggestions on how to do it
my way?

On Jan 30, 5:23 am, pyleaf  wrote:

i think that will not work,because 'include' excutes before the  
Variable.


On Sat, Jan 30, 2010 at 12:51 PM, Super McFly  
wrote:



Is it possible to use a template variable in the "include" template
tag. My actual problem is below...



{% include "content/{{ content.model_type }}/include.html" %}


{{ content.model_type }} by itself outputs "post" and the full  
string
outputs "content/post/include.html" and if that string is hard- 
coded

then the template is included.



--
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 
.




--
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: why does if statement fail with

2010-01-07 Thread Eric Abrahamsen


On Jan 8, 2010, at 12:54 PM, Russell Keith-Magee wrote:

On Fri, Jan 8, 2010 at 12:50 PM, Eric Abrahamsen <gir...@gmail.com>  
wrote:


On Jan 8, 2010, at 12:28 PM, neridaj wrote:


Can anyone tell me why this less than symbol is causing this if
statement to fail?

  {% if page_obj.number|add:"4" < paginator.count %}

  {% endif %}



Because the if tag doesn't accept comparison operators. If you're  
trying to
make a more complex pagination mechanism, you'll probably want to  
set it up

in the view, or use a custom template tag…


... unless, of course, you're using the 1.2 alpha or trunk version of
Django. Django 1.2 will include support for comparison operators in if
tags.


Hot damn.




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 
.





-- 
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: why does if statement fail with

2010-01-07 Thread Eric Abrahamsen


On Jan 8, 2010, at 12:28 PM, neridaj wrote:


Can anyone tell me why this less than symbol is causing this if
statement to fail?

   {% if page_obj.number|add:"4" < paginator.count %}

   {% endif %}



Because the if tag doesn't accept comparison operators. If you're  
trying to make a more complex pagination mechanism, you'll probably  
want to set it up in the view, or use a custom template tag…


Eric


Cheers,

J
--
You received this message because you are subscribed to the Google  
Groups "Django users" group.

To post to this group, send email to django-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: debugging cache

2010-01-04 Thread Eric Abrahamsen

On Dec 24, 2009, at 10:28 PM, brook wrote:

>
>
> On Dec 23, 5:13 am, Eric Abrahamsen <gir...@gmail.com> wrote:
>>
>> I'm using memcached with the cache_page decorator, and it simply  
>> wasn't caching
>> views.
>
>> CACHE_MIDDLEWARE_KEY_PREFIX = 'blah'
>> CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
>> CACHE_BACKEND = 'memcached://XX.XX.XX.XXX:6905/'
>>
>> I have no cache-related middlewares installed.
>>
>
> If you are using the "per-view" caching technique (using the
> cache_page decorator), and you haven't got caching middleware enabled,
> then CACHE_MIDDLEWARE_PREFIX and CACHE_MIDDLEWARE_ANONYMOUS_ONLY won't
> do anything. These are related to "per-site" caching, as detailed in
> the documentation: 
> http://docs.djangoproject.com/en/1.1/topics/cache/#the-per-site-cache
>
> You might consider using database caching[1] in your development
> environment, to make inspecting the cache easier. You can then look at
> the caching table in your database to check whether it is being
> populated as expected. That way you can start to narrow down where the
> problem lies (django's caching, or memcached).

Thanks for the tip! The database is being populated as expected by the  
cache framework, so the problem must lie with memcached somehow.

Could there be some permissions issues going on here? Some conflict  
between the apache user and my user, which started memcached?

Any hints appreciated, in the meantime I'll continue poking.

E


>
> [1] http://docs.djangoproject.com/en/1.1/topics/cache/#database- 
> caching
>
> --
>
> 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: debugging cache

2009-12-24 Thread Eric Abrahamsen

On Dec 24, 2009, at 1:57 AM, Peter Rowell wrote:

>> CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
>
> I know this is a silly question, but have your tried this *as an
> anonymous user*? I ask because it's easy to forget you are logged in.
> When in doubt use something like Firefox's Web Developer Toolbar and
> clear all the cookies for your test site.

Yup. From the web side I've tried it as a variety of different roles.  
And from a python shell, that ought to bypass the authentication  
system altogether, yes?

Very perplexing.

E

>
> --
>
> 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.




debugging cache

2009-12-22 Thread Eric Abrahamsen
Hi,

I noticed a while ago that my cache wasn't doing anything – I'm using  
memcached with the cache_page decorator, and it simply wasn't caching  
views. I've verified that memcached is running, and my settings.py  
file is pointed at the right address. Here are my relevant settings:

CACHE_MIDDLEWARE_KEY_PREFIX = 'blah'
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
CACHE_BACKEND = 'memcached://XX.XX.XX.XXX:6905/'

I have no cache-related middlewares installed.

On my live server I can go into the shell and do this:

 >>> import django
 >>> django.get_version()
u'1.2 pre-alpha SVN-11778'
 >>> from django.core.cache import cache
 >>> cache.set("dogfood","yummy",500)
 >>> cache.get("dogfood", "no dog food")
'no dog food'
 >>> s = cache._cache.servers[0]
 >>> s.port
6905


So django seems to be finding the cache backend okay, just not putting  
anything into the cache. Can someone point out the logical next step  
in debugging this? Are there any intermediate steps that I can push  
through, and see where this is hanging up?

Thanks!
Eric

--

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: admin for "regular" users - still a bad idea?

2009-11-26 Thread Eric Abrahamsen


On Nov 27, 11:50 am, Count László de Almásy  wrote:
> ok, fair enough. does generic views have the machinery to replicate
> the admin interface?

Generic views take most of the pain out of CRUD, and also take care of
producing and validating forms. You can also steal some of the nice
javascript widgets out of the admin code. You've still got to do the
templating yourself, though, which means that most of the
functionality that you can presently put into admin.py (things like
how the changelists are displayed and filtered, how the forms are laid
out, not to mention admin actions) you'll have to do yourself. I don't
believe you can do inline formsets with generic views, which is
unfortunate, but it's not hard with a simple custom view.

All in all, I've found that doing my own admin functionality really
isn't hard at all, and you suddenly have a huge amount of freedom; the
only real pain in the ass is that you're starting from scratch with
the html and css. Boring!

Eric

>
> On Nov 26, 7:28 pm, Skylar Saveland  wrote:
>
>
>
> > Yep, still a bad idea.  Permissions are by table not by row.  Use
> > generic views for basic CRUD.
>
> > Count László de Almásy wrote:
>
> > > i've seen notes in some django documentation that implies that using /
> > > admin/ for non-trusted users is not a good idea. which is unfortunate
> > > since it seems like the admin interface is about 95% of what i want
> > > for my users to be able to view and manipulate their sales
> > > transactions data over the web. each user has their own table in the
> > > db for transactions, and they can do whatever they want to their own
> > > data. i wouldn't want them to be able to touch anyone else's tables,
> > > but it seems like django has a permissions system to restrict that.
>
> > > with the latest django, is it still considered a bad idea to do this?
> > > if so, what is the alternative, writing custom views to mimic what the
> > > admin interface does?

--

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: Is django comment's honeypot really useful?

2009-10-08 Thread Eric Abrahamsen


On Oct 8, 2009, at 8:20 PM, Joshua Partogi wrote:

>
>> even the developers who know what is happening shouldn't complain.
>>
>> I have a site that seems to get crawled by bots quite frequently. I  
>> had a
>> feedback form that didn't have a honeypot originally. I got about  
>> 3-4 pieces
>> of spam a day. Turning on the honey pot, I only have gotten a few  
>> pieces of
>> spam.
>>
>> The honeypot isn't the most effective spam measure but it is an  
>> easy and
>> cheap way to catch the type of spam bots that crawl looking for any  
>> input to
>> place their ugliness. You don't need to ping a service like Askimet  
>> and the
>> item doesn't need to hit the db.
>>
>> IMO there is no reason not to have this in any form that you think  
>> might get
>> spammed. It helps out, and it doesn't harm anything. I would still  
>> use
>> another service for spam as well, but this is the most base check I  
>> can
>> think of.
>
> Okay fair enough. I guess it really is useful to reduce the number of
> spams, although you would still expect spams :-) I have implemented
> captcha before, but I found it very inconvenient for the visitors and
> as you said the operation is quite expensive. Do you have any other
> recommendation of another spam preventer service? I haven't tried
> akismet, it sounds really user-friendly compared to captcha.

+1 for akismet, once you've got it set up it works like a charm, and  
you can adjust your signals so it won't check logged in users or  
approved IPs or whatever. In a year or so of using it I've gotten only  
one real comment marked as spam, and maybe three or four spams have  
gotten through. Not bad.

Michael's point is good: having several layers of spam protection is a  
great idea, and if you put the lightweight ones out front, you can  
maximize protection while minimizing hits on databases or external  
services.

E

>
> Thanks heaps.
>
> -- 
> Certified Scrum Master
> http://twitter.com/scrum8 | http://blog.scrum8.com | http://jobs.scrum8.com
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Leaking python app structure

2009-09-09 Thread Eric Abrahamsen

I have a site with SEND_BROKEN_LINK_EMAILS = True in the settings,  
which means I get both legitimate 404s and also probes where the bot  
is being clever by putting the fake URL in the referer heading.

Today I got a series of 404 messages that were alarming because they  
were probing legitimate urls with parts of my application structure  
appended to the end. Something like 
http://mysite.com/actual/url/appname.modelname 
, with the name of an app and a model stuck on the end with a dot in  
between, just like you'd see in a python import statement.

I can't think of any place in the public-facing site where the names  
of any models appear directly, let alone the name of an app. This  
makes me nervous. Has anyone seen anything like this before? I can't  
think of any immediate threat it could pose, but nevertheless this  
seems like a Bad Thing. Any words of wisdom?

Thanks,
Eric

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: misunderstanding

2009-08-16 Thread Eric Abrahamsen


On Aug 17, 2009, at 9:33 AM, Mike Dewhirst wrote:

>
> There's something here I'm not seeing. If anyone can point out the  
> docco
> which refers I would be most grateful ... I'm using py2.6 and Django
> from svn head.
>
> The template below displays the title correctly but claims "No meta
> dictionary passed". Since the title is one of the meta_dict key:value
> pairs I feel this should not be. Also, when I uncomment the #print  
> line
> below, the entire meta_dict, including 'title': 'META items' prints.
>
> Thanks for any pointers ...
>
> Mike
>
>  views.py (excerpt) ---
> def display_meta(request):
> dct = {'title':'META items',}
> meta_dict = dict(request.META.items())
> meta_dict.update(dct)
> #print(meta_dict)
> return render_to_response('polls/meta_dict.html', meta_dict)

Variables should be passed to the template as a dictionary, so this  
response line should look like this:

return render_to_response('polls/meta_dict.html', {'meta_dict':  
meta_dict}

Then it will be available in your template. My guess is that, since  
meta_dict is itself a dictionary, you can currently access its  
contents in your template by directly using its keys as variables.

Hope that works,
Eric

> 
>
>  meta_dict.html 
> {% extends "base_polls.html" %}
> {% block content_title %}{{ title }}{% endblock %}
> {% block content %}
> {% if meta_dict %}
> 
> {% for key, value in meta_dict.items %}
>  {{ key }} {{ value }}
> {% endfor %}
> 
> {% else %}
> No meta dictionary passed
> {% endif %}
> {% endblock %}
> -
>
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: slug regular expression: which should I use

2009-08-10 Thread Eric Abrahamsen


On Aug 10, 2009, at 1:56 PM, J0hnsmith wrote:

>
> Which should I use to match a slug made using slugify?
>
> (?P[a-zA-Z0-9-]+)
>
> or
>
> (?P[\w-]+)

They're not exactly the same. Most of the time \w is alphanumeric (ie  
equivalent to your first regex) but Django compiles the  
RegexURLPattern with the UNICODE flag, which means that \w will match  
the numbers, plus anything that could be considered a Unicode  
character. At least, that's my understanding.

Hope that answers your question,
Eric

>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to deploy Django on the web server?

2009-08-08 Thread Eric Abrahamsen

On Aug 8, 2009, at 8:24 PM, justin jools wrote:

> ok well thanks for your reply:
>
> first I have free access and they have told me python is installed  
> but it's not working as I ran a hello world test script which doesbt  
> execute. That is the first of my problems.
>
> My second problem is installing Django...
>
> and third configuring the django scripts to run as outlined in the  
> django book, but I am stuck and the first and second hurdles...
>
> I have been looking for a web host server that does support but  
> seems there isnt any.. python support is a paid for service.

Yep, free services will often be limited to static web pages... If you  
want full control over your installation you'll probably have to pay a  
bit!

E

>
> 
>
> If you can offer any advice here its would be great. I guess the  
> first thing i need to do is bug the administrator to get a Python  
> test script running.
>
> On Fri, Aug 7, 2009 at 10:45 PM, Daniel Roseman  
>  wrote:
>
> On Aug 7, 9:56 pm, justin jools  wrote:
> > thanks for the reply but I have access to a server for free so I  
> wanted to
> > set it up myself, how can it be so difficult? Django is renowned  
> as an easy
> > rapid development framework so why is it so difficult to deploy?
> >
> You haven't said why you think it's difficult. The documentation is
> clear, and most people here have found it fairly easy to deploy. What
> has been your problem? Why has the Django book not told you want you
> want?
> --
> DR.
>
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to deploy Django on the web server?

2009-08-08 Thread Eric Abrahamsen

On Aug 8, 2009, at 5:14 PM, justin jools wrote:

> Yes Ive read these docs and I understand certain script changes are  
> needed before running on the server but I want to know about:
>
>  installing Django on the server, do i need to use telnet to do  
> this? or can i upload already executed django directory from local  
> server?

Django is a Python library like any other, so you'll need to be able  
to add new libraries to your webhost's python installation. Whether  
you do that as a svn checkout or upload a directory doesn't matter,  
but you will need access to the python installation (or be able to  
talk them into installing the library themselves). Django doesn't  
really need to be compiled/executed, if you can just get the source  
directory uploaded, into a place that's accessible to the python path,  
that will be enough.

Installing django is extremely easy, provided you've got a host that  
allows you to install libraries. If they don't, then it could be very  
hard/impossible. Unfortunately, free hosts often aren't willing to  
give you shell access, or much put themselves out on your behalf,  
simply because they're free.

Once you've got django installed, your own website is a similar deal:  
a set of files in a directory that needs to be on the python path. If  
you can install django you can install your own website. If you cant  
do one, you can't do the other.

Hope that's what you were after,
Eric

>
> On Fri, Aug 7, 2009 at 10:25 PM, Milan Andric   
> wrote:
>
>
> Justin, it's not.  Have you seen the deployment docs?
>
> http://docs.djangoproject.com/en/dev/howto/deployment/#howto-deployment-index
>
> --
> Milan
>
> On Aug 7, 1:56 pm, justin jools  wrote:
> > thanks for the reply but I have access to a server for free so I  
> wanted to
> > set it up myself, how can it be so difficult? Django is renowned  
> as an easy
> > rapid development framework so why is it so difficult to deploy?
> >
> >
> >
> > On Fri, Aug 7, 2009 at 8:34 PM, lzantal  wrote:
> >
> > > On Aug 7, 12:06 pm, justin jools   
> wrote:
> > > > This has been driving me nuts for a month.
> >
> > > > I wanted to use a free web server to do development testing  
> and have
> > > > found : 000webhost.com and heliohost.com which apparently  
> support
> > > > Python, but what about Django? Do I install that myself?
> >
> > > > I have read the django book on deployment chapter but find it  
> doesnt
> > > > tell me what I want.
> >
> > > > Could someone please just tell me simply how I can get my  
> scripts
> > > > running on the webserver.
> >
> > > Tryhttp://webfaction.com.
> > > They have super easy install for django through their control  
> panel
> >
> > > hope that helps
> >
> > > lzantal
> > >http://twitter.com/lzantal
> >
> > > > justinjo...@googlemail.com
>
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: [solved]Re: test if GET is "empty"

2009-07-29 Thread Eric Abrahamsen


On Jul 29, 2009, at 9:57 PM, Salvatore Leone wrote:

>
>
>> Given the way boolean tests go in Python, you should just be able to
>> test for the dictionary itself:
>>
>> if request.GET:
>>   
>> else:
>>   
>>
>> E
>>
>
> mmm I don't think so, I think request.GET is true even if the  
> dictionary
> is empty, isn't it?

No, I just tried it out to make sure, and it does work, though Luke's  
solution is more robust and accurate.

E

>
> so the test will allways return true for a GET request.
>
> -Salvatore
>
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: [solved]Re: test if GET is "empty"

2009-07-29 Thread Eric Abrahamsen


On Jul 29, 2009, at 6:06 PM, Salvatore Leone wrote:

>
> I answer my self:
>
> all I need is to test the length of the dictionary.
>
> if request.method == "GET" and len(request.GET) != 0:

Given the way boolean tests go in Python, you should just be able to  
test for the dictionary itself:

if request.GET:
   
else:
   

E

>  #do stuff
>> Hello,
>>
>> I need to test if the request.GET is empty or if it holds some  
>> variable.
>> So if is empty I can redirect to a page, and if there is some  
>> variable
>> (like user_id='2') I can process the request and do something with
>> theese variables.
>>
>>
>> Is there any way or do I have to test for every single variable?
>>
>> You know, it's boring to write "if request.GET['var1'] and
>> request.GET['var2'] and ..."
>>
>> Regards,
>> Salvatore
>>
>>>
>>
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: using modelformsets

2009-07-06 Thread Eric Abrahamsen


On Jul 5, 2009, at 11:32 PM, Matthias Kestenholz wrote:

>
> Hi,
>
> On Sun, Jul 5, 2009 at 11:42 PM, Eric Abrahamsen<gir...@gmail.com>  
> wrote:
>>
>> I'm somehow failing to use modelformsets, this is the relevant view
>> and error traceback:
>>
>> http://dpaste.org/evHq/
>>
>> I'm validating a whole bunch of forms at the same time, but I don't
>> see how that could cause the formset failure. Sample is a model  
>> with a
>> ForeignKey to Author (though the ForeignKey field itself is called
>> 'translator', stupid naming practice). I'm hoping there's something
>> obviously wrong with what I'm doing there, but I can provide more
>> details if necessary...
>>
>
>
> It seems that the modelformset code cannot find the primary key values
> in the POST request. You need to include the primary key hidden field
> in your form code, otherwise it will not work; something like this:
>
> {% for form in formset %}
>   {{ form.id }}
>   {# the rest of your code #}
> {% endfor %}
>
>
> I don't recall whether this is documented or not. This approach worked
> for me, though.

And it worked for me too! That solved the problem – I was looking in  
the wrong direction completely. It's all documented, I just never paid  
close attention to the model formset stuff below the section on views.  
Thanks for dragging me back on track.

E


>
>
>
> Matthias
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



using modelformsets

2009-07-05 Thread Eric Abrahamsen

I'm somehow failing to use modelformsets, this is the relevant view  
and error traceback:

http://dpaste.org/evHq/

I'm validating a whole bunch of forms at the same time, but I don't  
see how that could cause the formset failure. Sample is a model with a  
ForeignKey to Author (though the ForeignKey field itself is called  
'translator', stupid naming practice). I'm hoping there's something  
obviously wrong with what I'm doing there, but I can provide more  
details if necessary...

TIA,
Eric

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: filtering on reverse foreignkey using isnull

2009-06-01 Thread Eric Abrahamsen

On Jun 2, 2009, at 2:07 AM, Karen Tracey wrote:

> On Sun, May 31, 2009 at 11:40 PM, Eric Abrahamsen <gir...@gmail.com>  
> wrote:
>
> On May 31, 2009, at 11:45 PM, Karen Tracey wrote:
>
>> On Sun, May 31, 2009 at 10:13 AM, Eric Abrahamsen  
>> <gir...@gmail.com> wrote:
>>
>> Hi,
>>
>> I've got two models, Author and Entry, with a foreignkey from Entry  
>> to
>> Author. There are many Authors with no related entries, and until
>> recently I've been able to put this manager on the Author model to
>> only select Authors with Entries:
>>
>> def contributors():
>>  return self.exclude(entry__isnull=True)
>>
>> Recently this started returning a FieldError, saying it could not
>> resolve "entry" into a field.
>>
>> What changed?  Did you update Django?  Change your code?  Something  
>> must have changed, and if you could identify it, that would be a  
>> clue.
>> [snip]
>
> I identified the commit in my own code that blew things up (thanks  
> to my excellent version-tracking habits, it's a pretty large and  
> tangled commit). This commit touches neither the Author nor the  
> Entry model, it's got:
>
> Two new models, one called Sample with a ForeignKey to Author, one  
> called TranslatorProfile with a OneToOneField to Author (no related  
> names on either).
>
> ModelForms for both of these new models. I also moved two existing  
> modelforms to a different place in the file.
>
> I'm putting the diff file into dpaste here: http://dpaste.com/ 
> 49912/, in case anyone's got the patience to look at it. That's a  
> diff between -r301, which works, and working copy, which doesn't.  
> The whole models.py file (broken working copy) is here: 
> http://dpaste.com/49913/
>
> The only other possibly relevant thing I can think of is that  
> Entries also have a ManyToMany to Authors. An Entry is written by an  
> Author (the ForeignKey), but can also be "about" some unspecified  
> number of Authors. The ManyToMany has a related name on it, the  
> ForeignKey doesn't, but changing that doesn't fix the code, and  
> besides it has been working fine like that up until now.
>
>
> Identifying the commit is a good first step, next would be to  
> identify which part of the commit caused the break.  (Even though it  
> doesn't seem like any part of that commit should have caused the  
> break.  But it did, so you need to narrow it down to what exact part  
> of the commit in order to possibly figure out why.)
>
> Playing around with your models file and reducing it to the  
> essentials to recreate the problem reveals it's the new SampleForm.   
> Sample also has a ForeignKey to Author, one with a limit_choices_to  
> depending on a field in Author.  Having that limit_choices_to AND  
> defining the SampleForm before the Entry model apparently results in  
> an incomplete Author model.  I've opened #11247 to track this.  In  
> the meantime, moving all ModelForm definitions out of the models  
> file (or at least after all model definitions) avoids the problem.

Holy crow, this is simultaneously genius on your part, and also  
something I should have been able to figure out (or at least pinpoint)  
on my own :)

Thanks enormously for the solution – moving all model forms to the  
bottom of the file did the trick, and I'll keep an eye on that ticket.  
Thanks for getting me past this.

Eric



>
> Karen
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: filtering on reverse foreignkey using isnull

2009-05-31 Thread Eric Abrahamsen

On May 31, 2009, at 11:45 PM, Karen Tracey wrote:

> On Sun, May 31, 2009 at 10:13 AM, Eric Abrahamsen <gir...@gmail.com>  
> wrote:
>
> Hi,
>
> I've got two models, Author and Entry, with a foreignkey from Entry to
> Author. There are many Authors with no related entries, and until
> recently I've been able to put this manager on the Author model to
> only select Authors with Entries:
>
> def contributors():
>  return self.exclude(entry__isnull=True)
>
> Recently this started returning a FieldError, saying it could not
> resolve "entry" into a field.
>
> What changed?  Did you update Django?  Change your code?  Something  
> must have changed, and if you could identify it, that would be a clue.
>
> I'm running the most recent version of
> django. Before I go tearing up my app trying to figure out what I
> changed, I'd like to make sure – is this the recommended way to check
> for Authors with no Entries? I just found a couple of hints online
> saying to expect errors from this kind of code, though it has worked
> to date (and appears to still be working on some production code).
> Should this work?
>
> Where are these hints to expect errors from this sort of code?  In  
> the Django docs would be a reliable source (but I'd hope it would be  
> a lot clearer than a hint of possible errors), random blogs or old  
> mailing list threads not so much.

Thanks for the detailed response, Karen. I was just worried at first  
that isnull was an improper way of checking for Authors with no Entry  
(the hints came from this message 
[http://groups.google.com/group/django-users/msg/47ba69359ceace29 
] which I may have misinterpreted, the docs don't seem to reference  
this situation directly). But now I see that all filters using Entry  
are returning the same error, not just isnull, so it's definitely a  
problem in my code.

I identified the commit in my own code that blew things up (thanks to  
my excellent version-tracking habits, it's a pretty large and tangled  
commit). This commit touches neither the Author nor the Entry model,  
it's got:

Two new models, one called Sample with a ForeignKey to Author, one  
called TranslatorProfile with a OneToOneField to Author (no related  
names on either).

ModelForms for both of these new models. I also moved two existing  
modelforms to a different place in the file.

I'm putting the diff file into dpaste here: http://dpaste.com/49912/,  
in case anyone's got the patience to look at it. That's a diff between  
-r301, which works, and working copy, which doesn't. The whole  
models.py file (broken working copy) is here: http://dpaste.com/49913/

The only other possibly relevant thing I can think of is that Entries  
also have a ManyToMany to Authors. An Entry is written by an Author  
(the ForeignKey), but can also be "about" some unspecified number of  
Authors. The ManyToMany has a related name on it, the ForeignKey  
doesn't, but changing that doesn't fix the code, and besides it has  
been working fine like that up until now.

Many thanks for any insight!

Eric



and, for the heck of it, the traceback:

Traceback:
File "/Library/Python/2.5/site-packages/django-trunk/django/core/ 
handlers/base.py" in get_response
   92. response = callback(request, *callback_args,  
**callback_kwargs)
File "/Library/Python/2.5/site-packages/django-trunk/django/utils/ 
decorators.py" in _wrapped_view
   48. response = view_func(request, *args, **kwargs)
File "/Users/eric/stuff/dbase/views.py" in contributors
   128. conts = list(Author.objects.contributors())
File "/Users/eric/stuff/dbase/managers.py" in contributors
   34. return  
self 
.select_related 
("user").filter(is_contributor=True).exclude(entry__isnull=True)
File "/Library/Python/2.5/site-packages/django-trunk/django/db/models/ 
query.py" in exclude
   474. return self._filter_or_exclude(True, *args, **kwargs)
File "/Library/Python/2.5/site-packages/django-trunk/django/db/models/ 
query.py" in _filter_or_exclude
   483. clone.query.add_q(~Q(*args, **kwargs))
File "/Library/Python/2.5/site-packages/django-trunk/django/db/models/ 
sql/query.py" in add_q
   1610. self.add_q(child, used_aliases)
File "/Library/Python/2.5/site-packages/django-trunk/django/db/models/ 
sql/query.py" in add_q
   1614. can_reuse=used_aliases)
File "/Library/Python/2.5/site-packages/django-trunk/django/db/models/ 
sql/query.py" in add_filter
   1512. negate=negate,  
process_extras=process_extras)
File "/Library/Python/2.5/site-packages/django-trunk/django/db/models/ 
sql/query.py" in setup_joins
   1677. "Choices are: %s" % (name, ",  
"

filtering on reverse foreignkey using isnull

2009-05-31 Thread Eric Abrahamsen

Hi,

I've got two models, Author and Entry, with a foreignkey from Entry to
Author. There are many Authors with no related entries, and until
recently I've been able to put this manager on the Author model to
only select Authors with Entries:

def contributors():
  return self.exclude(entry__isnull=True)

Recently this started returning a FieldError, saying it could not
resolve "entry" into a field. I'm running the most recent version of
django. Before I go tearing up my app trying to figure out what I
changed, I'd like to make sure – is this the recommended way to check
for Authors with no Entries? I just found a couple of hints online
saying to expect errors from this kind of code, though it has worked
to date (and appears to still be working on some production code).
Should this work?

Thanks,
Eric
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to use next with comments?

2009-05-31 Thread Eric Abrahamsen


On May 29, 2009, at 5:40 AM, Kevin Fullerton wrote:

>
>
> On Thu, May 28, 2009 14:31, Eric Abrahamsen wrote:
>>
>> The default comment form does not include a next parameter, so if you
>> don't override the builtin comment templates you won't get any next
>> parameters in the forms.  The most sure way of doing this is using a
>> custom comment form with a next field – that way the form will  
>> include
>> the field no matter where it is used in your project. Otherwise, you
>> can use custom comment form and preview form templates – I'm guessing
>> you originally didn't have a custom preview template, which meant it
>> was using the builtin one, which meant... no next parameter in the
>> html form.
>
> Looking at the django source the next parameter is included in the  
> default
> preview template -
> http://code.djangoproject.com/browser/django/trunk/django/contrib/comments/templates/comments/preview.html
> line 9
>

Hmm, no kidding, not sure how I missed that. Dmitri's suggestion and  
the linked ticket would work for a GET parameter "next", but for  
previews and error corrections a simple form input value should work  
(and does work, in my case). Have you tried getting rid of your GET  
parameter value altogether, and only using the form input? Are you  
doing anything else strange in comment submissions? Also, why are you  
giving different next values in the GET parameter and the form input  
value, below?

E

> The code I'm using to submit the comment looks similar to
>
> {% get_comment_form for object as form %}
> http://blog.kenwa-solutions.co.uk/; method="POST">
> value="{{ object.get_absolute_url }}" />
>
> 
>
> So I'm not sure why the default preview form isn't picking it up
>
> Many thanks
>
> Kevin
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to use next with comments?

2009-05-28 Thread Eric Abrahamsen


On May 28, 2009, at 3:17 PM, Kevin Fullerton wrote:

>
> On Thu, May 28, 2009 01:50, Eric Abrahamsen wrote:
>>
>> On May 28, 2009, at 4:02 AM, Kevin Fullerton wrote:
>>
>>>
>>> I'm working with django.contrib.comments at the moment, and so far
>>> most
>>> things are working as expected.
>
> 
>
>>
>> It's a known problem and the patch for this is already in trunk –
>> update to r10418 or later, or you can stick the patch in yourself
>> (it's a pretty clean one-liner).
>>
>> HTH,
>> Eric
>>
>
> Thanks Eric, I'm running r10858 and having this problem - I've  
> removed any
> comments templates I've overridden in my application and still  
> getting the
> same problem - when the next parameter is passed in, it gets  
> ignored :(

The default comment form does not include a next parameter, so if you  
don't override the builtin comment templates you won't get any next  
parameters in the forms. The most sure way of doing this is using a  
custom comment form with a next field – that way the form will include  
the field no matter where it is used in your project. Otherwise, you  
can use custom comment form and preview form templates – I'm guessing  
you originally didn't have a custom preview template, which meant it  
was using the builtin one, which meant... no next parameter in the  
html form.

Hopefully something in there will work!

Eric

>
> Many thanks
>
> Kevin
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to use next with comments?

2009-05-27 Thread Eric Abrahamsen


On May 28, 2009, at 4:02 AM, Kevin Fullerton wrote:

>
> I'm working with django.contrib.comments at the moment, and so far  
> most
> things are working as expected.
>
> I'm building the submission form using {% get_comment_form for  
> object as
> form %} and have added the following as part of the form
>
>  value="{{ object.get_absolute_url }}" />
>
> As I understand it, that should force comments to redirect to that URL
> after successful submission - the problem is it doesn't.
>
> If I view the source of the submission form, the tag is there and
> populated correctly - if I preview or submit an incorrect POST then it
> brings up the preview screen, but there isn't a hidden next field in
> there.
>
> If I submit a correctly formed comment, it brings up the "Thank you  
> for
> your comment" template but doesn't redirect back to the original  
> object.
>
> I've tried removing the hidden field and doing
>
> 
>
> and have the same problem - is this a known problem, or is it  
> developer
> error (me)?

It's a known problem and the patch for this is already in trunk –  
update to r10418 or later, or you can stick the patch in yourself  
(it's a pretty clean one-liner).

HTH,
Eric


>
> Many thanks
>
> Kevin
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Rendering models using their own templates

2009-05-19 Thread Eric Abrahamsen


On May 20, 2009, at 10:53 AM, Roberto Cea wrote:

>
> I have a large amount of optional components (with a model for each
> one) that will be freely inserted by my users, and it would be
> impractical to render each one in a single large template.
> I want to give each component a ".render()" method, so I can just call
> that from the template.
> However, I don't want to have to put together each component's HTML in
> its model definition. Ideally, each component would have a
> corresponding template file, that would be added together with the
> page's other components' output to generate the complete page's HTML.
> Is there a way to specify, for each model, a small template-snippet
> file that will be used to represent it? Hopefully using Django
> standard template syntax?

I'm not sure this will completely solve your problem, but in several  
cases I've added python-only (non-database) attributes to models,  
pointing at a template in my template dirs directory. That way you can  
use generic code to render snippets for a variety of different models.  
You could create a mixin class that provides the render() method,  
using django's template rendering functions and a reference to  
self.component_template, then have models subclass this mixin and  
provide their own component_template attribute.

Hope that's what you were looking for.

Eric

> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: please help me

2009-05-16 Thread Eric Abrahamsen


On May 17, 2009, at 1:26 AM, Apple wrote:

>
> I write some code like following:
> 
> #coding=utf8
> from django.shortcuts import render_to_response
> from django.http import *
> from django.contrib.auth.models import User
> from django.contrib.auth.decorators import login_required
> import datetime
> import md5
>
> def to_reg(request):
>section = '欢迎注册为本系统的合法用户'
>return render_to_response('user_manage/to_reg.html',
> {'section':section})
> def reg(request):
>username = request.POST['user_name']
>first_name = request.POST['first_name']
>last_name = request.POST['last_name']
>email = request.POST['email']
>password = request.POST['password']
>re_password = request.POST['re_password']
>#获取当前时间
>nowtime = datetime.datetime.now()
>
>try:
>user = User.objects.get(username=username)
>msg = '此用户名已经被注册,请选用其他的用户名'
>return HttpResponse('alert(\'' + msg +
> '\');history.go(-1)')
>except:
>pass
>
>if password != re_password:
>msg = '您两次输入的密码不一致,请重新输入!'
>return HttpResponse('alert(\'' + msg +
> '\');history.go(-1)')
>else:
>try:
>user = User()
>user.username = username
>user.first_name = first_name
>user.last_name = last_name
>user.email = email
>user.password = md5.md5(password).hexdigest()#出于安全 
> 性的考虑
>user.is_staff = 0 #没有管理权限
>user.is_active = 1 #默认注册即激活
>user.is_superuser = 0 #不是超级用户
>user.last_login = nowtime #当前时间即最后登陆时间
>user.date_joined = nowtime #注册时间
>user.save()
>msg = '注册成功,请登陆后使用系统提供的各项功能!'
>return HttpResponse('alert(\'' + msg +
> '\');window.location.href="/"')
>except:
>msg = '注册失败,请重新尝试!'
>return HttpResponse('alert(\'' + msg +
> '\');history.go(-1)')
>
> def login(request):
>username = request.POST['user_name']
>password = request.POST['password']
>password = md5.md5(password).hexdigest()
>try:
>user = User.objects.get(username=username)
>real_password = user.password
>if  password == real_password and user.is_active == 1:
>msg = '登陆成功,您将进入会员中心!'
>return HttpResponse('alert(\'' + msg +
> '\');window.location.href="/user/user_center/"')

All you're doing here is checking that the password matches, you're  
not actually logging the user in (which requires sessions and cookies  
and all that). Take a look at this section of the docs to see how to  
do that:

http://docs.djangoproject.com/en/dev/topics/auth/#how-to-log-a-user-in

If you don't need your login view to do anything special, you can just  
use the built-in view that comes with the auth contrib app, found at  
django.contrib.auth.views.login. You can tie that directly into your  
url config.

Hope that helps,
Eric


>else:
>return HttpResponse("密码不正确")
>except:
>msg = '此用户不存在,或者因其他原因被禁止!'
>return HttpResponse('alert(\'' + msg + '\');history.go
> (-1)')
>
> @login_required
> def user_center(request):
>section = '用户中心'
>user = request.user
>user_id = user.id
>return render_to_response('user_manage/user_center.html',
> {'section':section},context_instance=RequestContext(request))
> ***
>
> I login the system successfully ,but when I redirect to the url that
> processed by the function user_center ,it said that i didn't login and
> redirect the page to the login page . why ? I really logged in ! Where
> is the point ?
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'base' template

2009-05-09 Thread Eric Abrahamsen

On May 9, 2009, at 1:21 PM, lisa holper wrote:

> Hi,
>
> I thanks for your answer again.
> Everything is showing up as plain text! It seems that the template  
> base.html would not be used.
>
> Do you have a further idea?

Nothing very likely, sorry to say. It sounds like your main problem is  
not that base.html isn't getting used, but that django is not loading  
and rendering the templates correctly. Is there a chance that you're  
looking at your template directory using a local apache installation,  
rather than a running django instance? Are your  
settings.TEMPLAT_LOADERS and settings.TEMPLATE_DIRS variables what  
they should be? Are permissions on the templates and parent  
directories set correctly? Someone else might have to step in here,  
and you'll probably have to provide a little more information: how is  
your project structured, what system/django version are you running,  
and how exactly are you running the development server.

Yours,
Eric

> Lisa
>
> On Fri, May 8, 2009 at 11:10 PM, Eric Abrahamsen <gir...@gmail.com>  
> wrote:
>
> On May 9, 2009, at 2:37 AM, lisa holper wrote:
>
>> Hi,
>>
>> Yes, I did and this shows up written on the page.
>> I can see the website on http://127.0.0.1:8000/ but not on my  
>> website-url. Do I need to change the settings?
>
> These are two very different questions... Are the other template  
> elements (variables and tags) getting rendered correctly, or is  
> everything showing up as plain text?
>
> And yes, you certainly do have to change the settings to deploy your  
> site at a different URL! Look through this:
> http://docs.djangoproject.com/en/dev/howto/deployment/#howto-deployment-index
>
> But you should probably back up and start with the tutorial:
> http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro- 
> tutorial01
>
> Eric
>
>
>>
>> Thanks, Lisa
>>
>> On Fri, May 8, 2009 at 5:57 AM, Eric Abrahamsen <gir...@gmail.com>  
>> wrote:
>>
>>
>> On May 8, 2009, at 4:35 PM, lisa holper wrote:
>>
>>> Hi,
>>>
>>> I created a website with django.
>>> My problem: When I insert all .html pages in my directory, I can  
>>> see the website but without using the 'base' template.
>>
>> Do you have {% extends 'base.html' %} at the top of all your  
>> templates? You have to extend from base explicitly.
>>
>> Eric
>>
>>
>>
>>>
>>> I would be glad for your help.
>>>
>>> Lisa
>>>
>>>
>>
>>
>>
>>
>>
>>
>>
>
>
>
>
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'base' template

2009-05-08 Thread Eric Abrahamsen

On May 9, 2009, at 2:37 AM, lisa holper wrote:

> Hi,
>
> Yes, I did and this shows up written on the page.
> I can see the website on http://127.0.0.1:8000/ but not on my  
> website-url. Do I need to change the settings?

These are two very different questions... Are the other template  
elements (variables and tags) getting rendered correctly, or is  
everything showing up as plain text?

And yes, you certainly do have to change the settings to deploy your  
site at a different URL! Look through this:
http://docs.djangoproject.com/en/dev/howto/deployment/#howto-deployment-index

But you should probably back up and start with the tutorial:
http://docs.djangoproject.com/en/dev/intro/tutorial01/#intro-tutorial01

Eric


>
> Thanks, Lisa
>
> On Fri, May 8, 2009 at 5:57 AM, Eric Abrahamsen <gir...@gmail.com>  
> wrote:
>
>
> On May 8, 2009, at 4:35 PM, lisa holper wrote:
>
>> Hi,
>>
>> I created a website with django.
>> My problem: When I insert all .html pages in my directory, I can  
>> see the website but without using the 'base' template.
>
> Do you have {% extends 'base.html' %} at the top of all your  
> templates? You have to extend from base explicitly.
>
> Eric
>
>
>
>>
>> I would be glad for your help.
>>
>> Lisa
>>
>>
>
>
>
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 'base' template

2009-05-08 Thread Eric Abrahamsen


On May 8, 2009, at 4:35 PM, lisa holper wrote:

> Hi,
>
> I created a website with django.
> My problem: When I insert all .html pages in my directory, I can see  
> the website but without using the 'base' template.

Do you have {% extends 'base.html' %} at the top of all your  
templates? You have to extend from base explicitly.

Eric



>
> I would be glad for your help.
>
> Lisa
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Question regarding django.contrib.comments

2009-04-22 Thread Eric Abrahamsen


On Apr 18, 2009, at 6:03 PM, SoCow wrote:

>
> Hi there,
>
> I've implemented django.contrib.comments and activated the custom
> redirect option by including the following line in the comments form:
>
>  value="{{ object.get_absolute_url }}" />
>
> This works great for redirecting back to the original object from
> which it was called. However, I can't work out how to achievie this
> from the preview.html form view, the above method sends me to:
>
> comments/post/c?c=x
>
> where x is the comment number. How would I return the user to the
> original page from which the comment was attempted to be entered?

What version of django are you using? Revision 10418 fixes this so  
that the "next" parameter gets passed in to the preview view. You can  
update to this version or later, or look at the patch and apply it  
yourself, it's pretty simple.

Yours,
Eric

>
> I'm a total newbie so please give as much detail as you can.
>
> Many thanks, much appreciated.
>
> Brap!
>
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



custom comment app migration

2009-04-09 Thread Eric Abrahamsen

I'm planning on migrating an existing (django.contrib) comments setup  
into a custom comment app, and I'm wondering if anyone's got any  
experience to impart in this regard. I have done cross-app data  
migration before, and cocked it up horribly. These are the steps I'm  
considering; if anyone's got suggestions, or sees anything wrong here,  
for god's sake speak up please.

1. Make my custom comment app, then copy all models, forms, peripheral  
models, comment-related signals, etc etc, into it. Leave existing  
stuff in place. Add the appropriate get_model() and get_form()  
functions to __init__.py. Augment new models as necessary. Run syncdb  
to make tables for the new app.

2. Add COMMENTS_APP to settings.py, pointing to my new app. Alter the  
existing django_content_type table to also point to this new app. (I  
see the existing app_label is just 'comments', if I call my custom app  
'comments' too, can I get away with not changing anything in this  
table?).

3. Go into the shell and copy data from existing comment instances  
(I've also got Commenter and CommentNotification models) into the new  
app models.

4. Pull changes onto production server, run syncdb, repeat steps 2 and  
3 above, restart.

5. Delete old code and old db tables from both development and  
production environments.

6. Golden.

Does this seem right? I'm particularly worried about problems that  
might arise from having the existing code pointing to a new app. Is  
there anything besides django_content_type that needs to know what's  
changed?


If this works I hope it will be useful as a roadmap to others equally  
frightened of databases.

Thanks,
Eric

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: redirect back after save

2009-03-28 Thread Eric Abrahamsen


On Mar 28, 2009, at 8:04 PM, Paddy Joy wrote:

>
> I have a form that can be called from multiple places. What's the best
> way to redirect back to the original page after the form has been
> saved.

I think the standard way to do this is to include a hidden form  
element (usually called "next") the value of which is set to the  
current page (or wherever you want to send the user). This value  
sticks during form processing, and is used as a redirect value  
afterwards. Many built-in or third-party forms are already set up to  
take advantage of a "next" (or something similar), and it's easy  
enough to do for your own forms.

HTH,
Eric


>
> Do I need to extract the HTTP referrer or is there a better way?
>
> Paddy
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Design patterns for create/update view

2009-03-23 Thread Eric Abrahamsen


On Mar 23, 2009, at 6:48 PM, Liubomir.Petrov wrote:

>
> Yep, i'm already using generic views, but its a big pain (a lot of
> code) for a single view that embeds create & update in one place.
> I wanned to ask here, because maybe my approach (the single create/
> update view) is not right ?

I'm not quite sure what you mean here, are you saying it's a lot of  
code in your url config to have CRUD lines for each model in each app?  
You could take a look at the admin app to see how it does model  
autodiscovery, and get some ideas about how you might automatically  
create url config lines for each model. The code lives in contrib/ 
admin/sites.py

Is that what you meant?


>
> On Mar 23, 12:13 pm, Eric Abrahamsen <gir...@gmail.com> wrote:
>> On Mar 23, 2009, at 6:06 PM, Lyubomir Petrov wrote:
>>
>>
>>
>>> Just wondering are there any docs/examples of design pattern with
>>> django for creating a "create/update" view.
>>
>> These views are written for you! See the CRUD section of the Generic
>> Views page:
>>
>> http://docs.djangoproject.com/en/dev/ref/generic-views/#create- 
>> update...
>>
>> All you have to do is design the URLs, and you can take hints from  
>> the
>> admin contrib app for that.
>>
>> Yours,
>> Eric
>>
>>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Design patterns for create/update view

2009-03-23 Thread Eric Abrahamsen


On Mar 23, 2009, at 6:06 PM, Lyubomir Petrov wrote:

>
> Just wondering are there any docs/examples of design pattern with
> django for creating a "create/update" view.

These views are written for you! See the CRUD section of the Generic  
Views page:

http://docs.djangoproject.com/en/dev/ref/generic-views/#create-update-delete-generic-views

All you have to do is design the URLs, and you can take hints from the  
admin contrib app for that.

Yours,
Eric


> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Need help with combined feed

2009-03-09 Thread Eric Abrahamsen


On Mar 10, 2009, at 12:43 AM, bax...@gretschpages.com wrote:

>
> I'm trying to build a combined feed, and not having much luck. Here's
> what I have:
>
> class CombinedFeed(Feed):
>title = site.name +" combined feed"
>link = "/"
>description = "Latest updates from all "+site.name +" feeds"
>description_template = 'feeds/combined.html'
>
>def items(self):
>combined = []
>articles   =   Article.objects.all().order_by('-created')[:
> 40]
>events =   
> Event.objects.filter(start_date__gte=now).order_by
> ('start_date')[:50]
>news   =   
> News_item.objects.filter(pub_date__lte=now).order_by('-
> pub_date')[:20]
>combined   =   itertools.chain(news, articles, projects, 
> issues,
> events)
>for item in combined:
>   try:
>  item.date = item.created
>   except:
>  try:
>item.date = item.topic_modification_date
>  except:
> try:
>item.date = item.pub_date
> except:
>try:
>   item.date = item.start_date
>except:
>   item.date = now
>return combined

Itertools.chain returns a generator. Once you've run through the  
generator a single time (as you're doing with "for item in combined")  
it's exhausted: your return statement is returning an empty iterable.

Here's how I do something similar with one of my feeds:

def items(self):
   el = list(Entry.objects.open()[:10])

el 
.extend(list(NewsLink.objects.filter(post_date__gte=el[-1].disp_date)))
   el.sort(key=lambda x: getattr(x, x._meta.ordering[0].strip('-')),  
reverse=True)
   return el

I've just decided that there aren't enough items to fret about calling  
list() on the whole thing, and it's important to me that everything  
return in proper order. If you're worried about prematurely evaluating  
the querysets (though you're doing that right now!), I remember once  
seeing a recipe on activestate or somewhere for a iter-style function  
that took several iterables and then returned items from each iterable  
in sorted order.

Also, you can avoid the whole attribute-testing chain (which would  
allow you to return an un-evaluated QuerySet), by using the  
_meta.ordering[0] trick to get the proper attribute name. Or specify  
the proper date attribute using a python-only attribute on each model.  
I do something similar to specify different templates to use for  
different models when rendering the feed: each model has a non-db  
'feed_template' string attribute.

Hope something in there is useful,

Eric

>
>
> Which doesn't appear to do anything. No error, but no ojb in
> combined.html, either.
> Suggestions?
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Overriding the HTML id in ModelForm

2009-03-05 Thread Eric Abrahamsen


On Mar 5, 2009, at 11:14 AM, Alex Gaynor wrote:

>
> On 3/4/09, Eric Abrahamsen <gir...@gmail.com> wrote:
>>
>>
>> On Mar 5, 2009, at 8:05 AM, Romain wrote:
>>
>>>
>>> Hello,
>>>
>>> On the same page I have 2 ModelForm that happen to have an attribute
>>> with the same name. Is it possible to choose the name of the HTML id
>>> generated by the form without having to change the real name of the
>>> model attribute?
>>
>> A simple solution would be to instantiate your ModelForms with a  
>> prefix:
>> http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for- 
>> forms
>>
>> Another, finer-grained choice is using the auto_id argument:
>> http://docs.djangoproject.com/en/dev/ref/forms/api/#configuring-html-label-tags
>>
>> Hope that's what you're looking for,
>>
>> Eric
>>
>>>
>>> e.g.
>>> class A(models.Model):
>>> amount = models.IntegerField()
>>>
>>> class B(models.Model):
>>> amount = models.IntegerField()
>>>
>>>
>>> class AForm(ModelForm):
>>> class Meta:
>>>   model = A
>>>
>>> class BForm(ModelForm):
>>> class Meta:
>>>   model = B
>>>
>>> Conflict of ids when forms printed:
>>> ...
>>> 
>>> ...
>>> 
>>> ...
>>>
>>> Thanks a lot,
>>>
>>> Romain
>>>
>>>>
>>
>>
>>>
>>
>
> Auto_I'd won't help. The issue is the names conflict in the POST so
> this is an issue for prefix.

Whoops, thanks for pointing that out!

E


>
> Alex
>
> -- 
> "I disapprove of what you say, but I will defend to the death your
> right to say it." --Voltaire
> "The people's good is the highest law."--Cicero
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Overriding the HTML id in ModelForm

2009-03-04 Thread Eric Abrahamsen


On Mar 5, 2009, at 8:05 AM, Romain wrote:

>
> Hello,
>
> On the same page I have 2 ModelForm that happen to have an attribute
> with the same name. Is it possible to choose the name of the HTML id
> generated by the form without having to change the real name of the
> model attribute?

A simple solution would be to instantiate your ModelForms with a prefix:
http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms

Another, finer-grained choice is using the auto_id argument:
http://docs.djangoproject.com/en/dev/ref/forms/api/#configuring-html-label-tags

Hope that's what you're looking for,

Eric

>
> e.g.
> class A(models.Model):
>  amount = models.IntegerField()
>
> class B(models.Model):
>  amount = models.IntegerField()
>
>
> class AForm(ModelForm):
>  class Meta:
>model = A
>
> class BForm(ModelForm):
>  class Meta:
>model = B
>
> Conflict of ids when forms printed:
> ...
> 
> ...
> 
> ...
>
> Thanks a lot,
>
> Romain
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Sending a list of items by email

2009-03-03 Thread Eric Abrahamsen


On Mar 3, 2009, at 7:52 PM, Alfonso wrote:

>
> Thinking this should be easy but not sure of the correct path to
> success!
>
> Got a simple filter queryset that pulls order products from a db:
>
> order_list = CustomerBasket.objects.all()
> customer = UserProfile.objects.get(user=user).customer
> email = EmailMessage(
>'New Customer Order: %s ' % customer,
>'%s' % order_list, to = ['email']
> )
> email.send()
>
> So when running the  above I get this in the sent email:
>
> [, , ]
>
> At least it's sending the email :-)  My question is, what's a
> straightforward way to iterate through the items in 'order list' and
> print them nicely in the email body.

You'll probably want to make a plain text template for your email  
bodies, and then render it using render_to_string and putting that  
string into the EmailMessage(). It's going to look ugly otherwise, as  
it appears string formatting runs model instances through repr() when  
they're inside another data structure (your list, in this case). If  
you don't want to do that you can use '\n'.join([unicode(x) for x in  
order_list]) to produce slightly nicer-looking formatting.

Yours,
Eric


>
> Thanks
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to select a single field from database with django QuerySet API?

2009-02-26 Thread Eric Abrahamsen


On Feb 26, 2009, at 6:23 PM, marco sedda wrote:

>
> Hi,
>   I want to select a "single" field from a table, i've read the
> QuerySet API reference but i can't find anything to solve my query.
>
> Just to explain:
>
> If i've a table like:
>
> User
>   first_name = models.CharField(max_length=30)
>   last_name = models.CharField(max_length=30)
>
> how i can execute a sql query "SELECT first_name FROM User" with
> QuerySet API?

You want the values() queryset call 
(http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-fields 
). Your query would probably look like  
User.objects.values('first_name'), or if you wanted a plain list  
(values usually returns a dictionary), you can use values_list() with  
the 'flat' parameter.

Hope that helps,
Eric

>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Passing HTML Table to a Template

2009-02-26 Thread Eric Abrahamsen


On Feb 26, 2009, at 4:30 PM, tykun...@gmail.com wrote:

>
> Hi I am trying to pass an HTML table to a template and have it display
>
> Currently I have{{table1}} inside my template to mark the position
> I wish to display the table
>
> In my views.py I havereturn render_to_response('results_s.html',
> {'table1': table1})
>
> From this all I get back is the code for the HTML table inside my
> template rather than having the template recognize it as HTML

You're almost certainly getting autoescaped 
(http://docs.djangoproject.com/en/dev/topics/templates/#id2 
). Try using {{ table1|safe }} in your template.

Yours,
Erc


>
> Any suggestions on how I can pass the table and display it inside a
> template.
>
> thanks
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django

2009-02-19 Thread Eric Abrahamsen


On Feb 19, 2009, at 10:05 PM, Nalini wrote:

>
> While inputting an invalid username and password it should throw an
> alert message saying "invalid user". How to get this in django? Do i
> need to add something in views.py?

It's hard to know exactly what you're doing here, but I'm going to  
guess that you want to use the views that come with contrib.auth. See  
this page for details:

http://docs.djangoproject.com/en/dev/topics/auth/#authentication-in-web-requests

If that's not what you wanted, give us a little more information about  
what you're up to.

Yours,
Eric


>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Changing an ImageField file without re-upload

2009-02-16 Thread Eric Abrahamsen


On Feb 17, 2009, at 5:17 AM, Carmelly wrote:

>
> My situation is this: I want to allow my users to upload multiple
> userpics and then choose between them. So I have a Profile model with
> an ImageField for the userpic. When users upload a file it is
> displayed around the site as usual. When they upload a new file, that
> file replaces their the "userpic" field in their Profile and is
> displayed all over the site, but the old userpic is not overwritten on
> disk. This is what we want.

Have you tried this out? So far as I can see, ImageField and FileField  
uploads don't overwrite old files, even if the filename is the same  
(underscores are appended to the filename). This much should be  
working already.

> Now, if I display a page for the user with all the userpics they ever
> uploaded and let them choose between them, how can I set the path in
> the ImageField to the file the chose? I know there is a userpic.save()
> method, but I'm not sure what to pass into it, or if this is even the
> correct way to go about it.

You could do something hacky where a view displays the contents of a  
directory and allows you to manipulate what you find there, but  
probably what you want is a separate UserPic model, with a M2M  
relation to your Profile. That way each user can have as many pics as  
they want, they can be accessible inline from their profile page, and  
you'll have the convenience of working with a proper django model  
instance. Put a datetime attribute on each photo, and you can use that  
to sort and display the most recently uploaded.

Hope that helps,
Eric

> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: getting database definition in line

2009-02-03 Thread Eric Abrahamsen



On 2月4日, 下午12时03分, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Tue, 2009-02-03 at 19:47 -0800, Eric Abrahamsen wrote:
>
> > On Feb 4, 11:25 am, Malcolm Tredinnick <malc...@pointy-stick.com>
> > wrote:
> > > On Tue, 2009-02-03 at 19:10 -0800, Eric Abrahamsen wrote:
> > > > Hi there,
>
> > > > I'm unable to do any testing -- my fixtures fail with a "Duplicate
> > > > Entry" error when loading. From what I've googled, this might have
> > > > something to do with a mismatch between my model definitions and the
> > > > sql table definition.
>
> > > "Duplicate Entry" is the database telling you that some column(s) with a
> > > unique constraint are failing the constraint check. So it's
> > > database-level data related and the first thing to check is the data
> > > you're trying to insert.
>
> > Aha! I had assumed duplicate entry meant it thought there were two
> > rows with the same pk. On second thought, that wouldn't make too much
> > sense.
>
> It could very well mean that. A primary key column has a uniqueness
> constraint as part of the requirement (it has to be unique and not-NULL,
> pretty much by definition). In fact, since the only column with a unique
> constraint in the table you give is the primary key column, it almost
> has to be that one that is the problem.

I guess the problem wasn't duplicate pks, but egregious quantities of
otherwise-illegal data, mostly NULL values where empty strings were
required. Even after correcting the bad data (and doing a reset and
reloading it with loaddata, which went without a hitch) I still got
the error whenever I dumped the entire database and loaded it in
testcases as a single fixture. But dumping apps separately, and
loading them only as needed for individual testcases, has cleared
things up. It's left me a little suspicious of my whole setup (can I
get a test framework for my test framework?), but at least it's
working.

Thanks for pushing me in the right direction.

E


>
> > This only helps a little bit, though, since none of the fields have
> > unique=True, none of the db columns are unique, and I've got no
> > unique_together constraints. The fixture is a direct output of
> > dumpdata, in xml format (I get the same error with JSON). The pks are
> > included, but there's no duplication there.
>
> The database would like to disagree with you and I'm inclined to trust
> it.
>
> So either (a) there is a duplicate primary key value, (b) the database
> table is not empty to start with and one of the existing entries clash,
> or (c) you are trying to load that fixture more than once without
> flushing the previous data.
>
> The problem is definitely in the data and/or the number of times it's
> being loaded. So trim things down. For example, what happens if you cut
> it in half? If you reduce it to only a single line? Just the second half
> instead of the first half? What happens if you try to load the data
> manually using "loaddata" into an empty database, instead of using the
> test framework? Et cetera, et cetera.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: getting database definition in line

2009-02-03 Thread Eric Abrahamsen



On Feb 4, 11:25 am, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Tue, 2009-02-03 at 19:10 -0800, Eric Abrahamsen wrote:
> > Hi there,
>
> > I'm unable to do any testing -- my fixtures fail with a "Duplicate
> > Entry" error when loading. From what I've googled, this might have
> > something to do with a mismatch between my model definitions and the
> > sql table definition.
>
> "Duplicate Entry" is the database telling you that some column(s) with a
> unique constraint are failing the constraint check. So it's
> database-level data related and the first thing to check is the data
> you're trying to insert.

Aha! I had assumed duplicate entry meant it thought there were two
rows with the same pk. On second thought, that wouldn't make too much
sense.

This only helps a little bit, though, since none of the fields have
unique=True, none of the db columns are unique, and I've got no
unique_together constraints. The fixture is a direct output of
dumpdata, in xml format (I get the same error with JSON). The pks are
included, but there's no duplication there.

This is the full model definition: http://dpaste.com/116418/
and the full output of describe table: http://dpaste.com/116419/

If you've got a moment and can see anything in there that's obviously
wrong, I'd appreciate any pointers. Otherwise, I've got a better sense
of how to go about hunting this down now.

Thanks a lot,
Eric



> [...]
>
> > The only unusual thing about the second record is that it's the first
> > one with "characters" set to an empty string. I'm using a django
> > updated earlier in the day.
>
> If the primary key specified in the data you're trying to insert? If so,
> and it's not different between the two, that's one case of a unique
> field that will be causing you problems.
>
> If you know which two records are causing the problem, another part of
> reducing the problem to the simplest case is to try a few experiements.
> Each time, change one of the pieces of data in the second entry. At some
> point, you'll change the attribute that is causing the problem, so
> you'll at least know which one it is.
>
>
>
> > model
> > 
>
> > class Author(models.Model):
> >   surname = models.CharField(max_length=30)
> >   given_name = models.CharField(max_length=30)
> >   slug = models.SlugField(blank=True)
> >   characters = models.CharField(max_length=6,blank=True)
> >   user = models.ForeignKey(User, blank=True, null=True)
> > ...more
>
> Yeah, that "more" bit is no doubt containing important information. For
> example, do you have a Meta inner class that is defining any
> unique_together constraints? Do any of the fields you've omitted have
> unique=True on them? Which columns in the database table require the
> entries to be unique?
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



getting database definition in line

2009-02-03 Thread Eric Abrahamsen

Hi there,

I'm unable to do any testing -- my fixtures fail with a "Duplicate
Entry" error when loading. From what I've googled, this might have
something to do with a mismatch between my model definitions and the
sql table definition. This fails on a model that I've done a lot of
manual sql editing on, so it's likely that I've inadvertently screwed
something up. After messing with this for an afternoon, I'm just going
to post the first few lines of the model and the output of DESCRIBE
TABLE, and I hope someone will see something obviously wrong here. The
fixture loading fails like this:
IntegrityError: (1062, "Duplicate entry 'dbase-author' for key 2")

The only unusual thing about the second record is that it's the first
one with "characters" set to an empty string. I'm using a django
updated earlier in the day.

model


class Author(models.Model):
  surname = models.CharField(max_length=30)
  given_name = models.CharField(max_length=30)
  slug = models.SlugField(blank=True)
  characters = models.CharField(max_length=6,blank=True)
  user = models.ForeignKey(User, blank=True, null=True)
...more

DESCRIBE TABLE
#
Field Type Null Key Default Extra
id int(11) no pri null auto_increment
surname varchar(30) no [blank] [blank] [blank]
given_name varchar(30) no [blank] [blank] [blank]
slug varchar(50) no [blank] [blank] [blank]
characters varchar(6) no [blank] [blank] [blank]
user_id int(11) yes mul null [blank]
...more


Is this something to do with having a foreignkey that's set to
blank=True,null=True?

TIA,
Eric
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Custom Template Tag - Passing variable for use in tag processing

2009-01-27 Thread Eric Abrahamsen


On Jan 28, 2009, at 1:52 AM, phoebebright wrote:

>
> I have duplicated as best I can the processing for handling variables
> in custom template tags mentioned in an earlier post but it's not
> working for me as I need the value of the variable before I parse it.
> Is there another way of making the variable available?
>
> The tag is being called from the tempalte with:
>
> {% page_links "category"  %}
>
> Where category is being passed into the template from a view.  (also
> tried "{{category}}" and {{category}} and category)
>
> I want to use the value of category to determine which list of pages
> to return.
>
> I KNOW THIS DOESN"T WORK:
>
> @register.tag(name="page_links")
> def get_page_links(parser,token):
>tag_name, cat = token.contents.split()
>return PageLink(cat[1:-1])
>
> class PageLink(template.Node):
>
>def __init__(self, cat):
>
>cat= template.Variable(cat)
>print cat   <-  outputs category
>if cat=='business':
>pages=BusinessPage.objects.filter
> (is_live=True).select_related().order_by('order')
>elif cat=='community':
>pages=CommunityPage.objects.filter
> (is_live=True).select_related().order_by('order')
>elif cat=='tourism':
>pages=TourismPage.objects.filter
> (is_live=True).select_related().order_by('order')
>
>else:
>pages = False
>
>self.pages = pages
>
>def render(self, context):
>context['pages'] = self.pages
>
>return ''
>

I might be missing something you're trying to do here, but the usual  
method for resolving a variable in a custom template tag is to first  
put it into the tag (without quotes) like so:
{% page_links category %}

Then attach that to your PageLink node in its __init__ method as a  
Variable:
self.cat = template.Variable(cat)

Then inside the render method first resolve it:
category = self.cat.resolve(context)

and then check the value of category against your various models. That  
all has to be done in render, not __init__, because context is only  
available in render.

This is all straight out of the docs:
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#passing-template-variables-to-the-tag

Apologies in advance if I've misunderstood what you're trying to do...

Eric




>
> This code works fine as long as I call it like this:
>
> {% page_links "business" %}
>
> @register.tag(name="page_links")
> def get_page_links(parser,token):
>
>tag_name, cat = token.contents.split()
>cat = cat[1:-1]
>
>if cat=='business':
>pages=BusinessPage.objects.filter
> (is_live=True).select_related().order_by('order')
>elif cat=='community':
>pages=CommunityPage.objects.filter
> (is_live=True).select_related().order_by('order')
>elif cat=='tourism':
>pages=TourismPage.objects.filter
> (is_live=True).select_related().order_by('order')
>else:
>pages = False
>
>return PageLink(pages)
>
> class PageLink(template.Node):
>
>def __init__(self, pages):
>self.pages = pages
>
>def render(self, context):
>context['pages'] = self.pages
>
>return ''
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to avoid hardcoding of logfile path in logging.conf file

2009-01-27 Thread Eric Abrahamsen


On Jan 27, 2009, at 9:45 PM, Rama Vadakattu wrote:

>
> Eric,
> can you please show me the code snippet of specifying a logfile in
> settings.py.

Sure, here's something I use to keep a separate log of requests to an  
RSS feed:

settings.py
###
LOG_FILE = '/path/to/log/file.log'

feeds.py
##
import logging
from mysite.settings import LOG_FILE as lf

... # later in the file

feedlog = logging.FileHandler(lf)
form = logging.Formatter("%(asctime)s: %(message)s")
feedlog.setFormatter(form)
root = logging.getLogger('')
root.addHandler(feedlog)

def feedlogger(fn):
 def wrapper(request,*args,**kwargs):
 root.info("%s %s" % (request.path,  
request.META.get('REMOTE_ADDR','')))
 resp = fn(request,*args,**kwargs)
 return resp
 return wrapper


Then I import the feedlogger wrapper into my urls.py and wrap the  
appropriate function there. The syntax for the logging handler is a  
bit of a PITA, but that's just how Python logging works...

Hope that helps,
Eric


> On Jan 27, 6:37 pm, Eric Abrahamsen <gir...@gmail.com> wrote:
>> On Jan 27, 2009, at 9:28 PM, Thomas Guettler wrote:
>>
>>
>>
>>> Rama schrieb:
>>>> please look at the below logging.conf file.
>>>> ...
>>>> can any one  guide me on how to avoid hardcoding of log file path ?
>>
>>> Hi,
>>
>>> I am not a logging expert, maybe there is a solution, but if you
>>> do your setup with python code, you can use e.g.  
>>> os.environ['HOME'] or
>>> settings.FOO.
>>
>> This last (specifying a logfile in settings.py) has always worked  
>> very
>> nicely for me.
>>
>> E
>>
>>> I never used a logging.conf file.
>>
>>> HTH,
>>>  Thomas
>>
>>> BTW: This is a pure python question. You get more and better answers
>>> on the newsgroup comp.lang.python.
>>
>>> --
>>> Thomas Guettler,http://www.thomas-guettler.de/
>>> E-Mail: guettli (*) thomas-guettler + de
>>
>>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to avoid hardcoding of logfile path in logging.conf file

2009-01-27 Thread Eric Abrahamsen


On Jan 27, 2009, at 9:28 PM, Thomas Guettler wrote:

>
> Rama schrieb:
>> please look at the below logging.conf file.
>> ...
>> can any one  guide me on how to avoid hardcoding of log file path ?
>>
>>
> Hi,
>
> I am not a logging expert, maybe there is a solution, but if you
> do your setup with python code, you can use e.g. os.environ['HOME'] or
> settings.FOO.

This last (specifying a logfile in settings.py) has always worked very  
nicely for me.

E



> I never used a logging.conf file.
>
> HTH,
>  Thomas
>
> BTW: This is a pure python question. You get more and better answers
> on the newsgroup comp.lang.python.
>
>
>
> -- 
> Thomas Guettler, http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + de
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can't get django comments to pick up alternate form

2009-01-24 Thread Eric Abrahamsen


On Jan 25, 2009, at 1:54 PM, Theme Park Photo, LLC wrote:

>
> Also from reading the source, I don't see any mechanism by which it
> would pick up form.html from any other than the three directories
> enumerated there. Am I really supposed to edit and setup.py install
> the django framework to change the comments template?

The three directories in the template_search_list there are meant to  
refer to directories in the templates folder of YOUR project, not the  
django contrib comments installation. This definitely works under  
normal circumstances, so something else must be going wrong. I don't  
know how to get a list of template directories except by inducing an  
error, say by temporarily misnaming the comments templates directory  
within the django installation. Do you have django.contrib.comments  
coming before your own app in INSTALLED_APPS, by any chance?

E

>
>
> On Jan 24, 5:13 pm, "Theme Park Photo, LLC"  wrote:
>> The documentation for render_comment_form hints that you can override
>> the default template by puttingcomments/form.html with your own form
>> in your templates directory.
>>
>> No matter what I do, it won't pick up my alternate form.
>>
>> Is there anyway to see the actual directoriesdjangois checking for
>> this template?
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Anyway to see full UrlConf list of available imported urls?

2009-01-22 Thread Eric Abrahamsen

Here's one way. There's likely a cleaner option somewhere else:

from django.core.urlresolvers import get_resolver

r = get_resolver('mysite.urls')

for pattern in r._get_url_patterns(): print pattern

That works, at any rate.

Yours,
Eric


On Jan 23, 2009, at 3:55 AM, NoviceSortOf wrote:

>
>
> * Is there a way to see a full URLConf list of all the imported URLs,
> in
>  an application?
>
> This seems it would be a big debuging help.
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: I am doing the tutorial part 1 and i got this error

2009-01-19 Thread Eric Abrahamsen


On Jan 19, 2009, at 4:17 PM, jazz wrote:

>
> c:\projects\mysite>python manage.py sql polls
> Traceback (most recent call last):
>  File "manage.py", line 11, in 
>execute_manager(settings)
>  File "C:\Python25\Lib\site-packages\django\core\management
> \__init__.py", line 340, in execute_manager
>utility.execute()
>  File "C:\Python25\Lib\site-packages\django\core\management
> \__init__.py", line 295, in execute
>self.fetch_command(subcommand).run_from_argv(self.argv)
>  File "C:\Python25\Lib\site-packages\django\core\management\base.py",
> line 195, in run_from_argv
>self.execute(*args, **options.__dict__)
>  File "C:\Python25\Lib\site-packages\django\core\management\base.py",
> line 221, in execute
>self.validate()
>  File "C:\Python25\Lib\site-packages\django\core\management\base.py",
> line 249, in validate
>num_errors = get_validation_errors(s, app)
>  File "C:\Python25\lib\site-packages\django\core\management
> \validation.py", line 28, in get_validation_errors
>for (app_name, error) in get_app_errors().items():
>  File "C:\Python25\lib\site-packages\django\db\models\loading.py",
> line 128, in get_app_errors
>self._populate()
>  File "C:\Python25\lib\site-packages\django\db\models\loading.py",
> line 57, in _populate
>self.load_app(app_name, True)
>  File "C:\Python25\lib\site-packages\django\db\models\loading.py",
> line 72, in load_app
>mod = __import__(app_name, {}, {}, ['models'])
>  File "c:\projects\mysite\..\mysite\polls\models.py", line 4, in
> 
>class Poll(models.model):
> AttributeError: 'module' object has no attribute 'model'
>

Capitalization is important, you want to subclass models.Model, not  
models.model.

That should do the trick,

Eric


> This is wat i did:
>
> from django.db import models
>
> # Create your models here.
> class Poll(models.model):
>question = models.CharField(max_length=200)
>pub_date = models.DateTimeField('date published')
>
> class Choice(models.Model):
>poll = models.ForeignKey(Poll)
>choice = models.CharField(max_length=200)
>votes = models.IntegerField()
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Definitive Captcha?

2009-01-17 Thread Eric Abrahamsen

There's not really much needed to get captcha or recaptcha working  
with django, mostly just a class or two. When I was using recaptcha I  
found that this module:
http://code.google.com/p/recaptcha-django/
did most of what I needed. If you're shopping, however, I'd recommend  
Akismet (http://www.voidspace.org.uk/python/akismet_python.html). It's  
less intrusive for the user, and pretty impressively accurate. I've  
never had a false positive, and only two false negatives out of maybe  
five hundred spam messages. Coupled with a cronjob that deletes marked  
spam once it's a day old or so, this has more or less solved the spam  
problem for me.

YMMV,
E

On Jan 18, 2009, at 12:47 AM, Tim wrote:

>
> Hi - can anyone tell me what the de-facto standard is for adding
> Captcha support to a Django project? I have seen many implementations
> - the first Google hit for "django captcha" describes itself as "rough
> around the edges" and seems to not have much associated activity.
>
> By standard I just mean a good, solid implementation with reasonably
> wide community support.
>
> - Tim
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do i combine a list and a form in the same page using django?

2009-01-16 Thread Eric Abrahamsen


On Jan 16, 2009, at 5:10 PM, Gath wrote:

>
> Am building a Q page, sort of stackoverflow.com kinda page! Am
> having a bit of a problem trying to render the form. Am pasing 3
> objects to the template that renders the page i.e. Question object,
> Answers related to the question and Answer form object.
>
> In the first part of the page i want to display the Question, then the
> answers list related to the question follows, then at the bottom of
> the page i display my form to enter the new answer.
>
> On my template when i use the {{ extends "base_site.html" }} tag,
> then only the form get rendered without the first part of questions,
> When i remove that tag then only the Question section get displayed
> minus the form!!

Generally when you extend another template you need to be filling in  
blocks in that template. So the template below, in addition to {%  
block title %}, should probably be putting the rest of the content  
into a block that corresponds to a block in the base_site.html  
template. What does base_site.html look like?

E


>
> How can i go round this problem?
>
> this my template;
>
> {% extends "base_site.html" %}
>
> {% block title %}{% endblock %}
>
> >
>
> 
>
> 
>
>
> 
>
>
>
> {{ questobj.question }}
>
>
>
>{{ questobj.notes }}
>
>
>
>   {% regroup answerobj.object_list by answer as ans_list %}{{ ans_list|
> length }} -->
>
>
>{% for answers in answerobj.object_list %}
>   {{ answers.answer 
> }}
>   posted on:{{ answers.post_date }} font>
>   by: href="/user_profile/">{{answers.userid}}
> 
>
>   {% endfor %}
>
>
>  
>  
>
>
> 
>
>  
>
>
>   
>
> {{ form.as_table }}
>
>   
>
>   
>
>   
>
>  
>
>  
>
> 
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Adding a view inside a view?

2009-01-14 Thread Eric Abrahamsen


On Jan 15, 2009, at 2:42 AM, Bradley wrote:

>
> I'm new to Django and I'm trying to modify an existing django website
> for a local newspaper.  They would like to have a polls on the their
> website.  I just used the tutorial from the djangoproject website to
> create the polls module.  It works fine, except that I need it to work
> inside a  section on the front page, not multiple pages like is
> used in the tutorial.  What is the standard procedure for something
> like this?
>
> The tutorial had me create entries for /polls/ in urls.py  I probably
> don't need those.
> Do I somehow Integrate the polls function into already existing
> function that are used to display the front page?  Not really sure how
> to proceed

If I'm understanding this correctly, you might want to look at  
template tags:
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags

This would allow you to make calls to the database to retrieve  
whatever poll and related answers you want, render them as a stand- 
alone chunk of html, and then insert that html into an existing  
template. You could put it into the template as:


  {% get_poll_question some_poll %}


Where 'some_poll' was a variable that originates in your view.

Hope that helps,
Eric


>
> Any help would be appreciated.
>
> Thanks,
> Brad
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: setting cookies following comment post

2009-01-11 Thread Eric Abrahamsen

Solving my own problem... This wasn't nearly as hard as I thought,
here's the solution that worked for me:

urls.py
#
from datetime import datetime, timedelta
from django.conf.urls.defaults import *
from django.contrib.comments.views import comments
...others...

def remember_wrapper(fn):
"Set a cookie for commenters who want their personal info to be
remembered."
def wrapper(request,*args,**kwargs):
resp = fn(request,*args,**kwargs)
if resp.status_code == 302: # 302 must mean successful
post
if request.POST.get("remember",False):
cookie_val = "%s,%s,%s" % (request.POST.get
("name",''),request.POST.get("email",''),request.POST.get("url",''))
exp = datetime.now() + timedelta(days=30)
resp.set_cookie('mysite_comment',cookie_val,expires=exp.strftime
('%a, %d %b %Y %H:%M:%S'))
else:
resp.delete_cookie('mysite_comment')
return resp
return wrapper

urlpatterns = patterns("",
...many...
(r'^comments/post/$',remember_wrapper(comments.post_comment)),
(r'^comments/', include('django.contrib.comments.urls')),
...and more...
)

The views that display comment forms check for this cookie, and use
the information to populate the form. I suppose that could be done as
a context processor.

Hope someone finds that useful,
Eric

On Jan 4, 12:03 pm, Eric Abrahamsen <gir...@gmail.com> wrote:
> Hi there,
>
> I'm adding a "remember me" checkbox tocommentforms, so that regular  
> commenters can avoid having to enter their personal information, if  
> they want. I was originally thinking of making this a function  
> attached to the comment_was_posted signal, but it will have to be  
> implemented using cookies, which need to be set on the outgoing  
> response, which isn't available in signal handlers...
>
> I'm wondering if anyone else has made a functionality like this using  
> thecommentcontrib app, and how they went about doing it. There  
> doesn't seem to be any point in the process where I could get hold of  
> the response.
>
> Thanks!
> Eric
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



small contenttypes mystery

2009-01-10 Thread Eric Abrahamsen

I've got a Topic model, which is a bit like a category. Then there are  
TopicItem objects, which have a foreign key to a Topic, and a generic  
foreign key to anything else in the website, so that I can attach  
anything to a particular Topic. In my admin site, a few models have a  
generic inline formset for TopicItems, for conveniences' sake (all  
that work quite nicely, thanks to whoever developed that), and then  
the Topics themselves each display theirTopicItems via plain old  
inline formsets.

My question is, how do the TopicItems appearing on the Topics page  
determine their heading? At the bottom of each Topic page there's a  
"Topic Items" section, and each item within that section has a little  
heading reading "Topic item: None". I don't want it to say "None",  
obviously, I want it to produce the unicode method of the object  
that's connected (via generic foreign key) to that TopicItem. The  
TopicItem __unicode__ method looks like this:

def __unicode__(self):
   return unicode(self.content_object)

This works great in the shell: if I print a TopicItem, it prints the  
unicode method of its related object. But in the admin it's mostly  
None. Except for in *one* case, where one instance of one model  
produces the correct title. Everything else is still None. So clearly  
this is confusing. I can't see anything special about that one  
instance of that one model, and I can't (despite lengthy poking)  
actually figures out from where in the source code this particular  
value arises. Can someone just point me to a file and line number? Or  
otherwise clarify this?

Many thanks in advance,

Eric

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: first newbie question

2009-01-09 Thread Eric Abrahamsen


On Jan 9, 2009, at 10:19 PM, _Sebastian_ wrote:

>
> Hi all,
>
> I've been following the tutorial 
> http://docs.djangoproject.com/en/dev/intro/tutorial01/#playing-with-the-api
> and working on a own test-project as well.
>
> so I tried to adapt from
>
> class Poll(models.Model):
>question = models.CharField('question',max_length=200)
>
>def __unicode__(self):
>return self.question
>
> to this
>
> class Poll2(models.Model):
>question_number = models.IntegerField()
>
>def __unicode__(self):
>return self.question_number
>
> to list the actual question number instead of Question Object in the
> admin interface.
>
> Somehow it was not working. How do I need to do it so it's right?

A couple of questions: what do you mean exactly by question number?  
And also, how is it not working? And, for good measure, what would it  
look like if it were right? As you've written this, it should work  
fine – when you create a Poll object its data will consist of a number  
(but no question!), and that number will be returned by the  
__unicode__ method. You might be trying to retrieve the primary key  
for Poll2 objects, which is a column that Django usually makes  
implicitly for you, in the background, unless you specify that you  
want to do it yourself. If this is the number you want, you can get it  
in the __unicode__ method as self.pk. That might not really be what  
you want, though, because that number will increment regardless of  
deletes or modifications, and you can't (or shouldn't) modify it  
manually. If you were hoping for a number attribute that you can  
modify, and use for ordering, etc., let us know, and that should be  
easy to arrange.

Welcome and good luck,
Eric


> cheers,
>
> seb
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: HttpResponse HTML links missing URL prefix when emailing

2009-01-08 Thread Eric Abrahamsen


On Jan 8, 2009, at 8:37 PM, Eki wrote:

>
> Hi guys,
>
> I'm implementing a view which sends a (nightly) status report email.
> The code works mostly fine. I can both receive the email and see the
> result rendered as I query the view. The HTML shown and emailed is
> gotten from the same response object. However, the links included in
> the report only work in the browser view, but not in the email. For
> the email, the links are rendered with a default prefix of "http://;,
> and they are missing the domain name and https protocol specifier.
> I've been digging, but so far unable to find any reason why the prefix
> should be lost between two lines of code.

My guess is that in the HTML all the links come out as absolute links,  
minus the hostname. Ie href="/home/leaf/page/", rather than 
href="http://www.domain.com/home/leaf/page 
". That's usually how it is on a webpage, because the server assumes  
that all links are relative to the same domain. It's not that your  
code is changing between html and email, but that the domain is left  
out altogether in both cases – which works fine on a webserver, not so  
well when clicking a link in an email message.

You might want to use a separate template for the emails, or else put  
the current HTTP_HOST in a variable and resolve that for the links in  
both html and email.

Hope that helps,
Eric


>
>
> Here are the relevant parts of my functions:
>
> def send_daily(request):
>...
>
>response = render_to_response('email/status.html',
>{ ... a bunch of context stuff ... })
>send_email('Daily project status', 'sen...@nowhere.not',
> 'recei...@nowhere.not',
>'This report can only be viewed in HTML, which appears not to
> be supported by your email client.',
>response._get_content())
>return response
>
> def send_email(subject, from_email, to, text, html):
>msg = EmailMultiAlternatives(subject, text, from_email, [to])
>msg.attach_alternative(html, "text/html")
>msg.send()
>
> Thanks for any hints.
>
> -- Eki
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Process file after upload

2009-01-07 Thread Eric Abrahamsen


On Jan 7, 2009, at 9:32 PM, dmishe wrote:

>
> Hey.
>
> I have FielField in my model for user to upload ZIP-archives. I want
> to unpack that zip, place some files in some dirs and delete it just
> after user uploaded it in admin.
>
> How can i do this? Model's save won't work because it gets called
> everytime model is saved regardless of were the file uploaded again or
> not. Custom storage/upload handler seems too complicated for this.

A common way to check if an object is getting saved for the first time  
or not is to check if it has a pk. A newly created object won't have a  
pk until you call the super save() method, so you can put whatever  
operations you want to conduct inside an "if not obj.pk:" block. See  
if that does what you want...

Eric

>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Redirect User on First Log In

2009-01-05 Thread Eric Abrahamsen


On Jan 6, 2009, at 6:41 AM, Aruna wrote:

>
> I'm trying to redirect a user on their first log in, to a special
> welcome page. Subsequent logins will go to a regular page. Is there a
> way to do that in the templates? Does Django have a way to check if
> it's a users first login?

User instances have both a last_login and a date_joined attribute.  
Check how these defaults are filled for new users – if last_login  
equals date_joined, you can assume it's their first login. Check all  
the User attributes in the source code, and something will probably  
become evident.

Eric


>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: FileSystemStorage content vs PIL Image - **Initial solution**

2009-01-05 Thread Eric Abrahamsen


On Jan 5, 2009, at 7:47 PM, Donn wrote:

>
> On Monday, 05 January 2009 00:51:03 Donn wrote:
>> I am stuck on the interface between a PIL Image and a
>> FilesystemStorage 'content' object.
>>
>> I can: img = Image.open(content)
>> But how do I pass 'img' back to Django for saving?
>
> I have some kind of working example now.  I won't say I savvy it  
> properly, but
> it's a case of finding objects that FileSystemStorage.save will  
> accept.
>
> This object needs a 'chunks' attribute. It's raw data must also be  
> in binary
> format. So, I need to go from a PIL 'img' out to this magical object:
>
> You need this class
> from django.core.files.base import ContentFile
>
> And this:
> try:
> from cStringIO import StringIO
> except ImportError:
> from StringIO import StringIO
>
> In the code, insert:
>
> #Make a thing to hold our data
> o = StringIO()
>
> #convert the image to a binary file-like memory object
> img.save(o,'PNG')
>
> # We NEED this object because it has 'chunks'
> content = ContentFile(o.getvalue())

Instead of instantiating a new object, have you tried writing back to  
the original "content" file object that was passed in as a parameter  
to save? It's got a write method:

content.write(o.getvalue())
super(CustomImageStorage,self).save(name, content)

That might avoid causing new problems...

E


>
>
> # Now the content is accepted.
> # CutsomImageStorage is my FileSystemStorage subclass, see OP.
> super( CustomImageStorage,self).save(name, content)
>
> HTH; any corrections for sheer stupidity? :)
>
> \d
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: FileSystemStorage content vs PIL Image

2009-01-04 Thread Eric Abrahamsen


On Jan 5, 2009, at 6:51 AM, Donn wrote:

>
> Hi,
> I am stuck on the interface between a PIL Image and a
> FilesystemStorage 'content' object.
>
> I can: img = Image.open(content)
> But how do I pass 'img' back to Django for saving?
>
> My short class is pasted at end. The problem reported stems from the  
> line:
> name=super(CustomImageStorage,self).save(name,img)
>
> It barfs in PIL saying:
> Exception Type:   AttributeError
> Exception Value:  
>
> chunks
>
> Exception Location:   /usr/lib/python2.5/site-packages/PIL/Image.py in
> __getattr__, line 493
>
>
> I dir() the content and img objects and sure enough, img has no  
> 'chunks'
> attribute.
>
> Anyway, I can always use img.save(path) but wanted to keep the image  
> in memory
> and not touch ground with it.
>
> Any ideas?
> \d
>
> Code:
> class CustomImageStorage( FileSystemStorage ):
>   def __init__(self, location, base_url,  
> makethumbs=False,dropshadow=None):
>
> super 
> (CustomImageStorage 
> ,self).__init__(location=location,base_url=base_url)
>   self._makethumbs = makethumbs
>   self._dropshadow = dropshadow
>
>   def get_available_name( self, name ):
>   self.delete(name)
>   return name
>
>   def save(self, name, content ):
>   content.seek(0)
>   img = Image.open(content)
>   if self._dropshadow:
>   img = dropShadow(img, background = 
> self._dropshadow['background'],
>   shadow = self._dropshadow['shadow'],
>   offset = self._dropshadow['offset'],
>   iterations = 
> self._dropshadow['iterations'],
>   border = self._dropshadow['border']
>   )
>   if self._makethumbs:
>   try:
>   thumb = img.copy()
>   fpaf = self.thumbPath(name)
>   thumb.thumbnail((64,64),Image.ANTIALIAS)
>   thumb.save( fpaf )
>   except:
>   pass # some damn error.
>   img.seek(0) # Random attempt at a fix
>   name = super( CustomImageStorage,self).save(name,img) # was 
> content
>   return name

On second thought, you should probably be writing the img back into  
the original "content" variable (which points to a File object), as  
that object might already have relevant attributes set...

E


>
>
>   def delete( self, name):
>   super(CustomImageStorage,self).delete(name)
>   if self._makethumbs:
>   # Now to remove the thumbnail too.
>   try:
>   fpaf = self.thumbPath(name)
>   os.unlink( fpaf )
>   except:
>   pass # Can't delete it... whatever.
>
>   def thumbPath( self, name ):
>   return os.path.join(self.location,'djanthumbs', name)
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: FileSystemStorage content vs PIL Image

2009-01-04 Thread Eric Abrahamsen


On Jan 5, 2009, at 6:51 AM, Donn wrote:

>
> Hi,
> I am stuck on the interface between a PIL Image and a
> FilesystemStorage 'content' object.
>
> I can: img = Image.open(content)
> But how do I pass 'img' back to Django for saving?
>
> My short class is pasted at end. The problem reported stems from the  
> line:
> name=super(CustomImageStorage,self).save(name,img)
>
> It barfs in PIL saying:
> Exception Type:   AttributeError
> Exception Value:  
>
> chunks
>
> Exception Location:   /usr/lib/python2.5/site-packages/PIL/Image.py in
> __getattr__, line 493
>
>
> I dir() the content and img objects and sure enough, img has no  
> 'chunks'
> attribute.
>
> Anyway, I can always use img.save(path) but wanted to keep the image  
> in memory
> and not touch ground with it.
>
> Any ideas?
> \d
>
> Code:
> class CustomImageStorage( FileSystemStorage ):
>   def __init__(self, location, base_url,  
> makethumbs=False,dropshadow=None):
>
> super 
> (CustomImageStorage 
> ,self).__init__(location=location,base_url=base_url)
>   self._makethumbs = makethumbs
>   self._dropshadow = dropshadow
>
>   def get_available_name( self, name ):
>   self.delete(name)
>   return name
>
>   def save(self, name, content ):
>   content.seek(0)
>   img = Image.open(content)
>   if self._dropshadow:
>   img = dropShadow(img, background = 
> self._dropshadow['background'],
>   shadow = self._dropshadow['shadow'],
>   offset = self._dropshadow['offset'],
>   iterations = 
> self._dropshadow['iterations'],
>   border = self._dropshadow['border']
>   )
>   if self._makethumbs:
>   try:
>   thumb = img.copy()
>   fpaf = self.thumbPath(name)
>   thumb.thumbnail((64,64),Image.ANTIALIAS)
>   thumb.save( fpaf )
>   except:
>   pass # some damn error.
>   img.seek(0) # Random attempt at a fix
>   name = super( CustomImageStorage,self).save(name,img) # was 
> content
>   return name

"Content" in this case is supposed to be an instance of  
django.core.files.File, not raw data (see 
http://docs.djangoproject.com/en/dev/ref/files/file/) 
. It's the File object that has the missing "chunks" attribute. At the  
very least, try instantiating a File object within your save method,  
write the img data to that file object, and the pass the file to the  
call to super().save(). Maybe there will be to it than just that, but  
that's a good place to start.

Yours,
Eric


>
>
>   def delete( self, name):
>   super(CustomImageStorage,self).delete(name)
>   if self._makethumbs:
>   # Now to remove the thumbnail too.
>   try:
>   fpaf = self.thumbPath(name)
>   os.unlink( fpaf )
>   except:
>   pass # Can't delete it... whatever.
>
>   def thumbPath( self, name ):
>   return os.path.join(self.location,'djanthumbs', name)
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: AttributeError when trying to access the Admin application

2009-01-04 Thread Eric Abrahamsen


On Jan 4, 2009, at 8:14 PM, HB wrote:

>
> Well, sorry but where to add those lines?

In your settings.py file. There might not be a MIDDLEWARE_CLASSES  
value at all at the moment (though I can't imagine where it went), so  
make sure there's something like this in settings:

MIDDLEWARE_CLASSES =  
("django.contrib.sessions.middleware.SessionMiddleware",  
"django.contrib.auth.middleware.AuthenticationMiddleware",  
"django.middleware.common.CommonMiddleware",  
"django.middleware.doc.XViewMiddleware")

Give that a shot.


Eric

>
>
> On Jan 4, 2:11 pm, Eric Abrahamsen <gir...@gmail.com> wrote:
>> On Jan 4, 2009, at 8:00 PM, HB wrote:
>>
>>
>>
>>
>>
>>> Here is the full traceback:
>>> +++
>>> Environment:
>>
>>> Request Method: GET
>>> Request URL:http://localhost:8000/admin/
>>> Django Version: 1.0.2 final
>>> Python Version: 2.5.2
>>> Installed Applications:
>>> ['django.contrib.auth',
>>> 'django.contrib.contenttypes',
>>> 'django.contrib.sessions',
>>> 'django.contrib.sites',
>>> 'django.contrib.admin',
>>> 'djdrive.books']
>>> Installed Middleware:
>>> ()
>>
>> You weren't kidding, you've got no middleware installed. The default
>> values should be:
>>
>> ("django.contrib.sessions.middleware.SessionMiddleware",
>> "django.contrib.auth.middleware.AuthenticationMiddleware",
>>   "django.middleware.common.CommonMiddleware",
>> "django.middleware.doc.XViewMiddleware")
>> try that, and things might work.
>>
>>
>>
>>
>>
>>> Traceback:
>>> File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
>>> in get_response
>>>  86. response = callback(request, *callback_args,
>>> **callback_kwargs)
>>> File "/usr/lib/python2.5/site-packages/django/contrib/admin/ 
>>> sites.py"
>>> in root
>>>  140. if not self.has_permission(request):
>>> File "/usr/lib/python2.5/site-packages/django/contrib/admin/ 
>>> sites.py"
>>> in has_permission
>>>  99. return request.user.is_authenticated() and
>>> request.user.is_staff
>>
>>> Exception Type: AttributeError at /admin/
>>> Exception Value: 'WSGIRequest' object has no attribute 'user'
>>> +++
>>
>>> I'm new to Django and I'm reading "The Definitive Guide to Django"
>>> which seems to me too out dated...
>>
>> Yep, quite a lot has changed since that book was written...
>>
>> Yours,
>> Eric
>>
>>
>>
>>> On Jan 4, 1:34 pm, Eric Abrahamsen <gir...@gmail.com> wrote:
>>>> On Jan 4, 2009, at 7:19 PM, HB wrote:
>>
>>>>> I don't have middleware classes.
>>>>> I just created some model classes and tried to create Admin
>>>>> application for them.
>>>>> Maybe I have to comment some of INSTALLED_APPS that Django  
>>>>> uncomment
>>>>> them by default.
>>>>> Suspects are auth, contenttypes, sessions
>>>>> Right?
>>
>>>> Everybody's got middleware classes! But it sounds like you're
>>>> probably
>>>> running the defaults, which should be sufficient to make the admin
>>>> work. And you'll need all those contrib apps in INSTALLED_APPS, so
>>>> don't comment them out. Try posting the full traceback, and if that
>>>> doesn't jog my memory we'll just see if someone else can jump in...
>>
>>>> E
>>
>>>>> On Jan 4, 1:06 pm, Eric Abrahamsen <gir...@gmail.com> wrote:
>>>>>> On Jan 4, 2009, at 4:58 PM, HB wrote:
>>
>>>>>>> Hey,
>>>>>>> I'm trying to create Admin application for my Django project,  
>>>>>>> here
>>>>>>> are
>>>>>>> some snippets:
>>>>>>> +++
>>>>>>> from django.contrib import admin
>>>>>>> admin.autodiscover()
>>
>>>>>>> urlpatterns = patterns('',
>>>>>>> (r'^admin/(.*)', admin.site.root),
>>>>>>> )
>>
>>>>>>> INSTALLED_APPS = (
>>>>>>>'django.contrib.auth',
>>>>>>>'django.contrib.contenttypes',
>>>>>>>'django.contrib.sessions',
>>>>>>>'django.contrib.sites',
>>>>>>>'django.contrib.admin',
>>>>>>>'djdrive.books',
>>>>>>> )
>>>>>>> +++
>>
>>>>>> Can you also paste your middleware classes?
>>
>>>>>> I've had this happen and can't for the life of me remember where
>>>>>> yet,
>>>>>> but I think it had something to do with the Session and
>>>>>> Authentication
>>>>>> middleware...
>>
>>>>>> Eric
>>
>>>>>>> But when trying to access /admin , I got this exception:
>>>>>>> +++
>>>>>>> AttributeError at /admin/
>>>>>>> 'WSGIRequest' object has no attribute 'user'
>>>>>>> +++
>>
>>>>>>> Any ideas?
>>>>>>> Platform:
>>>>>>> Django 1.0.2
>>>>>>> Ubuntu 8.04
>>>>>>> Thanks for help.
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: AttributeError when trying to access the Admin application

2009-01-04 Thread Eric Abrahamsen

On Jan 4, 2009, at 8:00 PM, HB wrote:

>
> Here is the full traceback:
> +++
> Environment:
>
> Request Method: GET
> Request URL: http://localhost:8000/admin/
> Django Version: 1.0.2 final
> Python Version: 2.5.2
> Installed Applications:
> ['django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.sites',
> 'django.contrib.admin',
> 'djdrive.books']
> Installed Middleware:
> ()

You weren't kidding, you've got no middleware installed. The default  
values should be:

("django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
  "django.middleware.common.CommonMiddleware",
"django.middleware.doc.XViewMiddleware")
try that, and things might work.

>
>
>
> Traceback:
> File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
> in get_response
>  86. response = callback(request, *callback_args,
> **callback_kwargs)
> File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
> in root
>  140. if not self.has_permission(request):
> File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
> in has_permission
>  99. return request.user.is_authenticated() and
> request.user.is_staff
>
> Exception Type: AttributeError at /admin/
> Exception Value: 'WSGIRequest' object has no attribute 'user'
> +++
>
> I'm new to Django and I'm reading "The Definitive Guide to Django"
> which seems to me too out dated...

Yep, quite a lot has changed since that book was written...

Yours,
Eric

>
>
>
> On Jan 4, 1:34 pm, Eric Abrahamsen <gir...@gmail.com> wrote:
>> On Jan 4, 2009, at 7:19 PM, HB wrote:
>>
>>
>>
>>> I don't have middleware classes.
>>> I just created some model classes and tried to create Admin
>>> application for them.
>>> Maybe I have to comment some of INSTALLED_APPS that Django uncomment
>>> them by default.
>>> Suspects are auth, contenttypes, sessions
>>> Right?
>>
>> Everybody's got middleware classes! But it sounds like you're  
>> probably
>> running the defaults, which should be sufficient to make the admin
>> work. And you'll need all those contrib apps in INSTALLED_APPS, so
>> don't comment them out. Try posting the full traceback, and if that
>> doesn't jog my memory we'll just see if someone else can jump in...
>>
>> E
>>
>>> On Jan 4, 1:06 pm, Eric Abrahamsen <gir...@gmail.com> wrote:
>>>> On Jan 4, 2009, at 4:58 PM, HB wrote:
>>
>>>>> Hey,
>>>>> I'm trying to create Admin application for my Django project, here
>>>>> are
>>>>> some snippets:
>>>>> +++
>>>>> from django.contrib import admin
>>>>> admin.autodiscover()
>>
>>>>> urlpatterns = patterns('',
>>>>> (r'^admin/(.*)', admin.site.root),
>>>>> )
>>
>>>>> INSTALLED_APPS = (
>>>>>'django.contrib.auth',
>>>>>'django.contrib.contenttypes',
>>>>>'django.contrib.sessions',
>>>>>'django.contrib.sites',
>>>>>'django.contrib.admin',
>>>>>'djdrive.books',
>>>>> )
>>>>> +++
>>
>>>> Can you also paste your middleware classes?
>>
>>>> I've had this happen and can't for the life of me remember where  
>>>> yet,
>>>> but I think it had something to do with the Session and
>>>> Authentication
>>>> middleware...
>>
>>>> Eric
>>
>>>>> But when trying to access /admin , I got this exception:
>>>>> +++
>>>>> AttributeError at /admin/
>>>>> 'WSGIRequest' object has no attribute 'user'
>>>>> +++
>>
>>>>> Any ideas?
>>>>> Platform:
>>>>> Django 1.0.2
>>>>> Ubuntu 8.04
>>>>> Thanks for help.
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: AttributeError when trying to access the Admin application

2009-01-04 Thread Eric Abrahamsen


On Jan 4, 2009, at 7:19 PM, HB wrote:

>
> I don't have middleware classes.
> I just created some model classes and tried to create Admin
> application for them.
> Maybe I have to comment some of INSTALLED_APPS that Django uncomment
> them by default.
> Suspects are auth, contenttypes, sessions
> Right?
>

Everybody's got middleware classes! But it sounds like you're probably  
running the defaults, which should be sufficient to make the admin  
work. And you'll need all those contrib apps in INSTALLED_APPS, so  
don't comment them out. Try posting the full traceback, and if that  
doesn't jog my memory we'll just see if someone else can jump in...

E


> On Jan 4, 1:06 pm, Eric Abrahamsen <gir...@gmail.com> wrote:
>> On Jan 4, 2009, at 4:58 PM, HB wrote:
>>
>>
>>
>>
>>
>>> Hey,
>>> I'm trying to create Admin application for my Django project, here  
>>> are
>>> some snippets:
>>> +++
>>> from django.contrib import admin
>>> admin.autodiscover()
>>
>>> urlpatterns = patterns('',
>>> (r'^admin/(.*)', admin.site.root),
>>> )
>>
>>> INSTALLED_APPS = (
>>>'django.contrib.auth',
>>>'django.contrib.contenttypes',
>>>'django.contrib.sessions',
>>>'django.contrib.sites',
>>>'django.contrib.admin',
>>>'djdrive.books',
>>> )
>>> +++
>>
>> Can you also paste your middleware classes?
>>
>> I've had this happen and can't for the life of me remember where yet,
>> but I think it had something to do with the Session and  
>> Authentication
>> middleware...
>>
>> Eric
>>
>>
>>
>>> But when trying to access /admin , I got this exception:
>>> +++
>>> AttributeError at /admin/
>>> 'WSGIRequest' object has no attribute 'user'
>>> +++
>>
>>> Any ideas?
>>> Platform:
>>> Django 1.0.2
>>> Ubuntu 8.04
>>> Thanks for help.
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: AttributeError when trying to access the Admin application

2009-01-04 Thread Eric Abrahamsen


On Jan 4, 2009, at 4:58 PM, HB wrote:

>
> Hey,
> I'm trying to create Admin application for my Django project, here are
> some snippets:
> +++
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
> (r'^admin/(.*)', admin.site.root),
> )
>
> INSTALLED_APPS = (
>'django.contrib.auth',
>'django.contrib.contenttypes',
>'django.contrib.sessions',
>'django.contrib.sites',
>'django.contrib.admin',
>'djdrive.books',
> )
> +++

Can you also paste your middleware classes?

I've had this happen and can't for the life of me remember where yet,  
but I think it had something to do with the Session and Authentication  
middleware...


Eric



>
>
> But when trying to access /admin , I got this exception:
> +++
> AttributeError at /admin/
> 'WSGIRequest' object has no attribute 'user'
> +++
>
> Any ideas?
> Platform:
> Django 1.0.2
> Ubuntu 8.04
> Thanks for help.
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



setting cookies following comment post

2009-01-03 Thread Eric Abrahamsen

Hi there,

I'm adding a "remember me" checkbox to comment forms, so that regular  
commenters can avoid having to enter their personal information, if  
they want. I was originally thinking of making this a function  
attached to the comment_was_posted signal, but it will have to be  
implemented using cookies, which need to be set on the outgoing  
response, which isn't available in signal handlers...

I'm wondering if anyone else has made a functionality like this using  
the comment contrib app, and how they went about doing it. There  
doesn't seem to be any point in the process where I could get hold of  
the response.

Thanks!
Eric

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django form HTML is rendered as TEXT

2008-12-25 Thread Eric Abrahamsen


On Dec 26, 2008, at 10:56 AM, s4shre...@gmail.com wrote:

>
> Hi Guys,
> I am new to Django . My Django form HTML is rendered  as TEXT . It
> does not display the HTML as such.

Are you maybe getting autoescaped?

http://docs.djangoproject.com/en/dev/topics/templates/#id2

Eric

>
>
> Please assist.
>
> Thanks in Advance
> Regards
> Dmitri
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: The view didn't return an HttpResponse object.

2008-12-16 Thread Eric Abrahamsen


On Dec 17, 2008, at 3:23 PM, oops wrote:

>
> def OrderPlacedView(request):
>form = OrderPlaceForm()
>try:
>print "try"
>print request.POST
>#brand = BrandName.objects.get(pk=request.POST['brand'])
>except:
>print"nothing"
>return render_to_response('inventory/orderprocess.html',
> {'form':form})

This return statement is indented to be inside the except clause. If  
no exception is raised, the view doesn't return anything...

Yours,
Eric


>
>
> above is my view code when a try to call this view its give and error
> "The view  didn't return an HttpResponse object."
>
> i have similar type of view which works fine whats the problem with
> this ..
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Too Many Connections

2008-12-09 Thread Eric Abrahamsen


On Dec 10, 2008, at 1:30 AM, DULMANDAKH Sukhbaatar wrote:

>
>>  File
>> "/usr/local/python2.5/lib/python2.5/site-packages/ 
>> MySQL_python-1.2.2-py2.5-linux-i686.egg/MySQLdb/__init__.py",
>> line 74, in Connect
>>
>>  File
>> "/usr/local/python2.5/lib/python2.5/site-packages/ 
>> MySQL_python-1.2.2-py2.5-linux-i686.egg/MySQLdb/connections.py",
>> line 170, in __init__\nsuper(Connection, self).__init__(*args,
>> **kwargs2)
>>
>> OperationalError: (1040, 'Too many connections')

It's probably worth using django-logging or one of the other 3rd party  
packages to check how many queries your views are executing. The only  
time I ever saw this error was with high load on an extremely  
inefficient view (something like 60 queries in one view), and tweaking  
your use of the ORM can reduce those problems significantly.

Eric



>>
>
> as you can see above, it's mysql problem. mysql server have some
> default limitation on concurrent connections. you can increase
> max_connections in my.cnf. depending on your linux distro my.cnf may
> be located in different places. for me, or on ubuntu it's at
> /etc/mysql/my.cnf, and you need to uncomment the line, and increase
> the value.
>
> by default mysql gets 100 concurrent connections. and the question is
> why is dev site is getting that much connection?
>
>
> -- 
> Regards
> Dulmandakh
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: misreporting verify_exists

2008-12-06 Thread Eric Abrahamsen


On Dec 7, 2008, at 11:44 AM, Malcolm Tredinnick wrote:

>
>
> On Sun, 2008-12-07 at 14:42 +1100, Malcolm Tredinnick wrote:
> [...]
>
>> So have a look at the result of something like "curl -I http://...
>> " (or
>> equivalent tool if you don't have curl around). Basically, force a  
>> HEAD
>> request and see if that returns something sensible.
>
> Ignore me. I completely missed that you'd given the link. I tried the
> HEAD request and it returned a 200 response. So that isn't it. So I  
> have
> no idea. Sorry for the noise.

Thanks for the response, Malcolm. I wonder if I'm looking at the wrong  
part of the code? forms.fields.URLField.clean() seems to be using a  
full urllib2.urlopen, not just a HEAD request -- am I looking at the  
wrong code?

Eric


>
>
> Malcolm
>
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



misreporting verify_exists

2008-12-06 Thread Eric Abrahamsen

I've got a model with a URLField, with verify_exists set to True,  
which has suddenly started barfing "broken link" on a certain URL. I'm  
quite sure the URL exists, and can't figure out why it can't get past  
validation. This is the link:

http://www.rochester.edu/College/translation/threepercent/index.php?id=1482

The URLField itself is nothing special (unique=True, that's all). I  
get the same error in development and production, though using urllib  
on my production machine opens the URL fine, and I can open it in a  
browser on my development machine. I started a Python interpreter and  
manually typed in most of what goes on in  
forms.fields.URLField.clean() (minus the User Agent stuff, don't know  
what that is), and it opened with no problem. When the validation  
error comes back in the Admin interface, the url hasn't been truncated  
or altered in any way, so I don't think that's it. I've entered URLs  
with GET parameters before...

I can't think of anything else! Has someone got a bright idea? I'm  
running 1.1 pre-alpha SVN-9569.

Thanks,
Eric

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template tag

2008-12-05 Thread Eric Abrahamsen


On Dec 6, 2008, at 8:31 AM, Alfredo Alessandrini wrote:

>
> Hi,
>
> I've this variable in my template: {{ challenger.rating }}
>
> It'a a number...
>
> Can I calculate a sum like this:
>
> {{ challenger.rating }} + 200   ??
>
> I must write a custom tag?

There's already a filter for that:

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#add

Yours,
Eric


>
>
>
> Alfredo
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: XML templates

2008-12-02 Thread Eric Abrahamsen


On Dec 2, 2008, at 5:50 PM, Vicky wrote:

>
> I did as you said. Still its giving the same error :(

Do you have the correct permissions on the TEMPLATE_DIRS directories?  
Have you written the paths with forward slashes? That's all I can  
think of.

E

>
>
>
> On Dec 2, 11:38 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
>> On Mon, 2008-12-01 at 22:20 -0800, Vicky wrote:
>>> I tried the code below:
>>
>>> from django.template import loader, Context
>>
>>> def NewspaperSelect(request,u_id):
>>> t=loader.get_template(r'C:\django\noddler\news 
>>> \template.vxml')
>>>c=Context({ 'topic':'news', 'content':pn })
>>>return HttpResponse(t.render(c), mimetype='application/xml')
>>
>>> I verified that the file is in the location. But when i compile it
>>> keeps telling that template file does not exist. What to do?
>>
>> get_template() doesn't take a full path to a file. It takes the  
>> name of
>> a template, possibly with some directories in front -- but it's a
>> relative path. What the path is relative to depends on the template
>> loader being used. Unless you've done anything special to your setup,
>> Django will try the application loader first -- appending the path to
>> /templates/ for each app_name that you have installed.  
>> Then it
>> will try the filesystem loader, which will append the path to each
>> diretcory in the TEMPLATE_DIRS setting and see if it exists.
>>
>> So you either need to set up TEMPLATE_DIRS or put the templates in a
>> templates/ directory inside one (or more) of your applications.
>>
>> This ends up making the code very portable, by the way, since when  
>> you
>> install it somewhere else, you only have to change the TEMPLATE_DIRS
>> settings (at most) and all your templates will still load correctly.
>>
>> Regards,
>> Malcolm
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: XML templates

2008-12-02 Thread Eric Abrahamsen


On Dec 2, 2008, at 5:50 PM, Vicky wrote:

>
> I did as you said. Still its giving the same error :(

Are you using forward slashes instead of backslashes? The docs  
indicate that's necessary...


>
>
>
>
>
> On Dec 2, 11:38 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
>> On Mon, 2008-12-01 at 22:20 -0800, Vicky wrote:
>>> I tried the code below:
>>
>>> from django.template import loader, Context
>>
>>> def NewspaperSelect(request,u_id):
>>> t=loader.get_template(r'C:\django\noddler\news 
>>> \template.vxml')
>>>c=Context({ 'topic':'news', 'content':pn })
>>>return HttpResponse(t.render(c), mimetype='application/xml')
>>
>>> I verified that the file is in the location. But when i compile it
>>> keeps telling that template file does not exist. What to do?
>>
>> get_template() doesn't take a full path to a file. It takes the  
>> name of
>> a template, possibly with some directories in front -- but it's a
>> relative path. What the path is relative to depends on the template
>> loader being used. Unless you've done anything special to your setup,
>> Django will try the application loader first -- appending the path to
>> /templates/ for each app_name that you have installed.  
>> Then it
>> will try the filesystem loader, which will append the path to each
>> diretcory in the TEMPLATE_DIRS setting and see if it exists.
>>
>> So you either need to set up TEMPLATE_DIRS or put the templates in a
>> templates/ directory inside one (or more) of your applications.
>>
>> This ends up making the code very portable, by the way, since when  
>> you
>> install it somewhere else, you only have to change the TEMPLATE_DIRS
>> settings (at most) and all your templates will still load correctly.
>>
>> Regards,
>> Malcolm
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: XML templates

2008-12-01 Thread Eric Abrahamsen


On Dec 1, 2008, at 7:51 PM, Vicky wrote:

>
> Can we use XML files as templates instead of HTML?

Anything that comes as a plain text file can be produced by a  
template: HTML, XML, plain text, email, iCAL, source code...

Yours,
Eric


>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Modify uploaded image

2008-11-30 Thread Eric Abrahamsen


On Nov 30, 2008, at 10:36 PM, Alex Jonsson wrote:

>
> Hey guys,
>
> I have an application where I want my users to be able to upload a
> picture. The model contains a name field and a ImageField.
>
> My question is how the easiest way would be to modify this image
> before saving it? That is, cropping it down to a certain size and
> renaming it to the person's name instead of having randomly named
> files in my folders.

The most direct method is overriding the model's save() method. Every  
time a picture instance is saved, it will go through whatever you put  
in the save method -- usually this means using the PIL library, which  
may or may not be installed in your production environment. Use the  
PIL.Image class to open the image (ie img =  
Image.open(self.imagefield.path)) and manipulate it, then resave it.

Check out both PIL: http://www.pythonware.com/products/pil/

and the django file storage docs: 
http://docs.djangoproject.com/en/dev/ref/models/fields/#imagefield

Note that changing the path to something relative to the currently  
logged-in user will be a little more difficult. As far as I know the  
thread-locals hack is still required there...

E


>
>
> Thanks,
> Alex
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



  1   2   3   >