Skip to content

Commit

Permalink
- Updated several dependencies to fix safe_str_cmp werkzeug issue
Browse files Browse the repository at this point in the history
- refactor to use flask bluebird to fix circular dependency issue
- add .vscode to .gitignore
  • Loading branch information
5t33 committed Sep 4, 2022
1 parent af125b2 commit 42686a7
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
ve/
db/
.vscode
14 changes: 7 additions & 7 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import logging

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from flask_babel import Babel, format_date
from config import Config
from slugify import slugify
from models import db
from cli import translate_blueprint
from views import blueprint
import pycountry

"""Import all web routes and CLI routes to run this app"""
logging.basicConfig(level=logging.DEBUG)

app = Flask(__name__)
app.config.from_object(Config())

db = SQLAlchemy(app)
db.init_app(app)
app.register_blueprint(blueprint)
app.register_blueprint(translate_blueprint)
migrate = Migrate(app, db, compare_type=True, render_as_batch=True)

login_manager = LoginManager(app)
Expand Down Expand Up @@ -60,7 +64,3 @@ def format_datetime(value, format="short"):
if value is None:
return ""
return format_date(value, format)


"""Import all web routes and CLI routes to run this app"""
import views, cli # noqa
16 changes: 5 additions & 11 deletions app/cli.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
from app import app
from flask import Blueprint
import os
import click

translate_blueprint = Blueprint('translate', __name__)

@app.cli.group()
def translate():
"""Translation and localization commands."""
pass


@translate.command()
@translate_blueprint.cli.command('update')
def update():
"""Update all languages."""
if os.system('pybabel extract -F babel.cfg -k _l -o messages.pot .'):
Expand All @@ -18,15 +13,14 @@ def update():
raise RuntimeError('update command failed')
os.remove('messages.pot')


@translate.command()
@translate_blueprint.cli.command('compile')
def compile():
"""Compile all languages."""
if os.system('pybabel compile -d translations'):
raise RuntimeError('compile command failed')


@translate.command()
@translate_blueprint.cli.command('init')
@click.argument('lang')
def init(lang):
"""Initialize a new language."""
Expand Down
5 changes: 4 additions & 1 deletion app/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from app import db
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash


db = SQLAlchemy()

