Exemple #1
0
 def get(self):
     try:
         id = self.request.GET["id"]
         user = ndb.Key(urlsafe=id).get()
 
         try:
             idcreak = self.request.GET["idcreak"]
             creak = ndb.Key(urlsafe=idcreak).get()
         except:
             creak = None
 
         if creak:
             like = Like(idcreak=creak.key.urlsafe(), iduser=user.username)
             like.put()
             time.sleep(1)
             if user.username != creak.user:
                 notification = Notification(user=creak.user,msg="@"+user.username+" liked your creak: '"+creak.creak+"'",read=0)
                 notification.put()
                 time.sleep(1)
             self.redirect("/welcome?id="+id)
         else:
             self.response.write("An error occurred.")
     except:
         self.response.write("An error occurred.")
         return
Exemple #2
0
    def get(self):
        try:
            id = self.request.GET["id"]
            user = ndb.Key(urlsafe=id).get()

            noReadMsg = Notification.query(Notification.user == user.username,
                                           Notification.read == 0)
            for i in noReadMsg:
                i.read = 1
                i.put()
                time.sleep(0.5)

            notifications = Notification.query(
                Notification.user == user.username).order(-Notification.date)

            values = {
                "username": user.username,
                "name": user.name,
                "surname": user.surname,
                "notifications": notifications,
                "id": id
            }
            jinja = jinja2.get_jinja2(app=self.app)
            self.response.write(
                jinja.render_template("shownotifications.html", **values))
            return
        except:
            self.response.write("An error occurred.")
            return
Exemple #3
0
    def get(self):
        try:
            id = self.request.GET["id"]
            user = ndb.Key(urlsafe=id).get()
            try:
                creak = self.request.get("idcreak", "").strip()
                creak = ndb.Key(urlsafe=creak).get()
            except:
                creak = None

            if creak:
                p = "RC from "+creak.name+" "+creak.surname+" @"+creak.user+" \r\n  "
                user.creaks = user.creaks + 1
                user.put()
                if user.username != creak.user:
                    notification = Notification(user=creak.user,msg="@"+user.username+" recreak your creak: '"+creak.creak+"'",read=0)
                    notification.put()
                    time.sleep(1)

                cr = Creak(creak=p+creak.creak, user=user.username, name=user.name, surname=user.surname)
                cr.put()
                self.redirect("/welcome?id="+id)
            else:
                self.response.write("An error occurred.")
                return
        except:
            self.response.write("An id error occurred.")
            return
Exemple #4
0
def send_add_photo_notifications(bout, from_user_email):
    if bout and from_user_email:
        Notification.create('photo_add', bout.owner, from_user_email, bout)
        photos = Photo.for_(bout)
        if len(photos)>0:
            for photo in photos:
                if photo.owner_email != from_user_email and photo.owner_email != bout.owner.email:
                    Notification.create('photo_add', photo.user, from_user_email, bout)
Exemple #5
0
 def post(self):
     user = util.get_user_from_session()
     message = self.request.get('message')
     owner_email = self.request.get('owner_email')
     bout_id = self.request.get('bout_id')
     bout = Bout.get_by_id(long(bout_id))
     photo = Photo.for_bout_user(bout, owner_email)
     Comment.create(user, photo, message)
     Notification.create('comment_add', photo.bout.owner, user.email, bout)
Exemple #6
0
def get_bind_info(uid):
    #n = Notification.delete_all(uid)     #测试删除缓存
    #return {}
    push = Notification.get_notification(uid)
    if push:
        push = Notification._notification_data(push)
        #push['notification_id'] = push['id']
        #del push['id']
        return push
    return {}
Exemple #7
0
def set_winner(bout):
    bout.change_status(2)
    participants = sorted(Photo.for_(bout), key=lambda x: Vote.count(x), reverse=True)
    if len(participants) > 0:
        max_vote_count = Vote.count(participants[0])
        if max_vote_count > 0:
            for participant in participants:
                current_vote_count = Vote.count(participant)
                if current_vote_count == max_vote_count:
                    winner = User.get_by_key_name(participant.owner_email)
                    Winner.create(winner, bout)
                    Notification.create('winner', winner, winner.email, bout)
                elif current_vote_count < max_vote_count:
                    break
