code: def __get_activity_by_name(self, name, category_id = None, resurrect = True):
          
  
          if category_id:
              query = """
                         SELECT a.id, a.name, a.deleted, coalesce(b.name, ?) as category
                           FROM activities a
                      LEFT JOIN categories b ON category_id = b.id
                          WHERE lower(a.name) = lower(?)
                            AND category_id = ?
                       ORDER BY a.deleted, a.id desc
                          LIMIT 1
              """
  
              res = self.fetchone(query, (self._unsorted_localized, name, category_id))
          else:
              query = """
                         SELECT a.id, a.name, a.deleted, coalesce(b.name, ?) as category
                           FROM activities a
                      LEFT JOIN categories b ON category_id = b.id
                          WHERE lower(a.name) = lower(?)
                       ORDER BY a.deleted, a.id desc
                          LIMIT 1
              """
              res = self.fetchone(query, (self._unsorted_localized, name, ))
  
          if res:
              keys = ('id', 'name', 'deleted', 'category')
              res = dict([(key, res[key]) for key in keys])
              res['deleted'] = res['deleted'] or False
  
              # if the activity was marked as deleted, resurrect on first call
              # and put in the unsorted category
              if res['deleted'] and resurrect:
                  update = """
                              UPDATE activities
                                 SET deleted = null, category_id = -1
                               WHERE id = ?
                          """
                  self.execute(update, (res['id'], ))
  
              return res
  
          return None
docs: get most recent, preferably not deleted activity by it's name