Django send_mail issue

2010-12-16 Thread Vikesh
Hi,
I have never used sendmail in Ubuntu and I am not too good at
networks. I was trying to implement a mail application in Django where
I send a mail to the newly registered user for confirmation. I used
the following settings in my settings.py file :

EMAIL_HOST='localhost'
#EMAIL_HOST_USER='vikesh'
#EMAIL_HOST_PASSWORD='vikesh'
EMAIL_PORT=1025
DEFAULT_FROM_EMAIL = "nore...@edciitr.com"
SERVER_EMAIL = "ad...@domain.com"
EMAIL_USE_TLS = False

I am sending the mail like this -
send_mail('Subject_Test','Content_Test','khanna.vik...@gmail.com',
['khanna.vik...@gmail.com'])

Using these settings I am able to see the output on the console when I
run the Python debugserver on port 1025 but when I change the port to
25, I am not able to send the mail using the same settings. My port 25
is open (which I confirmed by running sendmail and using netstat -an |
grep "LISTEN"). I am a beginner,  don't know if it is even possible to
send a mail like this. Help will be appreciated.

-- 
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: registering app level signal handlers

2010-12-16 Thread W. Craig Trader
I usually register the signals for a given application at the bottom of that
app's model.py file.

- Craig -

On Thu, Dec 16, 2010 at 19:04, dmitry b  wrote:

> On Dec 16, 3:28 pm, Graham Dumpleton 
> wrote:
> > On Friday, December 17, 2010 10:00:55 AM UTC+11, dmitry b wrote:
> >
> > Are you talking about UNIX process signals?
>
> I'm sorry, I forgot there are two ways to interpret my question.  It
> is about Django signals.
>
> --
> 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: Very strange lost network connection problem

2010-12-16 Thread bax...@gretschpages.com
Sorry for responding to my own post -- trying to add some additional
info.

Because of the way it's behaving, I'm wondering if it's middleware
related. Seems to be at a very low level in the request/response
cycle. So with that in mind, this is my middleware below. Does the
order look OK?
MIDDLEWARE_CLASSES = (
   'django.middleware.cache.UpdateCacheMiddleware',
   'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.doc.XViewMiddleware',
 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'django.middleware.http.ConditionalGetMiddleware',
'django.middleware.csrf.CsrfResponseMiddleware',
'utils.lastseen.LastSeen',
'django.middleware.gzip.GZipMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
)

On Dec 16, 9:40 am, "bax...@gretschpages.com" 
wrote:
> This is a weird one. On a handful of topics on my forum, accessing the
> topic and/or attempting to add a post or do anything else loses the
> network connection. It's only on a handful, and it just started
> recently. I have no idea how Django can even do such a thing, but you
> can see it here:
>
> http://gretschpages.com/forum/electromatics/on-the-2nd-day-of-christm...
>
> On initial load, you'll probably see at least a couple of images error
> out with a lost network connection error or "Failed to load resource",
> depending on what browser you're looking in. Or it may lose all static
> media. Hard to tell what it's going to do from one page load to the
> next.
>
> If you hit reload, it will probably lose ALL static media.
>
> If you were to try to add a post, it would go to a blank "server
> unexpectedly dropped the connection" type of page.
>
> It's just two or three topics. All others are unaffected. Whatever the
> problem, it seems to be centered on just these few topics.
>
> Nginx is handling static media and passing django stuff over to
> Apache.
>
> I don't see anything in the nginx or apache error logs.
>
> I've looked in the database, and nothing appears out of the ordinary
> with these topics, either.
>
> Any suggestions on where to look or how to debug this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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.



applying function in Paginator

2010-12-16 Thread piotr
Hello django community

I'm rendering some objects with paginator. I made a function for these
objects for being displayed as html, so I need the result of this
function in a variable to pass it to the html template. May be good
idea to implement a function to be aplied to displayed objects in the
Paginator? Would be a patch with this be accepted?

Pedro.

-- 
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: registering app level signal handlers

2010-12-16 Thread dmitry b
On Dec 16, 3:28 pm, Graham Dumpleton 
wrote:
> On Friday, December 17, 2010 10:00:55 AM UTC+11, dmitry b wrote:
>
> Are you talking about UNIX process signals?

I'm sorry, I forgot there are two ways to interpret my question.  It
is about Django signals.

-- 
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: registering app level signal handlers

2010-12-16 Thread Steve Holden
On 12/16/2010 6:28 PM, Graham Dumpleton wrote:
> Are you talking about UNIX process signals?
> 
He's almost certainly talking about Django signals.

I've never seen a definite recommendation as to how to do things exactly
once early on in the life of your server process, so I am afraid I
cannot offer any advice.

regards
 Steve
-- 
DjangoCon US 2011 Portland, OR: September 6-8 http://djangocon.us/

-- 
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: registering app level signal handlers

2010-12-16 Thread Graham Dumpleton


On Friday, December 17, 2010 10:00:55 AM UTC+11, dmitry b wrote:
>
> Hi, What is the best place to register a signal handler so that the 
> registration happens when the app is first initialized into django? I have 
> an app that needs to listen to signals generated by another app and fire off 
> celery tasks in response. I've tried placing the registration code into the 
> app's __init__.py, but since I have other reusable code there, doing so 
> created cyclical references when importing modules. Is there another 
> location within the app's code that is guaranteed to be picked up when 
> django is being initialized (like an django app level init rather than 
> python level module init)? Thanks Dmitry


Are you talking about UNIX process signals?

If you are then you will have a problem with portability of your 
application. This is because UNIX process signals are usually the domain of 
the hosting environment in which you are deploying your Python web 
application. For that reason, under Apache/mod_wsgi you will be blocked from 
registering your own UNIX signal handlers so as to avoid problems with your 
signal handler registrations interfering with the hosting environments own 
use of signals to manage its processes. You can in the case of 
Apache/mod_wsgi override this so you can do what you want, but you do risk 
causing problems or preventing certain features of the web hosting 
environment from working properly.

I would strongly suggest you find an alternate way of doing things if you 
are considering using UNIX process signals.

Graham

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



registering app level signal handlers

2010-12-16 Thread dmitry b
Hi,

