Esempio n. 1
0
def create_task(rule):
    response = {'response': 'Pleas enter correct URL'}
    if rule == 'auto':
        date_appearence, content = task_analization.main(request.args.get('content'))
    elif rule == 'manually':
        date_appearence = request.args.get('date_executions')
        content  = request.args.get('content')
    else:
        return json.dumps(response)
    for item in QueryPg(table='users',
                        column='role_id',
                        data={'id': request.args.get('author')}).select():
        for iter in QueryPg(table='role',
                            column='cost',
                            data={'id': item}).select():
            if QueryMongo(collection_type=request.args.get('table_name'),
                          data={
                                  'date_appearance': datetime.now(),
                                  'date_executions': date_appearence,
                                  'cost': iter,
                                  'completed': False,
                                  'content_task': [{
                                      'type': request.args.get('type'),
                                      'content': content
                                  }]}).insert():
                response['response'] = 'success'
    return json.dumps(response)
Esempio n. 2
0
def delete_contact_user():
    response = {'response': 'error'}
    initiator_id = request.args.get('user_id')
    invite_id = request.args.get('friend_id')
    name_box = QueryPg(table='user_contacts', child_name='_' + initiator_id, data={'friend_id': invite_id}).select()
    for item in name_box:
        if QueryPg(table='user_contacts', data={'message_box': item['message_box']}).delete() == 2:
            QueryMongo(collection_type=str(item['message_box']), query_type=0).delete()
            response['response'] = 'success'
    return json.dumps(response)
Esempio n. 3
0
def new_contact_user():
    response = {'response': 'error'}
    initiator_id = request.args.get('user_id')
    invite_id = request.args.get('friend_id')
    name_box = 'message_box_u'+initiator_id+"_u"+invite_id
    if len(QueryPg(table='user_contacts', data={'message_box': name_box}).select()) == 0:
        id_message = QueryMongo(collection_type=name_box, data={mongo_collections['message_box']}).insert()
        QueryMongo(collection_type=name_box, data={"_id": ObjectId(id_message)}).delete()
        QueryPg(table='user_contacts_'+initiator_id, data={'user_id': initiator_id,
                                                           'friend_id': invite_id, 'message_box': name_box}).insert()
        QueryPg(table='user_contacts_'+invite_id, data={'user_id': invite_id,
                                                        'friend_id': initiator_id, 'message_box': name_box}).insert()
        response['response'] = 'success'
    return json.dumps(response)
Esempio n. 4
0
def edit_data_user():
    response = {'response': 'error'}
    user = QueryPg(column=request.args.get('column'), data={'id': request.args.get('id'),
                                                            'new': request.args.get('new')}).update()
    if user:
        response['response'] = 'success'
    return json.dumps(response)
Esempio n. 5
0
def delete_user():
    response = {'response': 'error'}
    user = QueryPg(data={'id': request.args.get('id')}).delete()
    if user > 0:
        QueryMongo(collection_type='task_board_u', name_collection=request.args.get('id'), query_type=0).delete()
        response['response'] = 'success'
    return json.dumps(response)
Esempio n. 6
0
def delete_user_group():
    response = {'response': 'error'}
    if QueryPg(table='group_contacts_',
               child_name=request.args.get('group_id'),
               data={'user_id': request.args.get('user_id')}).delete():
        response['response'] = 'success'
    return json.dumps(response)
Esempio n. 7
0
def add_role():
    response = {'response': 'error'}
    if QueryPg(table='role',
               data={'name': request.args.get('name'),
                     'discription': request.args.get('discription'),
                     'cost': request.args.get('cost')}).insert():
        response['response'] = 'success'
    return json.dumps(response)
Esempio n. 8
0
def update_user_role_group():
    response = {'response': 'error'}
    if QueryPg(table='group_contacts_',
               child_name=request.args.get('group_id'),
               data={'id': request.args.get('id'),
                     'role_id': request.args.get('role_id')},
               column='role_id').update():
        response['response'] = 'success'
    return json.dumps(response)