Exemple #8
0
 def post(self):
     ids_str = self.request.get('ids')
     ids = [id for id in ids_str.split(';') if len(id) > 0]
     bout_id = self.request.get('bout_id')
     if len(ids) <= 0:
         return
     invited_by = util.get_user_from_session()
     bout = Bout.get_by_id(long(bout_id))
     for id in ids:
         user = User.get_by_key_name(id)
         Invited(key_name=bout_id, parent=user, timestamp=datetime.datetime.now(), invited_by=invited_by).put()
         Notification.create('invited', user, invited_by.email, bout)
         message = "%s invited you to the bout %s"%(invited_by.name, bout.name)
         deferred.defer(send_push_notification, user.email, message, bout_id)
    def get(self):
        try:
            id = self.request.GET["id"]
            user = ndb.Key(urlsafe=id).get()
            noReadMsg = Notification.query(Notification.user == user.username, Notification.read == 0)
            for i in noReadMsg:
                if i.read == 0:
                    noReadMsg = 0
                break

            follow = Follow.query(Follow.username == user.username)
            values = {
                "username": user.username,
                "name": user.name,
                "surname": user.surname,
                "creaks": user.creaks,
                "follow": user.follow,
                "followers": user.followers,
                "id": id,
                "follows": follow,
                "noReadMsg": noReadMsg
            }
            jinja = jinja2.get_jinja2(app=self.app)
            self.response.write(jinja.render_template("showfollow.html", **values))
            return
        except:
            self.response.write("An error occurred.")
            return
Exemple #10
0
    def get(self):
        id = self.request.GET["id"]
        user = ndb.Key(urlsafe=id).get()
        if user:
            noReadMsg = Notification.query(Notification.user == user.username,
                                           Notification.read == 0)
            for i in noReadMsg:
                if i.read == 0:
                    noReadMsg = 0
                break

            values = {
                "username": user.username,
                "name": user.name,
                "surname": user.surname,
                "email": user.email,
                "creaks": user.creaks,
                "follow": user.follow,
                "followers": user.followers,
                "id": id,
                "noReadMsg": noReadMsg
            }

            jinja = jinja2.get_jinja2(app=self.app)
            self.response.write(jinja.render_template("profile.html",
                                                      **values))
            return
 def get(self):
     user = users.get_current_user()
     
     # Check that user is logged in
     if not user:
         self.error(401)
         return
         
     # Check that user_id is provided to request with
     if not self.request.get('user_id'):
         self.error(400)
         return
     
     # Check if user is requesting data of someone else
     if self.request.get('user_id') != user.user_id() and not users.is_current_user_admin():
         self.error(401)
         return
     
     # Query the database for the users notifications
     notification_qry = anna_notification.query(anna_notification.receiver_id == self.request.get('user_id')).order(-anna_notification.creation_date)
     # Return the 50 latest notifications
     notifications = notification_qry.fetch(50)
     
     # Make a list of the notifications in dictionary format
     notifs = []
     for notification in notifications:
         notifs.append(notification.to_dict())
     
     # Send the notifications in json format
     self.response.headers['Content-type'] = 'application/json'
     self.response.out.write(json.dumps(notifs))
Exemple #12
0
    def get(self):
        try:
            id = self.request.GET["id"]
            user = ndb.Key(urlsafe=id).get()
            noReadMsg = Notification.query(Notification.user == user.username,
                                           Notification.read == 0)
            for i in noReadMsg:
                if i.read == 0:
                    noReadMsg = 0
                break

            likes = Like.query(Like.iduser == user.username)
            var = []
            for i in likes:
                var.append(ndb.Key(urlsafe=i.idcreak).get())

            values = {
                "username": user.username,
                "name": user.name,
                "surname": user.surname,
                "creaks": user.creaks,
                "follow": user.follow,
                "followers": user.followers,
                "id": id,
                "liked_creaks": var,
                "noReadMsg": noReadMsg
            }
            jinja = jinja2.get_jinja2(app=self.app)
            self.response.write(
                jinja.render_template("showlikes.html", **values))
            return
        except:
            self.response.write("An error occurred.")
        pass
