Model Formsets.save(commit=False) behaviour

2009-05-09 Thread gorans

Hi all,

I'm trying to use the .save(commit=False) method on a model formset in
my view but for some strange reason, the django code executes the
model's save method.

My understanding of the docs is that when (commit=False) is passed -
the formset will return a list of model instances but not commit them
to the db.  However, when the formset's .save(commit=False) is called,
I note that the model instances are saved. Documentation: [http://
docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-
formsets]

I tried to trace through the django forms code to find out where this
happens but could not.

The code in my view is available here: http://dpaste.com/42538/

I note that there is a line where the model gets explicitly saved so
when I actually run that code the model gets saved twice - which I
don't want to happen.

Any help is much appreciated.

Cheers

Goran
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Cross Site Request Forgery (csrf) via POST / JQuery

2011-02-22 Thread gorans
Hi

I'm using Django's CSRFViewMiddleware and am making a POST request in
a page (using JQuery) in the form of:

$.post('{% url posted_to_wall %}', {
network: 'FBK',
action_type: 'feed',
effect: 1
});

In order to satisfy the csrf_token check, I have implemented the
instructions from the Django docs: 
http://docs.djangoproject.com/en/dev/ref/contrib/csrf/
(with some tweaks to only run the csrf on POST and not GET)

$('html').ajaxSend(function(event, xhr, settings) {
xhr.setRequestHeader("x-testing1", 'testme1');
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
// optimise this!
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we
want?
if (cookie.substring(0, name.length + 1) == (name +
'=')) {
cookieValue =
decodeURIComponent(cookie.substring(name.length + 1));
//console.log('cookie is ' + cookieValue);
break;
}
}
}
return cookieValue;
}

//console.log(/^http:.*/.test(settings.url));

if (settings.type == 'POST') {
if (!(/^http:.*/.test(settings.url) || /
^https:.*/.test(settings.url))) {
// Only send the token to relative URLs i.e. locally.
// console.log('we\'re local ajax');
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
}
}
});

However, the X-CSRFToken request is not being set by the command
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));

I have tried on both Chrome 11.0.672.2 dev and Firefox 4.0b11

I have worked around the issue by adding  csrfmiddlewaretoken: $
('input[name|="csrfmiddlewaretoken"]').attr('value')  to my POST data,
but would prefer to have it all done with the .ajaxSend method
presented in the Django Docs.

Does anyone have any suggestions as to why the xhr.setRequestHeader()
doesn't work?

Thanks is advance

Goran!

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



Track number of hits on object

2008-04-02 Thread gorans

Hi all,

I'm still quite new to django coding and am trying to learn to work
inline with Django's DRY and other principles.

In this case I'm having trouble deciding what is the more Django way
of counting the number of times an object has been open.

I know that the code will be executed in the View for the object but
should the .increase_hits() method be defined in the Model or in the
models manager?

class Post(model.Model)
...
hits = PositiveInteger(default=0)

def increase_hits(self):

self.hits += 1
self.save()

or have a manager method to perform this?

Cheers

Goran
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Best practices for sending bulk (+4000) mail in Django / Python

2008-04-23 Thread gorans

Hi,

I've been sending out email to a list of around 8000 people on a
monthly basis using django and was wondering whether there is a way to
optimise the process.

Currently, I open a mail connection [ mail_connection =
SMTPConnection(fail_silently=True) ] and then loop through each
message calling the .send() method.

however, this takes about 2 seconds per message which is ridiculous!

Is there are better way to do mass emailing to our subscribers?

Cheers

Goran

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



Customizing the settings configuration

2007-07-24 Thread gorans

Hi,

I develop Django sites on my mac and then publish them to another web
server. In between, they live in a happy SVN repository on my
development server.

Each time I make a change to the project's settings.py I have to then
go over and modify the live file version (in respect to the database
type / name, media directory etc.)

I though that there could be a way to trick Django into reading
special development settings for me, something like having a settings
'package' import separate settings files:

e.g.

myproject/

manage.py
...
settings/
__init__.py
coresettings.py
localsettings.py

so that we use the variable from coresettings first, and then try:
import localsettings and if successful use those subsequent values.

That way, I can have an un-versioned localsettings.py living on my
mac, whilst keeping the live settings intact. Additionally, other
developers on the project can do the same!

Is this possible? (I'm sure it is but my Python just isn't good enough
to know how to import all the variables from each module)

