Example #1
0
    def get(self):
        # req_json = json.loads(self.request.body)
        # note_id = req_json[IDENTIFIER_NOTE_ID]
        note_id = self.request.get(IDENTIFIER_NOTE_ID)
        # user_email = req_json[IDENTIFIER_USER_EMAIL]
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)
        # description = req_json[IDENTIFIER_DESCRIPTION_NAME]
        description = self.request.get(IDENTIFIER_DESCRIPTION_NAME)

        reply_id = uuid.uuid4()
        notes = Note.query(Note.id == note_id).fetch()
        note = notes[0]

        user_lst = User.query(User.user_email == user_email).fetch()
        user = user_lst[0]

        new_reply = Reply(author_email=user_email,
                          note_id=str(note_id),
                          reply_id=str(reply_id),
                          description=description,
                          nick_name=user.nick_name)
        new_reply.put()
        note.reply_id_lst.append(str(reply_id))
        note.put()

        self.respond(reply_id=str(reply_id), status="Success")
Example #2
0
    def get(self):
        apt_name = self.request.get(IDENTIFIER_APT_NAME)
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)
        apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch()

        # print "called: " + user_email + ", " + apt_name
        cur_apt = None
        for apt in apt_lst:
            if user_email in apt.user_email_lst:
                cur_apt = apt

        cur_notebook_lst = NoteBook.query(
            NoteBook.notebook_id == cur_apt.notebook_id).fetch()
        if len(cur_notebook_lst) == 0:
            response = {}
            response[
                'error'] = 'we dont have notebook for the apt: ' + apt_name
            return self.respond(**response)

        cur_notebook = cur_notebook_lst[0]

        retList = []
        for noteid in cur_notebook.note_id_lst:
            note_lst = Note.query(Note.id == noteid).fetch()
            cur_note = note_lst[0]
            ret_note = {}
            ret_note['author'] = cur_note.author_email
            ret_note['description'] = cur_note.description
            date = str(cur_note.date)
            ret_note['last_edit_date'] = date
            retList.append(ret_note)

        self.respond(AllNoteLst=retList, status="Success")
Example #3
0
        def get(self):
            # req_json = json.loads(self.request.body)
            # note_id = req_json[IDENTIFIER_NOTE_ID]
            note_id = self.request.get(IDENTIFIER_NOTE_ID)
            # user_email = req_json[IDENTIFIER_USER_EMAIL]
            user_email = self.request.get(IDENTIFIER_USER_EMAIL)
            # description = req_json[IDENTIFIER_DESCRIPTION_NAME]
            description = self.request.get(IDENTIFIER_DESCRIPTION_NAME)

            reply_id = uuid.uuid4()
            notes = Note.query(Note.id == note_id).fetch()
            note = notes[0]

            user_lst = User.query(User.user_email == user_email).fetch()
            user = user_lst[0]

            new_reply = Reply(author_email = user_email,
                              note_id = str(note_id),
                              reply_id = str(reply_id),
                              description = description,
                              nick_name = user.nick_name
                              )
            new_reply.put()
            note.reply_id_lst.append(str(reply_id))
            note.put()

            self.respond(reply_id = str(reply_id),
                         status="Success")
Example #4
0
    def get(self):

        # req_json = json.loads(self.request.body)
        # user_email = req_json[IDENTIFIER_USER_EMAIL]
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)
        # note_id = req_json[IDENTIFIER_NOTE_ID]
        note_id = self.request.get(IDENTIFIER_NOTE_ID)
        # new_description = req_json[IDENTIFIER_NEW_DESCRIPTION_NAME]
        new_description = self.request.get(IDENTIFIER_NEW_DESCRIPTION_NAME)

        cur_note_lst = Note.query(Note.id == note_id).fetch()

        if len(cur_note_lst) == 0:
            response = {}
            response['error'] = 'the note with id : ' + note_id + ' is valid'
            return self.respond(**response)

        cur_note = cur_note_lst[0]

        if user_email != cur_note.author_email:
            response = {}
            response['error'] = 'you cannot edit this note'
            return self.respond(**response)

        cur_note.description = new_description
        cur_note.put()

        self.respond(status="Success")
