Esempio n. 1
0
 def getShout(self,_key):
     shout = Shout().get(_key)
     if shout == None:
         raise KnownError(["Shout does not exist"])        
     if not(shout.google_id == users.get_current_user().user_id()):
         raise KnownError(["You are accessing a shout you do not have access to."])
     return shout    
Esempio n. 2
0
 def getFriend(self, _key, _error):
     friend = Friend().get(_key)
     if friend == None:
         raise KnownError(["Friend does not exist"])
     if not (friend.google_id == users.get_current_user().user_id()):
         raise KnownError([_error])
     return friend
Esempio n. 3
0
 def doesFriendExist(self, _friend_name, _friend_id):
     '''
     If they use an e-mail, then check for e-mail
     Otherwise just check name
     '''
     if not (_friend_id == ''):
         #someone already a friend
         q2 = self.all()
         q2.filter("google_id = ", users.get_current_user().user_id())
         q2.filter("request_to_email = ", _friend_id.lower())
         for friend in q2.run(limit=1):
             if friend.is_deleted:
                 friend.friend_name = _friend_name
                 friend.is_deleted = False
                 friend.put()
                 raise KnownError([
                     "Your deleted friend has been re-activated. No previous shouts are available for viewing.  Refresh browser immediately!"
                 ])
             else:
                 raise KnownError([
                     "You already have a friend (or sent request) for this name (%s) and email (%s)."
                     % (friend.friend_name, friend.request_to_email)
                 ])
         #a friend request from the same person
         q3 = self.all()
         q3.filter("friend_id = ", users.get_current_user().email().lower())
         q3.filter("request_from_email = ", _friend_id.lower())
         for friend in q3.run(limit=1):
             raise KnownError([
                 "You have a friend request for this name (%s) and email (%s)."
                 % (friend.request_from_name, friend.request_from_email)
             ])
             q1 = self.all()
     else:
         #No email address, so check name
         q1 = self.all()
         q1.filter("google_id = ", users.get_current_user().user_id())
         q1.filter("friend_name = ", _friend_name)
         for friend in q1.run(limit=1):
             #someone of the same name
             if friend.is_deleted:
                 if friend.friend_id == '':
                     logging.info("Create a new blank friend - who cares")
                 else:
                     raise KnownError([
                         "You have a deleted friend by this name (%s), with email %s. Either rename or re-activate friend using email as well."
                         % (friend.friend_name, friend.request_to_email)
                     ])
             else:
                 raise KnownError([
                     "You already have a friend by this name (%s)" %
                     _friend_name
                 ])
Esempio n. 4
0
 def getAdministratorByUrl(self, url):
     query = Administrator.all()
     query.filter("friendly_url = ", url)
     result = query.fetch(1)
     if len(result) > 1:
         raise KnownError(['There are multiple sites with the same url'])
     elif len(result) == 1:
         return result[0]
     else:
         raise KnownError([
             'There is no site for the url you are viewing.  Please check the url.'
         ])
Esempio n. 5
0
 def get_list(self, key):
     try:
         ls = self.get(key)
     except:
         raise KnownError(['You are trying to fetch a list that does not exist'])
     if ls.private:
         try:
             if ls.google_id <> users.get_current_user().user_id():
                 raise KnownError(['You do not have access to that list.'])
         except:
             raise KnownError(['Not available to you'])
     return ls.toDict()
Esempio n. 6
0
    def delete_list(self, key):
        try:
            ls = self.get(key)
        except:
            raise KnownError(['You are trying to delete a list that does not exist'])

        try:
            if ls.google_id <> users.get_current_user().user_id():
                raise KnownError(['You do not have access to that list.'])
        except:
            raise KnownError(['You do not have access to that list to delete'])
        ls.delete()
        return {"success":True}
Esempio n. 7
0
    def save_entry(self, items):
        '''
        Only save or deleting
        no updating
        '''
        errors = []
        self.google_id = users.get_current_user().user_id()
        new_item = items['task'].strip()
        if new_item == '': errors.append('Must enter a value for task')
        self.task = new_item

        try:
            self.minutes = int(items['minutes'])
        except:
            errors.append('Minutes must be an integer')

        try:
            self.date = convertToDate(items['date'])
        except:
            errors.append('Invalid date format - yyyy-mm-dd')

        if items['add'] == 'yes':
            Person().updateTimesheetTask(new_item)

        if len(errors) > 0: raise KnownError(errors)
        self.createNew()
        return str(self.key())
Esempio n. 8
0
    def update_timsheet(self, items):
        '''
        only updating task currently
        '''
        new_task = items['task'].strip()
        current_key = items['key'].strip()

        errors = self.validate_task(new_task)

        ts = self.get(current_key)
        if users.get_current_user().user_id() <> ts.google_id:
            errors.append('This is not your task to update')
        ts.task = new_task

        try:
            ts.minutes = int(items['minutes'])
        except:
            errors.append('Minutes must be an integer')
        try:
            ts.date = convertToDate(items['date'])
        except:
            errors.append('Invalid date format - yyyy-mm-dd')

        if len(errors) > 0: raise KnownError(errors)

        ts.update()