What is the best place to register a signal handler so that the
registration happens when the app is first initialized into django?  I
have an app that needs to listen to signals generated by another app
and fire off celery tasks in response.  I've tried placing the
registration code into the app's __init__.py, but since I have other
reusable code there, doing so created cyclical references when
importing modules.  Is there another location within the app's code
that is guaranteed to be picked up when django is being initialized
(like an django app level init rather than python level module init)?


Thanks
Dmitry

-- 
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: virtualenv and deployment

2010-12-16 Thread Graham Dumpleton


On Friday, December 17, 2010 1:21:26 AM UTC+11, Craig Trader wrote:
>
> Alex ...
>
> This is the point where my experience ends -- I'm not operating in a 
> hosting environment.  I can tell you that mod_python has to be compiled for 
> a specific version of Apache AND Python (one of the reasons that mod_wsgi is 
> better is that it breaks the Python-version dependency).


No it doesn't. As is the case with mod_python, mod_wsgi is also compile time 
bound to specific Python major/minor version.

Graham
 

> If you need a different Python (2.6 in this case), you'll need a differ 
> mod_python.  I won't know how it gets installed and configured in your 
> hosting environment.  Sorry.
>
> - Craig -
>
> On Thu, Dec 16, 2010 at 03:51, Álex González  wrote:
>
>> Thanks for your reply Craig,
>>
>> to use mod_python in my hosting I'm using this .htaccess file:
>>
>> SetHandler python-program
>> PythonOption django.root /
>> PythonHandler django.core.handlers.modpython
>> PythonPath "['/var/www/vhosts/myhosting.com/httpdocs'] + sys.path"
>> SetEnv DJANGO_SETTINGS_MODULE settings
>> PythonDebug On
>>
>> The problem is that when I need to install something I must talk with the 
>> shared hosting admin, and this isn't working because the python is 2.3. The 
>> administrator said me that I must activate python26-mod_python.so but I 
>> can't use the LoadModule directive in .htaccess so I don't know what he want 
>> and I'm waiting for a reply yet...
>>
>> You are using your self handler in python code to load the webpage? Can I 
>> force here to use the python2.6 interpreter instead the 2.3?
>>
>> Thanks for you help!
>>  
>> On Thu, Dec 16, 2010 at 00:57, W. Craig Trader wrote:
>>
>>> Alex ...
>>>
>>> You're not going to be able to trick your host into loading mod_wsgi from 
>>> an .htaccess file -- Apache doesn't allow the load directives in .htaccess 
>>> files.
>>>
>>> While mod_python is not supported, and it has a large number of open 
>>> issues, there aren't any specific security holes you really need to worry 
>>> about; I'm using mod_python on a project at work because mod_wsgi isn't 
>>> supported in our deployment environment.  I wouldn't recommend mod_python 
>>> as 
>>> the direction for all future work, but it will get the job done until you 
>>> can get mod_wsgi deployed with your host (or move to another host).
>>>
>>> See my earlier post from today (look for Re: running projects on the 
>>> back of a base URL and having issues with the homepage) for more details 
>>> about making mod_wsgi work with VirtualEnv.  The apache script for 
>>> mod_python is similar to the one I posted earlier ; the only differences 
>>> involve making certain that you chdir to your project directory, and that 
>>> you import the Django mod_python handler.
>>>
>>> The mod_python configuration is significantly different from the mod_wsgi 
>>> configuration, and look like this:
>>>
>>> 
>>>   SetHandler python-program
>>>   PythonPath "[ '/data/web/foo/apache', ] + sys.path"
>>>   PythonHandler django_mp
>>>   PythonInterpreter foo
>>> 
>>>
>>>   Alias /static/ /data/web/foo/site/foo/static/
>>>   
>>> SetHandler None
>>>   
>>>
>>> In this case, mp_python represents /data/web/foo/apache/mp_python.py, 
>>> which is my script to deal with configuring the VirtualEnv environment and 
>>> then starting the Django mod_python handler.  It's basically an amalgam of 
>>> the VirtualEnv activate_this.py script, and the mod_python startup script 
>>> from the Django documentation.
>>>  
>>> - Craig -
>>>
>>> On Wed, Dec 15, 2010 at 16:56, Álex González  wrote:
>>>
 Hi guys!

 Thanks for your replies!

 My hosting is a shared hosting and I think that I can only uses 
 mod_python at the moment. I can load mod_wsgi from htaccess (I test it) 
 but 
 I can edit my virtualhosts or something similar... any trick to get 
 mod_wsgi 
 up?

 About the virtualenv as Piotr said, some modules must be compiled, so my 
 solution was create a requeriments files as he said, but include in my 
 code 
 django-registration and django-piston because the versions installed with 
 pip doesn't work for me (it said me that it's the correct version, but I 
 can 
 get a actual version at bitbucket).

 Now my question is, mod_python is deprecated but it's dangerous to use 
 it for a months (until I get money to migrate the code to a non-shared 
 hosting?). And the old question: can I trick the hosting to use mod_wsgi 
 if 
 I can load it from htaccess?

 Thanks!


 On Wed, Dec 15, 2010 at 19:49, Ovnicraft  wrote:

>
>
> On Wed, Dec 15, 2010 at 11:48 AM, Álex González wrote:
>
>> Hi!
>>
>> I'm using virtualenv with --no-site-packages and now I like to do a 
>> deployment of my app... I'm using a sharing hosting, 

Re: Django model question from a newbee

2010-12-16 Thread Reino
Thanks Tom,

I was confusing an instance of a ModelForm with an instance of the
Model it represents. You suggestion about the mod_time is good idea.
However, I still can't get the password stored as an md5 hash.

Matteius, it is not an option to use Djangos User object, and user
database.

Matteius. since the fields that are supposed to be excuded with the
exclude statemant, are still visible, I figure I am doing things
wrong.

The password is still stored in clear text, and shown in clear text in
the form.

I modified the model slightly, and put a few comment is in it.

My new model:

from django.db import models
from django.contrib import admin
from django.forms import ModelForm, PasswordInput, CharField

import datetime
try:
from hashlib import md5
except:
from md5 import new as md5

class CasDomain(models.Model):
name = models.CharField(max_length=64, primary_key=True)
class Meta:
db_table = u'cas_domain'

def __unicode__(self):
return self.name

