コード例 #1
0
    def post(self):
        if self.ensure_is_logged_in() and self.ensure_has_display_name():
            self.check_CSRF()
            user_id = self.user_id
            message_accept = self.request.get('accept')
            message_decline = self.request.get('decline')

            if message_accept:
                sender_id = EnkiModelMessage.get_by_id(
                    int(message_accept)).sender
                if sender_id:
                    EnkiModelFriends.add_friend(user_id, sender_id)
                    self.add_infomessage(
                        MSG.SUCCESS(),
                        MSG.FRIEND_ADDED(
                            EnkiModelDisplayName.get_display_name(sender_id)))
            elif message_decline:
                sender_id = EnkiModelMessage.get_by_id(
                    int(message_decline)).sender
                if sender_id:
                    EnkiModelMessage.remove_messages_crossed(
                        user_id, sender_id)

            self.render_tmpl('messages.html',
                             data=EnkiModelMessage.get_messages(self.user_id))
コード例 #2
0
 def remove_friend(cls, user_id, friend_id):
     friends = cls.get_key_by_user_ids(user_id, friend_id)
     if friends:
         friends.delete()
     # clean up any remaining friend invitations (from either side)
     EnkiModelMessage.remove_messages_crossed(user_id, friend_id)
コード例 #3
0
 def add_friend(cls, user_id, friend_id):
     if not cls.exist_by_user_ids(user_id, friend_id):
         friends = cls(friends=[user_id, friend_id])
         friends.put()
     # clean up any remaining friend invitations (from either side)
     EnkiModelMessage.remove_messages_crossed(user_id, friend_id)