mgt c7 finish
This commit is contained in:
		@@ -3,7 +3,7 @@ from config import Config
 | 
			
		||||
from flask_sqlalchemy import SQLAlchemy
 | 
			
		||||
from flask_migrate import Migrate
 | 
			
		||||
from flask_login import LoginManager
 | 
			
		||||
import logging
 | 
			
		||||
import logging, sys
 | 
			
		||||
from logging.handlers import SMTPHandler
 | 
			
		||||
 | 
			
		||||
app = Flask(__name__)
 | 
			
		||||
@@ -13,5 +13,25 @@ migrate = Migrate(app, db)
 | 
			
		||||
login = LoginManager(app)
 | 
			
		||||
login.login_view = 'login'
 | 
			
		||||
 | 
			
		||||
if not app.debug:
 | 
			
		||||
    if app.config['MAIL_SERVER']:
 | 
			
		||||
        auth = None
 | 
			
		||||
        secure = None
 | 
			
		||||
        mail_handler = SMTPHandler(
 | 
			
		||||
                mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']),
 | 
			
		||||
                fromaddr=app.config['FROM_ADDRESS'],
 | 
			
		||||
                toaddrs=app.config['ADMINS'], subject='MB failure.',
 | 
			
		||||
                credentials=auth, secure=secure)
 | 
			
		||||
        mail_handler.setLevel(logging.ERROR)
 | 
			
		||||
        app.logger.addHandler(mail_handler)
 | 
			
		||||
 | 
			
		||||
    if app.config['DC_LOGGING']:
 | 
			
		||||
        print('#################### DEBUGHERE', file=sys.stderr)
 | 
			
		||||
        dclog = logging.StreamHandler(stream=sys.stderr)
 | 
			
		||||
        dclog.setLevel(logging.INFO)
 | 
			
		||||
        dclog.propagate = False
 | 
			
		||||
        app.logger.addHandler(dclog)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
from app import routes, models, errors
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -32,3 +32,17 @@ class EditProfileForm(FlaskForm):
 | 
			
		||||
    username = StringField('Username', validators=[DataRequired()])
 | 
			
		||||
    about_me = TextAreaField('About me', validators=[Length(min=0, max=140)])
 | 
			
		||||
    submit = SubmitField('Update')
 | 
			
		||||
 | 
			
		||||
    def __init__(self, original_username, *args, **kwargs):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
        self.original_username = original_username
 | 
			
		||||
 | 
			
		||||
    def validate_username(self, username):
 | 
			
		||||
        if username.data != self.original_username:
 | 
			
		||||
            user = db.session.scalar(sa.select(User).where(User.username == username.data))
 | 
			
		||||
            if user is not None:
 | 
			
		||||
                raise ValidationError('Please use a different username.')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ def before_request():
 | 
			
		||||
@app.route('/index')
 | 
			
		||||
@login_required
 | 
			
		||||
def index():
 | 
			
		||||
    app.logger.info("AAAAAAAAAAAAAAAAAAAAA")
 | 
			
		||||
 | 
			
		||||
    user = {'username': 'Finnaa'}
 | 
			
		||||
    posts = [
 | 
			
		||||
@@ -74,6 +75,7 @@ def register():
 | 
			
		||||
@login_required
 | 
			
		||||
def user(username):
 | 
			
		||||
    user = db.first_or_404(sa.select(User).where(User.username == username))
 | 
			
		||||
    #app.logger.info('PROFILE DEBUG  ###############################')
 | 
			
		||||
    posts = [
 | 
			
		||||
        {'author': user, 'body': 'Test1'},
 | 
			
		||||
        {'author': user, 'body': 'Test2?'}
 | 
			
		||||
@@ -83,7 +85,7 @@ def user(username):
 | 
			
		||||
@app.route('/edit_profile', methods=['GET', 'POST'])
 | 
			
		||||
@login_required
 | 
			
		||||
def edit_profile():
 | 
			
		||||
    form = EditProfileForm()
 | 
			
		||||
    form = EditProfileForm(current_user.username)
 | 
			
		||||
    if form.validate_on_submit():
 | 
			
		||||
        current_user.username = form.username.data
 | 
			
		||||
        current_user.about_me = form.about_me.data
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user