Re: Running doctests

2008-09-01 Thread Guillaume Lederrey

Thanks for your very fast answer ! But ... see inline

2008/9/1 Malcolm Tredinnick <[EMAIL PROTECTED]>:
>
>
> On Mon, 2008-09-01 at 22:48 +0200, Guillaume Lederrey wrote:
>> Hello !
>>
>> I have an app that has a "utils.py" module. I have written quite a few
>> doctests inline. Now my problem is to actually run those tests.
>> Reading the documentation, I get the feeling that I should be able to
>> call them from the tests.py file, but I cant find an example. I have
>> seen a few projects where there is doctests in tests.py that test
>> other modules, but it seems to me that this defeats the purpose of
>> having the tests inline, very close to the implementation.
>
> Right now, Django's testing framework looks for doctests in two places:
> the "models" module and the "tests" module.
>
> It doesn't entirely defeat the purpose, since you can pull in tests from
> other places into "tests" for example, but it doesn't scan every single
> file.

What do you mean by "since you can pull in tests from other places
into "tests"" ? I am pretty new to python, and I might me missing
something obvious here ...

Thanks for the help !


> Regards,
> Malcolm
>
>
>
> >
>



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/
* http://trock.ch/
Others :
* http://kiva.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-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
-~--~~~~--~~--~--~---



Running doctests

2008-09-01 Thread Guillaume Lederrey

Hello !

I have an app that has a "utils.py" module. I have written quite a few
doctests inline. Now my problem is to actually run those tests.
Reading the documentation, I get the feeling that I should be able to
call them from the tests.py file, but I cant find an example. I have
seen a few projects where there is doctests in tests.py that test
other modules, but it seems to me that this defeats the purpose of
having the tests inline, very close to the implementation.

Did I miss something ?

Thanks for your help !

MrG


-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/
* http://trock.ch/
Others :
* http://kiva.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-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: "core" is not a field constructor argument anymore

2008-09-01 Thread Guillaume Lederrey

