Example #1
0
def create(sender, instance, **kwargs):
    if instance.is_new:
        profile = Profile(user=instance)
        profile.token = uuid.uuid4()
        profile.save()
        msg = Msg(user=instance)
        msg.save()
Example #2
0
def create(sender, instance, **kwargs):
	if instance.is_new:
		profile = Profile(user = instance)
		profile.token = uuid.uuid4()
		profile.save()
		msg = Msg(user=instance)
		msg.save()
Example #3
0
def add_to_database(userText):
    data_list = userText.split(',')
    check_float_list = list(map(isfloat, data_list))
    if sum(check_float_list[0:2]) != 0 or sum(check_float_list[2:]) != 2:
        return "Error input data is not valid"
    else:
        profile = Profile(name=data_list[0],
                          occupation=data_list[1],
                          experience=data_list[2],
                          salary=data_list[3])
        db.session.add(profile)
        db.session.commit()
        return 'Thanks Data is Added to local!'
def user_with_profile(db):
    """ Creates a user with a profile with a username and bio """
    from my_app.models import User, Profile
    user = User(firstname='Person', lastname='Three', email='*****@*****.**')
    user.profile = Profile(username='******',
                           bio="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ac tempor metus. "
                               "Aenean mattis, tortor fringilla iaculis pharetra, dui justo imperdiet turpis, "
                               "at faucibus risus eros vitae dui. Nam finibus, nibh eu imperdiet feugiat, nisl lacus "
                               "porta tellus, a tincidunt nibh enim in urna. Aliquam commodo volutpat ligula at "
                               "tempor. In risus mauris, commodo id mi non, feugiat convallis ex. Nam non odio dolor. "
                               "Cras egestas mollis feugiat. Morbi ornare laoreet varius. Pellentesque fringilla "
                               "convallis risus, sit amet laoreet metus interdum et.")
    user.set_password('password3')
    db.session.add(user)
    db.session.commit()
    return user
Example #5
0
def create_profile():
    form = ProfileForm()
    if request.method == 'POST' and form.validate_on_submit():
        # Set the filename for the photo to None, this is the default if the user hasn't chosen to add a profile photo
        filename = None
        # Check if the form contains a photo (photo is the field name we used in the ProfileForm class)
        if 'photo' in request.files:
            # As long as the filename isn't empty then save the photo
            if request.files['photo'].filename != '':
                # Save the photo using the global variable photos to get the location to save to
                filename = photos.save(request.files['photo'])
        # Build a new profile to be added to the database based on the fields in the form
        # Note that the area.data is an object and we want to access the area property of the object
        p = Profile(area=form.area.data.area, username=form.username.data, photo=filename, bio=form.bio.data,
                    user_id=current_user.id)
        db.session.add(p)  # Add the new Profile to the database session
        db.session.commit()  # Saves the new Profile to the database
        return redirect(url_for('community.display_profiles', username=p.username))
    return render_template('profile.html', form=form)
 def setUp(self):
     db.session.commit()
     db.drop_all()
     db.create_all()
     # Add the local authority data to the database (this is a workaround you don't need this for your coursework!)
     csv_file = Path(__file__).parent.parent.joinpath(
         "data/household_recycling.csv")
     df = pd.read_csv(csv_file, usecols=['Code', 'Area'])
     df.drop_duplicates(inplace=True)
     df.set_index('Code', inplace=True)
     df.to_sql('area', db.engine, if_exists='replace')
     # Add a user and profile to the database
     u = User(firstname='TestFirstname1',
              lastname='TestLastname1',
              email='*****@*****.**')
     u.set_password('test1')
     p = Profile(username='******',
                 bio='Something about test1.',
                 area='Barnet',
                 user_id=u.id)
     u.profiles.append(p)
     db.session.add(u)
     db.session.commit()
Example #7
0
def create_app(config_classname):
    """
    Initialise and configure the Flask application.
    :type config_classname: Specifies the configuration class
    :rtype: Returns a configured Flask object
    """
    app = Flask(__name__)
    app.config.from_object(config_classname)

    db.init_app(app)
    login_manager.login_view = 'auth.login'
    login_manager.init_app(app)
    #csrf.init_app(app)
    configure_uploads(app, photos)

    with app.app_context():
        from my_app.models import User, Profile, Area
        db.create_all()

        # Add the local authority data to the database (this is a workaround you don't need this for your coursework!)
        csv_file = Path(__file__).parent.parent.joinpath(
            "data/household_recycling.csv")
        df = pd.read_csv(csv_file, usecols=['Code', 'Area'])
        df.drop_duplicates(inplace=True)
        df.set_index('Code', inplace=True)
        df.to_sql('area', db.engine, if_exists='replace')

        # Add sample data for the REST API exercise
        u = User.query.first()
        if u is None:
            p1 = Profile(username='******',
                         bio='something about me',
                         area='Barnet')
            p2 = Profile(username='******',
                         bio='something interesting',
                         area='Barnet')
            u1 = User(firstname='Jo',
                      lastname='Bloggs',
                      email='*****@*****.**',
                      profiles=[p1])
            u2 = User(firstname='Fred',
                      lastname='Smith',
                      email='*****@*****.**',
                      profiles=[p2])
            u3 = User(firstname='Santa',
                      lastname='Claus',
                      email='*****@*****.**')
            u4 = User(firstname='Robert',
                      lastname='Plant',
                      email='*****@*****.**')
            u1.set_password('test')
            u2.set_password('test')
            u3.set_password('test')
            u4.set_password('test')
            db.session.add_all([u1, u2, u3, u4])
            db.session.commit()

        from dash_app.dash import init_dashboard
        app = init_dashboard(app)

    from my_app.main.routes import main_bp
    app.register_blueprint(main_bp)

    from my_app.community.routes import community_bp
    app.register_blueprint(community_bp)

    from my_app.auth.routes import auth_bp
    app.register_blueprint(auth_bp)

    from my_app.api.routes import api_bp
    app.register_blueprint(api_bp)

    return app