def create(username): user = User.get_or_none(User.name == username) obj = request.form.get("objective") Objective.create(objective=obj, user=user.id) if user.id != current_user.id: Notification.create(notification_type=1, sender=current_user.id, recipient=user.id) flash("Objective succesfully added") return redirect(url_for('users.show', username=username))
def create_mention_notification(self, user:UserProfile) -> Notification: """ user: The user being mentioned """ n = Notification.create( target = user, user = self.user, notification_type = 'mention' ) self._notify_user(n) return n
def create_follow_notification(self, target:UserProfile) -> Notification: """ target: The user receiving the notification """ n = Notification.create( target = target, user = self.user, notification_type = 'follow', ) self._notify_user(n) return n
def create_like_notification(self, status: Status) -> Notification: """ status: The status we are liking (this can ve either a image or a comment) """ n = Notification.create( target = status.user, user = self.user, status = status, notification_type = 'like', ) self._notify_user(n) return n
def like_status(status, user): """ status - the status target of the like - Status user - the user liking the post - UserProfile """ r = redis.StrictRedis(host=os.environ.get('REDIS_HOST', 'localhost')) #Add id to the like timeline TimelineManager(status.user).push_likes(status) notification = Notification.create( user = user, target = status.user, status = status, notification_type = notification_types['like'] ) json_file = json.dumps(status.json(), default=str) r.publish(f'timeline:{status.user.id}', f'notification {json_file}')