Re: Admin Model Validation on ManyToMany Field

2010-07-15 Thread Heleen
Thanks very much for your reply!
I got it working now. At first I couldn't get my head around how it
would work using the clean of the intermediary model. But after a
night's sleep it made sense to me.
In the Admin my Permission model (the users field) is an inline of
Application and when I put the validation on Permission it also
automatically works in the Application Admin.

So now I have:

admin.py
class PermissionInline(admin.TabularInline):
form = PermissionForm
model = Permission
extra = 3

forms.py
class PermissionForm(forms.ModelForm):
class Meta:
model = Permission

def clean(self):
cleaned_data = self.cleaned_data
user = cleaned_data['user']
role = cleaned_data['role']
if role.id != 1:
folder = cleaned_data['application'].folder
if len(filter(lambda x:x in
user.profile.company.all(),folder.company.all())) > 0: # this is an
intersection
raise forms.ValidationError("One of the users of this
Application works for one of the Repository's organisations!")
return cleaned_data

And this works!

On Jul 14, 5:16 pm, jaymzcd  wrote:
> Hi Heleen,
>
> I think this is because your running the users through an intermediate
> model. That changes the way you need to work with the M2M data. You
> should be working on the Permission model/objects instead. If you
> check out the M2M docs for models via an intermediate:
>
> http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> You'll see the example is pretty much what you have only with Group
> instead of Application.
>
> "The only way to create this type of relationship is to create
> instances of the intermediate model. Unlike normal many-to-many
> fields, you can't use add, create, or assignment (i.e.,
> beatles.members = [...]) to create relationships:"
>
> jaymz
>
> On Jul 14, 2:32 pm, Heleen  wrote:
>
> > Thank you for your reply.
>
> > Yes I have selected a user and folder.
> > I believe ManyToMany fields are always optional (hence many to many).
> > So my users and company fields are optional, but my folder field
> > isn't.
> > When I add a new Application in the Admin I do specify a folder and
> > users (if I don't I would at least get a 'Required field' error for
> > the folder field).
> > I've tested the method above (clean function) with another model that
> > has a manytomany field, and it does exactly the same thing, even when
> > I really do fill in the data. In fact, if I delibirately throw an
> > error and look in the debug info I can see the ManyToMany field data
> > being present in the POST data, just like I can when I do the same
> > thing with the above models.
>
> > Btw, I just noticed a typo in my Folder model description above,
> > that's not the issue as it's correct in my original model.
>
> > On Jul 14, 2:02 pm, Nuno Maltez  wrote:
>
> > > Hi,
>
> > > Just a guess: have you actually selected a user and a folder when
> > > submitting the form? I think only valid field are present on the
> > > cleaned_data dict, and your users and folder fields are not optional
> > > (blank=True, null=True).
>
> > > hth,
> > > nuno
>
> > > On Tue, Jul 13, 2010 at 1:45 PM, Heleen  wrote:
> > > > Hello,
>
> > > > I have the following classes:
> > > > class Application(models.Model):
> > > >  users = models.ManyToManyField(User, through='Permission')
> > > >  folder = models.ForeignKey(Folder)
>
> > > > class Folder(models.Model):
> > > >  company = models.ManyToManyField(Compnay)
>
> > > > class UserProfile(models.Model):
> > > >  user = models.OneToOneField(User, related_name='profile')
> > > >  company = models.ManyToManyField(Company)
>
> > > > Now when I save application, I would like to check if the users do not
> > > > belong to the application's folder's companies.
> > > > I have posed this question before and someone came up with the
> > > > following sollution:
> > > > forms.py:
> > > > class ApplicationForm(ModelForm):
> > > >    class Meta:
> > > >        model = Application
>
> > > >    def clean(self):
> > > >        cleaned_data = self.cleaned_data
> > > >        users = cleaned_data['users']
> > > >        folder = cleaned_data['folder']
> > > >        if
> > > > users.filter(profile__company__in=folder.company.all()).count() > 0:
> > > >            raise forms.ValidationError('One of the users of this
> > > > Application works in one of the Folder companies!')
> > > >        return cleaned_data
>
> > > > admin.py
> > > > class ApplicationAdmin(ModelAdmin):
> > > >    form = ApplicationForm
>
> > > > This seems like right the way to go about this. The problem is that
> > > > neither the users nor folder fields are in the cleaned_data and I get
> > > > a keyerror when it hits the users = cleaned_data['users'] line.
>
> > > > I was hoping that someone here could explain to me why these
> > > > manytomany fields don't show up in cleaned_data and that someone could
> > > > possibly give me a sollution to my problem.
>

Re: Redefine True and False for Boolean and/or NullBoolean Fields?

2010-07-15 Thread Tom Evans
On Thu, Jul 15, 2010 at 7:47 AM, rmschne  wrote:
> Oh ... by the way, we aren't using Access as a front end to Django.
> There is nothing (far as I know) in Django to front-end to!
>
> This app has been successfully making us money for more than 20
> years.  The data side moved to MySQL a long time ago (can't remember
> when) to enhance performance and security, but the relatively
> sophisticated Access side remained in place and continued to evolve.
> Still see no viable replacement on the horizon for Access for the
> front end for use by people.  There are a number of tools that have
> suficient capability to replace it but all would cost a fortune to
> make it happen.  Instead, we're using Python/Django as a basis now for
> enhanced reporting/number-crunching and future automation (which sends
> us in the direction of having so many people having to use the Access
> app).   Had we had Python and Django in the late 1980's we'd probably
> be there now.
>

The thing I was trying to get across is that the model definitions is
basically a contract of what kind of data is stored in the database,
and every time you modify the data directly and not through the ORM,
you must take extra special care not to break the contract.

In your case, you actually have two contracts, one with your legacy
application, and one with django, and your django contract contradicts
your legacy one, so you had these problems.

Cheers

Tom

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



Re: How can view tweak response object to go to a specific *anchor* on the template?

2010-07-15 Thread Daniel Roseman
On Jul 15, 5:56 am, Chris Seberino  wrote:
> How can a view tweak the response object so that client sees a
> specific anchor  instead of the top of the page?
>
> Chris

The fragment - the bit of the URL after the "#" which determines which
anchor to scroll to - is never sent to the client, so Django can't
know whether the user has one or not. So, the obvious solution - send
a redirect to the same URL with the fragment attached - won't work,
because it will be an infinite redirection loop.

The only practical way to do this is via javascript. You just need a
script that runs on page load:

 window.location = window.location + '#whatever'

--
DR.

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



Re: How can view tweak response object to go to a specific *anchor* on the template?

2010-07-15 Thread Oleg Lomaka
I see two ways to implement this. 

First without javascript. You cat check URL of HttpRequest and if it is without 
#anchor element, then send redirect to the same URL with #anchor.

Second using javascript. For example in jquery you can include something like 
this in your head tag:



...
http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"; >

  $(document).ready(function() {
var offset = $('#anchor').offset().top;
$('html, body').animate({scrollTop: offset});
  });

...


...

...






On Jul 15, 2010, at 7:56 AM, Chris Seberino wrote:

> 
> How can a view tweak the response object so that client sees a
> specific anchor  instead of the top of the page?
> 
> Chris
> 
> -- 
> 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: How can view tweak response object to go to a specific *anchor* on the template?

2010-07-15 Thread Oleg Lomaka
Opps, Daniel is right, #anchor element isn't contains in URL, so the only way 
is javascript.


On Jul 15, 2010, at 11:57 AM, Oleg Lomaka wrote:

> I see two ways to implement this. 
> 
> First without javascript. You cat check URL of HttpRequest and if it is 
> without #anchor element, then send redirect to the same URL with #anchor.
> 
> Second using javascript. For example in jquery you can include something like 
> this in your head tag:
> 
> 
> 
> ...
> src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"; >
>
>  $(document).ready(function() {
>var offset = $('#anchor').offset().top;
>$('html, body').animate({scrollTop: offset});
>  });
>
> ...
> 
> 
> ...
> 
> ...
> 
> 
> 
> 
> 
> 
> On Jul 15, 2010, at 7:56 AM, Chris Seberino wrote:
> 
>> 
>> How can a view tweak the response object so that client sees a
>> specific anchor  instead of the top of the page?
>> 
>> Chris
>> 
>> -- 
>> 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: Error with passing 'form_class' arg in urls.py for Django Profiles app

2010-07-15 Thread Subhranath Chunder
Could you provide the code for the custom ProfileForm class and the views
first.

Thanks,
Subhranath Chunder.

On Thu, Jul 15, 2010 at 2:49 AM, Ricko  wrote:

> Using ubernostroms Django Registration app coupled with his Profile
> app, both highly recommended, got the default app up and running no
> problems at all.
> I'm unable to override any default behaviour the proper way, as I
> can't seem to pass any extra parameters through the urls.py file. Here
> is my urls:
>
> from django.conf.urls.defaults import *
> from profiles import views
> from django.contrib.auth.decorators import login_required
> from userinfo.forms import ProfileForm
>
> urlpatterns = patterns('',
>   url(r'^edit/$',
>   login_required(views.edit_profile),
> {'form_class' : ProfileForm},
>   name='profiles_edit_profile'),
>   url(r'^(?P\w+)/$',
>   login_required(views.profile_detail),
>   name='profiles_profile_detail'),
>   )
>
> I have my custom form class ProfileForm. When I try this I get a
> stack:
>
> Original Traceback (most recent call last):
>  File "/Library/Python/2.5/site-packages/django/template/debug.py",
> line 71, in render_node
>result = node.render(context)
>  File "/Library/Python/2.5/site-packages/django/template/
> defaulttags.py", line 155, in render
>nodelist.append(node.render(context))
>  File "/Library/Python/2.5/site-packages/django/template/debug.py",
> line 87, in render
>output = force_unicode(self.filter_expression.resolve(context))
>  File "/Library/Python/2.5/site-packages/django/utils/encoding.py",
> line 71, in force_unicode
>s = unicode(s)
> TypeError: unbound method __unicode__() must be called with
> ProfileForm instance as first argument (got nothing instead)
>
>
> Now, the docs say to pass in the Class name, and the stack seems to be
> saying I need an Instance? Whatever extra parameter I pass I get the
> same error.
>
> What am I doing wrong?
>
> --
> 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: www.djangoproject.com

2010-07-15 Thread George Sakkis
On Jul 15, 4:55 am, Danny Adair  wrote:

> Hi,
>
> I had the exact same problem, and I had _not_ installed Weave.
> The offending config entry in my case was:
> "chrome://global/locale/intl.properties"
> and it was at the bottom of the accepted languages list. This is on
> Firefox 3.6.6
>
> I can reproduce the problem anytime by visiting about:config and
> changing "intl.accept_languages" to
> en-nz,en,de,chrome://global/locale/intl.properties
>
> *.djangoproject.com will stop responding, (all?) other websites seem fine.

I didn't write down the offending entry in my case but I think it was
the same or similar to yours. In any case, I can confirm that by
setting it the problem is reproduced.

Trying to reverse engineer the pattern of the offending values, I
believe that the issue is the string length: any value up to 16 bytes
works fine, 17 or more hangs.

George

-- 
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: Plain Python traceback (not error page)

2010-07-15 Thread Tom Evans
On Wed, Jul 14, 2010 at 8:48 PM, Jonathan Hayward
 wrote:
> I am working on debugging a basic template, and after correcting some other
> error, I got:
>
> Traceback (most recent call last):
>
>   File
> "/usr/local/lib/python2.6/site-packages/django/core/servers/basehttp.py",
> line 280, in run
> self.result = application(self.environ, self.start_response)
>
>   File
> "/usr/local/lib/python2.6/site-packages/django/core/servers/basehttp.py",
> line 674, in __call__
> return self.application(environ, start_response)
>
>   File
> "/usr/local/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line
> 245, in __call__
> response = middleware_method(request, response)
>
>   File
> "/usr/local/lib/python2.6/site-packages/django/contrib/sessions/middleware.py",
> line 26, in process_response
> patch_vary_headers(response, ('Cookie',))
>
>   File "/usr/local/lib/python2.6/site-packages/django/utils/cache.py", line
> 127, in patch_vary_headers
> if response.has_header('Vary'):
>
> AttributeError: 'SafeUnicode' object has no attribute 'has_header'
>
> This wasn't the usual format for a Django traceback, and the traceback is
> only in Django code, no reference to my project.
> Suggestions? Would it make sense to open a bug?
>

The error isn't triggered in your code, but it is triggered by your code.

You must return a HttpResponse object from a view, not a string.
Whatever view you are hitting here is returning a SafeUnicode, so it
is probably coming from a template renderer.

Cheers

Tom

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



Re: www.djangoproject.com

2010-07-15 Thread Nick Raptis

On 07/15/2010 05:55 AM, Danny Adair wrote:

Hi,

I had the exact same problem, and I had _not_ installed Weave.
The offending config entry in my case was:
"chrome://global/locale/intl.properties"
and it was at the bottom of the accepted languages list. This is on
Firefox 3.6.6

I can reproduce the problem anytime by visiting about:config and
changing "intl.accept_languages" to
en-nz,en,de,chrome://global/locale/intl.properties

*.djangoproject.com will stop responding, (all?) other websites seem fine.

Cheers,
Danny


Yep, that's the one!
I tried to open chrome://global/locale/intl.properties as a link in 
Firefox, and (oh, the surprise :P ) it's a settings file.
Either the file doesn't get resolved unto something useful in my 
platform (I'm using ubuntu-based) or it's something depreciated and it's 
a migration issue.
Also checked the Firefox bugzilla and there are indeed a couple of bug 
reports for it.


My feelings still stand. Other than making sure that django itself 
handles such erroneous values gracefully,  the list shouldn't be too 
concerned about it.


Now, I wonder if there's a way we can give a heads-up to the 
djangoproject.com and djangobook.com maintainers a heads-up on this is 
issue, so they can cater for it.


Nick

--
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: www.djangoproject.com

2010-07-15 Thread Tom Evans
On Thu, Jul 15, 2010 at 11:02 AM, George Sakkis  wrote:
> On Jul 15, 4:55 am, Danny Adair  wrote:
>
>> Hi,
>>
>> I had the exact same problem, and I had _not_ installed Weave.
>> The offending config entry in my case was:
>> "chrome://global/locale/intl.properties"
>> and it was at the bottom of the accepted languages list. This is on
>> Firefox 3.6.6
>>
>> I can reproduce the problem anytime by visiting about:config and
>> changing "intl.accept_languages" to
>> en-nz,en,de,chrome://global/locale/intl.properties
>>
>> *.djangoproject.com will stop responding, (all?) other websites seem fine.
>
> I didn't write down the offending entry in my case but I think it was
> the same or similar to yours. In any case, I can confirm that by
> setting it the problem is reproduced.
>
> Trying to reverse engineer the pattern of the offending values, I
> believe that the issue is the string length: any value up to 16 bytes
> works fine, 17 or more hangs.
>
> George
>

Hmm - mine is way longer than 17 characters, and I do not have any issues.
intl.accept_languages="en-US,en,fr-FR,fr,ja-JP,ja,en-GB,nl-NL,nl,en-gb"
works just fine for me.

Maybe firefox version is pertinent. This is firefox-3.6.4,1 from ports
on FreeBSD 7/i386.

Hmm, adding 'chrome://global/locale/intl.properties' does affect it...

Using wireshark to capture the traffic it seems no response is sent
for the offending request. I've created a minimum test case that can
be used to trigger the situation, using nc (nc will just hang waiting
for a response):

> $ nc www.djangoproject.com 80 < django_http_fail.req

django_http_fail.req:
GET http://www.djangoproject.com/ HTTP/1.1
Host: www.djangoproject.com
Accept-Language: en;q=0.9,chrome://global/locale/intl.properties;q=0.1


The good news (on some part) is that this doesn't seem to affect all
django sites. None of my sites become inaccessible after making these
changes. I guess djangoproject.com has some middleware that gets
stymmied by this invalid entry.

Cheers

Tom

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



Re: www.djangoproject.com

2010-07-15 Thread George Sakkis
On Jul 15, 1:14 pm, Tom Evans  wrote:
> On Thu, Jul 15, 2010 at 11:02 AM, George Sakkis  
> wrote:
> > On Jul 15, 4:55 am, Danny Adair  wrote:
>
> >> Hi,
>
> >> I had the exact same problem, and I had _not_ installed Weave.
> >> The offending config entry in my case was:
> >> "chrome://global/locale/intl.properties"
> >> and it was at the bottom of the accepted languages list. This is on
> >> Firefox 3.6.6
>
> >> I can reproduce the problem anytime by visiting about:config and
> >> changing "intl.accept_languages" to
> >> en-nz,en,de,chrome://global/locale/intl.properties
>
> >> *.djangoproject.com will stop responding, (all?) other websites seem fine.
>
> > I didn't write down the offending entry in my case but I think it was
> > the same or similar to yours. In any case, I can confirm that by
> > setting it the problem is reproduced.
>
> > Trying to reverse engineer the pattern of the offending values, I
> > believe that the issue is the string length: any value up to 16 bytes
> > works fine, 17 or more hangs.
>
> > George
>
> Hmm - mine is way longer than 17 characters, and I do not have any issues.
> intl.accept_languages="en-US,en,fr-FR,fr,ja-JP,ja,en-GB,nl-NL,nl,en-gb"
> works just fine for me.

Sorry, I meant to say a single item in the comma separated list has to
be up to 16 characters. intl.accept_languages="1234567890123456"
works, intl.accept_languages="12345678901234567" doesn't.

George

-- 
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: www.djangoproject.com

2010-07-15 Thread Russell Keith-Magee
On Thu, Jul 15, 2010 at 7:11 PM, Nick Raptis  wrote:
> On 07/15/2010 05:55 AM, Danny Adair wrote:
>>
>> Hi,
>>
>> I had the exact same problem, and I had _not_ installed Weave.
>> The offending config entry in my case was:
>> "chrome://global/locale/intl.properties"
>> and it was at the bottom of the accepted languages list. This is on
>> Firefox 3.6.6
>>
>> I can reproduce the problem anytime by visiting about:config and
>> changing "intl.accept_languages" to
>> en-nz,en,de,chrome://global/locale/intl.properties
>>
>> *.djangoproject.com will stop responding, (all?) other websites seem fine.
>>
>> Cheers,
>> Danny
>>
> Yep, that's the one!
> I tried to open chrome://global/locale/intl.properties as a link in Firefox,
> and (oh, the surprise :P ) it's a settings file.
> Either the file doesn't get resolved unto something useful in my platform
> (I'm using ubuntu-based) or it's something depreciated and it's a migration
> issue.
> Also checked the Firefox bugzilla and there are indeed a couple of bug
> reports for it.
>
> My feelings still stand. Other than making sure that django itself handles
> such erroneous values gracefully,  the list shouldn't be too concerned about
> it.
>
> Now, I wonder if there's a way we can give a heads-up to the
> djangoproject.com and djangobook.com maintainers a heads-up on this is
> issue, so they can cater for it.

You, mean, like... oh, I don't know... one of the core developers of
Django? Like the one that's been asking for details on how to
reproduce the problem? :-)

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.



Apache, wsgi and templates

2010-07-15 Thread lupuscramus
Hi.

I've made an app (django 1.2) which works fine for tests, on my laptop with 
the django built-in web server.

I want to put in production my app, with Apache and mod_wsgi.

I've verified I've django 1.2 on the production server.

The problem is I've no images. When I connect to the admin site (generated bu 
Django), I can see "Django Administration", the fields "connexion" and 
"password", but there is not the images of the interfaces - it's a simple 
page.

I use a template dir to replace Django Administration by my own title, but 
even I disable the template dir, I have no images.

My server uses Debian, and I've installed Django by aptitude. My files are 
located in /usr/share/pyshared/django.

I can see on the documentation of django about deploying an app with apache 
and wsgi that I should have another web server, or configure apache for the 
media files. It could be the problem  (Images are they media files ?).

In fact, I don't understand really this part of the doc. Are the defaults 
templates of django concerned by this part ?

Thanks,

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



check md5sum on an uploaded file

2010-07-15 Thread Hawit
how do we check the md5sum / checksum an uploded file in django?

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



retrieving record id after form save with generic views

2010-07-15 Thread MarcoS
Hi people, I use django.views.generic.create_update.create_object to
save a record and I need to retrieve the id of the record from the
just-saved form.
It's possible to do this using generic views?

-- 
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: www.djangoproject.com

2010-07-15 Thread Nick Raptis

On 07/15/2010 02:20 PM, Russell Keith-Magee wrote:


You, mean, like... oh, I don't know... one of the core developers of
Django? Like the one that's been asking for details on how to
reproduce the problem? :-)