class CasUser(models.Model):
ACCESS_LEVEL = (
(0, 'Administrator'),
(1, 'Manager'),
(2, 'Domain Manager'),
(3, 'Email'),
(255, 'None'),
)

id = models.AutoField(primary_key=True)
username = models.CharField(max_length=64)
password = models.CharField(max_length=32)
email = models.EmailField()
first_name = models.CharField(max_length=64, blank=True)
last_name = models.CharField(max_length=64, blank=True)
froxlor_mail_id = models.IntegerField(null=True, blank=True)
access_level = models.IntegerField(choices=ACCESS_LEVEL)
domain = models.ForeignKey(CasDomain,db_column='domain')
mod_time = models.DateTimeField(auto_now=True)
pub_time = models.DateTimeField()
class Meta:
db_table = u'cas_user'

def __unicode__(self):
return self.username

def __unicode__(self):
return self.password

def __unicode__(self):
return self.first_name

def __unicode__(self):
return self.last_name

class CasUserForm(ModelForm):
#   password = CharField(widget=PasswordInput())
class Meta:
model = CasUser
# Neiter the exclude line or the fields line below make any field to
be excluded
# in the admin form
exclude = ('froxlor_mail_id', 'mod_time','pub_time')
#   fields = ('username', 'password', 'first_name', 'last_name',
'email', 'access_level')
widgets = {
'password': PasswordInput()
}

def save(self, commit=False):
instance = super(CasUserForm, self).save(commit=False)
if not instance.id:
instance.pub_time = datetime.datetime.now
instance.password = md5(instance.password).hexdigest()
if commit:
instance.save()
return instance

class CasUserAdmin(admin.ModelAdmin):
# If i uncomment the line below, only the desired fields are present
in the form
# However then the pub_time is not stored and cause a error, since
pub_time is mandatory
#   fields = ('username', 'password', 'first_name', 'last_name',
'email', 'access_level')
class Meta:
form = CasUserForm

# Make sure the classes are available in the admin interface
admin.site.register(CasDomain)
admin.site.register(CasUser, CasUserAdmin)


On 16 Dec, 19:07, Matteius  wrote:
> Ok I did not mean to send that last post, it was an accident.
>
> 1.) Add exclude tuple here:
> class CasUserForm(ModelForm):
>         class Meta:
>               exclude = ('field1', 'field2')
>
> Now go ahead with part 2)
>
> 2.) Hide passwords in the form either by manually calling the fields
> and specifying a field with the correct name like:
> 
> or in the form you can do this:
> attrs_dict = { 'class': 'required' }
> class RegistrationForm(forms.Form):
>     password1 =
> forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict,
> render_value=False),
>                                 label=_("Password:"))
>
> 3.) Encrypting the password before storing it to the database is easy
> by calling the right Django method:
> User.objects.create_user(username, email, password)
>
> Hope this helps,
> Matteius
>
> On Dec 16, 6:47 am, Tom Evans  wrote:
>
> > On Thu, Dec 16, 2010 at 12:39 PM, Reino  wrote:
> > > I am new to Django, and I am building a simple application where I am
> > > going to manage a legacy user database from Djangos admin interface.
> > > Below is how my model looks like.
>
> > > My goal is to hide some of the fields in the form where I edit/add
> > > users. However, currently I can see all the fields except from the Id
> > > field. Furhermore, the password field is stored in clear 

Re: Confused about thread locals... again.

2010-12-16 Thread Doug Ballance
@ringemip
Thanks for the reply.  I've been considering something like that, but
given the number of views and tags involved, it would be a very long
process.  Especially since I used a new context instance in most of my
custom tags that render another template, rather the pushing,
rendering, poping the original like I should have.

As much as I don't want to use thread_locals, it seems like the best
(interim) approach.  The long term plan will definitely move to
something like you describe.  It will also give a nice consistent use
pattern when a request object isn't available (ie async mail
templates).

I'd still love to know why the import/locals object is so touchy.

-- 
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 model question from a newbee

2010-12-16 Thread Matteius
Ok I did not mean to send that last post, it was an accident.

1.) Add exclude tuple here:
class CasUserForm(ModelForm):
class Meta:
  exclude = ('field1', 'field2')

Now go ahead with part 2)

2.) Hide passwords in the form either by manually calling the fields
and specifying a field with the correct name like:

or in the form you can do this:
attrs_dict = { 'class': 'required' }
class RegistrationForm(forms.Form):
password1 =
forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict,
render_value=False),
label=_("Password:"))

3.) Encrypting the password before storing it to the database is easy
by calling the right Django method:
User.objects.create_user(username, email, password)


Hope this helps,
Matteius