Example #5
0
    def get(self):
        apt_name = self.request.get(IDENTIFIER_APT_NAME)
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)
        apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch()

        # print "called: " + user_email + ", " + apt_name
        cur_apt = None
        for apt in apt_lst:
            if user_email in apt.user_email_lst:
                cur_apt = apt

        cur_notebook_lst = NoteBook.query( NoteBook.notebook_id == cur_apt.notebook_id).fetch()
        if len(cur_notebook_lst) == 0:
            response = {}
            response['error'] = 'we dont have notebook for the apt: ' + apt_name
            return self.respond(**response)


        cur_notebook = cur_notebook_lst[0]


        retList = []
        for noteid in cur_notebook.note_id_lst:
            note_lst = Note.query(Note.id == noteid).fetch()
            cur_note = note_lst[0]
            ret_note = {}
            ret_note['author'] = cur_note.author_email
            ret_note['description'] = cur_note.description
            date = str(cur_note.date)
            ret_note['last_edit_date'] = date
            retList.append(ret_note)

        self.respond(AllNoteLst = retList, status="Success")
Example #6
0
    def get(self):

        # req_json = json.loads(self.request.body)
        # user_email = req_json[IDENTIFIER_USER_EMAIL]
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)
        # note_id = req_json[IDENTIFIER_NOTE_ID]
        note_id = self.request.get(IDENTIFIER_NOTE_ID)
        # new_description = req_json[IDENTIFIER_NEW_DESCRIPTION_NAME]
        new_description = self.request.get(IDENTIFIER_NEW_DESCRIPTION_NAME)

        cur_note_lst = Note.query(Note.id == note_id).fetch()

        if len(cur_note_lst) == 0:
            response = {}
            response['error'] = 'the note with id : ' + note_id + ' is valid'
            return self.respond(**response)

        cur_note = cur_note_lst[0]

        if user_email != cur_note.author_email:
            response = {}
            response['error'] = 'you cannot edit this note'
            return self.respond(**response)

        cur_note.description = new_description
        cur_note.put()

        self.respond(status="Success")
Example #7
0
    def get(self):

        user_email = self.request.get(IDENTIFIER_USER_EMAIL)
        note_id = self.request.get(IDENTIFIER_NOTE_ID)

        cur_note_lst = Note.query(Note.id == note_id).fetch()

        if len(cur_note_lst) == 0:
            response = {}
            response['error'] = 'The ID is not available: ' + note_id
            return self.respond(**response)

        cur_note = cur_note_lst[0]

        retValue = {}
        retValue['author'] = cur_note.author_email
        retValue['last_edit_date'] = str(cur_note.date)
        retValue['description'] = cur_note.description
        self.respond(Note=retValue, status="Success")
Example #8
0
    def get(self):

        user_email = self.request.get(IDENTIFIER_USER_EMAIL)
        note_id = self.request.get(IDENTIFIER_NOTE_ID)

        cur_note_lst = Note.query(Note.id == note_id).fetch()

        if len(cur_note_lst) == 0:
            response = {}
            response['error'] = 'The ID is not available: ' + note_id
            return self.respond(**response)

        cur_note = cur_note_lst[0]

        retValue = {}
        retValue['author'] = cur_note.author_email
        retValue['last_edit_date'] = str(cur_note.date)
        retValue['description'] = cur_note.description
        self.respond(Note = retValue, status="Success")
