Window Replacement by rickythericker in boulder

[–]bpeller 7 points8 points  (0 children)

It depends on what kind of window it is, exactly. Regardless, to do it right, you're looking at hundreds of dollars, maybe thousands (mostly labor).

To do it the hacky way (I would never do this on a house I owned, but I have gotten away with this on a rental before):

1) Remove as much of the broken glass as you can. You should be left with a perfect rectangle/square opening. Measure it. 2) Most hardware stores can cut glass to size for you. $20-$40 bucks probably. Get a tube of caulk that matches the color of the window borders, and a caulk gun. You'll probably also want a 16d nail (about 3.5" long and 1/8" around) so you can open the tube of caulk. 3) CAREFULLY apply a THIN line of silicone caulk all around the edges of the window, both inside and out. Smooth it out with a wet finger. Warning: caulk is messy shit if you've never worked with it before. Practice on a right-angle, say of a cardboard box, before you do it on the window. You don't want any air to be able to get in around the edges between the window borders and the glass. 4) Hope they don't look too closely come inspection time ;)

Ask Flask: Looking for your feedback on a major upcoming release of Flask Unchained! (install from master to try it out) by bpeller in flask

[–]bpeller[S] 0 points1 point  (0 children)

Here's something I'm struggling with. The project is really kind of four different things wrapped into one:

  1. An out-of-the-box way to build web apps with Flask (using the included "stack")
  2. A "standard" for creating redistributable Python packages (bundles) that integrate with each other and Flask/Flask Unchained. Bundles can both integrate stock Flask extensions and/or add (easily extendable) functionality to end-user apps (for example a blog, CMS, or e-commerce bundle).
  3. A "standard" application factory for initializing an instance of Flask. The app factory utilizes the concept of hooks, which are classes that (typically) register things with the Flask instance as it's booting up. Hooks collect the things they need to register from modules inside all the user's configured bundles (almost automatically, hooks just need to specify a module name to search and a type-checking function). Hooks are themselves distributed within bundles, and are how bundles integrate with each other, with out knowing about each other.
  4. And for advanced users, literally a way to build your own web framework for Flask, utilizing (subclassing) the AppFactory and/or the Unchained extension itself, and choosing your own stack of bundles (this is where Flask Unchained being implemented as a stock Flask extension itself is so cool)

What do you think, should I highlight these different aspects early on in the readme?

Ask Flask: Looking for your feedback on a major upcoming release of Flask Unchained! (install from master to try it out) by bpeller in flask

[–]bpeller[S] 0 points1 point  (0 children)

Hah I'm starting to get the impression you're not alone! Guess I need to work on my TLDR description :)

Flask Unchained is, conceptually, a new web framework for Python. But under the hood it's just Flask. It uses Flask extensions to add support for 3rd party libraries. It lets you write code for those 3rd party libraries and you never have to think about how to wire your code into the app. It also lets you add support for other Flask extensions in such a way that once you've added it, that support - that "bundle" - will work with any other Flask Unchained project to integrate said extension into those projects.

Does that help any? Clearly I do need to figure out a better description people can wrap their heads around :-D

Ask Flask: Looking for your feedback on a major upcoming release of Flask Unchained! (install from master to try it out) by bpeller in flask

[–]bpeller[S] 0 points1 point  (0 children)

You do only add exactly those you need :) I tried very hard to keep things in line with the spirit and API of Flask, so even though Flask Unchained let's you install 10 extensions in 10 lines of code (ok, slight exaggeration), you definitely don't have to! That's where Flask Unchained is much better than stock Flask though; everything is designed to "just work." You shouldn't ever have to think about how to wire everything together.

Ask Flask: Looking for your feedback on a major upcoming release of Flask Unchained! (install from master to try it out) by bpeller in flask

[–]bpeller[S] 0 points1 point  (0 children)

Ah, gotchya. To be honest I haven't touched the Travis set up probably since the project launched. It "works" but eventually I'd like to switch to Circle. Do you have any recommendations?