On Dec 16, 6:47 am, Tom Evans  wrote:
> On Thu, Dec 16, 2010 at 12:39 PM, Reino  wrote:
> > I am new to Django, and I am building a simple application where I am
> > going to manage a legacy user database from Djangos admin interface.
> > Below is how my model looks like.
>
> > My goal is to hide some of the fields in the form where I edit/add
> > users. However, currently I can see all the fields except from the Id
> > field. Furhermore, the password field is stored in clear text, but is
> > supposed to be stored as an md5 hash, and the password is visible in
> > clear text in the form. Any hints what I am doing wrong, and how to
> > improve things?
>
> > from django.db import models
> > from django.contrib import admin
> > from django.forms import ModelForm, PasswordInput
>
> > import datetime
> > try:
> >        from hashlib import md5
> > except:
> >        from md5 import new as md5
>
> > class CasDomain(models.Model):
> >        name = models.CharField(max_length=64, primary_key=True)
> >        class Meta:
> >                db_table = u'cas_domain'
>
> >        def __unicode__(self):
> >                return self.name
>
> > class CasUser(models.Model):
> >        ACCESS_LEVEL = (
> >        (0, 'Administrator'),
> >        (1, 'Manager'),
> >        (2, 'Domain Manager'),
> >        (3, 'Email'),
> >        (255, 'None'),
> >        )
>
> >        id = models.AutoField(primary_key=True)
> >        username = models.CharField(max_length=64)
> >        password = models.CharField(max_length=32)
> >        email = models.EmailField()
> >        first_name = models.CharField(max_length=64, blank=True)
> >        last_name = models.CharField(max_length=64, blank=True)
> >        froxlor_mail_id = models.IntegerField(null=True, blank=True)
> >        access_level = models.IntegerField(choices=ACCESS_LEVEL)
> >        domain = models.ForeignKey(CasDomain,db_column='domain')
> >        mod_date = models.DateField()
> >        pub_date = models.DateField()
> >        class Meta:
> >                db_table = u'cas_user'
>
> >        def __unicode__(self):
> >                return self.username
>
> >        def __unicode__(self):
> >                return self.password
>
> >        def __unicode__(self):
> >                return self.first_name
>
> >        def __unicode__(self):
> >                return self.last_name
>
> > class CasUserForm(ModelForm):
> >        class Meta:
> >                model = CasUser
> >                fields = ('username', 'first_name', 'first_name', 'email',
> > 'access_level')
> >                widgets = {
> >                        'password': PasswordInput(),
> >                }
>
> >        def save(self):
> >                if not self.id:
> >                        self.pub_date = datetime.date.today()
> >                        self.password = md5(self.password).hexdigest()
> >                self.mod_date = datetime.datetime.today()
> >                super(CasUserForm, self).save()
>
> > class CasUserAdmin(admin.ModelAdmin):
> >        class Meta:
> >                form = CasUserForm
>
> > # Make sure the classes are available in the admin interface
> > admin.site.register(CasDomain)
> > admin.site.register(CasUser, CasUserAdmin)
>
> I'd recommend you use contrib.auth, rather than roll your own.
>
> I would have thought the first issue is that you are confusing an
> instance of a ModelForm with an instance of the Model it represents.
> Your save() method should look more like this:
>
> def save(self, commit=False):
>     instance = super(CasUserForm, self).save(commit=False)
>     if not instance.id:
>         instance.pub_date = datetime.date.today()
>         instance.password = md5(instance.password).hexdigest()
>     instance.mod_date = datetime.datetime.today()
>     if commit:
>         instance.save()
>     return instance
>
> Finally, if you want a modified field, it should simply be defined as
> models.DateTimeField(auto_now=True), no need to handle it manually.
>
> HTH
>
> Tom

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

Re: Django model question from a newbee

2010-12-16 Thread Matteius
OK So these are UI issues and how you are saving Users to the
database.  The database field itself is a CharField.

1.) To hide form elements add a tupple inside the FormField under
class meta like so:
class CasUserForm(ModelForm):

exclude = [field1, field2]

2.)

On Dec 16, 6:39 am, Reino  wrote:
> I am new to Django, and I am building a simple application where I am
> going to manage a legacy user database from Djangos admin interface.
> Below is how my model looks like.
>
> My goal is to hide some of the fields in the form where I edit/add
> users. However, currently I can see all the fields except from the Id
> field. Furhermore, the password field is stored in clear text, but is
> supposed to be stored as an md5 hash, and the password is visible in
> clear text in the form. Any hints what I am doing wrong, and how to
> improve things?
>
> from django.db import models
> from django.contrib import admin
> from django.forms import ModelForm, PasswordInput
>
> import datetime
> try:
>         from hashlib import md5
> except:
>         from md5 import new as md5
>
> class CasDomain(models.Model):
>         name = models.CharField(max_length=64, primary_key=True)
>         class Meta:
>                 db_table = u'cas_domain'
>
>         def __unicode__(self):
>                 return self.name
>
> class CasUser(models.Model):
>         ACCESS_LEVEL = (
>         (0, 'Administrator'),
>         (1, 'Manager'),
>         (2, 'Domain Manager'),
>         (3, 'Email'),
>         (255, 'None'),
>         )
>
>         id = models.AutoField(primary_key=True)
>         username = models.CharField(max_length=64)
>         password = models.CharField(max_length=32)
>         email = models.EmailField()
>         first_name = models.CharField(max_length=64, blank=True)
>         last_name = models.CharField(max_length=64, blank=True)
>         froxlor_mail_id = models.IntegerField(null=True, blank=True)
>         access_level = models.IntegerField(choices=ACCESS_LEVEL)
>         domain = models.ForeignKey(CasDomain,db_column='domain')
>         mod_date = models.DateField()
>         pub_date = models.DateField()
>         class Meta:
>                 db_table = u'cas_user'
>
>         def __unicode__(self):
>                 return self.username
>
>         def __unicode__(self):
>                 return self.password
>
>         def __unicode__(self):
>                 return self.first_name
>
>         def __unicode__(self):
>                 return self.last_name
>
> class CasUserForm(ModelForm):
>         class Meta:
>                 model = CasUser
>                 fields = ('username', 'first_name', 'first_name', 'email',
> 'access_level')
>                 widgets = {
>                         'password': PasswordInput(),
>                 }
>
>         def save(self):
>                 if not self.id:
>                         self.pub_date = datetime.date.today()
>                         self.password = md5(self.password).hexdigest()
>                 self.mod_date = datetime.datetime.today()
>                 super(CasUserForm, self).save()
>
> class CasUserAdmin(admin.ModelAdmin):
>         class Meta:
>                 form = CasUserForm
>
> # Make sure the classes are available in the admin interface
> admin.site.register(CasDomain)
> admin.site.register(CasUser, CasUserAdmin)

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



Very strange lost network connection problem

2010-12-16 Thread bax...@gretschpages.com
This is a weird one. On a handful of topics on my forum, accessing the
topic and/or attempting to add a post or do anything else loses the
network connection. It's only on a handful, and it just started
recently. I have no idea how Django can even do such a thing, but you
can see it here:

http://gretschpages.com/forum/electromatics/on-the-2nd-day-of-christmas-my-true-love-gave-to-me/36273/page1/

On initial load, you'll probably see at least a couple of images error
out with a lost network connection error or "Failed to load resource",
depending on what browser you're looking in. Or it may lose all static
media. Hard to tell what it's going to do from one page load to the
next.

If you hit reload, it will probably lose ALL static media.

If you were to try to add a post, it would go to a blank "server
unexpectedly dropped the connection" type of page.

It's just two or three topics. All others are unaffected. Whatever the
problem, it seems to be centered on just these few topics.

Nginx is handling static media and passing django stuff over to
Apache.

I don't see anything in the nginx or apache error logs.

I've looked in the database, and nothing appears out of the ordinary
with these topics, either.

Any suggestions on where to look or how to debug this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: getting back max date from a joined table for list_display

