Пример #1
0
def insert_user_departments():
    users = User.list()
    department_A = Department.find(id=60430)
    department_B = Department.find(id=60350)
    for user in users:
        user.departments.append(department_A)
        user.departments.append(department_B)

    print 'associated users with departments'
Пример #2
0
def insert_user_departments():
    users = User.list()
    department_A = Department.find(id=60430)
    department_B = Department.find(id=60350)
    for user in users:
        user.departments.append(department_A)
        user.departments.append(department_B)

    print 'associated users with departments'
Пример #3
0
def insert_departments():
    reader = csv.reader(open(os.path.join(__location__, 'departments.csv')),
                        delimiter=',',
                        quotechar='"')
    for row in reader:
        if Department.find(name=row[0]) is None:
            department = Department(name=row[0], id=row[1])

            department.save()

            parent = Department.find(id=row[2])

            if parent is not None:
                parent.children.append(department)

    print 'inserted departments.'
Пример #4
0
def insert_departments():
    reader = csv.reader(open(os.path.join(__location__, 'departments.csv')), delimiter=',', quotechar='"')
    for row in reader:
        if Department.find(name=row[0]) is None:
            department = Department(
                name=row[0],
                id=row[1]
            )

            department.save()

            parent = Department.find(id=row[2])

            if parent is not None:
                parent.children.append(department)

    print 'inserted departments.'
Пример #5
0
    def put(self, id):
        json = request.json['user']
        print json
        user = UserModel.find(id=id)
        user.email = json['email']
        user.role = json['role']
        user.employee_id = json['employee_id']
        user.status = json['status']
        user.departments = []
        for department in json['departments']:
            user.departments.append(Department.find(id=department['id']))


        user.save()

        departments = []
        for department in user.departments:
            departments.append({
                'id': department.id,
                'parent_id': department.parent_id,
                'name': department.name,
                'description': department.description
            })

        work_orders = []
        for work_order in current_user.work_orders:
            work_orders.append({
                'id': work_order.id,
                'department': work_order.department_id,
                'user': work_order.user_id,
                'asset': work_order.asset_id
            })

        model = {
            'user': {
                'id': user.id,
                'user_id': user.id,
                'firstname': user.firstname,
                'lastname': user.lastname,
                'email': user.email,
                'username': user.username,
                'employee_id': user.employee_id,
                'status': user.status,
                'role': user.role,
                'departments': departments,
                'work_orders': work_orders
            }
        }

        return jsonify(model)
Пример #6
0
    def put(self, id):
        json = request.json['user']
        print json
        user = UserModel.find(id=id)
        user.email = json['email']
        user.role = json['role']
        user.employee_id = json['employee_id']
        user.status = json['status']
        user.departments = []
        for department in json['departments']:
            user.departments.append(Department.find(id=department['id']))

        user.save()

        departments = []
        for department in user.departments:
            departments.append({
                'id': department.id,
                'parent_id': department.parent_id,
                'name': department.name,
                'description': department.description
            })

        work_orders = []
        for work_order in current_user.work_orders:
            work_orders.append({
                'id': work_order.id,
                'department': work_order.department_id,
                'user': work_order.user_id,
                'asset': work_order.asset_id
            })

        model = {
            'user': {
                'id': user.id,
                'user_id': user.id,
                'firstname': user.firstname,
                'lastname': user.lastname,
                'email': user.email,
                'username': user.username,
                'employee_id': user.employee_id,
                'status': user.status,
                'role': user.role,
                'departments': departments,
                'work_orders': work_orders
            }
        }

        return jsonify(model)
Пример #7
0
    def post(self):
        json = request.json['user']

        user = UserModel(firstname=json['firstname'],
                         lastname=json['lastname'],
                         email=json['email'],
                         username=json['firstname'] + '.' + json['lastname'],
                         employee_id=json['employee_id'],
                         status=json['status'],
                         password=''.join(
                             random.choice(string.ascii_uppercase +
                                           string.digits) for _ in range(12)),
                         role=json['role'])

        for department in json['departments']:
            user.departments.append(Department.find(id=department['id']))

        user.save()

        departments = []
        for department in user.departments:
            departments.append({
                'id': department.id,
                'parent_id': department.parent_id,
                'name': department.name,
                'description': department.description
            })

        model = {
            'user': {
                'id': user.id,
                'user_id': user.id,
                'firstname': user.firstname,
                'lastname': user.lastname,
                'email': user.email,
                'username': user.username,
                'employee_id': user.employee_id,
                'status': user.status,
                'role': user.role,
                'departments': departments
            }
        }
        print model
        return jsonify(model), 201
Пример #8
0
    def post(self):
        json = request.json['user']

        user = UserModel(
            firstname=json['firstname'],
            lastname=json['lastname'],
            email=json['email'],
            username=json['firstname'] + '.' + json['lastname'],
            employee_id=json['employee_id'],
            status=json['status'],
            password=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(12)),
            role=json['role']
        )

        for department in json['departments']:
            user.departments.append(Department.find(id=department['id']))

        user.save()

        departments = []
        for department in user.departments:
            departments.append({
                'id': department.id,
                'parent_id': department.parent_id,
                'name': department.name,
                'description': department.description
            })

        model = {
            'user': {
                'id': user.id,
                'user_id': user.id,
                'firstname': user.firstname,
                'lastname': user.lastname,
                'email': user.email,
                'username': user.username,
                'employee_id': user.employee_id,
                'status': user.status,
                'role': user.role,
                'departments': departments
            }
        }
        print model
        return jsonify(model), 201