recipe_tag = db.Table(
'recipe_tag',
db.Column('recipe_id', db.Integer, db.ForeignKey('recipe.id'), primary_key=True),
Expand Down
Empty file modified app/prestart.sh
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Flask-Migrate==2.6.0
Flask-Login==0.5.0
Flask-Login==0.6.2
Flask-Babel==1.0.0
Flask-WTF==0.14.3
Flask-WTF==1.0.1
python-slugify==4.0.0
pycountry==19.8.18
PyMySQL==0.9.3
sqlalchemy==1.3.24
sqlalchemy==1.3.24
4 changes: 2 additions & 2 deletions app/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h1><i class="calendar icon"></i>{{ _("Meal planning") }}</h1>
</td>
<td></td>
<td>
<a class="ui labeled icon button" href="{{ url_for('recipes', schedule='24-3-2020') }}">
<a class="ui labeled icon button" href="{{ url_for('main.recipes', schedule='24-3-2020') }}">
<i class="binoculars icon"></i>
{{ _("Search") }}
</a>
Expand All @@ -91,7 +91,7 @@ <h1><i class="calendar icon"></i>{{ _("Meal planning") }}</h1>
<i class="calendar plus outline icon"></i>
{{ _("Add week") }}
</button>
<a class="ui labeled icon button" href="{{ url_for('scheduler') }}">
<a class="ui labeled icon button" href="{{ url_for('main.scheduler') }}">
<i class="calendar alternate outline icon"></i>
{{ _("Scheduler") }}
</a>
Expand Down
6 changes: 3 additions & 3 deletions app/templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<img src="/static/food/example-{{ recipe.id }}.jpg">
</a>
<div class="content">
<a class="ui teal right ribbon label" href="{{ url_for('recipes', category=recipe.category.name or 'none'|slugify) }}" style="position: relative; top: -0.5rem;">{{ recipe.category.name }}</a>
<a class="ui teal right ribbon label" href="{{ url_for('main.recipes', category=recipe.category.name or 'none'|slugify) }}" style="position: relative; top: -0.5rem;">{{ recipe.category.name }}</a>
<a class="header" href="{{ url }}" style="margin-top: -2rem; margin-bottom: -0.5rem; padding-right: 3rem;">{{ recipe.name }}</a>
</div>
<div class="extra content meta">
<a href="{{ url_for('recipes', duration=recipe.prep_time ) }}"><i class="stopwatch icon"></i> {{ recipe.prep_time }}min</a>
<a href="{{ url_for('recipes', duration=recipe.cook_time ) }}"><i class="clock outline icon"></i> {{ recipe.cook_time }}min</a>
<a href="{{ url_for('main.recipes', duration=recipe.prep_time ) }}"><i class="stopwatch icon"></i> {{ recipe.prep_time }}min</a>
<a href="{{ url_for('main.recipes', duration=recipe.cook_time ) }}"><i class="clock outline icon"></i> {{ recipe.cook_time }}min</a>
</div>
</div>
{% endmacro %}
Expand Down
10 changes: 5 additions & 5 deletions app/templates/recipe.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
<img src="/static/food/example-{{ recipe.id }}.jpg">
</a>
<div class="content">
<a class="ui teal right ribbon label" href="{{ url_for('recipes', category=recipe.category.name) }}">{{ recipe.category.name }}</a>
<a class="ui teal right ribbon label" href="{{ url_for('main.recipes', category=recipe.category.name) }}">{{ recipe.category.name }}</a>
<a class="header" href="{{ recipe_url(recipe) }}" style="margin-top: -1rem; font-size: 2rem; padding-right: 3rem;">{{ recipe.name }}</a>
<a href="/edit" style="position: absolute; right: 0px; bottom: 0px; color: black;"><i class="pen icon"></i></a>
</div>

<div class="extra content meta">
<a href="{{ url_for('recipes', duration=recipe.prep_time ) }}"><i class="stopwatch icon"></i> {{ recipe.prep_time }}min</a>
<a href="{{ url_for('recipes', duration=recipe.cook_time ) }}"><i class="clock outline icon"></i> {{ recipe.cook_time }}min</a>
<a href="{{ url_for('main.recipes', duration=recipe.prep_time ) }}"><i class="stopwatch icon"></i> {{ recipe.prep_time }}min</a>
<a href="{{ url_for('main.recipes', duration=recipe.cook_time ) }}"><i class="clock outline icon"></i> {{ recipe.cook_time }}min</a>
<i class="utensils icon"></i> serves {{ recipe.servings }}
<div class="ui yellow rating" data-icon="star" data-rating="{{ recipe.rating }}" data-max-rating="5" style="margin-left: 1rem;"></div>
</div>

{% if recipe.tags %}
<div class="extra content">
{% for tag in recipe.tags %}
<a href="{{ url_for('recipes', tag=tag.name|slugify) }}" class="ui tag label floated" style="margin-right: 1rem;">{{ tag.name }}</a>
<a href="{{ url_for('main.recipes', tag=tag.name|slugify) }}" class="ui tag label floated" style="margin-right: 1rem;">{{ tag.name }}</a>
{% endfor %}
</div>
{% endif %}
Expand Down Expand Up @@ -78,7 +78,7 @@
$(document).ready(function(){
$('.ui.rating').rating({
onRate: function(value) {
let uri = '{{ url_for('recipe_update', id=recipe.id) }}'
let uri = '{{ url_for('main.recipe_update', id=recipe.id) }}'
let recipe = new Recipe(uri)
recipe.rating = value
}
Expand Down
4 changes: 2 additions & 2 deletions app/templates/recipes.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h1>{{ _('Your recipes') }}</h1>

<div class="ui stackable grid">
<form class="row ui form" method="get" action="{{ url_for('recipes') }}">
<form class="row ui form" method="get" action="{{ url_for('main.recipes') }}">
<div class="eight wide column">
<div class="ui fluid right action left icon input">
<i class="search link icon"></i>
Expand Down Expand Up @@ -90,7 +90,7 @@ <h1>{{ _('Your recipes') }}</h1>
<button class="ui blue button" type="button" data-tooltip="Select recipe for {{ day|date('EEEE d MMMM') }}"><i class="calendar alternate outline icon" style="margin-right: 0; margin-left: 0;"></i></button>
</div>
{% endif %}
<a class="ui button" data-tooltip="Add a new recipe" href="{{ url_for('recipe_new') }}">
<a class="ui button" data-tooltip="Add a new recipe" href="{{ url_for('main.recipe_new') }}">
<i class="plus icon" style="margin-right: 0; margin-left: 0;"></i>
</a>
</div>
Expand Down
13 changes: 7 additions & 6 deletions app/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2>{{ _('Your profile') }}</h2>
<input type="password" name="password" placeholder="{{ _('Password') }}" value="*************">
</div>
<button class="ui button" type="submit">{{ _('Save profile') }}</button>
<a class="ui button" href="{{ url_for('logout') }}">{{ _('Logout') }}</a>
<a class="ui button" href="{{ url_for('main.logout') }}">{{ _('Logout') }}</a>
</form>
</div>

Expand All @@ -32,7 +32,7 @@ <h2>{{ _('Your data') }}</h2>
<div class="ui three column grid">
<div class="row">
<div class="centered column">
<a class="ui huge statistic" href="{{ url_for('recipes') }}">
<a class="ui huge statistic" href="{{ url_for('main.recipes') }}">
<div class="value">
{{ count.recipes }}
</div>
Expand All @@ -44,7 +44,7 @@ <h2>{{ _('Your data') }}</h2>
</div>

<div class="column">
<a class="ui statistic" href="{{ url_for('ingredients') }}">
<a class="ui statistic" href="{{ url_for('main.ingredients') }}">
<div class="value">
{{ count.ingredients }}
</div>
Expand All @@ -55,7 +55,7 @@ <h2>{{ _('Your data') }}</h2>
</div>

<div class="column">
<a class="ui statistic" href="{{ url_for('tags') }}">
<a class="ui statistic" href="{{ url_for('main.tags') }}">
<div class="value">
{{ count.tags }}
</div>
Expand All @@ -66,7 +66,7 @@ <h2>{{ _('Your data') }}</h2>
</div>

<div class="column">
<a class="ui statistic" href="{{ url_for('categories') }}">
<a class="ui statistic" href="{{ url_for('main.categories') }}">
<div class="value">
{{ count.categories }}
</div>
Expand Down Expand Up @@ -182,7 +182,8 @@ <h2>{{ _('About groceri.es') }}</h2>
function profile() {
let form = document.getElementById('profile-form')
form.addEventListener('submit', function(event) {
let uri = '{{ url_for('profile') }}'
// setting this to main.home for now instead of main.profile because it's causing problems
let uri = '{{ url_for('main.home') }}'
let profile = new Profile(uri)

profile.name = this.elements.name.value
Expand Down
Loading

0 comments on commit 42686a7

Please sign in to comment.