Exemple #13
0
 def post(self):
     response = {}
     user = util.get_user_from_session()
     email = user.key().name()
     owner_email = self.request.get('owner_email')
     bout_id = long(self.request.get('bout_id'))
     bout = Bout.get_by_id(bout_id)
     photo = Photo.get_by_key_name(owner_email, parent=bout)
     if Vote.update(email, photo, bout):
         Notification.create('photo_vote', bout.owner, user.email, bout)
         message = "%s voted on your photo in the Bout %s."%(user.name, bout.name)
         util.send_push_notification(photo.user.email, message, bout.id)
         response = {"success": True, "voted": True}
     else:
         response = {"success": True, "voted": False}
     vote_count = Vote.count(photo)
     response["vote_count"] = vote_count
     self.response.write(json.dumps(response))
Exemple #14
0
def setup():
    user_1 = User.create('email1', 'firstname1', 'lastname1', 'password1')
    tp_user_1 = ThirdPartyUser(key_name='FB', parent=user_1)
    tp_user_1.network_id = '359059317608175'
    tp_user_1.put()
    user_2 = User.create('email2', 'firstname2', 'lasstname2', 'password2')
    tp_user_2 = ThirdPartyUser(key_name='FB', parent=user_2)
    tp_user_2.network_id = '359059317608175'
    tp_user_2.put()
    bout_1 = Bout.create(user_1, 'bout1', 'desc1', 1, 1)
    util.schedule_end(bout_1)
    photo_1 = Photo.create(bout_1, user_1, 'image_blob_key_1')
    photo_2 = Photo.create(bout_1, user_2, 'image_blob_key_2')
    bout_2 = Bout.create(user_2, 'bout2', 'desc2', 1, 2)
    util.schedule_end(bout_2)
    Vote.create('email1', photo_1)
    Vote.create('email2', photo_1)
    Vote.create('email2', photo_2)
    #photo_add, photo_vote, comment_add, winner, invited
    Notification.create('photo_add', bout_1.owner, user_2.email, bout_1)
    Notification.create('photo_vote', bout_1.owner, user_2.email, bout_1)
    Notification.create('comment_add', bout_1.owner, user_2.email, bout_1)
    Notification.create('winner', user_1, user_2.email, bout_1)
    Notification.create('invited', user_1, user_2.email, bout_1)
    #Winner.create(user_1, bout_1)
    Comment(parent=photo_1, user=user_1, message='message1', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_1, user=user_2, message='message2', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_1, message='message3', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_1, message='message4', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_2, message='message5', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_1, message='message6', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_2, message='message7', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_2, message='message8', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_2, message='message9', timestamp=datetime.datetime.now()).put()
    Follower.create('email1', user_2)
    Following.create(user_1, 'email2')
Exemple #15
0
def _handle_face_notification(icum_face_id, person=None, attributes=None):
    """
    No person implies that the person is unknown
    :type icum_face_id: str
    :type person: Person
    """
    if not person:
        msg = "Unknown person detected !"
        msg_type = 'unknown'
        attributes = attributes
    else:
        msg = "Person '{}' detected !".format(person.name)
        msg_type = 'known'

    notification = Notification(msg=msg,
                                icum_face_id=icum_face_id,
                                msg_type=msg_type,
                                attributes=attributes)
    notification.save()

    event_hub_connection_string = get_secret(
        "NOTIFICATION-HUB-CONNECTION-STRING")
    notifier = NotifierREST(event_hub_connection_string)
    return notifier.notify(notification)
