示例#1
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")
示例#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")
示例#3
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)
        # apt_name = req_json[IDENTIFIER_APT_NAME]
        apt_name = self.request.get(IDENTIFIER_APT_NAME)
        # description = req_json[IDENTIFIER_DESCRIPTION_NAME]
        description = self.request.get(IDENTIFIER_DESCRIPTION_NAME)

        apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch()

        cur_apt = None
        for apt in apt_lst:
            if user_email in apt.user_email_lst:
                cur_apt = apt

        if cur_apt == None:
            response = {}
            response[
                'error'] = 'the apt: ' + apt_name + ' is not available for user: '******'error'] = 'we dont have notebook for the apt: ' + apt_name
            return self.respond(**response)

        cur_note_book = cur_note_book_lst[0]

        note_id = uuid.uuid4()
        note = Note(id=str(note_id),
                    description=description,
                    author_email=user_email,
                    notebook_id=cur_note_book_id)

        cur_note_book.note_id_lst.append(str(note_id))

        cur_note_book.put()
        note.put()

        self.respond(note_id=str(note_id),
                     notebook_id=cur_note_book_id,
                     status="Success")
示例#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)
        # apt_name = req_json[IDENTIFIER_APT_NAME]
        apt_name =  self.request.get(IDENTIFIER_APT_NAME)
        # description = req_json[IDENTIFIER_DESCRIPTION_NAME]
        description = self.request.get(IDENTIFIER_DESCRIPTION_NAME)

        apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch()

        cur_apt = None
        for apt in apt_lst:
            if user_email in apt.user_email_lst:
                cur_apt = apt

        if cur_apt == None:
            response = {}
            response['error'] = 'the apt: ' + apt_name + ' is not available for user: '******'error'] = 'we dont have notebook for the apt: ' + apt_name
            return self.respond(**response)

        cur_note_book = cur_note_book_lst[0]

        note_id = uuid.uuid4()
        note = Note(id = str(note_id), description = description, author_email = user_email, notebook_id = cur_note_book_id)

        cur_note_book.note_id_lst.append(str(note_id))

        cur_note_book.put()
        note.put()

        self.respond(note_id = str(note_id), notebook_id = cur_note_book_id, status="Success")
示例#5
0
    def get(self):
        apt_id = uuid.uuid4()
        # req_json = json.loads(self.request.body)

        # apt_name = req_json[IDENTIFIER_APT_NAME]
        apt_name = self.request.get(IDENTIFIER_APT_NAME)
        # user_email = req_json[IDENTIFIER_USER_EMAIL]
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)

        # user_email_lst = req_json[IDENTIFIER_USER_EMAIL_LIST]
        user_emails = self.request.get(IDENTIFIER_USER_EMAIL_LIST)

        user_email_lst = user_emails.split(",")
        cover_url = None

        user_email_lst.insert(0, user_email)

        # get rid of empty entity
        print("user_email_lst before filtering" + str(user_email_lst))
        user_email_lst = filter(None, user_email_lst)
        print("user_email_lst after filtering" + str(user_email_lst))

        # print user_email_lst

        # if IDENTIFIER_APT_PHOTO in req_json:
        #     cover_url = req_json[IDENTIFIER_APT_PHOTO]

        # check whether all of these email are valid users
        for user in user_email_lst:
            print user
            # user = user.encode('utf8')
            users = User.query(User.user_email == user).fetch()
            print("query user result" + str(len(users)))
            if len(users) == 0:
                response = {}
                response[
                    'error'] = 'the email: ' + user + ' has not been registered'
                return self.respond(**response)
            if users[0].apt_id is not None:
                response = {}
                response[
                    'error'] = 'the email: ' + user + ' has already joined other apartment'
                return self.respond(**response)

        for user in user_email_lst:
            users = User.query(User.user_email == user).fetch()
            cur_user = users[0]
            cur_user.apt_id = str(apt_id)
            cur_user.put()

        note_book_id = uuid.uuid4()
        new_note_book = NoteBook(notebook_id=str(note_book_id),
                                 apt_id=str(apt_id))
        new_note_book.put()

        new_apt = Apartment(apt_id=str(apt_id),
                            apt_name=apt_name,
                            creater_email=user_email,
                            user_email_lst=user_email_lst,
                            cover_url=cover_url,
                            notebook_id=str(note_book_id),
                            total_cost=0)
        new_apt.put()

        self.respond(apt_id=str(apt_id), status="Success")
示例#6
0
    def get(self):
        apt_id = uuid.uuid4()
        # req_json = json.loads(self.request.body)

        # apt_name = req_json[IDENTIFIER_APT_NAME]
        apt_name = self.request.get(IDENTIFIER_APT_NAME)
        # user_email = req_json[IDENTIFIER_USER_EMAIL]
        user_email = self.request.get(IDENTIFIER_USER_EMAIL)

        # user_email_lst = req_json[IDENTIFIER_USER_EMAIL_LIST]
        user_emails = self.request.get(IDENTIFIER_USER_EMAIL_LIST)

        user_email_lst = user_emails.split(",")
        cover_url = None

        user_email_lst.insert(0, user_email)

        # get rid of empty entity
        print("user_email_lst before filtering" + str(user_email_lst))
        user_email_lst = filter(None, user_email_lst)
        print("user_email_lst after filtering" + str(user_email_lst))

        # print user_email_lst

        # if IDENTIFIER_APT_PHOTO in req_json:
        #     cover_url = req_json[IDENTIFIER_APT_PHOTO]

        # check whether all of these email are valid users
        for user in user_email_lst:
            print user
            # user = user.encode('utf8')
            users = User.query(User.user_email == user).fetch()
            print("query user result" + str(len(users)))
            if len(users) == 0:
                response = {}
                response['error'] = 'the email: ' + user + ' has not been registered'
                return self.respond(**response)
            if users[0].apt_id is not None:
                response = {}
                response['error'] = 'the email: ' + user + ' has already joined other apartment'
                return self.respond(**response)


        for user in user_email_lst:
            users = User.query(User.user_email == user).fetch()
            cur_user = users[0]
            cur_user.apt_id = str(apt_id)
            cur_user.put()

        note_book_id = uuid.uuid4()
        new_note_book = NoteBook(notebook_id = str(note_book_id),
                                 apt_id = str(apt_id))
        new_note_book.put()

        new_apt = Apartment(apt_id = str(apt_id),
                            apt_name = apt_name,
                            creater_email = user_email,
                            user_email_lst = user_email_lst,
                            cover_url = cover_url,
                            notebook_id = str(note_book_id),
                            total_cost = 0)
        new_apt.put()

        self.respond(apt_id = str(apt_id), status="Success")