Skip to content
Snippets Groups Projects
Commit e8fcbcbe authored by MCAyd's avatar MCAyd
Browse files

new structure initialized, post routes are fixed and mostly ready

parent 1faa5577
No related branches found
No related tags found
No related merge requests found
Showing
with 44 additions and 88 deletions
###makefile informations here
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from blog.config import Config
db = SQLAlchemy()
bcrypt = Bcrypt()
def create_app(config_class=Config):
app = Flask(__name__)
app.config.from_object(Config)
db.init_app(app)
bcrypt.init_app(app)
from blog.posts.routes import posts
from blog.main.routes import main
app.register_blueprint(posts)
app.register_blueprint(main)
return app
###revise it accordingly.
import os
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY')
SQLALCHEMY_DATABASE_URI = os.environ.get('SQLALCHEMY_DATABASE_URI')
MAIL_SERVER = 'smtp.googlemail.com'
MAIL_PORT = 587
MAIL_USE_TLS = True
MAIL_USERNAME = os.environ.get('EMAIL_USER')
MAIL_PASSWORD = os.environ.get('EMAIL_PASS')
###home and categorized discussion routes here
####post.db will be there
###write forms here
###write routes here
# application/__init__.py
# application/frontend/__init__.py
# application/frontend/api/PostClient.py
# from flask import session
import requests
def get_posts():
# headers = {
# 'Authorization': 'Basic ' + session['user_api_key']
# }
url = 'http://172.16.238.130:5002/api/posts'
response = requests.request(method="GET", url=url)
print(response)
return response
get_posts()
\ No newline at end of file
# application/frontend/api/UserClient.py
# application/frontend/forms.py
# application/frontend/views.py
####initialize class config here, users specifically.
import os
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY')
SQLALCHEMY_DATABASE_URI = os.environ.get('SQLALCHEMY_DATABASE_URI')
MAIL_SERVER = 'smtp.googlemail.com'
MAIL_PORT = 587
MAIL_USE_TLS = True
MAIL_USERNAME = os.environ.get('EMAIL_USER')
MAIL_PASSWORD = os.environ.get('EMAIL_PASS')
###write User class and def load_user here
###write imports
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
firstname = db.Column(db.String(30), unique=True, nullable=False)
lastname = db.Column(db.String(20), unique=True, nullable=False)
phonenumber = db.Column(db.String(20), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
role = db.Column(db.String(10), unique=False, nullable=False)
image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
password = db.Column(db.String(60), nullable=False)
posts = db.relationship('Post', backref='author', lazy=True)
comments = db.relationship('Comment', backref='author', lazy='dynamic')
def get_reset_token(self, expires_sec=1800):
s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
return s.dumps({'user_id': self.id}).decode('utf-8')
@staticmethod
def verify_reset_token(token):
s = Serializer(current_app.config['SECRET_KEY'])
try:
user_id = s.loads(token)['user_id']
except:
return None
return User.query.get(user_id)
def __repr__(self):
return f"User('{self.username}', '{self.email}', '{self.image_file}')"
###users.db will be there
###write forms here
###write user routes here
###write utils here
# application/__init__.py
from flask import Flask
from flask_login import LoginManager
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
login_manager = LoginManager()
def create_app():
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///posts-service.db'
db.init_app(app)
login_manager.init_app(app)
with app.app_context():
# Register blueprints
from .post_api import post_api_blueprint
app.register_blueprint(post_api_blueprint)
from .models import Post,Comment
db.create_all()
return app
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment