Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage dependencies with Poetry #605

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_migrate import Migrate
from flask_wtf.csrf import CSRFProtect
from flask_mail import Mail
Expand All @@ -17,6 +18,7 @@
csrf_protect = CSRFProtect()
mail = Mail()
bootstrap = Bootstrap()
login_manager = LoginManager()


def create_app(config_settings=None):
Expand All @@ -34,6 +36,7 @@ def create_app(config_settings=None):
csrf_protect.init_app(app)
mail.init_app(app)
bootstrap.init_app(app)
login_manager.init_app(app)

from app.main import main_bp # noqa: E402
app.register_blueprint(main_bp)
Expand Down Expand Up @@ -71,18 +74,10 @@ def create_app(config_settings=None):
from app.styleguide import styleguide_bp
app.register_blueprint(styleguide_bp)

from app.models import User
from app.auth.forms import CustomUserManager
user_manager = CustomUserManager(app, db, User)

from app.webhooks import webhooks_bp
csrf_protect.exempt(webhooks_bp)
app.register_blueprint(webhooks_bp)

@app.context_processor
def context_processor():
return dict(user_manager=user_manager)

# Initialize Email and Logging
init_email_and_logs_error_handler(app)

Expand Down
11 changes: 2 additions & 9 deletions app/auth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
"""
Defines forms needed for Flask-User login
"""
from flask_user.forms import RegisterForm
from flask_user import UserManager
from wtforms import StringField, BooleanField
from wtforms.ext.sqlalchemy.fields import QuerySelectField
from wtforms.validators import DataRequired
from app.utils.form_utils import possible_affiliation_types


class CustomRegisterForm(RegisterForm):
class CustomRegisterForm():
"""
Custom Form Class to define custom members of the User Model
"""
Expand All @@ -20,10 +17,6 @@ class CustomRegisterForm(RegisterForm):
affiliation = StringField('Affiliation',
validators=[DataRequired('Please enter the insitution'
' with which you are affiated')])
affiliation_type = QuerySelectField('Current Status',
query_factory=possible_affiliation_types,
get_label='label', allow_blank=False)

agreeToTerms = BooleanField('I Agree to the CONP Terms and Conditions',
validators=[DataRequired('Need to agree to the terms to register account')])

Expand All @@ -35,7 +28,7 @@ def validate_affiliation_type(form, field):
pass


class CustomUserManager(UserManager):
class CustomUserManager():
"""
Custom User Manager for overriding Flask-User Forms
"""
Expand Down
9 changes: 7 additions & 2 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Module that contains the Data Models

"""
from app import db
from flask_user import UserMixin
from app import db, login_manager
from flask_login import UserMixin
from flask_dance.consumer.storage.sqla import OAuthConsumerMixin
from sqlalchemy.orm.collections import attribute_mapped_collection
from datetime import datetime, timedelta
Expand Down Expand Up @@ -136,6 +136,11 @@ def __repr__(self):
return '<User {}: {}>'.format(self.email, self.full_name)


@login_manager.user_loader
def load_user(user_id):
return User.get(user_id)


class AffiliationType(db.Model):
"""
Provides The Types of Affiliations that a user can select
Expand Down
3 changes: 1 addition & 2 deletions app/oauth/orcid_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

"""
from flask import flash, redirect, session, url_for, current_app, Markup
from flask_user import current_user
from flask_login import login_user
from flask_login import login_user, current_user
from app.oauth.orcid_flask_dance import make_orcid_blueprint
from flask_dance.consumer import oauth_authorized, oauth_error
from flask_dance.consumer.storage.sqla import SQLAlchemyStorage
Expand Down
4 changes: 0 additions & 4 deletions app/oauth/orcid_flask_dance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import os.path
from functools import partial

from flask.globals import LocalProxy, _lookup_app_object
from flask_dance.consumer import OAuth2ConsumerBlueprint
from flask_dance.consumer.requests import OAuth2Session

Expand Down Expand Up @@ -98,6 +97,3 @@ def set_applocal_session():
ctx = stack.top
ctx.orchid_oauth = orcid_bp.session
return orcid_bp


orcid = LocalProxy(partial(_lookup_app_object, "orcid_oauth"))
5 changes: 0 additions & 5 deletions app/profile/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from flask_wtf import FlaskForm
from wtforms import StringField
from wtforms.widgets import ListWidget
from wtforms.ext.sqlalchemy.fields import QuerySelectField
from wtforms.validators import DataRequired, ValidationError
from app.utils.form_utils import possible_affiliation_types, RoleMultiField

Expand All @@ -19,10 +18,6 @@ class UserProfileForm(FlaskForm):
affiliation = StringField('Affiliation',
validators=[DataRequired('Please enter the insitution'
' with which you are affiated')])
affiliation_type = QuerySelectField('Current Status',
query_factory=possible_affiliation_types,
get_label='label', allow_blank=False)

roles = RoleMultiField('Roles',
widget=ListWidget(prefix_label=True))

Expand Down
3 changes: 1 addition & 2 deletions app/profile/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Currently this module contains all of the routes for profile blueprint
"""
from flask import render_template, redirect, url_for, flash, request, session
from flask_user import current_user, login_required, roles_accepted
from flask_login import current_user, login_required
from app import db
from app.profile import profile_bp
from app.profile.forms import UserProfileForm
Expand Down Expand Up @@ -41,7 +41,6 @@ def current_user_profile_page():


@profile_bp.route('/profile/admin_edit_user_profile', methods=["GET", "POST"])
@roles_accepted('admin')
def admin_user_profile_page():
"""
Route that provides an path to another users profile page for admin editting
Expand Down
10 changes: 1 addition & 9 deletions app/templates/fragments/navigation_bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
<div class="collapse navbar-collapse justify-content-between" id="navbarSupportedContent">
<a class="navbar-brand" href="https://conp.ca/"><img style="max-width:100px;" src="/static/img/conp.png" alt="conp logo" /></a>
<ul class="navbar-nav">
{% if not current_user.is_anonymous %}
<li class="nav-item px-3">
<a class="nav-link" href="{{ url_for('profile.current_user_profile_page') }}">Profile</a>
</li>
<li class="nav-item px-3">
<a class="nav-link" href="/#/">Settings</a>
</li>
{% endif %}
<li class="nav-item px-3">
<a class="nav-link" href="{{url_for('main.about')}}">About</a>
</li>
Expand Down Expand Up @@ -84,4 +76,4 @@
});
});
}
</script>
</script>
3 changes: 0 additions & 3 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ <h2><span style="color: red">CONP</span> Portal</h2>
{% block appcontent %}

<!-- Display Username Login -->
{% if not current_user.is_anonymous %}
<div class="display-user">Welcome <strong>{{ user.username }}</strong></div>
{% endif %}
<div class="d-flex flex-column">
<div class="p-2 flex-fill">
<div class="card" data-type="dashboard">
Expand Down
Loading