示例#1
0
 def get(self):
     #grab and sanitize the query
     q = self.get_argument(u'q', u'')
     q = username_sanitizer.sub('', q)
     #query: *q*
     users = User.find({u'username': re.compile(q)})
     self.output([user[u'username'] for user in users])
示例#2
0
 def invite(self, usernames=None, contacts=None, tz=None):
     if usernames is not None:
         #prevent people from inviting themselves
         if self[u'creator'] in usernames:
             usernames.remove(self[u'creator'])
         # convert usernames to user objects
         users = list(User.find({u'username': {'$in': usernames}}))
     else:
         users = list()
     ret = None
     if contacts is not None:
         registered, out_of_numbers, has_username = SMS.register(self, 
                 contacts, tz=tz)
         users += has_username
         users += [reg for reg in registered if reg not in users]
         if len(out_of_numbers) > 0:
             ret = out_of_numbers
     
     for user in users:
         Attendant(user=user[u'id'], event=self[u'id']).save()
         #send the invite notification
         if user[u'username'] is not None: name = user[u'username']
         else: name = user[u'id']
         
         notifications.send(name, {u'type': 'invite', 
                                   u'event_revision': self[u'revision'],
                                   u'event_id': self[u'id']})
     return ret
示例#3
0
 def to_notify(cls, event, skip=list()):
     atts = cls.find({u'event': event[u'id']})#, u'status': status.ATTENDING})
     ids = [ObjectId(a[u'user']) for a in atts]
     users = User.find({u'_id': {u'$in': ids}})
     ret = [event[u'creator']]
     for u in users:
         if u[u'username'] is not None:
             ret.append(u[u'username'])
         else:
             ret.append(u[u'id'])
     ret = [u for u in ret if u not in skip]
     return ret
示例#4
0
 def usernames(self):
     ids = [ObjectId(a[u'user']) for a in self]
     users = User.find({u'_id': {u'$in': ids}})
     usernames = [u[u'username'] for u in users if u[u'username'] is not None]
     return usernames
示例#5
0
 def followers(self, users=True):
     usernames = [f[u'follower'] for f in self]
     if users:
         return User.find({u'username': {u'$in': usernames}})
     else:
         return usernames