Exemplo n.º 1
0
 def get(self):
     user = users.get_current_user()
     if user:
         person = login.is_roommate_account_initialized(user)
         if person:
             if (person.do_not_disturb):
                 person.do_not_disturb = False
                 data = {'dnd_state': 'Do not disturb is off.'}
                 person.put()
             else:
                 person.do_not_disturb = True
                 data = {'dnd_state': 'DO NOT DISTURB!'}
                 person.put()
                 sender_address = 'Roommates <*****@*****.**>'
                 occupants = Home.query().filter(
                     Home.key == person.home_key).fetch()[0].occupants
                 for occupant in occupants:
                     receipient = Person.query().filter(
                         Person.user_id == occupant).fetch()[0]
                     receipient = receipient.email_address
                     if receipient == person.email_address:
                         logging.info(occupant)
                     else:
                         helpers.send_dnd_mail(sender_address, person.name,
                                               receipient)
             render.render_page_with_data(self, 'doNotDisturb.html',
                                          "Do Not Disturb Toggle", data)
             helpers.redirect(self, '/dashboard', 1000)
         else:
             helpers.redirect(self, '/', 0)
     else:
         helpers.redirect(self, '/', 0)
Exemplo n.º 2
0
 def get(self):
     user = users.get_current_user()
     if user:
         person = login.is_roommate_account_initialized(user)
         if person:
             render_data = helpers.getDashData(self, person)
             render.render_page_with_data(self, 'dashboard.html',
                                          person.name + "'s Dashboard",
                                          render_data)
         else:
             helpers.redirect(self, '/', 0)
     else:
         helpers.redirect(self, '/', 0)
Exemplo n.º 3
0
 def get(self):
     user = users.get_current_user()
     if user:
         person = login.is_roommate_account_initialized(user)
         if person:
             home = Home.query(Home.key == person.home_key).fetch()[0]
             rotation_list = []
             for user_id in home.occupants:
                 p = Person.query().filter(
                     Person.user_id == user_id).fetch()[0]
                 rotation_list.append(p)
             data = {'rotation_list': rotation_list}
             render.render_page_with_data(self, 'chores.html',
                                          'Create a Chore', data)
         else:
             helpers.redirect(self, '/', 0)
     else:
         helpers.redirect(self, '/', 0)
Exemplo n.º 4
0
 def get(self):
     user = users.get_current_user()
     if user:
         person = login.is_roommate_account_initialized(user)
         if person:
             home = Home.query(Home.key == person.home_key).fetch()[0]
             possible_payers = []
             for user_id in home.occupants:
                 p = Person.query().filter(
                     Person.user_id == user_id).fetch()[0]
                 possible_payers.append(p)
             data = {'payers': possible_payers}
             render.render_page_with_data(self, 'bills.html',
                                          'Assign a Bill', data)
         else:
             helpers.redirect(self, '/', 0)
     else:
         helpers.redirect(self, '/', 0)
Exemplo n.º 5
0
 def get(self):
     user = users.get_current_user()
     if user:
         person = login.is_roommate_account_initialized(user)
         if person:
             if (person.location):
                 person.location = False
                 person.put()
             else:
                 person.location = True
                 person.put()
             if (person.location):
                 data = {'check_in_state': 'Checked In!'}
             else:
                 data = {'check_in_state': 'Checked Out!'}
             render.render_page_with_data(self, 'checkInState.html',
                                          "Check In or Out", data)
             helpers.redirect(self, '/dashboard', 1000)
         else:
             helpers.redirect(self, '/', 0)
     else:
         helpers.redirect(self, '/', 0)
Exemplo n.º 6
0
    def post(self):

        name = self.request.get('name')
        phone_number = int(
            self.request.get('phone_number1') +
            self.request.get('phone_number2') +
            self.request.get('phone_number3'))
        #create new person object
        user = users.get_current_user()

        color = self.request.get('color')
        person = Person(name=name,
                        color=color,
                        phone_number=phone_number,
                        user_id=user.user_id(),
                        email_address=user.email(),
                        calendar_id=user.email())

        #retrieve data from form
        home_name = self.request.get('home_name')
        password = helpers.hashPass(self.request.get('password'))
        # Query for home object
        potential_home = Home.query().filter(
            Home.name == home_name, Home.password == password).fetch()
        if potential_home:
            potential_home[0].occupants.append(user.user_id())
            home_key = potential_home[0].put()
            person.put()
            person.home_key = home_key

            #Share Calendar
            calID = potential_home[0].calendar_id

            #Share calendar with user
            scopes = ['https://www.googleapis.com/auth/calendar']
            credentials = ServiceAccountCredentials.from_json_keyfile_name(
                'service_account.json', scopes=scopes)
            http_auth = credentials.authorize(Http())
            rule = {
                'scope': {
                    'type': 'user',
                    'value': user.email()
                },
                'role': 'reader'
            }

            created_rule = service.acl().insert(
                calendarId=calID, body=rule).execute(http=http_auth)

            logging.info(calID)

            #Update new calendar with events of person who just joined
            #Gets primary calendary ID
            http = decorator.http()
            #Call the service using the authorized Http object.
            now = datetime.datetime.utcnow().isoformat(
            ) + 'Z'  # 'Z' indicates UTC time
            requestResults = service.events().list(
                calendarId='primary',
                timeMin=now,
                singleEvents=True,
                orderBy='startTime').execute(http=http)

            for event in requestResults['items']:
                helpers.addEventToCal(self, event, calID)

            # requestResults = service.events().list(calendarId='primary', timeMin=now, singleEvents=True, orderBy='startTime').execute(http=http)

            # for event in requestResults['items']:
            # 	helpers.addEventToCal(self, event, calID)

            #DONE WITH PASTED CODE

            person.put()
            data = {'home_name': home_name}
            render.render_page_with_data(self, 'successfullyJoinedHome.html',
                                         'Successfully Joined Home', data)
            helpers.redirect(self, '/dashboard', 1000)
        else:
            # REPORT to client to try again. wrong name or password
            data = {
                'error': 'You have entered an incorrect home name or password'
            }
            render.render_page_with_data_no_header(
                self, 'newJoinHome.html', 'Error: Wrong Name or Password',
                data)