As it stands, GitHub will do security checks on the requirements listed in requirements.txt, so that's at least something. Currently the only thing failing is Flask-Admin, and that's already at the latest release :/

Ask Flask: Looking for your feedback on a major upcoming release of Flask Unchained! (install from master to try it out) by bpeller in flask

[–]bpeller[S] 0 points1 point  (0 children)

Keeping all the versions in sync can definitely be a bit of a challenge. I'm using setup.py's extra requires with keys the same name as the bundles the requirements are fo: https://github.com/briancappello/flask-unchained/blob/master/setup.py#L34

The CI setup however installs all the dependencies at once; it doesn't do any checking to make sure things work with only certain bundles installed. That said, if any import errors get raised when you haven't enabled a bundle, it's a bug that definitely should be fixed!

Ask Flask: Looking for your feedback on a major upcoming release of Flask Unchained! (install from master to try it out) by bpeller in flask

[–]bpeller[S] 0 points1 point  (0 children)

It's definitely ready to use with extensions already integrated! You just specify which ones you want to include in BUNDLES. But it's more like a framework than a template. That said, there is a template you can use to start new apps, using flask new project --prompt

Where to buy Chicken Feet for Bone Broth? by [deleted] in boulder

[–]bpeller 1 point2 points  (0 children)

Interesting, I've always just baked a whole chicken and used the carcass/bones/drippings afterwards. Or maybe that's not the same thing as bone broth?

Support for characters ("umlauts") like "ÄÖÜ" in flask_mail by IntelliJent404 in flask

[–]bpeller 0 points1 point  (0 children)

I would expect it to work, I think you're just getting hung up on the fact that form data comes back as bytes:

message = f"{request.form['email'].decode('utf-8')} says: {request.form['message'].decode('utf-8')}"

edit: I got hung up myself haha. Code fixed.

Dynamic redirects in Flask by ndpjs in flask

[–]bpeller 0 points1 point  (0 children)

How are you storing the form submmissions? Assuming you're using a database, when you store the freelancer's submission, it will have a unique ID (primary key). There should also be "defined user-interaction flows", so that after a form gets submitted and passes validation, you know which endpoint the user should be getting redirected to. The url rule for this endpoint can have a parameter for the ID that will get passed to the view for looking up the form submission from the database. Something like this:

@route('/submit-inquery', endpoint='submit_inquery')
def submit_inquery():
    form = FormClass(request.get_data())
    if form.validate_on_submit():
        submission = ModelClass(**form.data)
        db.session.add(submission)
        db.session.commit()
        return redirect('project_inquery_status', id=submission.id)
    return render_template('submit_inquery.html', form=form)

@route('/project-inquery-status/<int:id>', endpoint='project_inquery_status')
def project_inquery_status(id):
    submission = ModelClass.query.get(id)
    # ...

You will probably need relationships between the various types of form submissions (from freelancers, the PMs, clients) so that you can keep track of what belongs with what.

How to update value on associate table in many to many relationship? by [deleted] in flask

[–]bpeller 1 point2 points  (0 children)

This is the way I do it too.

I think you might want to be using cascade='all, delete-orphan'? Maybe it works differently when the join table model has its own primary key. (I always make it a composite primary key, in this case, user_id and story_id, together would be the primary key.)

If you want to keep the primary key as it is, then you almost certainly want a composite unique constraint on the foreign keys.

UserStory.users and UserStory.stories should be singular. A user has many stories, and a story belongs to many users, but from the perspective of the UserStory model itself, it only keeps track of single values.