2010-12-16 Thread Michael Dippery
On Dec 16, 2010, at 3:53 AM, dan kirkland wrote:

> Hi, I'm new to python and django and need to join two tables together
> - the first table holds details about a customer and I think is
> probably passed as the obj parameter of the following function. The
> second is a CallBackRequest table that holds details of when I should
> next call a customer. The callback has a foreign key (customer_id) to
> the customer table. I want the customers and their next callback
> (based on max date) to be displayed in a list - see the list_display
> line. Note, there's a one-to-many relationship between customer and
> callbackrequest records.
> 
> The details in the customer table are retrieved and displayed
> successfully in the list but the date of the next call back is blank.
> I'm almost certain it's to do with the filter but not sure how to join
> the foreign key of the callbackrequest with the primary key of the obj
> record. Almost certainly the pk reference is wrong as it's the foreign
> key I need anyway. The foreign key within callbackrequests is called
> customer_id.

What about this?

def next_call_back_due(self, obj):
call_records = 
CallbackRequest.objects.filter(customer_id=obj.id).order_by('-call_back_date')
if call_records.count() > 0:
return call_records[0].call_back_date
else:
return None# Or whatever default you want to return




Michael Dippery
mdipp...@gmail.com | www.monkey-robot.com



smime.p7s
Description: S/MIME cryptographic signature


Re: use table not in the model

2010-12-16 Thread Tonton
thanks for yours ansewers i wiil read that

i try this

def getExtentFromaMap(amap):
idx =[]
e=[]
listcouche = get_list_or_404(Layer, carte_id=amap.id)
for l in range(len(listcouche)):
x=listcouche[l].dataset_id
idx.append (x)
for ds in range(len(idx)):
y = idx[ds].sourcetable
cursor=connection.cursor()
cursor.execute("""SELECT st_find_extent(y,'geometry')from courly""")
p=row[0]
e.append (p)
return e

sure it is not work but i am interest to use function and it seems possible
but how to use varaible ine the request ?
here it is my table name store in y

:)

On Thu, Dec 16, 2010 at 4:02 PM, W. Craig Trader wrote:

> Tonton ...
>
> See  for details on
> how to use so-called 'raw' SQL (ie: not managed with models) within Django.
>
> - Craig -
>
> On Thu, Dec 16, 2010 at 09:16, Tonton  wrote:
>
>> Hello
>> i like to use some database table that are not in my models.py
>> in fact some of table will be add and remove by script
>>
>> is it possible to use some sql queries with it ? on not at all ?
>>
>> regards
>>
>> tonton
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: use table not in the model

2010-12-16 Thread W. Craig Trader
Tonton ...

See  for details on how
to use so-called 'raw' SQL (ie: not managed with models) within Django.

- Craig -

On Thu, Dec 16, 2010 at 09:16, Tonton  wrote:

> Hello
> i like to use some database table that are not in my models.py
> in fact some of table will be add and remove by script
>
> is it possible to use some sql queries with it ? on not at all ?
>
> regards
>
> tonton
>
> --
> 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: use table not in the model

2010-12-16 Thread bruno desthuilliers
On 16 déc, 15:16, Tonton  wrote:
> Hello
> i like to use some database table that are not in my models.py
> in fact some of table will be add and remove by script
>
> is it possible to use some sql queries with it ?

Of course it is.

>>> from django.db import connection
>>> cursor = connection.cursor()
>>> cursor.execute("create table foo(id integer auto_increment primary key, 
>>> title varchar(30))")
0L
>>> for title in ("foo", "bar", "baaz"):
... cursor.execute("insert into foo(title) values(%s)", (title,))
...
1L
1L
1L
>>> cursor.execute("select * from foo")
3L
>>> for row in cursor:
... print row
...
(1L, u'foo')
(2L, u'bar')
(3L, u'baaz')
>>> cursor.execute("drop table foo")
0L
>>>

-- 
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: use table not in the model

2010-12-16 Thread Mark (Nosrednakram)
On Dec 16, 7:16 am, Tonton  wrote:
> Hello
> i like to use some database table that are not in my models.py
> in fact some of table will be add and remove by script
>
> is it possible to use some sql queries with it ? on not at all ?
>
> regards
>
> tonton

Hello Tonton,

Yes, you have full access to SQL if you need it regardless of whether
django know about the tables or not.  You can also create a model for
your table as long as the schema is the same, look at inspectdb,
django doesn't care how the table was created.  I have used views to
aggregate date that I only need read only queries and made a model for
the view then set all columns to have editable = False to keep admin
etc from trying to update.

Mark

-- 
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: simple.direct_to_template and query objects

2010-12-16 Thread MarcoS
Yes, you're correct.
Thank you so much

On 16 Dic, 13:40, Marcos Moyano  wrote:
> I think you are looking for object_detail, not 
> direct_to_template.http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-...
>
> Rgds,
> Marcos
>
>
>
> On Thu, Dec 16, 2010 at 9:32 AM, MarcoS  wrote:
> > Hi people, I want to define a generic view using
> > simple.direct_to_template, something like this:
>
> > (r'^detail_event/(?P\d+)/$', simple.direct_to_template,
> > {
> >        'extra_context': {'event': Event.objects.get(id=object_id),}
> >    }),
>
> > Of course this doesn't work, django tell me that 'object_id' is not
> > defined.
> > How can I access at the object_id value?
>
> > --
> > 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.
>
> --
> Some people, when confronted with a problem, think “I know, I'll use regular
> expressions.” Now they have two problems.
>
> Jamie Zawinski, in comp.emacs.xemacs

-- 
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: virtualenv and deployment

2010-12-16 Thread W. Craig Trader
Alex ...

This is the point where my experience ends -- I'm not operating in a hosting
environment.  I can tell you that mod_python has to be compiled for a
specific version of Apache AND Python (one of the reasons that mod_wsgi is
better is that it breaks the Python-version dependency).  If you need a
different Python (2.6 in this case), you'll need a differ mod_python.  I
won't know how it gets installed and configured in your hosting
environment.  Sorry.

- Craig -

On Thu, Dec 16, 2010 at 03:51, Álex González  wrote:

> Thanks for your reply Craig,
>
> to use mod_python in my hosting I'm using this .htaccess file:
>
> SetHandler python-program
> PythonOption django.root /
> PythonHandler django.core.handlers.modpython
> PythonPath "['/var/www/vhosts/myhosting.com/httpdocs'] + sys.path"
> SetEnv DJANGO_SETTINGS_MODULE settings
> PythonDebug On
>
> The problem is that when I need to install something I must talk with the
> shared hosting admin, and this isn't working because the python is 2.3. The
> administrator said me that I must activate python26-mod_python.so but I
> can't use the LoadModule directive in .htaccess so I don't know what he want
> and I'm waiting for a reply yet...
>
> You are using your self handler in python code to load the webpage? Can I
> force here to use the python2.6 interpreter instead the 2.3?
>
> Thanks for you help!
>
> On Thu, Dec 16, 2010 at 00:57, W. Craig Trader wrote:
>
>> Alex ...
>>
>> You're not going to be able to trick your host into loading mod_wsgi from
>> an .htaccess file -- Apache doesn't allow the load directives in .htaccess
>> files.
>>
>> While mod_python is not supported, and it has a large number of open
>> issues, there aren't any specific security holes you really need to worry
>> about; I'm using mod_python on a project at work because mod_wsgi isn't
>> supported in our deployment environment.  I wouldn't recommend mod_python as
>> the direction for all future work, but it will get the job done until you
>> can get mod_wsgi deployed with your host (or move to another host).
>>
>> See my earlier post from today (look for Re: running projects on the back
>> of a base URL and having issues with the homepage) for more details about
>> making mod_wsgi work with VirtualEnv.  The apache script for mod_python is
>> similar to the one I posted earlier ; the only differences involve making
>> certain that you chdir to your project directory, and that you import the
>> Django mod_python handler.
>>
>> The mod_python configuration is significantly different from the mod_wsgi
>> configuration, and look like this:
>>
>> 
>>   SetHandler python-program
>>   PythonPath "[ '/data/web/foo/apache', ] + sys.path"
>>   PythonHandler django_mp
>>   PythonInterpreter foo
>> 
>>
>>   Alias /static/ /data/web/foo/site/foo/static/
>>   
>> SetHandler None
>>   
>>
>> In this case, mp_python represents /data/web/foo/apache/mp_python.py,
>> which is my script to deal with configuring the VirtualEnv environment and
>> then starting the Django mod_python handler.  It's basically an amalgam of
>> the VirtualEnv activate_this.py script, and the mod_python startup script
>> from the Django documentation.
>>
>> - Craig -
>>
>> On Wed, Dec 15, 2010 at 16:56, Álex González wrote:
>>
>>> Hi guys!
>>>
>>> Thanks for your replies!
>>>
>>> My hosting is a shared hosting and I think that I can only uses
>>> mod_python at the moment. I can load mod_wsgi from htaccess (I test it) but
>>> I can edit my virtualhosts or something similar... any trick to get mod_wsgi
>>> up?
>>>
>>> About the virtualenv as Piotr said, some modules must be compiled, so my
>>> solution was create a requeriments files as he said, but include in my code
>>> django-registration and django-piston because the versions installed with
>>> pip doesn't work for me (it said me that it's the correct version, but I can
>>> get a actual version at bitbucket).
>>>
>>> Now my question is, mod_python is deprecated but it's dangerous to use it
>>> for a months (until I get money to migrate the code to a non-shared
>>> hosting?). And the old question: can I trick the hosting to use mod_wsgi if
>>> I can load it from htaccess?
>>>
>>> Thanks!
>>>
>>>
>>> On Wed, Dec 15, 2010 at 19:49, Ovnicraft  wrote:
>>>


 On Wed, Dec 15, 2010 at 11:48 AM, Álex González 
 wrote:

> Hi!
>
> I'm using virtualenv with --no-site-packages and now I like to do a
> deployment of my app... I'm using a sharing hosting, can I uypload all my
> enviroment dir (with the packages installed with pip) to the server and 
> use
> them?
>
> What's the better way to the deployment? mod_python, mod_wsgi, perhaps
> fast-cgi?
>


 Remember mod_python is deprecated.

 Regards,


> Thanks!
>
> --
> @agonzalezro 
> 

use table not in the model

2010-12-16 Thread Tonton
Hello
i like to use some database table that are not in my models.py
in fact some of table will be add and remove by script

is it possible to use some sql queries with it ? on not at all ?

regards

tonton

-- 
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: Limit number of concurrent non-admin/non-superuser users

2010-12-16 Thread Stodge
I added an ajax call to log the user out when they close the browser.
It works in Firefox and Chrome but is this an acceptable/safe
practice?

I experimented with

SESSION_SAVE_EVERY_REQUEST=True
SESSION_COOKIE_AGE = 300

which works but I can't guarantee that requests are sent frequently
enough to ensure a user remains logged in. Typically with my site,
requests are sent at least every minute to refresh displayed data.



On Dec 10, 10:45 am, Daniel Roseman  wrote:
> On Dec 10, 3:07 pm, Stodge  wrote:
>
>
>
>
>
>
>
>
>
> > I'm trying to limit the number of concurrent users attached to my
> > Django website. For example I need to implement a floating license
> > system. I've seen a few snippets but so far I think they all implement
> > a middleware. I'm trying to avoid using a middleware because I don't
> > want the overhead on every request and because I want to try to limit
> > this when the user tries to login. I only want to restrict the number
> > of non-admin and non-superuser users.
>
> > I thought I could check all current sessions with expiry times in the
> > future but this makes the assumption that a session's expiry time will
> > be set to the current time when the user logs out of when they close
> > their browser (SESSION_EXPIRE_AT_BROWSER_CLOSE = True). However, my
> > understanding of the session system was incorrect and this isn't
> > possible.
>
> > Any ideas how this can be implemented?
> > Thanks
>
> The problem is the stateless nature of HTTP. Between requests, there's
> nothing that identifies to the server that the browser is still
> 'connected', so you can't identify how many people are passively
> browsing a page, and how many have turned off their computer or even
> just gone to another site.
>
> You're not going to be able to do it without some sort of overhead. I
> would suggest something like a bit of Javascript, which pings the
> server every 20 seconds or so while the user is on a logged-in page,
> to show that it is still active. But that certainly has non-trivial
> overhead.
> --
> 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: Django model question from a newbee