Exemple #16
0
    def register_notification(self, noti_type, title, text, finish_date,
                              employee_id, condominium_id):
        try:
            finish_date = datetime.datetime.strptime(finish_date, '%Y-%m-%d')
            notification = Notification(type=noti_type,
                                        title=title,
                                        text=text,
                                        finish_date=finish_date,
                                        employee_id=employee_id,
                                        condominium_id=condominium_id)
            db.session.add(notification)
            db.session.commit()

            return notification.id

        except exc.IntegrityError:
            db.session.rollback()
            return None
Exemple #17
0
    def post(self):
        id = self.request.GET["id"]
        user = ndb.Key(urlsafe=id).get()

        if user:
            noReadMsg = Notification.query(Notification.user == user.username,
                                           Notification.read == 0)
            for i in noReadMsg:
                if i.read == 0:
                    noReadMsg = 0
                break
            try:
                edit = self.request.GET["edit"]

                values = {
                    "username": user.username,
                    "name": user.name,
                    "surname": user.surname,
                    "email": user.email,
                    "id": id,
                    "noReadMsg": noReadMsg
                }
                jinja = jinja2.get_jinja2(app=self.app)
                self.response.write(
                    jinja.render_template("edituser.html", **values))
                return
            except:
                name = self.request.get("name", "").strip()
                surname = self.request.get("surname", "").strip()
                email = self.request.get("email", "").strip()

                if len(name) == 0 or len(surname) == 0 or len(email) == 0:
                    self.response.write(
                        "It is necessary to complete all fields.")

                user.name = name
                user.surname = surname
                user.email = email
                user.put()
                self.redirect("/welcome?id=" + id)
                return
Exemple #18
0
    def get(self):
        id = self.request.GET["id"]
        user = ndb.Key(urlsafe=id).get()
        follows = Follow.query(Follow.username == user.username)
        noReadMsg = Notification.query(Notification.user == user.username,
                                       Notification.read == 0)
        for i in noReadMsg:
            if i.read == 0:
                noReadMsg = 0
            break
        creaks = []
        if follows.count() != 0:
            for i in follows:
                if i.username == user.username:
                    creaks.append(i.usernameToFollow)

            user_creaks = Creak.query(
                ndb.OR(Creak.user == user.username,
                       Creak.user.IN(creaks))).order(-Creak.time)
            for n in user_creaks:
                i = 0
                t = ""
                for c in n.creak:
                    t += c
                    if i == 54:
                        t += c + "\n"
                        i = 0
                    i += 1
                n.creak = t
            likes = []
            like = Like.query(Like.iduser == user.username)
            for j in like:
                likes.append(j.idcreak)

            values = {
                "username": user.username,
                "name": user.name,
                "surname": user.surname,
                "creaks": user.creaks,
                "follow": user.follow,
                "followers": user.followers,
                "id": id,
                "user_creaks": user_creaks,
                "like": likes,
                "noReadMsg": noReadMsg
            }
        else:
            user_creaks = Creak.query(
                Creak.user == user.username).order(-Creak.time)
            for n in user_creaks:
                i = 0
                t = ""
                for c in n.creak:
                    t += c
                    if i == 54:
                        t += c + "\n"
                        i = 0
                    i += 1
                n.creak = t

            likes = []
            like = Like.query(Like.iduser == user.username)
            for j in like:
                likes.append(j.idcreak)

            values = {
                "username": user.username,
                "name": user.name,
                "surname": user.surname,
                "creaks": user.creaks,
                "follow": user.follow,
                "followers": user.followers,
                "id": id,
                "user_creaks": user_creaks,
                "like": likes,
                "noReadMsg": noReadMsg
            }
        jinja = jinja2.get_jinja2(app=self.app)
        self.response.write(jinja.render_template("welcome.html", **values))
        return