Yours,
Russ Magee %-)

   

Ahaha! Exactly! Nice to make your acquittance Russ.
Knowing who is who is a bit of magic art on lists, unless of course you 
google every email :)


To my mind, the devs and the site maintainers don't have to be the same 
people, but I threw it on the list so someone (turns out to be you) 
could get the word through.

Mischief managed :)

your obliged new-guy,
Nick

--
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: check md5sum on an uploaded file

2010-07-15 Thread Jim
Could you clarify what you want to do beyond saving the file somewhere
and running  md5 on it?

-- 
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: Apache, wsgi and templates

2010-07-15 Thread jaymzcd
There's a few ways to do it. An easy way if your just serving up some
css, images etc is to symlink your admin_media folder in your media
directory to the media folder in your django admin install:

[ja...@293230-app1 ~]$ ls /var/django-projects/udox/public/media/ -l
total 28
lrwxr-xr-x  1 root  root 62 Jun 25 09:34 admin -> /usr/local/
pyvans/lib/python2.6/site-packages/grappelli/media/
drwxr-xr-x  2 jaymz apache 4096 Jul  9 06:12 css
drwxr-xr-x 32 jaymz apache 4096 Jun 14 11:21 galleries

And in settings:
ADMIN_MEDIA_PREFIX = '/media/admin/'