Esempio n. 9
0
    def createOrUpdate(self, request):
        '''
        Creates admin basic record and puts into the datastore
        '''
        logging.debug("Creating a %s admin record" %
                      (users.get_current_user().user_id()))

        query = Administrator.all()
        query.filter("google_id = ", users.get_current_user().user_id())
        result = query.fetch(10)
        if len(result) > 1:
            raise KnownError([
                "User %s has multiple entries..." %
                users.get_current_user().email()
            ])
        elif len(result) == 1:
            result[0].updateFieldsFromPost(request)
            result[0].booking_email = users.get_current_user().email()
            result[0].update()
            return {"saved": "Admin details updated"}
        else:
            admin = Administrator()
            admin.google_id = users.get_current_user().user_id()
            admin.updateFieldsFromPost(request)
            admin.booking_email = users.get_current_user().email()
            admin.createNew()
            return {"saved": "Admin details created"}
Esempio n. 10
0
 def delete_list(self, list_of_items):
     ts = self.get(list_of_items)
     for x in ts:
         if users.get_current_user().user_id() <> x.google_id:
             raise KnownError(
                 'One or more of the documents are not yours to delete!')
         x.delete()
Esempio n. 11
0
 def rejectFriendRequest(self, _key):
     #Check that it is a friend request FOR ME before removing
     friend = Friend().get(_key)
     if not (friend.friend_id == users.get_current_user().email().lower()):
         raise KnownError(['Not a valid friend request to cancel.'])
     self.clearFriendRequest(friend)
     friend.update()
     return {}
Esempio n. 12
0
 def addName(self, new_name):
     '''
     The premise for this code logic is
     1. User cannot change their name
     2. Checks for name in all existing users
     '''
     person = self.getCurrentPerson()
     if person.name <> "": raise KnownError(["Already has a name (%s)" % person.name])
     if new_name=='': raise KnownError(["You must enter the persons name"])
     
     #check for duplicate names
     query=Person.all()
     query.filter("name = ", new_name)
     result=query.fetch(10)
     if len(result)>0:raise KnownError(["Name already exists, please chose another"])        
     
     #do the update
     person.name=new_name
     person.update()        
Esempio n. 13
0
 def acceptFriendRequest(self, _key):
     #Check that it is a friend request FOR ME before accepting
     friend = Friend().get(_key)
     if not (friend.friend_id == users.get_current_user().email().lower()):
         raise KnownError(['Not a valid friend request to accept.'])
     response = self.createFromRequest(friend)
     friend.is_request = False
     friend.friend_id = users.get_current_user().user_id()
     friend.update()
     return response
Esempio n. 14
0
 def getPerson(self):
     query = self.all()
     query.filter("google_id = ", self.google_id)
     result = query.fetch(10)
     if len(result) > 1:
         raise KnownError([
             "User %s has multiple entries..." %
             users.get_current_user().email()
         ])
     elif len(result) == 1:
         person = result[0]
     else:
         person = Person(google_id=self.google_id)
         person.createNew()
     return person
Esempio n. 15
0
 def save_list(self, form):
     '''
     TO-DO Check the data in the backend
     '''
     errors=[]
     self.google_id=users.get_current_user().user_id()
     self.name = form['name']
     self.name_index1 = form['name'].lower()[0:3]
     self.description = form['description']
     self.items = form['items']
     self.private = form['private']
     
     if len(errors)>0: raise KnownError(errors)
     
     self.createNew()
     
     return True
Esempio n. 16
0
    def update_list(self, form):
        '''
        TO-DO Check the data in the backend
        '''
        
        ls = self.get(form['loaded_id'])
        if users.get_current_user().user_id()<>ls.google_id:
            raise KnownError(['Cannot update because you are not the owner of this list'])  
        
        ls.name = form['name']
        ls.name_index1 = form['name'].lower()[0:3]
        ls.description = form['description']
        ls.items = form['items']
        ls.private = form['private']

        ls.update()
        
        return True
Esempio n. 17
0
 def getPersonByGoogleId(self, googleId):
     '''
     Retrieves the person based on their google ID
     If the person does not exist, then returns None
     '''
     query=Person.all()
     query.filter("google_id = ", googleId)
     result=query.fetch(10)
     if len(result)>1:
         raise KnownError(["User %s has multiple entries..." % users.get_current_user().email()])
     elif len(result)==1:
         return result[0]
     else:
         person = Person()
         person.name="";
         person.google_id=users.get_current_user().user_id()
         person.google_email=users.get_current_user().email()
         person.createNew() 
         return person    
Esempio n. 18
0
 def checkErrorBeforeRaising(self, _error, _friend):
     if _friend.is_deleted:
         _friend.is_deleted = False
         _friend.put()
     else:
         raise KnownError([_error])
Esempio n. 19
0
 def updateField(self, field_name, field_value):
     if field_name=='name':
         self.addName(field_value)
     else:
         KnownError(["Attempting to update invalid field (%s)" % field_name])