Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>
Basic foundation of a cycle
src/__init__.py | 2 src/alembic/versions/6e334556e8f8_create_cycles.py | 35 +++++++++++ src/blueprints/cycles.py | 17 +++++ src/types/cycle.py | 49 ++++++++++++++++
diff --git a/src/__init__.py b/src/__init__.py index 8fe250475168f5faaf90236806100b6d88bb5dd9..2eb1badb78280da05cda67bc28c0767d7c48c892 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -27,11 +27,13 @@ from .blueprints.auth import auth from .blueprints.groups import groups from .blueprints.products import pro as products from .blueprints.product_categories import product_categories + from .blueprints.cycles import cycles app.register_blueprint(basic) app.register_blueprint(auth) app.register_blueprint(product_categories) app.register_blueprint(products) app.register_blueprint(groups) + app.register_blueprint(cycles) with app.app_context(): db.create_all() diff --git a/src/alembic/versions/6e334556e8f8_create_cycles.py b/src/alembic/versions/6e334556e8f8_create_cycles.py new file mode 100644 index 0000000000000000000000000000000000000000..ffccaaea7186f687fe50431315a94f635a4a28a1 --- /dev/null +++ b/src/alembic/versions/6e334556e8f8_create_cycles.py @@ -0,0 +1,35 @@ +"""create cycles + +Revision ID: 6e334556e8f8 +Revises: d6a05e473bc9 +Create Date: 2019-12-04 02:11:55.635795 + +""" +from alembic import op +import sqlalchemy as sa +import sqlalchemy_utils as sau + +# revision identifiers, used by Alembic. +revision = '6e334556e8f8' +down_revision = 'd6a05e473bc9' +branch_labels = None +depends_on = None + + +def upgrade(): + op.create_table('cycles', + sa.Column('id', sa.Integer, primary_key = True), + sa.Column('name', sa.String(255), nullable = False), + sa.Column('description', sa.Text), + sa.Column('start_at', sa.DateTime, nullable = False), + sa.Column('end_at', sa.DateTime, nullable = False), + sa.Column('delivery_start_at', sa.DateTime, nullable = False), + sa.Column('delivery_end_at', sa.DateTime, nullable = False), + sa.Column('status', sa.String(255), server_default = 'draft'), + sa.Column('created_at', sa.DateTime), + sa.Column('updated_at', sa.DateTime) + ) + + +def downgrade(): + op.drop_table('cycles') diff --git a/src/blueprints/cycles.py b/src/blueprints/cycles.py new file mode 100644 index 0000000000000000000000000000000000000000..e8df9ff64c7d7ec26cf43d6dc228f15d3b6ced6a --- /dev/null +++ b/src/blueprints/cycles.py @@ -0,0 +1,17 @@ +from flask import Blueprint, url_for, request, render_template, redirect + +cycles = Blueprint('cycles', __name__, url_prefix = '/cycles') + +@cycles.route('/', methods = ['GET', 'POST']) +def index(): + if request.method == 'GET': + return 'yo' + else: + create(request.form) + +@cycles.route('/new', methods = ['GET']) +def new(): + return render_template('new_cycle.html', title = "Abrir novo Ciclo - Feira Virtual Bem da Terra") + +def create(params): + return "co" diff --git a/src/templates/new_cycle.html b/src/templates/new_cycle.html new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 Binary files /dev/null and b/src/templates/new_cycle.html differ diff --git a/src/types/cycle.py b/src/types/cycle.py new file mode 100644 index 0000000000000000000000000000000000000000..63be69f220d5d74add0a3a3db3d82c299b5f90e0 --- /dev/null +++ b/src/types/cycle.py @@ -0,0 +1,49 @@ +from . import db +from datetime import datetime as dt +import sqlalchemy as sa +import sqlalchemy_utils as sau +import enum + +class CycleStatus(Enum): + draft = "draft" + published = "published" + closed = "closed" + delivered = "delivered" + +class Cycle(db.Model): + __tablename__ = "cycles" + + id = db.Column(db.Integer, primary_key = True) + name = db.Column(db.String, nullable = False) + description = db.Column(db.Text) + + start_at = db.Column(db.DateTime, nullable = False) + end_at = db.Column(db.DateTime, nullable = False) + + delivery_start_at = db.Column(db.DateTime, nullable = False) + delivery_end_at = db.Column(db.DateTime, nullable = False) + + status = db.Column(sau.ChoiceType(CycleStatus, impl = sa.String()), server_default = 'draft') + + created_at = db.Column(db.DateTime, default = dt.utcnow) + updated_at = db.Column(db.DateTime, default = dt.utcnow) + + def __init__(self, name, description, start_at, end_at, delivery_start_at, delivery_end_at): + self.name = name + self.description = description + self.start_at = start_at + self.end_at = end_at + self.delivery_start_at = delivery_start_at + self.delivery_end_at = delivery_end_at + + def create(self): + db.session.add(self) + db.session.commit() + + def to_json(self): + return { + "name": self.name, + "description": self.description, + "start_at": self.start_at.__str__(), + "end_at": self.end_at.__str__(), + }