2008/8/30 James Bennett <[EMAIL PROTECTED]>:
>
> On Fri, Aug 29, 2008 at 5:58 PM, Guillaume Lederrey
> <[EMAIL PROTECTED]> wrote:
>> After updating to the latest trunk, I get a couple of errors when I
>> have field that define "core=True". After digging into the code, I
>> find changeset 8616 (http://code.djangoproject.com/changeset/8616)
>> that documents that. However, this doesnt seem to be include in the
>> backward incompatible changes
>> (http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges).
>
> You want to read the section on the admin changes; basically, anything
> you used to use to specify/control admin behavior (which is what
> 'core' did) has changed.

My mistake, I didnt read carefully enough ...

Thanks for the pointer !

MrG

> --
> "Bureaucrat Conrad, you are technically correct -- the best kind of correct."
>
> >
>



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/
* http://trock.ch/
Others :
* http://kiva.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-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: Working but ugly model code. Need advice.

2008-09-01 Thread Guillaume Lederrey

If you just want to have a clean working solution, have a look at
django-photologue (http://code.google.com/p/django-photologue/). It is
amazing, and really easy to integrate well. Also have a look at
sorl-thumbnail (http://code.google.com/p/sorl-thumbnail/).

If you want to write your own code and make it a bit cleaner, I think
you should first try to break things a bit more
(http://en.wikipedia.org/wiki/Separation_of_concerns). For example,
having different picture sizes is a presentation problem, not a
persistence problem. So if you solve the that in a template tag, it
will probably be much cleaner.

Just my own 2 cents ... and yes, I know that I didnt really answer
your question ... sorry

  Good luck !

2008/8/29 drbig <[EMAIL PROTECTED]>:
>
> Hi!
>
> Before I paste the code here is what I want to achieve:
> 1) All content is supplied via django admin, no custom upload/edit
> forms
> 2) The Photo class holds title and note (the text data), two images
> (full and thumb), and stats data of hits and comments count
> 3) The stamp should be updated only when the text data or full image
> change (only full as...)
> 4) When image is uploaded it should be resized if too large and the
> thumbnail should be auto(re)generated
>
> Here is the code:
> from django.db import models
> from django.conf import settings
> from PIL import Image
> from datetime import datetime as dt
> import md5, time, os
>
> class Tag(models.Model):
>stamp = models.DateTimeField(auto_now = True)
>name = models.CharField(max_length = 32)
>
>class Meta:
>ordering = ['name']
>get_latest_by = '-stamp'
>
>def __unicode__(self):
>return self.name
>
> class Photo(models.Model):
>stamp = models.DateTimeField(auto_now_add = True)
>title = models.CharField(max_length = 255)
>note = models.TextField()
>content_hash = models.CharField(max_length = 32, editable = False)
>upload_image = models.ImageField(upload_to = 'photos/tmp', blank =
> True)
>ifull = models.CharField(max_length = 128, editable = False)
>ithumb = models.CharField(max_length = 128, editable = False)
>image_hash = models.CharField(max_length = 32, editable = False)
>hits = models.PositiveIntegerField(default = 0, editable = False)
>comments_count = models.PositiveIntegerField(default = 0, editable =
> False)
>tags = models.ManyToManyField(Tag)
>
>class Meta:
>ordering = ['-stamp']
>get_latest_by = '-stamp'
>
>def __unicode__(self):
>return self.title
>
>def save(self):
>try:
>new_hash =
> md5.new(self.upload_image.read(num_bytes = 1024)).hexdigest()
>if new_hash != self.image_hash:
>if self.ifull:
>name = self.ifull.split('/')
> [-1]
>else:
>name = str(int(time.time())) +
> '.jpg'
>img =
> Image.open(self.upload_image.path)
>img.load()
>self.upload_image.delete(save = False)
>if img.size > (800, 600):
>img.thumbnail((800, 600),
> Image.ANTIALIAS)
>img.save(settings.MEDIA_ROOT + 'photos/
> full/' + name, 'jpeg')
>img.thumbnail((128, 128),
> Image.ANTIALIAS)
>img.save(settings.MEDIA_ROOT + 'photos/
> thumb/' + name, 'jpeg')
>self.ifull = '/data/photos/full/' +
> name
>self.ithumb = '/data/photos/thumb/' +
> name
>self.image_hash = new_hash
>self.stamp = dt.now()
>except Exception, e:
>pass
>new_hash = md5.new(self.title + self.note).hexdigest()
>if new_hash != self.content_hash:
>self.content_hash = new_hash
>self.stamp = dt.now()
>super(Photo, self).save()
>
>def delete(self):
>if self.ifull:
>name = self.ifull.split('/')[-1]
>try:
>os.remove(settings.MEDIA_ROOT +
> 'photos/thumb/' + name)
>os.remove(settings.MEDIA_ROOT +
> 'photos/full/' + name)
>except Exception, e:
>pass
>super(Photo, self).delete()
>
> class Comment(models.Model):
>stamp = models.DateTimeField(auto_now_add = True)
>ip = models.IPAddressField()
>signature = models.CharField(max_length = 64)
>content = models.TextField()
>

"core" is not a field constructor argument anymore

2008-08-29 Thread Guillaume Lederrey

Hello !

After updating to the latest trunk, I get a couple of errors when I
have field that define "core=True". After digging into the code, I
find changeset 8616 (http://code.djangoproject.com/changeset/8616)
that documents that. However, this doesnt seem to be include in the
backward incompatible changes
(http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges).

So ... if anybody else has the same problem ...

-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/
* http://trock.ch/
Others :
* http://kiva.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-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: how to locate the OS currently logged in user??

2008-08-27 Thread Guillaume Lederrey

2008/8/27 PeteDK <[EMAIL PROTECTED]>:
> On 21 Aug., 16:25, "Guillaume Lederrey" <[EMAIL PROTECTED]>
> wrote:
>> 2008/8/21 PeteDK <[EMAIL PROTECTED]>:
>> > On 21 Aug., 13:10, "Guillaume Lederrey" <[EMAIL PROTECTED]>
>> > wrote:
>> >> 2008/8/21 PeteDK <[EMAIL PROTECTED]>:
>> >> I'm still not clear on how your user log into the server. Via SSH,
>> >> HTTP Auth, other ?
>>
>> > Sorry i failed to answer your question. I must admit i don't know
>> > exactly how the user logs in. I will try to get that information :-)
>>
>> I'm pretty sure we will be able to give you more meaningful answers
>> with that piece of information ... ;-)
>
> I now have some new information. I now believe that what i need is the
> visitors information.
>
> On another system on the same network(written in Perl) it is done this
> way:
> $loginbruger=uc($ENV{AUTHENTICATE_SAMACCOUNTNAME});
>
> (loginbruger is danish for loginuser)
>
> can i do the same thing in python?? get the visitors username?

Again, without understanding how the users log into the server, we can
only guess ...

SAMACCOUNTNAME makes me think about Windows (SAM = Security Account
Manager), but that's just based on the name, and that name could well
mean something else in your context.

>From what I understand, the name is stored in an environment variable
(but I dont know how it gets there). Usually, the environment of a
process isnt changed from the outside after creation. And Django is a
long running process, so it should not pick up users logging in after
startup. But I can be completely wrong on that one ...

Assuming I am wrong above, you should be able to access the same
environment variable from python code with :

import os
loginbruger = os.environ['AUTHENTICATE_SAMACCOUNTNAME']

More infos on http://docs.python.org/lib/os-procinfo.html

The real problem I see there is that if there is multiple users
connected to the server, I dont see how the right user could be
associated with an HTTP session ...

Good luck, and please, try to get the info on how the login process works !



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/
* http://trock.ch/
Others :
* http://kiva.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-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: how to locate the OS currently logged in user??

2008-08-21 Thread Guillaume Lederrey

2008/8/21 PeteDK <[EMAIL PROTECTED]>:
>
>
>
> On 21 Aug., 13:10, "Guillaume Lederrey" <[EMAIL PROTECTED]>
> wrote:
>> 2008/8/21 PeteDK <[EMAIL PROTECTED]>:
>>
>>
>>
>> > The server is running Debian Linux and they are logging on to the
>> > server using the username and password stored in the active directory
>> > on one of the other servers.
>>
>> I'm still not clear on how your user log into the server. Via SSH,
>> HTTP Auth, other ?
>
> Sorry i failed to answer your question. I must admit i don't know
> exactly how the user logs in. I will try to get that information :-)

