def dehydrate(self, bundle): try: if bundle.obj.user is not None: user_name = bundle.obj.user.get_nice_name() user_image = bundle.obj.user.get_small_profile_image() user_profile = bundle.obj.user.get_profile_url() else: user_name = UserProfile.get_default_moniker() user_image = UserProfile.get_default_avatar_image() user_profile = "" bundle.data["verb"] = bundle.obj.get_verb_past(), bundle.data["object"] = bundle.obj.get_object_singular(), bundle.data["item_name"] = bundle.obj.get_object_name(), bundle.data["item_url"] = bundle.obj.get_object_url(), bundle.data["user_name"] = user_name, bundle.data["user_profile"] = user_profile, bundle.data["user_image"] = user_image return bundle except AttributeError, ae: self.logger.debug("AttributeError: Error dehydrating activity, %s" % ae.message)
def dehydrate(self, bundle): if bundle.obj.user is not None: bundle.data['avatar_image'] = bundle.obj.user.get_profile().get_avatar_image() bundle.data['user_url'] = bundle.obj.user.get_profile().get_absolute_url() bundle.data['user_name'] = bundle.obj.user.get_profile().get_nice_name() else: bundle.data['avatar_image'] = UserProfile.get_default_avatar_image() bundle.data['user_url'] = "/" bundle.data['user_name'] = "Anonymouse" if bundle.request.user.is_authenticated(): bundle.data['can_edit'] = bundle.request.user.is_staff or bundle.obj.user_id == bundle.request.user.id else: bundle.data['can_edit'] = False return bundle
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): self.send_notification_email() sessions = self.to_user.user.session_set.all() avatar_image = UserProfile.get_default_avatar_image() if self.from_user is not None: avatar_image = self.from_user.get_avatar_image() for session in sessions: post_notification( session.session_key, avatar_image, self.notification_html) return super(Notification, self).save(force_insert, force_update, using, update_fields)
def get_from_user(self): return UserProfile.get_user(self.from_user)
def user_display_name(self): if self.user is None: return UserProfile.get_default_display_name() else: return self.user.userprofile.get_nice_name()
def avatar_image(self): if self.user is None: return UserProfile.get_default_avatar_image() else: return self.user.userprofile.get_avatar_image()