Esempio n. 1
0
    def take_job(self, job_id):
        from Items import Job

        user_jobs = Job.get_by_user_id(self.user_id)
        if any([job_id == job.job_id for job in user_jobs]):
            return False
        job = Job.get_by_id(job_id)

        if job is None:
            return False

        query("INSERT INTO user_jobs (user_id, job_id) VALUES (?, ?)",
              [self.user_id, job_id])

        return True
Esempio n. 2
0
 def __init__(self):
     self.username = session.get("username", None)
     self.tasks_progress = None
     self.data = None
     if self.username is not None:
         self.data = query("SELECT * FROM users WHERE username = ?",
                           [self.username],
                           one=True)
         self.user_id = self.data['user_id']
Esempio n. 3
0
    def get_user_status_by_task_id(task_id):
        user = User()
        props = query(
            "SELECT * FROM user_status WHERE task_id = ? AND user_id = ?",
            [task_id, user.user_id],
            one=True)
        if props is None:
            return False

        return Status(props)
Esempio n. 4
0
 def get_by_id(task_id):
     props = query("SELECT * FROM tasks WHERE task_id = ?", [task_id],
                   one=True)
     return Task(props)
Esempio n. 5
0
 def get_by_job_id(job_id):
     props = query("SELECT * FROM tasks WHERE job_id = ?", [job_id])
     return map(Task, props)
Esempio n. 6
0
 def get_by_user_id(user_id):
     all_props = query(
         "SELECT j.* FROM jobs as j INNER JOIN user_jobs as uj ON (j.job_id = uj.job_id) WHERE uj.user_id=?",
         [user_id])
     return [Job(prop) for prop in all_props]
Esempio n. 7
0
 def get_all_jobs():
     all_props = query("SELECT * FROM jobs")
     return map(Job, all_props)
Esempio n. 8
0
 def get_by_id(job_id):
     props = query("SELECT * FROM jobs WHERE job_id = ?", [job_id],
                   one=True)
     return Job(props)
Esempio n. 9
0
 def get_all_store_items():
     props = query("SELECT * FROM store_items")
     return map(Store, props)
Esempio n. 10
0
 def get_examples_by_task_id(task_id):
     props = query("SELECT * FROM examples WHERE task_id = ?", [task_id])
     return map(Example, props)
Esempio n. 11
0
 def drop_job(self, job_id):
     query("DELETE FROM user_jobs WHERE user_id = ? AND job_id = ?",
           [self.user_id, job_id])
Esempio n. 12
0
 def add_user(username, password):
     query("INSERT INTO users (username, password) VALUES (?, ?)",
           [username, password])
Esempio n. 13
0
 def username_exists(username):
     return len(query("SELECT * FROM users WHERE username= ?",
                      [username])) > 0
Esempio n. 14
0
 def verify_login(username, password):
     return len(
         query("SELECT * FROM users WHERE username= ? AND password= ?",
               [username, password])) == 1