2010-12-16 Thread Tom Evans
On Thu, Dec 16, 2010 at 12:39 PM, Reino  wrote:
> I am new to Django, and I am building a simple application where I am
> going to manage a legacy user database from Djangos admin interface.
> Below is how my model looks like.
>
> My goal is to hide some of the fields in the form where I edit/add
> users. However, currently I can see all the fields except from the Id
> field. Furhermore, the password field is stored in clear text, but is
> supposed to be stored as an md5 hash, and the password is visible in
> clear text in the form. Any hints what I am doing wrong, and how to
> improve things?
>
> from django.db import models
> from django.contrib import admin
> from django.forms import ModelForm, PasswordInput
>
> import datetime
> try:
>        from hashlib import md5
> except:
>        from md5 import new as md5
>
> class CasDomain(models.Model):
>        name = models.CharField(max_length=64, primary_key=True)
>        class Meta:
>                db_table = u'cas_domain'
>
>        def __unicode__(self):
>                return self.name
>
> class CasUser(models.Model):
>        ACCESS_LEVEL = (
>        (0, 'Administrator'),
>        (1, 'Manager'),
>        (2, 'Domain Manager'),
>        (3, 'Email'),
>        (255, 'None'),
>        )
>
>        id = models.AutoField(primary_key=True)
>        username = models.CharField(max_length=64)
>        password = models.CharField(max_length=32)
>        email = models.EmailField()
>        first_name = models.CharField(max_length=64, blank=True)
>        last_name = models.CharField(max_length=64, blank=True)
>        froxlor_mail_id = models.IntegerField(null=True, blank=True)
>        access_level = models.IntegerField(choices=ACCESS_LEVEL)
>        domain = models.ForeignKey(CasDomain,db_column='domain')
>        mod_date = models.DateField()
>        pub_date = models.DateField()
>        class Meta:
>                db_table = u'cas_user'
>
>        def __unicode__(self):
>                return self.username
>
>        def __unicode__(self):
>                return self.password
>
>        def __unicode__(self):
>                return self.first_name
>
>        def __unicode__(self):
>                return self.last_name
>
> class CasUserForm(ModelForm):
>        class Meta:
>                model = CasUser
>                fields = ('username', 'first_name', 'first_name', 'email',
> 'access_level')
>                widgets = {
>                        'password': PasswordInput(),
>                }
>
>        def save(self):
>                if not self.id:
>                        self.pub_date = datetime.date.today()
>                        self.password = md5(self.password).hexdigest()
>                self.mod_date = datetime.datetime.today()
>                super(CasUserForm, self).save()
>
> class CasUserAdmin(admin.ModelAdmin):
>        class Meta:
>                form = CasUserForm
>
> # Make sure the classes are available in the admin interface
> admin.site.register(CasDomain)
> admin.site.register(CasUser, CasUserAdmin)
>

I'd recommend you use contrib.auth, rather than roll your own.

I would have thought the first issue is that you are confusing an
instance of a ModelForm with an instance of the Model it represents.
Your save() method should look more like this:


def save(self, commit=False):
instance = super(CasUserForm, self).save(commit=False)
if not instance.id:
instance.pub_date = datetime.date.today()
instance.password = md5(instance.password).hexdigest()
instance.mod_date = datetime.datetime.today()
if commit:
instance.save()
return instance

Finally, if you want a modified field, it should simply be defined as
models.DateTimeField(auto_now=True), no need to handle it manually.

HTH

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: simple.direct_to_template and query objects

2010-12-16 Thread Marcos Moyano
I think you are looking for object_detail, not direct_to_template.
http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-list-detail-object-detail

Rgds,
Marcos

On Thu, Dec 16, 2010 at 9:32 AM, MarcoS  wrote:

> Hi people, I want to define a generic view using
> simple.direct_to_template, something like this:
>
> (r'^detail_event/(?P\d+)/$', simple.direct_to_template,
> {
>'extra_context': {'event': Event.objects.get(id=object_id),}
>}),
>
> Of course this doesn't work, django tell me that 'object_id' is not
> defined.
> How can I access at the object_id value?
>
> --
> 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.
>
>


-- 
Some people, when confronted with a problem, think “I know, I'll use regular
expressions.” Now they have two problems.

Jamie Zawinski, in comp.emacs.xemacs

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



getting back max date from a joined table for list_display

2010-12-16 Thread dan kirkland
Hi, I'm new to python and django and need to join two tables together
- the first table holds details about a customer and I think is
probably passed as the obj parameter of the following function. The
second is a CallBackRequest table that holds details of when I should
next call a customer. The callback has a foreign key (customer_id) to
the customer table. I want the customers and their next callback
(based on max date) to be displayed in a list - see the list_display
line. Note, there's a one-to-many relationship between customer and
callbackrequest records.

The details in the customer table are retrieved and displayed
successfully in the list but the date of the next call back is blank.
I'm almost certain it's to do with the filter but not sure how to join
the foreign key of the callbackrequest with the primary key of the obj
record. Almost certainly the pk reference is wrong as it's the foreign
key I need anyway. The foreign key within callbackrequests is called
customer_id.

The (wrong) code I currently have is as follows:

def next_call_back_due(self, obj):

   max_call_record = CallBackRequest.objects.filter(customer_id =
obj.id).filter(call_back_date=CallBackRequest.objects.filter(customer_id=obj.id).aggregate(Max('call_back_date'))
['call_back_date__max'])

   callback_date = max_call_record.call_back_date

   return callback_date

list_display = ('firstname', 'surname', 'telephone_number',
'next_call_back_due')

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



Django model question from a newbee

2010-12-16 Thread Reino
I am new to Django, and I am building a simple application where I am
going to manage a legacy user database from Djangos admin interface.
Below is how my model looks like.

My goal is to hide some of the fields in the form where I edit/add
users. However, currently I can see all the fields except from the Id
field. Furhermore, the password field is stored in clear text, but is
supposed to be stored as an md5 hash, and the password is visible in
clear text in the form. Any hints what I am doing wrong, and how to
improve things?

from django.db import models
from django.contrib import admin
from django.forms import ModelForm, PasswordInput

import datetime
try:
from hashlib import md5
except:
from md5 import new as md5

class CasDomain(models.Model):
name = models.CharField(max_length=64, primary_key=True)
class Meta:
db_table = u'cas_domain'

