set svn:keywords property for proper keywords expansion
[plcapi.git] / PLC / Persons.py
index 7e7578e..0b0fe68 100644 (file)
@@ -4,7 +4,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: Persons.py,v 1.34 2007/03/28 19:15:34 tmack Exp $
+# $Id$
 #
 
 from types import StringTypes
@@ -100,8 +100,15 @@ class Person(Row):
         if len(domain) < 2:
             raise invalid_email
 
-        conflicts = Persons(self.api, [email])
-        for person in conflicts:
+               # check only against users on the same peer  
+       if 'peer_id' in self:
+            namespace_peer_id = self['peer_id']
+        else:
+            namespace_peer_id = None
+         
+       conflicts = Persons(self.api, {'email':email,'peer_id':namespace_peer_id}) 
+       
+       for person in conflicts:
             if 'person_id' not in self or self['person_id'] != person['person_id']:
                 raise PLCInvalidArgument, "E-mail address already in use"
 
@@ -210,6 +217,18 @@ class Person(Row):
         self['site_ids'].remove(site_id)
         self['site_ids'].insert(0, site_id)
 
+    def update_last_updated(self, commit = True):
+        """
+        Update last_updated field with current time
+        """
+       
+       assert 'person_id' in self
+       assert self.table_name
+       
+       self.api.db.do("UPDATE %s SET last_updated = CURRENT_TIMESTAMP " % (self.table_name) + \
+                       " where person_id = %d" % (self['person_id']) )
+        self.sync(commit)
+
     def delete(self, commit = True):
         """
         Delete existing user.
@@ -287,7 +306,7 @@ class Persons(Table):
        
        # postgres will return timestamps as datetime objects. 
        # XMLPRC cannot marshal datetime so convert to int
-       timestamps = ['date_created', 'last_updated']
+       timestamps = ['date_created', 'last_updated', 'verification_expires']
        for field in fields:
            if field in timestamps:
                fields[fields.index(field)] = \
@@ -303,10 +322,18 @@ class Persons(Table):
                 ints = filter(lambda x: isinstance(x, (int, long)), person_filter)
                 strs = filter(lambda x: isinstance(x, StringTypes), person_filter)
                 person_filter = Filter(Person.fields, {'person_id': ints, 'email': strs})
-                sql += " AND (%s)" % person_filter.sql(api, "OR")
+                sql += " AND (%s) %s" % person_filter.sql(api, "OR")
             elif isinstance(person_filter, dict):
                 person_filter = Filter(Person.fields, person_filter)
-                sql += " AND (%s)" % person_filter.sql(api, "AND")
+                sql += " AND (%s) %s" % person_filter.sql(api, "AND")
+            elif isinstance (person_filter, StringTypes):
+                person_filter = Filter(Person.fields, {'email':[person_filter]})
+                sql += " AND (%s) %s" % person_filter.sql(api, "AND")
+            elif isinstance (person_filter, int):
+                person_filter = Filter(Person.fields, {'person_id':[person_filter]})
+                sql += " AND (%s) %s" % person_filter.sql(api, "AND")
+            else:
+                raise PLCInvalidArgument, "Wrong person filter %r"%person_filter
 
        # aggregate data
        all_persons = {}