organizations&organizationtypes
This commit is contained in:
0
organizationtypes/__init__.py
Normal file
0
organizationtypes/__init__.py
Normal file
13
organizationtypes/controller.py
Normal file
13
organizationtypes/controller.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from src.controller import BaseController
|
||||
|
||||
from .model import Organizationtype
|
||||
class OrgController(BaseController):
|
||||
__myclass__=Organizationtype
|
||||
__jsonid__='organizationtype'
|
||||
|
||||
#def get_all():
|
||||
# Organizationtype.query.all()
|
||||
|
||||
#def get(id):
|
||||
# Organizationtype.query.get(id)
|
||||
controller=OrgController()
|
||||
34
organizationtypes/model.py
Normal file
34
organizationtypes/model.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from sqlalchemy import Column, Integer, String, Boolean, DateTime, Text, ForeignKey, Index, TIMESTAMP
|
||||
from sqlalchemy.orm import relationship, validates
|
||||
|
||||
from datetime import datetime
|
||||
from src.database import Base,db_session
|
||||
from marshmallow import Schema, fields, post_load, ValidationError
|
||||
from src import clogger
|
||||
import json
|
||||
import flask
|
||||
from src.models import Section
|
||||
import re
|
||||
|
||||
def validate_image(k, img):
|
||||
return True
|
||||
class FullOrganizationtypeSchema(Schema):
|
||||
id = fields.Integer()
|
||||
name = fields.String()
|
||||
image = fields.String()
|
||||
updated_at = fields.DateTime()
|
||||
created_at = fields.DateTime()
|
||||
|
||||
class Organizationtype(Base):
|
||||
__tablename__ = 'organizationtypes'
|
||||
name=Column(String(250), unique=True, nullable=False)
|
||||
organizations=relationship("Organization", back_populates="organizationtype")
|
||||
image=Column(String(250))
|
||||
|
||||
__schema__= FullOrganizationtypeSchema
|
||||
__whiteattrs__= ["url", "name", "image"]
|
||||
__jsonattrs__=None # None means all
|
||||
|
||||
def __init__(self, data={}):
|
||||
self.update(data,False)
|
||||
|
||||
50
organizationtypes/views.py
Normal file
50
organizationtypes/views.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from flask import Blueprint, jsonify, render_template, abort, redirect, url_for, request
|
||||
organizationtype_pages = Blueprint('organizationtypes', __name__)
|
||||
|
||||
#from .model import Organizationtype #, Organizationtypeschema
|
||||
#from .model import SectionSchema
|
||||
#from datetime import datetime
|
||||
#import json
|
||||
#from src import clogger
|
||||
from src.organizationtypes.controller import controller
|
||||
#from src.database import db_session, read_json
|
||||
#import flask
|
||||
|
||||
@organizationtype_pages.route("/")
|
||||
@organizationtype_pages.route("")
|
||||
@organizationtype_pages.route(".json")
|
||||
def index():
|
||||
organizationtypes=controller.get_all()
|
||||
return jsonify(organizationtypes=organizationtypes)
|
||||
|
||||
@organizationtype_pages.route("/<int:id>",methods=['GET'])
|
||||
@organizationtype_pages.route("/<int:id>.json",methods=['GET'])
|
||||
def get(id):
|
||||
organizationtype=controller.get(id)
|
||||
return jsonify(organizationtype=organizationtype)
|
||||
|
||||
@organizationtype_pages.route("/<int:id>",methods=['GET'])
|
||||
@organizationtype_pages.route("/<int:id>.json",methods=['GET'])
|
||||
def get_articles(id):
|
||||
articles=controller.get_articles(id)
|
||||
return jsonify(articles=articles)
|
||||
|
||||
|
||||
@organizationtype_pages.route("/<int:id>",methods=['PUT'])
|
||||
@organizationtype_pages.route("/<int:id>.json",methods=['PUT'])
|
||||
def update(id):
|
||||
o,errors=controller.update(id,request)
|
||||
return jsonify(organizationtype=o,errors=errors)
|
||||
|
||||
|
||||
@organizationtype_pages.route("/",methods=['POST'])
|
||||
@organizationtype_pages.route("",methods=['POST'])
|
||||
@organizationtype_pages.route(".json",methods=['POST'])
|
||||
def create():
|
||||
organizationtype=controller.create(request)
|
||||
# a=read_json(request)
|
||||
# organizationtype=Organizationtype(a["organizationtype"])
|
||||
# controller.
|
||||
# db_session.add(organizationtype)
|
||||
# db_session.commit()
|
||||
return jsonify(organizationtype=organizationtype)
|
||||
Reference in New Issue
Block a user