def __unicode__(self):
return self.name

class CasUser(models.Model):
ACCESS_LEVEL = (
(0, 'Administrator'),
(1, 'Manager'),
(2, 'Domain Manager'),
(3, 'Email'),
(255, 'None'),
)

id = models.AutoField(primary_key=True)
username = models.CharField(max_length=64)
password = models.CharField(max_length=32)
email = models.EmailField()
first_name = models.CharField(max_length=64, blank=True)
last_name = models.CharField(max_length=64, blank=True)
froxlor_mail_id = models.IntegerField(null=True, blank=True)
access_level = models.IntegerField(choices=ACCESS_LEVEL)
domain = models.ForeignKey(CasDomain,db_column='domain')
mod_date = models.DateField()
pub_date = models.DateField()
class Meta:
db_table = u'cas_user'

def __unicode__(self):
return self.username

def __unicode__(self):
return self.password

def __unicode__(self):
return self.first_name

def __unicode__(self):
return self.last_name

class CasUserForm(ModelForm):
class Meta:
model = CasUser
fields = ('username', 'first_name', 'first_name', 'email',
'access_level')
widgets = {
'password': PasswordInput(),
}

def save(self):
if not self.id:
self.pub_date = datetime.date.today()
self.password = md5(self.password).hexdigest()
self.mod_date = datetime.datetime.today()
super(CasUserForm, self).save()

class CasUserAdmin(admin.ModelAdmin):
class Meta:
form = CasUserForm

# Make sure the classes are available in the admin interface
admin.site.register(CasDomain)
admin.site.register(CasUser, CasUserAdmin)

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



simple.direct_to_template and query objects

2010-12-16 Thread MarcoS
Hi people, I want to define a generic view using
simple.direct_to_template, something like this:

(r'^detail_event/(?P\d+)/$', simple.direct_to_template,
{
'extra_context': {'event': Event.objects.get(id=object_id),}
}),

Of course this doesn't work, django tell me that 'object_id' is not
defined.
How can I access at the object_id value?

-- 
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: virtualenv and deployment

2010-12-16 Thread Álex González
Thanks for your reply Craig,

to use mod_python in my hosting I'm using this .htaccess file:

SetHandler python-program
PythonOption django.root /
PythonHandler django.core.handlers.modpython
PythonPath "['/var/www/vhosts/myhosting.com/httpdocs'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE settings
PythonDebug On

The problem is that when I need to install something I must talk with the
shared hosting admin, and this isn't working because the python is 2.3. The
administrator said me that I must activate python26-mod_python.so but I
can't use the LoadModule directive in .htaccess so I don't know what he want
and I'm waiting for a reply yet...

You are using your self handler in python code to load the webpage? Can I
force here to use the python2.6 interpreter instead the 2.3?

Thanks for you help!

On Thu, Dec 16, 2010 at 00:57, W. Craig Trader wrote:

> Alex ...
>
> You're not going to be able to trick your host into loading mod_wsgi from
> an .htaccess file -- Apache doesn't allow the load directives in .htaccess
> files.
>
> While mod_python is not supported, and it has a large number of open
> issues, there aren't any specific security holes you really need to worry
> about; I'm using mod_python on a project at work because mod_wsgi isn't
> supported in our deployment environment.  I wouldn't recommend mod_python as
> the direction for all future work, but it will get the job done until you
> can get mod_wsgi deployed with your host (or move to another host).
>
> See my earlier post from today (look for Re: running projects on the back
> of a base URL and having issues with the homepage) for more details about
> making mod_wsgi work with VirtualEnv.  The apache script for mod_python is
> similar to the one I posted earlier ; the only differences involve making
> certain that you chdir to your project directory, and that you import the
> Django mod_python handler.
>
> The mod_python configuration is significantly different from the mod_wsgi
> configuration, and look like this:
>
> 
>   SetHandler python-program
>   PythonPath "[ '/data/web/foo/apache', ] + sys.path"
>   PythonHandler django_mp
>   PythonInterpreter foo
> 
>
>   Alias /static/ /data/web/foo/site/foo/static/
>   
> SetHandler None
>   
>
> In this case, mp_python represents /data/web/foo/apache/mp_python.py, which
> is my script to deal with configuring the VirtualEnv environment and then
> starting the Django mod_python handler.  It's basically an amalgam of the
> VirtualEnv activate_this.py script, and the mod_python startup script from
> the Django documentation.
>
> - Craig -
>
> On Wed, Dec 15, 2010 at 16:56, Álex González wrote:
>
>> Hi guys!
>>
>> Thanks for your replies!
>>
>> My hosting is a shared hosting and I think that I can only uses mod_python
>> at the moment. I can load mod_wsgi from htaccess (I test it) but I can edit
>> my virtualhosts or something similar... any trick to get mod_wsgi
>> up?
>>
>> About the virtualenv as Piotr said, some modules must be compiled, so my
>> solution was create a requeriments files as he said, but include in my code
>> django-registration and django-piston because the versions installed with
>> pip doesn't work for me (it said me that it's the correct version, but I can
>> get a actual version at bitbucket).
>>
>> Now my question is, mod_python is deprecated but it's dangerous to use it
>> for a months (until I get money to migrate the code to a non-shared
>> hosting?). And the old question: can I trick the hosting to use mod_wsgi if
>> I can load it from htaccess?
>>
>> Thanks!
>>
>>
>> On Wed, Dec 15, 2010 at 19:49, Ovnicraft  wrote:
>>
>>>
>>>
>>> On Wed, Dec 15, 2010 at 11:48 AM, Álex González 
>>> wrote:
>>>
 Hi!

 I'm using virtualenv with --no-site-packages and now I like to do a
 deployment of my app... I'm using a sharing hosting, can I uypload all my
 enviroment dir (with the packages installed with pip) to the server and use
 them?

 What's the better way to the deployment? mod_python, mod_wsgi, perhaps
 fast-cgi?

>>>
>>>
>>> Remember mod_python is deprecated.
>>>
>>> Regards,
>>>
>>>
 Thanks!

 --
 @agonzalezro 
 Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx,
 .ppt and/or .pptx

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

>>>
>>>
>>>
>>> --
>>> Cristian Salamea
>>> @ovnicraft
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>>