I'm pretty sure we will be able to give you more meaningful answers
with that piece of information ... ;-)

  MrG


-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/
* http://trock.ch/
Others :
* http://kiva.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-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: how to locate the OS currently logged in user??

2008-08-21 Thread Guillaume Lederrey

2008/8/21 PeteDK <[EMAIL PROTECTED]>:
>
> The server is running Debian Linux and they are logging on to the
> server using the username and password stored in the active directory
> on one of the other servers.

I'm still not clear on how your user log into the server. Via SSH,
HTTP Auth, other ?



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/
* http://trock.ch/
Others :
* http://kiva.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-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: Browser timeout on long processes

2008-08-20 Thread Guillaume Lederrey

2008/8/20 Julien Phalip <[EMAIL PROTECTED]>:
>
>> If the view is running a loop -  how would you provide a variable to another
>> view (that Ajax is calling) about the situation? Let's say a percentage
>> complete -- I immediately think of a global variable, but am not sure how
>> this works in a multi-user web situation.
>
> You could use the cache by setting a key that the other view can look
> up.

The (arguably) right way to store / share data in a webapp is to use
the session. Django provides good session management as explained in
http://www.djangoproject.com/documentation/sessions/

Good luck !

  MrG


> Julien
> >
>



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/
* http://trock.ch/
Others :
* http://kiva.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-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: how to locate the OS currently logged in user??

2008-08-20 Thread Guillaume Lederrey

2008/8/20 PeteDK <[EMAIL PROTECTED]>:
> I want to retreive the name of the currently logged in user on the OS
> on which my django app lives.
> Is this possible?

You should realize that there is no direct connection between the user
logged in the webserver and the user connecting via HTTP to your
Django app. There is nothing preventing a user to connect to your
Django app without logging to the server first ...

> The thing is. The app is to be used in a private environment, so all
> the users have to log on to the webserver first(this cant be changed).
> I would be nice to avoid having them to log into the django app
> afterwards.

So what you seem to be looking for is a Single Sign On (SSO) solution.
I dont know of any standard way to do that under Linux, but if you are
using Windows, there is a standard mechanism for that. I think it is
based on Kerberos and integrates with Active Directory. I'm far from a
Windows expert, so dont ask me for the details, but I have been using
this solution :

* use IIS as a front proxy, IIS will do the authentication
* IIS will forward the request to the backend server (in your case
Django, running on Apache or even running on IIS)
* the request is forwarded with additional HTTP headers describing the
authentication (including the username)
* you can then write a specialized authentication middleware that will
use those headers to associate the session with the user