This means anyone can access your admin css/js files etc, it's
unlikely to be an issue for you.

Another way is to set your admin_media_prefix to something like /
admin_media/ and then in your apache conf set an alias for it.

Alias /admin_media/ /usr/local/pyvans/lib/python2.6/site-packages/
grappelli/media/

Both work and are pretty painless. Your paths will be different of
course (i'm using django-grappelli as a backend theme)

jaymz

On Jul 15, 2:04 am, lupuscramus  wrote:
> Hi.
>
> I've made an app (django 1.2) which works fine for tests, on my laptop with
> the django built-in web server.
>
> I want to put in production my app, with Apache and mod_wsgi.
>
> I've verified I've django 1.2 on the production server.
>
> The problem is I've no images. When I connect to the admin site (generated bu
> Django), I can see "Django Administration", the fields "connexion" and
> "password", but there is not the images of the interfaces - it's a simple
> page.
>
> I use a template dir to replace Django Administration by my own title, but
> even I disable the template dir, I have no images.
>
> My server uses Debian, and I've installed Django by aptitude. My files are
> located in /usr/share/pyshared/django.
>
> I can see on the documentation of django about deploying an app with apache
> and wsgi that I should have another web server, or configure apache for the
> media files. It could be the problem  (Images are they media files ?).
>
> In fact, I don't understand really this part of the doc. Are the defaults
> templates of django concerned by this part ?
>
> Thanks,

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



