Reasonably basic User definition. Probably would want additional attributes.
| 228 | |
| 229 | |
| 230 | class User(object): |
| 231 | """ |
| 232 | Reasonably basic User definition. |
| 233 | Probably would want additional attributes. |
| 234 | """ |
| 235 | |
| 236 | |
| 237 | @property |
| 238 | def permissions(self): |
| 239 | p = set() |
| 240 | for g in self.groups: |
| 241 | p |= set(g.permissions) |
| 242 | return p |
| 243 | |
| 244 | @property |
| 245 | def isAdmin(self): |
| 246 | return Permission.getAdminPermission() in self.permissions |
| 247 | |
| 248 | |
| 249 | @classmethod |
| 250 | def by_user_name(cls, username): |
| 251 | """ |
| 252 | A class method that permits to search users |
| 253 | based on their user_name attribute. |
| 254 | """ |
| 255 | return cls.query.filter_by(user_name=username).first() |
| 256 | |
| 257 | |
| 258 | @classmethod |
| 259 | def by_facebook_user_id(cls, facebook_user_id): |
| 260 | """ |
| 261 | A class method that permits to search users |
| 262 | based on their facebook_user_id attribute. |
| 263 | """ |
| 264 | return cls.query.filter_by(facebook_user_id=facebook_user_id).first() |
| 265 | |
| 266 | |
| 267 | def _set_password(self, password): |
| 268 | """ |
| 269 | encrypts password on the fly using the encryption |
| 270 | algo defined in the configuration |
| 271 | """ |
| 272 | self._password = identity.encrypt_password(password) |
| 273 | |
| 274 | |
| 275 | def _get_password(self): |
| 276 | """ |
| 277 | returns password |
| 278 | """ |
| 279 | return self._password |
| 280 | |
| 281 | password = property(_get_password, _set_password) |
| 282 | |
| 283 | |
| 284 | def getSavedCities(self, session): |
| 285 | savedCities = [] |
| 286 | #print "GETSAVEDCITIES USER", self, "CITIES", self.cities |
| 287 | for city in self.cities: |
no outgoing calls