Esempio n. 9
0
def update_group():
    response = {'response': 'error'}
    if QueryPg(table='groups',
               data={'id': request.args.get('id'),
                     'new': request.args.get('new')},
               column='name')\
            .update():
        response['response'] = 'success'
    return json.dumps(response)
Esempio n. 10
0
def login():
    response = {'response': 'error'}
    user_email = QueryPg(data={'email': request.args.get('username')}, condition='=').select()
    user_tel = QueryPg(data={'tel_number': request.args.get('username')}, condition='=').select()
    if len(user_email) > 0:
        check_list = user_email
    elif len(user_tel) > 0:
        check_list = user_tel
    else:
        check_list = []
    if len(check_list) > 0:
        for item in check_list:
            if (item['email'] == request.args.get('username') or item['tel_number'] == request.args.get('username')) and item['password'] == request.args.get('password'):
                response['response'] = 'user find, her id = ' + str(item['id'])
                contacts = QueryPg(table=item['contacts_list']).select()
                response['contacts'] = contacts_user(contacts)
            else:
                response['response'] = 'false password'
    return json.dumps(response)
Esempio n. 11
0
def new_user_group():
    response = {'response': 'error'}
    data = {}
    for key in pg_tables.values():
        data[key] = request.args.get(key)
    if QueryPg(table='group_contacts_',
               child_name=request.args.get('group_id'),
               data=data).insert():
        response['response'] = 'success'
    return json.dumps(response)
Esempio n. 12
0
def delete_group():
    response = {'response': 'error'}
    group_id = request.args.get('id')
    group = QueryPg(table='groups', data={'id': group_id}).delete()
    if group > 0:
        message_box = QueryMongo(collection_type='message_box_g' + group_id,
                                 query_type=0).delete()
        task_board = QueryMongo(collection_type='task_board_g' + group_id,
                                query_type=0).delete()
        if message_box and task_board:
            response['response'] = 'success'
    return json.dumps(response)
Esempio n. 13
0
def create_user():
    response = {'response': 'error'}
    data = {}
    cr_dict = pg_tables['users']
    if cr_dict.get('id') != None :
        cr_dict.pop('id')
    if cr_dict.get('contacts_list') != None:
        cr_dict.pop('contacts_list')
    if cr_dict.get('tasks_board') != None:
        cr_dict.pop('tasks_board')
    for key in cr_dict:
        if key == 'role_sys_id' or key == 'role_company_id':
            data[key] = int(request.args.get(key))
        elif key == "date_born":
            data[key] = datetime.datetime.strptime(request.args.get(key), "%Y-%m-%d")
        else:
            data[key] = request.args.get(key)
    user_id = QueryPg(data=data).insert()
    task_board = QueryMongo(collection_type="task_board_u" + user_id, data={mongo_collections['task_board']}).insert()
    if task_board:
        print(task_board)
        QueryMongo(collection_type="task_board_u", name_collection=user_id, data={'_id': ObjectId(task_board)}).delete()
        response['response'] = 'succsess'
    return json.dumps(response)
Esempio n. 14
0
def new_group():
    response = {'response': 'error'}
    data = {}
    cr_dict = pg_tables['groups']
    if cr_dict.get('id') !=None :
        cr_dict.pop('id')
    if cr_dict.get('group_contact') !=None :
        cr_dict.pop('group_contact')
    if cr_dict.get('group_message_box') !=None :
        cr_dict.pop('group_message_box')
    for key in cr_dict:
        data[key] = request.args.get(key)
    group_id = QueryPg(table='groups', data=data).insert()
    message_box = QueryMongo(collection_type='message_box_g'+group_id,
                             data={mongo_collections['message_box']}).insert()
    task_board = QueryMongo(collection_type='task_board_g' + group_id,
                            data={mongo_collections['task_board']}).insert()
    if message_box and task_board:
        QueryMongo(collection_type='message_box_g' + group_id,
                   data={'_id': ObjectId(message_box)}).delete()
        QueryMongo(collection_type='task_board_g' + group_id,
                   data={'_id': ObjectId(task_board)}).delete()
        response['response'] = 'success'
    return json.dumps(response)