Beispiel #1
0
 def test_edit_user(self):
     """Test for edit user function."""
     guid = add_user(**self.user_to_add)
     edited_data = dict(name='Akbar Gumbira',
                        email='*****@*****.**',
                        website='http://www.akbargumbira.com',
                        role=2,
                        email_updates='true',
                        latitude=-6.32,
                        longitude=102.03)
     guid = edit_user(guid, **edited_data)
     user = get_user(guid)
     for key in edited_data:
         if key != 'email_updates':
             self.assertEqual(edited_data[key], user[key])
     self.assertEqual(user['email_updates'], 1)
 def test_edit_user(self):
     """Test for edit user function."""
     guid = add_user(**self.user_to_add)
     edited_data = dict(
         name='Akbar Gumbira',
         email='*****@*****.**',
         website='http://www.akbargumbira.com',
         role=2,
         email_updates='true',
         latitude=-6.32,
         longitude=102.03)
     guid = edit_user(guid, **edited_data)
     user = get_user(guid)
     for key in edited_data:
         if key != 'email_updates':
             self.assertEqual(edited_data[key], user[key])
     self.assertEqual(user['email_updates'], 1)
Beispiel #3
0
def edit_user_controller():
    """Controller to edit a user.

    Handle post request via ajax and edit the user to the user.db

    :returns: A new json response containing status of editing
    :rtype: HttpResponse
    """
    # return any errors as json - see http://flask.pocoo.org/snippets/83/
    for code in default_exceptions.iterkeys():
        APP.error_handler_spec[None][code] = make_json_error

    # Get data from form
    guid = str(request.form['guid'])
    name = str(request.form['name']).strip()
    email = str(request.form['email']).strip()
    website = str(request.form['website'])
    role = int(request.form['role'])
    email_updates = str(request.form['email_updates'])
    latitude = str(request.form['latitude'])
    longitude = str(request.form['longitude'])

    # Validate the data:
    message = {}
    if not is_required_valid(name):
        message['name'] = 'Name is required'
    if not is_email_address_valid(email):
        message['email'] = 'Email address is not valid'
    if not is_required_valid(email):
        message['email'] = 'Email is required'
    if role not in [0, 1, 2]:
        message['role'] = 'Role must be checked'
    elif not is_boolean(email_updates):
        message['email_updates'] = 'Notification must be checked'

    # Modify the data:
    if email_updates == 'true':
        email_updates = True
    else:
        email_updates = False

    if len(website.strip()) != 0 and 'http' not in website:
        website = 'http://%s' % website

    # Process data
    if len(message) != 0:
        message['type'] = 'Error'
        return Response(json.dumps(message), mimetype='application/json')
    else:
        # Edit User
        guid = edit_user(
            guid=guid,
            name=name,
            email=email,
            website=website,
            role=int(role),
            email_updates=bool(email_updates),
            latitude=float(latitude),
            longitude=float(longitude))

    edited_user = get_user(guid)
    #noinspection PyUnresolvedReferences
    edited_user_json = render_template('json/user.json', user=edited_user)
    #noinspection PyUnresolvedReferences
    edited_user_popup_content = render_template(
        'html/user_info_popup_content.html', user=edited_user
    )
    edited_user_response = dict()
    edited_user_response['edited_user'] = edited_user_json
    edited_user_response['edited_user_popup'] = edited_user_popup_content
    # Return Response
    return Response(
        json.dumps(edited_user_response),
        mimetype='application/json')
Beispiel #4
0
def edit_user_controller():
    """Controller to edit a user.

    Handle post request via ajax and edit the user to the user.db

    :returns: A new json response containing status of editing
    :rtype: HttpResponse
    """
    # return any errors as json - see http://flask.pocoo.org/snippets/83/
    for code in default_exceptions.iterkeys():
        APP.error_handler_spec[None][code] = make_json_error

    # Get data from form
    guid = str(request.form['guid'])
    name = str(request.form['name']).strip()
    email = str(request.form['email']).strip()
    website = str(request.form['website'])
    role = int(request.form['role'])
    email_updates = str(request.form['email_updates'])
    latitude = str(request.form['latitude'])
    longitude = str(request.form['longitude'])

    # Validate the data:
    message = {}
    if not is_required_valid(name):
        message['name'] = 'Name is required'
    if not is_email_address_valid(email):
        message['email'] = 'Email address is not valid'
    if not is_required_valid(email):
        message['email'] = 'Email is required'
    if role not in [0, 1, 2]:
        message['role'] = 'Role must be checked'
    elif not is_boolean(email_updates):
        message['email_updates'] = 'Notification must be checked'

    # Modify the data:
    if email_updates == 'true':
        email_updates = True
    else:
        email_updates = False

    if len(website.strip()) != 0 and 'http' not in website:
        website = 'http://%s' % website

    # Process data
    if len(message) != 0:
        message['type'] = 'Error'
        return Response(json.dumps(message), mimetype='application/json')
    else:
        # Edit User
        guid = edit_user(guid=guid,
                         name=name,
                         email=email,
                         website=website,
                         role=int(role),
                         email_updates=bool(email_updates),
                         latitude=float(latitude),
                         longitude=float(longitude))

    edited_user = get_user(guid)
    #noinspection PyUnresolvedReferences
    edited_user_json = render_template('json/user.json', user=edited_user)
    #noinspection PyUnresolvedReferences
    edited_user_popup_content = render_template(
        'html/user_info_popup_content.html', user=edited_user)
    edited_user_response = dict()
    edited_user_response['edited_user'] = edited_user_json
    edited_user_response['edited_user_popup'] = edited_user_popup_content
    # Return Response
    return Response(json.dumps(edited_user_response),
                    mimetype='application/json')