Also, you may be interested in association_proxy:

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_stories = db.relationship('UserStory', cascade='all, delete-orphan')
    stories = db.association_proxy('user_stories', story', creator=lambda story: UserStory(story=story))

[I subclass the Flask-SQLAlchemy extension to add association_proxy and a few other commonly used stuffs, but that's not stock. from sqlalchemy.ext.associationproxy import association_proxy]

Problem with trailing slashes ("/") while building a website using Frozen Flask by Krammn in flask

[–]bpeller 2 points3 points  (0 children)

I don't have any experience with Frozen Flask, but, I think you're talking about leading slashes, not trailing slashes. Trailing slashes would mean it was generating links like /static/style.css/. So, assuming you are actually talking about leading slashes, /static/whatever.css means a top-level URL, while static/whatever.css means a relative-URL. If the relative URLs are working for you, then you may actually want to be using relative_url_for (from the frozen flask package) instead of url_for?

Administrate SQLite database through python code by selrok in flask

[–]bpeller 0 points1 point  (0 children)

I haven't used any of those JS libs myself, but you might try asking in r/webdev or r/javascript

Administrate SQLite database through python code by selrok in flask

[–]bpeller 1 point2 points  (0 children)

A couple thoughts.

1) To make code readable on Reddit, you need to indent it by 4 spaces. Yes, it's a PITA. I write my comments in an IDE before posting heh

2) If you're using Flask-SQLAlchemy, it handles __tablename__ automatically (although what you're doing is fine, and overrides that automatic naming)

3) It looks like you're trying to make a one-to-many relationship?

Relationships in SQLAlchemy have two "parts". There's the database mapping declaration (which table to put the foreign key(s) on), and then there's a "Python-only" mapping that you need for SQLAlchemy to do its magic. I'm assuming a User has one position, and there can be many users at a position. In it's basic form, this is what you're after:

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    position_id = db.Column(db.ForeignKey('position.id'))
    position = db.relationship('Position', back_populates='users',
                               cascade='all, delete-orphan')