Re: Django 1.2.1, Postgres 8.3 - Cast (text to int) Issue

2010-07-15 Thread rd-london
Hi,
Fixed it.

I took the following (from http://bit.ly/bO8m9A):

Comment.objects.filter(content_type=ContentType.objects.get_for_model(Entry ),
object_pk__in=Entry.objects.filter(category="some category")).

and used it as follows:

Comment.objects.filter(content_type=ContentType.objects.get_for_model(Entry),
object_pk__in=Entry.objects.filter(title=self.title))

With Django 1.2, Postgres 8.3, and 'postgresql_psycopg2', this no
longer works. Reason is that "object_pk" in the Comment model is a
"text" type in Postgres, whereas Entry.id is an "integer" - and there
is no longer an automatic conversion between the two.

So, my fix was to break things down as follows:

comment_list=Comment.objects.filter(content_type=ContentType.objects.get_for_model(Entry))
e=Entry.objects.filter(title=self.title)
entry_object_ids_string = str([ei.id for ei in e])
comment_tuple=comment_list.filter(object_pk__in=entry_object_ids_string).values_list('comment',
flat=True)

This seems to work fine.
This post is really a follow-on from "Filtering contrib.comments on
related object property?": http://bit.ly/bO8m9A


FYI - I wanted to use this to enable my Djapian-based on-site search
to be able to search comments that people had left. Again, seems to
work.

Thanks,
R



On Jul 14, 8:45 pm, rd-london  wrote:
> Hi,
> Wonder if someone can help.
> I have a piece of code (filtched from elsewhere) that retrieves the
> comments for a particular Entry (blog post):
>
> Comment.objects.filter(content_type=ContentType.objects.get_for_model(Entry ),
> object_pk__in=Entry.objects.filter(title=self.title))
>
> Problem is, that with Postgres 8.3 (and seemingly Django 1.2.1), this
> command fails:
>
> "
> django.db.utils.DatabaseError: operator does not exist: text = integer
> HINT:  No operator matches the given name and argument type(s). You
> might need to add explicit type casts.
> "
>
> Having searched around in various forms this appears to be a sort of
> known problem (seehttp://code.djangoproject.com/ticket/10015).
>
> The issue is that object_py in Comments is a "text" field, whereas the
> id field in Entry is an int - hence a cast is required. I can make the
> actual SQL work in Postgres 8.3 by altering the start of the WHERE to
> be:
>
> "WHERE (cast(django_comments.object_pk as int) IN (SELECT"  i.e.
> adding the 'cast'.
>
> So, my question is: what's the best way to go about this in Django
> 1.2.1 with Postgres 8.3? (8.3.8 to be exact). Any thoughts/
> recommendations most welcome.
>
> FYI - this is for use with Djapian.
>
> Thanks,
> R

-- 
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: ordering a model on multiple fields?

2010-07-15 Thread Scott Gould
The Django *admin* only uses one field, ever.

Bit of an irritating limitation, I grant you, but with the use of date
hierarchies and list filters it's not too bad.

On Jul 14, 7:40 pm, hjebbers  wrote:
> is there a way to have a model class sorted on multiple fields?
> in the meta class of my models I set the ordering, but django uses
> only the first field for ordering;
> a second field is just ignored.
>
> (I am aware that if a users starts to sort using table headers in the
> admin interface only one field will be used. It would just be great to
> have the initial ordering on 2 fields.)
>
> kind regards, henk-jan ebbers

-- 
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: Anyone want to take over maintaining Instant Django?

2010-07-15 Thread Sid

I would be willing to take it on or we can also do it as a community
effort?
Instant Django is how i got started into web dev and now i'm a full
time django freelancer so would love to give some love back.

-Sid
http://sidmitra.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-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: altering the sessions class

2010-07-15 Thread Sid
I think a custom middleware solution might work here? Just have a
custom middleware run initially that adds the instance of your session
class to the request object.
I haven't tried anything like this before but it might work.

-Sid


On Jul 14, 11:42 pm, "T.L"  wrote:
> So, I am using request.sessions in one of my views functions but I
> want to add a few more fields to the Session class so it will be
> customized for my project.  When I tried to go to the Session class
> (in django.contrib.sessions.models) and simply adding in an extra
> field, and then adding it to my admin (I put the django_session table
> to the admin), I got an error saying that attribute didnt exist.  My
> question is, where do I need to make changes so I can add my own
> fields to the Session class.  I also tried having another class
> inherit the Session class and add fields to the inherited class but
> the problem I had with that is I couldnt use request.inheritedClass
> where inheritedClass is the class that inherited the Sessions class.
> The error I received when I tried doing request.inheritedClass in one
> of my views function was this:
> 'WSGIRequest' object has no attribute 'inheritedClass'.
> To sum it up, can anyone tell me some way to customize the Session
> class to my liking?
>
> Thanks,
> Tony

-- 
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: altering the sessions class

2010-07-15 Thread David De La Harpe Golden
On 14/07/10 19:42, T.L wrote:
> So, I am using request.sessions in one of my views functions but I
> want to add a few more fields to the Session class so it will be
> customized for my project.  

> To sum it up, can anyone tell me some way to customize the Session
> class to my liking?
> 

It seems at least somewhat unlikely to me you _really_ want to do that -
django sessions store key-value pairs already, kinda
what they're there for, and if you go the route of customising
models.Session you'll exclude the use of session backends other than the
db.

http://docs.djangoproject.com/en/dev/topics/http/sessions/#using-sessions-in-views

request.session is just injected by the
django.contrib.sessions.middleware.SessionMiddleware
(probably in default settings.MIDDLEWARE_CLASSES)
If you really, truly want other behaviour you could supply your own
session middleware to put whatever you want on request.session


If your real goal is just improving session security somewhat, you might
want to look at django-paranoid-sessions:
http://github.com/rfk/django-paranoid-sessions/

-- 
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: Jquery nav disabled in Django base template??? help please

2010-07-15 Thread David De La Harpe Golden
On 15/07/10 13:40, justin jools wrote:

> 2. base.html with jquery nav, exactly the same except for
> {{ MEDIA_URL }} which is correct.
> 

FWIW, we use a jquery load line in our base template and it works fine
(pretty disastrous for us if it didn't).

You're 100% sure the pathss correct (like when you "view source" the
rendered page and look at the rendered links in your browser) -
forgetting a trailing slash on settings.MEDIA_URL is a common mistake,
as is inserting an extra one somewhere.

In case you've been away on mars or something: the "firebug" extension
for firefox is extremely useful for poking about rendered pages.

> 
  
{% block title %}BlahProj{% endblock title %}