Can anyone please give me directions / pointers as to how to do this?
Or alternatively, how you deal with this task.

Your help is very very much appreciated

cheers

Goran


--~--~-~--~~~---~--~~
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: Customizing the settings configuration

2007-07-24 Thread gorans

Thanks for the help.

That's going to save me heaps and heaps of time.

Thanks again.

Goran

On Jul 25, 10:01 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 7/24/07, gorans <[EMAIL PROTECTED]> wrote:
>
>
>
> > I though that there could be a way to trick Django into reading
> > special development settings for me, something like having a settings
> > 'package' import separate settings files:
>
> No need for any special handling - just use the --settings option to
> manage.py, or the DJANGO_SETTINGS_MODULE environment variable.
>
> ./manage.py --settings=mysite.localsettings runserver
>
> or
>
> ./manage.py --settings=mysite.serversettings runserver
>
> If there are common elements in the two settings file, then put
>
> from mysite.commonsettings import *
>
> at the top of your localsettings/serversettings file. This will pull
> in all the settings from the common settings file.
>
> If putting your settings files into a package will make organization
> easier, go right ahead - just remember to put the extra path into your
> --settings. e.g.:
>
> ./manage.py --settings=mysite.settings.serversettings runserver
>
> 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-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
-~--~~~~--~~--~--~---



Where art thou ImageField

2007-03-12 Thread gorans

Hi,

I'm trying to access the value of an image field which is uploaded in
the django admin interface - prior to calling the save.

I have a model called Photo with three attributes: large, medium and
small. Each are ImageFields.

I have overwritten the save( ) function in Photo so that I can check
that the uploaded file is 800 x 600 px (and then proceed to generate
medium and small) with PIL. However, when I call self.large I end up
with an empty string.

How would I access the filename of the uploaded image before the super
(save) has been called? (* I think this problem is happening because I
am using the admin *)

Is overwriting the save method the best way to go about this? I am
aware that I could create a custom Field but I would like to avoid
that.

Any direction will be greatly appreciated

Goran


--~--~-~--~~~---~--~~
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: Where art thou ImageField

2007-03-12 Thread gorans

Hmm.. I see the point there.

But where would be the right place to generate the set of thumbs from
the original image?

On Mar 13, 1:04 am, "akonsu" <[EMAIL PROTECTED]> wrote:
> hello,
>
> regarding the last part of your post: i have an unconfirmed suspicion
> that data validation should not be done in models but in the forms
> that manipulate data. does anyone know if this is correct?
>
> konstantin
>
> On Mar 12, 9:56 am, "gorans" <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I'm trying to access the value of an image field which is uploaded in
> > the django admin interface - prior to calling the save.
>
> > I have a model called Photo with three attributes: large, medium and
> > small. Each are ImageFields.
>
> > I have overwritten the save( ) function in Photo so that I can check
> > that the uploaded file is 800 x 600 px (and then proceed to generate
> > medium and small) with PIL. However, when I call self.large I end up
> > with an empty string.
>
> > How would I access the filename of the uploaded image before the super
> > (save) has been called? (* I think this problem is happening because I
> > am using the admin *)
>
> > Is overwriting the save method the best way to go about this? I am
> > aware that I could create a custom Field but I would like to avoid
> > that.
>
> > Any direction will be greatly appreciated
>
> > Goran


--~--~-~--~~~---~--~~
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: Where art thou ImageField

2007-03-13 Thread gorans

Thanks,

I found http://www.carcosa.net/jason/software/django/stockphoto/
pretty helpful!

Goran

On Mar 13, 11:48 am, "Jay Parlar" <[EMAIL PROTECTED]> wrote:
> You may want to check out the 'stockphoto' app. Even if you don't use
> it directly, it might give you ideas. It seems to handle thumbnails
> quite well.
>
> http://www.carcosa.net/jason/software/django/stockphoto/
>
> Jay P.


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



Admin History - Date not formatted

2007-03-31 Thread gorans

Hi,

This is probably a quick fix but the history section in the Django
Admin displays the date incorrectly:
SatPMAUS Eastern Standard TimeE_130AUS Eastern Standard Time20_AUS
Eastern Standard Time0MarE_March1177497646FalseFalse

I am using Windows with timezone (GMT +10:00 Canberra, Melbourne,
Sydney) and have set the settings.py variable to "Australia/Melbourne"

Does anyone know why Django is doing this?

Cheers

Goran


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