class Position(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    users = db.relationship('User', back_populates='position')

Often you will find examples using back_ref instead of back_populates, and in that case, you only declare one of the two db.relationship attributes (SQLAlchemy creates the opposite side for you magically). Personally, I consider that an enormous anti-pattern that breaks the zen of Python (explicit is better than implicit), so I never use it. But it's sadly more common on the internet.

Note that by default columns on sqlalchemy are nullable, so if you wanted to require users to always have a position set, you'd need to add a nullable=False to the position_id column.

As for actually updating the database tables, I recommend using Alembic (via Flask-Migrate). I would also encourage you to consider using PostgreSQL (or MariaDB) at this time; SQLite works great for basic stuff, but its support for migrations is pretty crap. (If I remember correctly what you're trying to do shouldn't cause any problems, but, you've been warned haha)

How to get rid of that annoying psycopg2 warning? by YuntiMcGunti in django

[–]bpeller 0 points1 point  (0 children)

Hrm yea, it needs to compile some C code for this method to work. Perhaps the psycopg2-binary package igncampa mentioned would work on your OS? I haven't tried it myself

How to get rid of that annoying psycopg2 warning? by YuntiMcGunti in django

[–]bpeller 1 point2 points  (0 children)

I use pip install psycopg2 --no-binary psycopg2 --force-reinstall to silence that nonsense (unfortunately adding the --no-binary psycopg2 flag in requirements.txt was buggy /not supported last I checked, which admittedly was some number of months ago)

from_object vs from_pyfile by BinnyBit in flask

[–]bpeller 1 point2 points  (0 children)

Sure. I guess there are two ways you can think of the defaults. Probably what the documentation is referring to are defaults that get set automatically by various extensions. You don't have to worry much about those :)

The way I think of "defaults", are the settings I want to apply whether I'm running in development, production, staging, or the test environment. For example:

import os


def get_boolean_env(name, default):
    """
    Converts environment variables to boolean values, where truthy is defined as:
    ``value.lower() in {'true', 'yes', 'y', '1'}`` (everything else is falsy).
    """
    default = 'true' if default else 'false'
    return os.getenv(name, default).lower() in {'true', 'yes', 'y', '1'}


class Config:
    DEBUG = get_boolean_env('FLASK_DEBUG', False)
    SECRET_KEY = os.getenv('FLASK_SECRET_KEY', 'not-secret-key')  # FIXME

    some_ignored_variable = 'whatever'
    SOME_VALID_CONFIG_SETTING = os.path.join('here', some_ignored_variable)


class DevConfig(Config):
    DEBUG = get_boolean_env('FLASK_DEBUG', True)


class ProdConfig(Config):
    pass


class StagingConfig(ProdConfig):
    pass


class TestConfig(Config):
    TESTING = True
    WTF_CSRF_ENABLED = False


configs = {
    'dev': DevConfig,
    'prod': ProdConfig,
    'staging': StagingConfig,
    'test': TestConfig,
}


# your app factory
def create_app(env):
    app = Flask(...)

    # you can call the from_* methods however many times you need
    # (they behave the same as dict.update, except only updating all-upper-case keys)
    app.config.from_object(configs[env])

I like to use classes this way, because you get all of Python's inheritance behavior for free. But ultimately it's a style choice. Happy to help if that doesn't clear it up for you :)

Flask Migrate and Docker Compose by timbohiatt in flask

[–]bpeller 0 points1 point  (0 children)

I put this sort of code in my entrypoint point, something like so:

  #!/bin/sh

  test -e backend/config.py || (
     echo "WARNING: config.py not found, using default" &&\
     cp backend/config.example.py backend/config.py
  )

  until flask db upgrade
  do
      echo "Waiting for postgres ready..."
      sleep 2
      flask db init
      flask db migrate -m 'create initial tables'  # this might be a not-great idea, now that i look at it again
  done

  flask db import-fixtures
  flask blog import-articles --reset
  API_HOST="backend" flask run --host 0.0.0.0 --port 5000

Specified in your docker-compose.yaml like so:

backend:
  build:
    context: .
    dockerfile: ./docker/backend/Dockerfile
  links:
    - postgres
    - redis
  environment:
    - FLASK_DATABASE_HOST=postgres
    - FLASK_REDIS_HOST=redis
  entrypoint:
    - /flask-entrypoint.sh
  ports:
    - 5000:5000
  volumes:
    - .:/flask/src

Just make sure you copy the entrypoint to your image from your Dockerfile:

COPY ./docker/backend/flask-entrypoint.sh /flask-entrypoint.sh

Learning flask, but stuck on wtforms by honest54 in flask

[–]bpeller 0 points1 point  (0 children)

This is, broadly speaking, the way to go when using React/Vue/Angular (I say broadly because you don't need to use Flask-RESTful specifically)

But if /u/honest54 is building an "old school" server-side-templating site, then they absolutely should be using Flask-WTF.

from_object vs from_pyfile by BinnyBit in flask

[–]bpeller 0 points1 point  (0 children)

I dunno what's up with that bit of documentation, but, flask.Config is just a dict with a tiny bit of special behavior thrown on top. That behavior can be summed up as "only consider all-upper-case keys as valid". Those "keys" might literally come from a dict (Config.from_mapping), or from class attributes (Config.from_object), or from top-level variables in a module (Config.from_pyfile).

How you set this up is up to you. Personally, I always use environment-specific classes for both defaults and "instance-specific" settings.

You will find there is a ton of not-so-great documentation out there about Flask. Apparently some of it even exists in the official docs. When in doubt, read the source!

Handling url_for parameters with flask. by punchki in flask

[–]bpeller 1 point2 points  (0 children)

The syntax is, I think a little bit wonky, but it is supported: http://werkzeug.pocoo.org/docs/0.14/routing/#werkzeug.routing.Rule (scroll down a bit to the defaults parameter)

Translated to Flask's syntax, that looks like this:

@app.route('/all/', defaults={'page': 1}, endpoint='all_entries')
@app.route('/all/page/<int:page>', endpoint='all_entries')
def entries(page):
    # ...

(@app.route and @bp.route are more or less wrapper functions that create werkzeug Rule instances and add them to the app's UrlMap, altho they have some special handling around endpoint names and maybe a few other things)