Example #9
0
    def get(self):
        note_id = self.request.get(IDENTIFIER_NOTE_ID)
        notes = Note.query(Note.id == note_id).fetch()
        note = notes[0]

        replys = note.getAllreply()
        reply_lst = []

        sorted_replys = sorted(replys, key=lambda reply: reply.date)

        for reply in sorted_replys:
            cur_reply = {}
            cur_reply['author'] = reply.nick_name
            cur_reply['author_email'] = reply.author_email
            cur_reply['description'] = reply.description
            cur_reply['reply_id'] = str(reply.reply_id)
            cur_reply['date'] = str(reply.date)
            reply_lst.append(cur_reply)

        self.respond(reply_lst=reply_lst, status="Success")
Example #10
0
    def get(self):
        note_id = self.request.get(IDENTIFIER_NOTE_ID)
        notes = Note.query(Note.id == note_id).fetch()
        note = notes[0]

        replys = note.getAllreply()
        reply_lst = []

        sorted_replys = sorted(replys, key=lambda reply:reply.date)

        for reply in sorted_replys:
            cur_reply = {}
            cur_reply['author'] = reply.nick_name
            cur_reply['author_email'] = reply.author_email
            cur_reply['description'] = reply.description
            cur_reply['reply_id'] = str(reply.reply_id)
            cur_reply['date'] = str(reply.date)
            reply_lst.append(cur_reply)

        self.respond(reply_lst = reply_lst,
                         status="Success")
Example #11
0
    def get(self):
        logging.info('stats calculator...starting')
        # create a UserStat object for all Users in the db
        users = list(User.query().fetch())
        data = dict(
            (user.key.id(), UserStats(user=user.key))
            for user in users
        )

        for user in users:
            user_stat = data[user.key.id()]
            user_stat.logins = user.login_count
            user_stat.logouts = user.logout_count
            user_stat.bio = 1 if user.bio else 0

        for photo in Photo.query().fetch():
            user_id = photo.user.id()
            user_stat = data[user_id]
            if photo.competition is None:
                user_stat.extra_photos += 1
            else:
                if photo.competition.get().status != COMPLETED:
                    # not interested in competition photos for incomplete
                    # competitions
                    continue
                user_stat.comp_photos += 1
                user_stat.total_points += photo.total_score
                if photo.position == 1:
                    user_stat.first_place += 1
                    user_stat.medals += 1
                elif photo.position == 2:
                    user_stat.second_place += 1
                    user_stat.medals += 1
                elif photo.position == 3:
                    user_stat.third_place += 1
                    user_stat.medals += 1

        completed_comp_count = Competition.count()
        for user_stat in data.values():
            if user_stat.comp_photos == completed_comp_count:
                user_stat.all_comps = 1

        for comment in Comment.query().fetch():
            # give
            data[comment.user.id()].comments_give += 1
            # receive
            receiver = comment.photo.get().user.id()
            data[receiver].comments_receive += 1

        for score in Scores.query().fetch():
            receiver = score.photo.get().user.id()
            if score.score == 10:
                # give 10
                data[score.user_from.id()].score_10_give += 1
                # receive 10
                data[receiver].score_10_receive += 1
            elif score.score == 0:
                # give 0
                data[score.user_from.id()].score_0_give += 1
                # receive 0
                data[receiver].score_0_recieve += 1

        for note in Note.query().fetch():
            data[note.user.id()].notes += 1

        # is this person a GIVER
        for user in data.values():
            if user.comments_give > user.comments_receive:
                user.giver += 1
            if user.score_10_give > user.score_10_receive:
                user.giver += 1

        # last place finishers
        self._last_positions(data)

        self._photo_with_most_comments(data)
        self._photo_with_high_score(data)
        self._houses(data)

        self._most(data, 'comments_give')
        self._most(data, 'comments_receive')
        self._most(data, 'notes')
        self._most(data, 'logins')
        self._most(data, 'logouts')
        self._most(data, 'medals')
        self._most(data, 'first_place')
        self._most(data, 'second_place')
        self._most(data, 'third_place')
        self._most(data, 'last_place')

        UserStats.delete_all()
        for stat in data.values():
            stat.put()

        logging.info(data)
        logging.info('stats calculator...finished')