[validators] - access to object.id field

2006-11-30 Thread Marcin Jurczuk

Hello,
I'm writing my own validator based on shipped with django and wondering
how get validated object.id field ?

Following function does not return it ..it should raised error with
message contained keys from validated object. It does but there is no
'id' field.

class ifFieldExistIsUnique(object):
def __init__(self,checked_value, error_message=gettext_lazy("Please
enter something for at least one field.")):
self.other, self.error_message = checked_value, error_message
self.always_test = True

def __call__(self,field_data,all_data):
from wtm.k.models import Customer
self.field = all_data.get(self.other)
lookup={self.other:self.field}
if len(self.field) != 0:

#sres=Customer.objects.exclude(id=all_data.get(id)).filter(**lookup)
raise validators.ValidationError, str(all_data.keys())

How pass id to valitador ?


--~--~-~--~~~---~--~~
 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: offtopic: delete *.pyc from subversion

2006-11-29 Thread Marcin Jurczuk

find . -name '*pyc' |xargs svn delete
to delete them:
find . -name '*pyc"|xargs rm -f


--~--~-~--~~~---~--~~
 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: 'User' object has no attribute 'get_permission_list'

2006-11-17 Thread Marcin Jurczuk

Problem solved ...remove django from site-packages and install again +
remove *pyc in the app code  tree :)


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



'User' object has no attribute 'get_permission_list'

2006-11-17 Thread Marcin Jurczuk

Trying to use perms module in templates but get following error:

AttributeError at /
'User' object has no attribute 'get_permission_list'
[cut]
Exception Value:'User' object has no attribute 'get_permission_list'
[cut]
--


In template dump red line is :
14  {{ perms.tickets }}


How enable this feature ??

settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n"
)


manage shell:

u=User.objects.filter(username='rd')
In [6]: u.g
u.getu.get_or_create  

In [6]: u.get


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



Access to models in validators

2006-09-14 Thread Marcin Jurczuk

Hello,
I'm trying to make my own validator which require access to models:
class Network(Model):
city =
CharField('Miejscowosc',maxlength=128,default='Bialystok')
description = CharField('Opis',maxlength=128)
network_ip = IPAddressField(unique=True)
network_prefix = CharField(maxlength=2)
router = IPAddressField(validator_list=[is_inside_network])
notice = TextField('Uwagi',blank=True,null=True)


class Host(Model):
ip = IPAddressField(unique=True)
#ip = IPAddressField(unique=True)
hostname = CharField('Nazwa hosta',maxlength=128)
description = CharField('Opis',maxlength=255,blank=True,null=True)
network = ForeignKey(Network)
hwaddr = CharField('MAC',maxlength=17,blank=True)
notice = TextField('Uwagi',blank=True,null=True)


When user adds host I'm trying to check if he choose proper network
using such validator:

# import above models
from wfs.hnm.models import *

def is_inside_chosen_network(field_data,all_data):
host_network=Network.objects.get(id=all_data['network'])
host_network_ip=host_network.network_ip
host_network_prefix=host_network.network_prefix
s=ipaddr.ip_set()

s.add_network(ipaddr.network(host_network_ip,int(host_network_prefix)))
if not s.contains(field_data):
raise validators.ValidationError("Adres IP host nie nalezy do
wybranej sieci - popraw siec lub adres IP")


Here is error I'm getting:
n [6]: is_inside_chosen_network("89.161.0.2",{})
---
exceptions.NameError Traceback (most
recent call last)

/home/spock/py/wfs/

/home/spock/py/wfs/hnm/validators.py in
is_inside_chosen_network(field_data, all_data)
 31
 32 def is_inside_chosen_network(field_data,all_data):
---> 33 host_network=Network.objects.get(id=all_data['network'])
 34 host_network_ip=host_network.network_ip
 35 host_network_prefix=host_network.network_prefix

NameError: global name 'Network' is not defined

It's seems like some loop :) - how to solve this ?

Thanks for attention :)


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