Exemplo n.º 1
0
def post_back_to_external_events():
    if request.method == "POST":
        event_data = request.get_data('data')
        event_json = Utils.bytes_to_json(event_data)
        TaskObjectBuilder.build_task(PlacedTask.get_task(
            event_json["id"])).save_to_db()
        PlacedTask.remove_placed_task(event_json["id"])
        return render_template("FullCalendar.html")
Exemplo n.º 2
0
def pull_from_teamwork():
    List.clear_task_list()
    TaskObjectBuilder.build_list(
        TaskObjectBuilder.get_from_teamwork(T.tasks, T.tasks_name))
    tsks = List.task_list
    for task in tsks:
        if not DatabaseChecker.does_task_exist_in_db(task):
            if not DatabaseChecker.does_placed_task_exist_in_db(task):
                task.save_to_db()
        elif DatabaseChecker.has_task_been_updated(task):
            # write an update method
            task.update_in_db()
Exemplo n.º 3
0
def pull_from_teamwork():
    List.clear_task_list()
    company = Database.find_one(CompanyConstants.COLLECTION,
                                {"_id": session["company_id"]})

    TaskObjectBuilder.build_list(
        TaskObjectBuilder.get_from_teamwork_scaled(T.tasks, T.tasks_name,
                                                   session["company_name"],
                                                   company["key"]))
    tsks = List.task_list
    for task in tsks:
        if not DatabaseChecker.does_task_exist_in_db(task):
            if not DatabaseChecker.does_placed_task_exist_in_db(task):
                task.save_to_db()
        elif DatabaseChecker.has_task_been_updated(task):
            # write an update method
            task.update_in_db()
Exemplo n.º 4
0
def pull_data_from_api():
    pull_from_teamwork()
    company = Database.find_one(CompanyConstants.COLLECTION,
                                {"_id": session["company_id"]})
    List.clear_task_list()
    TaskObjectBuilder.build_completed_list(
        TaskObjectBuilder.get_from_teamwork_scaled(T.completed_tasks,
                                                   T.completed_tasks_name,
                                                   session["company_name"],
                                                   company["key"]))
    ts = List.task_list
    for task in ts:
        if DatabaseChecker.does_task_exist_in_db(task):
            task.delete_from_db()
        elif DatabaseChecker.does_placed_task_exist_in_db(task):
            PlacedTask.remove_placed_task(task.task_id)
    return render_template("FullCalendar.html")
Exemplo n.º 5
0
 def update_users(company_name, company_key, company_id):
     people = TaskObjectBuilder.get_from_teamwork_scaled(CompanyConstants.people_action,
                                                         CompanyConstants.people_name,
                                                         company_name, company_key)
     for person in people:
         user = Database.find_one(UserConstants.COLLECTION, {"_id": int(person["id"])})
         if user is None:
             usr = User(person["id"], person["user-name"], "", company_id)
             usr.save_to_db()
Exemplo n.º 6
0
 def create_users(company_name, company_key, company_id):
     people = TaskObjectBuilder.get_from_teamwork_scaled(CompanyConstants.people_action,
                                                         CompanyConstants.people_name,
                                                         company_name, company_key)
     for person in people:
         user_name = person["user-name"]
         _id = person["id"]
         pin = ""
         user = User(_id, user_name, pin, company_id)
         user.save_to_db()
Exemplo n.º 7
0
def update_task():
    if request.method == "POST":
        event_data = request.get_data('data')
        event_json = Utils.bytes_to_json(event_data)
        print(event_json)
        task = TaskObjectBuilder.build_placed_task(
            PlacedTask.get_task(event_json["id"]), event_json["start"],
            event_json["end"], session["user_id"])
        task.update_task()
        return render_template("FullCalendar.html")
Exemplo n.º 8
0
 def create_user_id_list(company_name, company_key):
     people = TaskObjectBuilder.get_from_teamwork_scaled(CompanyConstants.people_action,
                                                         CompanyConstants.people_name,
                                                         company_name, company_key)
     user_ids = []
     for person in people:
         user_name = person["user-name"]
         _id = person["id"]
         pin = ""
         user_ids.append(_id)
     return user_ids
Exemplo n.º 9
0
def post_request():
    if request.method == "POST":
        event_data = request.get_data('data')
        event_json = Utils.bytes_to_json(event_data)
        task = TaskObjectBuilder.build_placed_task(
            Task.get_task(event_json["id"]), event_json["start"],
            event_json["end"], session["user_id"])
        task.save_placed_task()
        Task.remove_task(event_json["id"])
        # add to db.placed_tasks here
        # delete from db.External_tasks using the id
        return render_template("FullCalendar.html")
Exemplo n.º 10
0
    def register_company(company_name, company_password, key):
        company_data = Database.find_one(COLLECTION, {"company_name": company_name, "key": key})

        # needs to catch JSON decoder error and return invalid company name and key
        account = TaskObjectBuilder.get_from_teamwork_scaled(CompanyConstants.account_action,
                                                             CompanyConstants.account_name,
                                                             company_name, key)
        people = Company.create_user_id_list(company_name, key)
        if company_data is not None:
            return "already registered"

        elif "companyid" in account.keys():
            _id = account["companyid"]
            company = Company(_id, company_name, Utils.hash_password(company_password), key, people)
            company.save_to_db()
            Company.create_users(company_name, company_data["key"], _id)
            return "company registered"
        else:
            return "invalid company name or API key"