Exemple #19
0
    def get(self):
        search = self.request.get("search", "").strip()
        id = self.request.GET["id"]
        user = ndb.Key(urlsafe=id).get()
        noReadMsg = Notification.query(Notification.user == user.username,
                                       Notification.read == 0)
        if len(search) == 0:
            self.response.write("User to search can not be null.")
            return

        users = Register.query(Register.username == search)

        if users.count() == 0:
            user_creaks = Creak.query(
                Creak.user == user.username).order(-Creak.time)
            for n in user_creaks:
                i = 0
                t = ""
                for c in n.creak:
                    t += c
                    if i == 54:
                        t += c + "\n"
                        i = 0
                    i += 1
                n.creak = t
            values = {
                "error_login": "******",
                "username": user.username,
                "name": user.name,
                "surname": user.surname,
                "creaks": user.creaks,
                "follow": user.follow,
                "followers": user.followers,
                "id": id,
                "user_creaks": user_creaks,
                "noReadMsg": noReadMsg
            }
            jinja = jinja2.get_jinja2(app=self.app)
            self.response.write(jinja.render_template("welcome.html",
                                                      **values))
            return
        else:
            for i in users:
                users = Register(username=i.username,
                                 name=i.name,
                                 surname=i.surname,
                                 email=i.email,
                                 creaks=i.creaks,
                                 follow=i.follow,
                                 followers=i.followers)

            user_creaks = Creak.query(
                Creak.user == users.username).order(-Creak.time)
            for n in user_creaks:
                i = 0
                t = ""
                for c in n.creak:
                    t += c
                    if i == 54:
                        t += c + "\n"
                        i = 0
                    i += 1
                n.creak = t

            follow = Follow.query(
                ndb.AND(Follow.username == user.username,
                        Follow.usernameToFollow == users.username))
            likes = []
            like = Like.query(Like.iduser == user.username)
            for j in like:
                likes.append(j.idcreak)

            if follow.count() != 0:
                values = {
                    "id": id,
                    "username": user.username,
                    "name": user.name,
                    "surname": user.surname,
                    "creaks": user.creaks,
                    "follow": user.follow,
                    "followers": user.followers,
                    "usernameSearch": users.username,
                    "nameSearch": users.name,
                    "surnameSearch": users.surname,
                    "creaksSearch": users.creaks,
                    "followSearch": users.follow,
                    "followersSearch": users.followers,
                    "user_creaks": user_creaks,
                    "followed": "followed",
                    "like": likes,
                    "noReadMsg": noReadMsg
                }
                jinja = jinja2.get_jinja2(app=self.app)
                self.response.write(
                    jinja.render_template("viewuser.html", **values))
                return

            else:
                values = {
                    "id": id,
                    "username": user.username,
                    "name": user.name,
                    "surname": user.surname,
                    "creaks": user.creaks,
                    "follow": user.follow,
                    "followers": user.followers,
                    "usernameSearch": users.username,
                    "nameSearch": users.name,
                    "surnameSearch": users.surname,
                    "creaksSearch": users.creaks,
                    "followSearch": users.follow,
                    "followersSearch": users.followers,
                    "user_creaks": user_creaks,
                    "noReadMsg": noReadMsg
                }
                jinja = jinja2.get_jinja2(app=self.app)
                self.response.write(
                    jinja.render_template("viewuser.html", **values))
                return
Exemple #20
0
 def get(self):
     next = self.request.get('next')
     user = util.get_user_from_session()
     response = util.fetch_with_cursor(Notification.all().ancestor(user).order("-timestamp"), limit=20, cursor=next, mapper=make_notification_dict)
     self.response.write(json.dumps(response))
Exemple #21
0
def bind_bdinfo(bd_info):
    push = Notification.new(bd_info['uid'], bd_info['device'], bd_info['version'], bd_info['uuid'], bd_info['baidu_uid'], bd_info['baidu_cid'])
    return Notification._notification_data(push)
Exemple #22
0
def show_all_notifications():
    all_notifications = Notification.objects()
    return render_template('show_all_notifications.html',
                           notifications=all_notifications)