> So after they are logged into the webserver it would be fair to assume
> they are authorised users and if i could just locate their OS username
> somehow then i could use this username to login the current user, in
> the background with a standard password.
>
> I hope you get my meaning:)
>
> i have looked into the python standard library, and a module named
> getpass() however i cant get i to work:-(
>
> i hope someone has a clever idea to solve this problem.
>
> Thanks! :)
>
> /Pete
>
> PS: and the webserver runs linux. :-)
> >
>



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/
* http://trock.ch/
Others :
* http://kiva.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-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: time and attendance management system

2008-05-29 Thread Guillaume Lederrey

I'm afraid you missed step 7 :

7) profit !

2008/5/29 Tim Chase <[EMAIL PROTECTED]>:
>
>> hi...related to the same problem i also have to designe
>> forms,reports and tables for ma data base ...will plz guide me
>
> It's a fairly trivial process so I will guide you:
>
> 1) get a server (I recommend Debian GNU/Linux)
> 2) install the following:
>
>   Python
>   Django
>   a web-server such as Apache/lighttpd
>   a web-server interface:  mod_python/mod_wsgi/fastcgi/etc
>   a database (PostgreSQL, MySQL or sqlite are popular choices)
>
> 3) do lots of hard work:
>   - design your application, data-structures, and tests
>   - implement your design
>
> 4) deploy your design
>
> 5) fix bugs
>
> 6) repeat steps 3-6 until your code is perfect
>
> I leave step #3 as an exercise to the reader.  If you get stuck
> on particular issues, this list and the comp.lang.python mailing
> list are helpful places to get specific help.  However, as
> friendly as both places are, neither will be a replacement for
> doing the hard work yourself.
>
> -tim
>
>
>
>
>
>
> >
>



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

--~--~-~--~~~---~--~~
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: time and attendance management system

2008-05-29 Thread Guillaume Lederrey

Your question is very general, so it is difficult to give you a
meaningful answer ... If you give us a much more precise description
of your problem, or if you ask much more specific questions, you might
get a useful answer.

Here is a probably completely off-topic answer :

You will make your employee database using Django model as described
in the tutorial
(http://www.djangoproject.com/documentation/tutorial01/#creating-models)
or described in more details in the documentation
(http://www.djangoproject.com/documentation/model-api/). You might
also find appropriate examples in
http://www.djangoproject.com/documentation/models/

Good luck !

  MrG

2008/5/29 sesh <[EMAIL PROTECTED]>:
>
> i want to make time and attendance management system but how i make
> data base for employees for thisits realy argent
> >
>



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

--~--~-~--~~~---~--~~
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: urls() and request.user

2008-05-12 Thread Guillaume Lederrey

Hello !

I finally choose to create a decorator to implement this
functionality. I wanted something more generic than a wrapper in my
urls.py. The solution seems to work fine for me, and if anybody want
to do the same, the code is at
http://www.djangosnippets.org/snippets/753/

Of course, any suggestions of improvements are welcomed ...

MrG

2008/5/5 Nathaniel Whiteinge <[EMAIL PROTECTED]>:
>
>  On May 4, 5:42 am, "Guillaume Lederrey" <[EMAIL PROTECTED]>
>  wrote:
>
> > I havent done any functional programming in a long time , but ... isnt
>  > there a way to use an anonymous function (if that's what it is called)
>  > and do the wrapper "inline" ? Something like :
>
>  Yeah, something like that would work, although tying it into your
>  example above would look pretty ugly, I'm guessing::
>
> (r'^test/$', lambda request: HttpResponse('Hello, %s' %
>  request.user)),
>
>  If you're only trying to get the currently logged in user into the
>  template context, it's already there as ``{{ user }}`` if you're using
>  generic views [1]. Sorry I didn't mention that in my first reply.
>
>  .. [1] 
> http://www.djangoproject.com/documentation/templates_python/#django-core-context-processors-auth
>
>
> >
>



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

--~--~-~--~~~---~--~~
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: Empty Result set

2008-05-07 Thread Guillaume Lederrey

2008/5/6 jwwest <[EMAIL PROTECTED]>:
>  What's the preferred method of checking to see if a result set is
>  empty in a view? For instance, I'm writing blog software and have a
>  view by year method. If there are no posts, I want to raise a http404.
>
>  I've tried == {} and == [] to no avail.

Maybe you could have a look at
http://www.djangoproject.com/documentation/shortcuts/#get-list-or-404
...

Good luck !


-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

--~--~-~--~~~---~--~~
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: urls() and request.user

2008-05-04 Thread Guillaume Lederrey

2008/5/2 Nathaniel Whiteinge <[EMAIL PROTECTED]>:
>
>  On May 1, 10:04 am, "Guillaume Lederrey"
>
> <[EMAIL PROTECTED]> wrote:
>  > This of course doesnt work because the request isnt in the scope. I
>  > could redefine a view in my views.py and do the work on the request
>  > manually, but i have a feeling there is a solution to do that directly
>  > in my urls.py.
>
>  Sorry, there isn't a way to get at the request object in your urlconf.
>  You'll have to make a wrapper around the generic view -- when the
>  wrapper is small, I often just put it in my ``urls.py``::
>
> from django.conf.urls.defaults import *
> from whereever.youput.create_update import update_object
>
> urlpatterns = patterns('',
> ('^pattern/$', 'path.to.this.urlconf.mywrapper'),
> )
>
> def mywrapper(request):
> ...
> return update_object(request, ...)

I havent done any functional programming in a long time , but ... isnt
there a way to use an anonymous function (if that's what it is called)
and do the wrapper "inline" ? Something like :

urlpatterns = patterns('',
('^pattern/$', lambda(request)(
return update_object(request, ...)
),
)

Thanks for your help !



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

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



urls() and request.user

2008-05-01 Thread Guillaume Lederrey

Hello !

I am trying to use the update_object generic view  in
http://www.djangosnippets.org/snippets/635/

I am using it directly in my urls.py like this :

url(r'^(?P\d+)/edit/$',
permission_required('change_news')(update_object),
{
'model' : News,
'model_form' : NewsForm,
'login_required' : True,
},
),

which works fine. Now, I am trying to add an extra field like this :

url(r'^(?P\d+)/edit/$',
permission_required('change_news')(update_object),
{
'model' : News,
'model_form' : NewsForm,
'login_required' : True,
'extra_field' : {
'author' : request.user,
}
},
),

This of course doesnt work because the request isnt in the scope. I
could redefine a view in my views.py and do the work on the request
manually, but i have a feeling there is a solution to do that directly
in my urls.py.

any idea ?

Thanks !

  Guillaume


-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

--~--~-~--~~~---~--~~
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: date_based.archive_index and "IS NULL" query

2008-05-01 Thread Guillaume Lederrey

I forgot to add :

I'm running django-trunk, so it might be related to the queryset
refactoring merge ?

2008/5/1 Guillaume Lederrey <[EMAIL PROTECTED]>:
> Hello !
>
>  I am getting a strange query from the archive_index generic view :
>
>   SELECT DISTINCT CAST(DATE_FORMAT(`news_news`.`publication_date`,
>  '%Y-01-01 00:00:00') AS DATETIME) FROM `news_news` WHERE
>  `news_news`.`publication_date` IS NULL ORDER BY 1 ASC
>
>  I dont understand where the "IS NULL" comes from. As all the news in
>  my database have a publication_date, this query returns nothing and no
>  news is displayed.
>
>  Any help appreciated !
>
>  Here is my ulrs.py :
>
>  urlpatterns = patterns('',
> url(r'^$',
> date_based.archive_index,
> {
> 'queryset' : News.objects.all(),
> 'date_field' : 'publication_date',
> 'allow_future' : True,
> },
> ),
>  )
>
>
>  and the model :
>
>  class News(models.Model):
> """ News model """
> title = models.CharField(max_length=100, unique=True)
> slug = models.SlugField(prepopulate_from=("title",),
> unique_for_date='publication_date')
> author = models.ForeignKey(User)
> creation_date  = models.DateField(auto_now_add=True)
> modification_date = models.DateField(auto_now=True)
> publication_date = models.DateField(blank=True, null=True)
> ask_promotion = models.BooleanField(default=False,
> help_text=_("Ask for this news
>  to be promoted on the front page. For example, an artist might be able
>  to write news for its next gig, and have the news appear on the
>  artist's page, but not on the front page. The artist can ask a
>  moderator to promote the news on the front page by checking this
>  field."))
> promoted = models.BooleanField(default=False,
>help_text=_("If this field is
>  checked, the news will appear on the front page."))
> trock_news = models.BooleanField(default=False,
>  help_text=_("Check this field if
>  you want this news to be published in the next TrocK news."))
> text = models.TextField(blank=True)
>
> class Meta:
> """
> Defines meta data on the model.
> """
> verbose_name_plural = _('news')
> ordering = ['-publication_date', 'title',]
> permissions = (
> ("export_trock_news", _("Can export the list of news
>  selected for the next TrocK news")),
> )
>
> class Admin:
> """
> This model is available in the admin interface.
> """
> list_display = ('title', 'publication_date',)
>
> def __unicode__(self):
> return '%s' % self.title
>
> @permalink
> def get_absolute_url(self):
> """
> The URL to this news in the date based view.
> """
> return ('news_detail', (), {
> 'year' : self.publication_date.year,
> 'month' : self.publication_date.month,
> 'day' : self.publication_date.day,
> 'slug' : self.slug,
> })
>
> @permalink
> def get_absolute_url_by_id(self):
> """
> The URL to this news in the ID based view.
> """
> return ('news_detail_by_id', (), {
> 'object_id' : self.pk,
> })
>
>
>
>  --
>  Jabber : [EMAIL PROTECTED]
>  Skype : Guillaume.Lederrey
>  Projects :
>  * http://rwanda.ledcom.ch/
>



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

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



date_based.archive_index and "IS NULL" query

2008-05-01 Thread Guillaume Lederrey

Hello !

I am getting a strange query from the archive_index generic view :

 SELECT DISTINCT CAST(DATE_FORMAT(`news_news`.`publication_date`,
'%Y-01-01 00:00:00') AS DATETIME) FROM `news_news` WHERE
`news_news`.`publication_date` IS NULL ORDER BY 1 ASC

I dont understand where the "IS NULL" comes from. As all the news in
my database have a publication_date, this query returns nothing and no
news is displayed.

Any help appreciated !

Here is my ulrs.py :

urlpatterns = patterns('',
url(r'^$',
date_based.archive_index,
{
'queryset' : News.objects.all(),
'date_field' : 'publication_date',
'allow_future' : True,
},
),
)


and the model :

class News(models.Model):
""" News model """
title = models.CharField(max_length=100, unique=True)
slug = models.SlugField(prepopulate_from=("title",),
unique_for_date='publication_date')
author = models.ForeignKey(User)
creation_date  = models.DateField(auto_now_add=True)
modification_date = models.DateField(auto_now=True)
publication_date = models.DateField(blank=True, null=True)
ask_promotion = models.BooleanField(default=False,
help_text=_("Ask for this news
to be promoted on the front page. For example, an artist might be able
to write news for its next gig, and have the news appear on the
artist's page, but not on the front page. The artist can ask a
moderator to promote the news on the front page by checking this
field."))
promoted = models.BooleanField(default=False,
   help_text=_("If this field is
checked, the news will appear on the front page."))
trock_news = models.BooleanField(default=False,
 help_text=_("Check this field if
you want this news to be published in the next TrocK news."))
text = models.TextField(blank=True)

class Meta:
"""
Defines meta data on the model.
"""
verbose_name_plural = _('news')
ordering = ['-publication_date', 'title',]
permissions = (
("export_trock_news", _("Can export the list of news
selected for the next TrocK news")),
)

class Admin:
"""
This model is available in the admin interface.
"""
list_display = ('title', 'publication_date',)

def __unicode__(self):
return '%s' % self.title

@permalink
def get_absolute_url(self):
"""
The URL to this news in the date based view.
"""
return ('news_detail', (), {
'year' : self.publication_date.year,
'month' : self.publication_date.month,
'day' : self.publication_date.day,
'slug' : self.slug,
})

@permalink
def get_absolute_url_by_id(self):
"""
The URL to this news in the ID based view.
"""
return ('news_detail_by_id', (), {
'object_id' : self.pk,
})



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

--~--~-~--~~~---~--~~
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: Which kind of model inheritance is most suited?

2008-04-30 Thread Guillaume Lederrey

2008/4/29 francesco <[EMAIL PROTECTED]>:
>  I'd like to implement two kind of users in my system: a buyer and a
>  seller.
>  Both kind of users should, of course, inherit from a user model.
>  As I'd like to use the authentication framework from django.contrib,
>  should I have the "user" as table in the database or can I get by with
>  an abstract inheritance where no table is created for the user?

Hello !

In my experience, inheritance is overkill in this case. Composition is
very often a better alternative. In most cases, if you can express
your model both with inheritance and with composition, you should use
composition.

Let's be a bit more clear :

In your case, you can model with composition : a user has a function
(seller or buyer). It gives you a bit more functionnality (a user can
be both a seller and a buyer) and a bit more flexibility (a buyer can
become a seller, or the opposite).

Inheritance is a very strong relationship. It cant be changed
dynamically. It should be used carefully ...

Good luck !

   MrG



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

--~--~-~--~~~---~--~~
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: Largest django sites?

2008-04-23 Thread Guillaume Lederrey

2008/4/23 bcurtu <[EMAIL PROTECTED]>:
>  But, turning back to my question... Can you tell these sites with
>  thousands or hundreds of thousands hits per minute? Ok, let's leave
>  apart their stats... Any big name on the internet? slashdot? twitter
>  is RoR...

Pownce (http://pownce.com/) is built with Django.

-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

--~--~-~--~~~---~--~~
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: DateField widget, ModelForm and javascript

2008-04-22 Thread Guillaume Lederrey

2008/4/22 Peter Melvyn <[EMAIL PROTECTED]>:
>
>  On 4/21/08, Rishabh Manocha <[EMAIL PROTECTED]> wrote:
>
>  >  I'd be interested in knowing how to get it to show up too (what JS/CSS
>  >  files need to be added, whether there is some setting we can use in
>  >  the python code itself or do we have to print out each field
>  >  independently and insert the appropriate code for the picker etc.).
>
>  Date/Time pickers are bound via widget's class names vDateField and
>  vTimeField, hence you need to define them in your form definition.

That's the kind of solution I was thinking about. I actually would
like all of my DateFields to have a calendar widget. Is it possible to
register a custom Date widget as the default widget used by ModelForm
? Being able to create the Forms from the Models is a great
simplification for all the simple UI. It gets a bit less simple if all
those forms have to be customized to include a CSS class ...

Thank you for your help !

  MrG



-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

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



DateField widget, ModelForm and javascript

2008-04-21 Thread Guillaume Lederrey

Hello !

I have a model that I try to edit with a ModelForm. This model has a
DateField property. I render the form in my template with a simple :

{{ form.as_p }}

I expected the DateField to be displayed as in the admin interface,
with a javascript date picker. But I only get a text field. The value
format is validated as a date format, so I expect the field is treated
as a DateField.

Is there a way to automagically get the javascript date picker, or is
it something I have to add manually ?

Thanks for your help !

   MrG

-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

--~--~-~--~~~---~--~~
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: Distributed databases

2008-04-16 Thread Guillaume Lederrey

On 16/04/2008, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>  display this data. Would be also possible, to have different database
>  types (i would like to have several sqlite databases and one postgres
>  running)?
>
>  I need all this for scalability reasons. I am choosing framework for

IMHO : scalability & sqlite are not words I would put together that
easily. But I have to admit I havent dont any measurements. I have no
idea how Django can help you to solve your problem (I am pretty new to
Django) but I would suggest that you do some more research on the
exact scalability requirements that you have ...

  Good luck !

MrG


-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

--~--~-~--~~~---~--~~
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: Enterprise applications with Django

2008-04-16 Thread Guillaume Lederrey

On 16/04/2008, Thomas Guettler <[EMAIL PROTECTED]> wrote:
>
>  I guess YouTube is highly concurrent, distributed ...
>
>  I think you can create enterprise applications with django and python.
>
>  What do you think is possible with Java, that you can't do with python?

Having your production team agree to deploy python apps on the
production server is probably the hardest part !

Jokes apart, here is a couple of things I would not know how to do in
Python. Maybe they exist (I'm far from a Python /  Django expert) :

* distributed transaction (2-phase commit)
* a good admin console so that a production team can :
  - tune database connection pools easily
  - deploy to a server farm easily (for availability)
  - other day to day admin tasks ...

The admin console probably exists at some place like Google (or other
big Python fans) but is not readily available commercially (read as :
with commercial support). And that is a no-go for most of the
enterprises I know ...




-- 
Jabber : [EMAIL PROTECTED]
Skype : Guillaume.Lederrey
Projects :
* http://rwanda.ledcom.ch/

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