示例#1
0
 def updateUser(id):
     if request.method == 'PUT':
         requestJson = request.form.to_dict(flat=False)
         dict_keys = list(requestJson.keys())
         resultUpt = {dict_keys[i]: requestJson.get(dict_keys[i])[0] for i in range(len(dict_keys))}
         if 'imagen' in request.files:
             file_image = request.files['imagen']
             filename = secure_filename(file_image.filename)
             filename = '{}user_img.{}'.format(id, filename.split('.')[-1])
             file_image.save(
                 os.path.join(getConfig().get('upload_user_files'),
                  filename))
             resultUpt['imagen'] = getConfig().get('upload_user_files') + filename
         code, msg = user_control.updateData(id, resultUpt)
         return { 'code': code, 'message': msg }
 def newTransference(id):
     if request.method == 'POST':
         if 'transf_carta' not in request.files:
             return {'code': 406, 'message': 'Transference Letter Required'}
         else:
             requestJson = request.form.to_dict(flat=False)
             dict_keys = list(requestJson.keys())
             result = {
                 dict_keys[i]: requestJson.get(dict_keys[i])[0]
                 for i in range(len(dict_keys))
             }
             result['id'] = transf_id = str(uuid.uuid1())
             file_letter = request.files['transf_carta']
             filename = secure_filename(file_letter.filename)
             filename = '{}carta{}.{}'.format(id, transf_id,
                                              filename.split('.')[-1])
             file_letter.save(
                 os.path.join(getConfig().get('upload_user_files'),
                              filename))
             result['transf_carta'] = getConfig().get(
                 'upload_user_files') + filename
             result['usuario_id'] = id
             code, msg = transf_control.addTransference(result, id)
             return make_response({'message': msg}, code)
import sqlite3
from src.config.settings import getConfig

DB_PATH = getConfig().get('SQLITE_DB_PATH')

class Connection:
    def __init__(self, db_name):
        self.db_name = db_name
        try:
            db_dir = '{}{}.db'.format(DB_PATH, self.db_name)
            self.connection = sqlite3.connect(db_dir, check_same_thread = False)
            self.cursor = self.connection.cursor()
            print('DB: Database Conected')
        except sqlite3.OperationalError as error:
            print('Error:', error)

    def createTables(self, params_table):
        try:
            params = ''
            for prop in params_table:
                if params_table[0] is not prop:
                    params += ', '
                params += prop + ' TEXT'
            query = """CREATE TABLE
            IF NOT EXISTS {}({});
            """.format(self.db_name, params)
            self.cursor.execute(query)
            print('DB: Users Table created')
        except sqlite3.OperationalError as error:
            print('DB Error:', error)
示例#4
0
import os
from flask_mail import Mail, Message
from flask import Flask, render_template
from src.config.settings import getConfig

conf = getConfig().get('mail_config')


class EmailSender:
    def __init__(self, app: Flask):
        app.config['MAIL_SERVER'] = conf.get('server')
        app.config['MAIL_PORT'] = int(conf.get('port'))
        app.config['MAIL_USERNAME'] = conf.get('username')
        app.config['MAIL_PASSWORD'] = conf.get('password')
        app.config['MAIL_USE_TLS'] = False
        app.config['MAIL_USE_SSL'] = True
        app.config['MAIL_ASCII_ATTACHMENTS'] = True
        self.mail = Mail(app)

    def sendMessage(self,
                    subject: str,
                    message_data: dict,
                    to: list,
                    atts: list = None):
        msg = Message(subject, sender=conf.get('username'), recipients=to)
        if atts:
            for file in atts:
                print(' Server: Nuevos Archivos')
                # with open_resource(file) as fp:
                #     msg.attach(file, fp.read()) #msg.attach(file, "image/png", fp.read())
        msg.html = self.buildMessage(message_data)
# -*- coding: utf-8 -*-
import datetime
import json
from src.db.data_controller import DataController
from src.transference.assignement_controller import AssignementController
from src.config.settings import getConfig
from src.utils.format_objects import getObjById, buildMsgEmail, formatObjToDict

transf_control = None
user_control = None

MAIL_MESSAGES = getConfig().get('mail_messages')

with open(MAIL_MESSAGES) as config_file:
    config = json.load(config_file)
    admin_messages = config.get('admin')
    admin_msg_transf = admin_messages.get('transf_created')
    admin_msg_upt_transf = admin_messages.get('transf_update')

    user_messages = config.get('user')
    user_msg_transf = user_messages.get('transf_created')
    user_msg_upt_transf = user_messages.get('transf_update')

    managers_data = config.get('managers')
    registro_control = managers_data.get('registro_control')
    rc_cargo = registro_control.get('cargo')
    rc_cod_secc = registro_control.get('cod_secc')
    rc_cod_sede = registro_control.get('cod_sede')

    analista_registro = managers_data.get("analista_registro")
    anr_cargo = analista_registro.get('cargo')
# -*- coding: utf-8 -*-
import cx_Oracle
from src.config.settings import getConfig

connection = None
db_config = getConfig().get('db_config')


class Connection:
    def __init__(self):
        self.conn = None
        self.cursor = None
        if not self.conn:
            try:
                dsn = cx_Oracle.makedsn(db_config.get('host'),
                                        int(db_config.get('port')),
                                        db_config.get('service'))
                self.conn = cx_Oracle.connect(db_config.get('user'),
                                              db_config.get('password'), dsn)
                self.cursor = self.conn.cursor()
                print('Database: Database Connected')
            except cx_Oracle.Error as error:
                print('ERROR DB:', error)

    def getConnectionData(self):
        return self.conn, self.cursor

    def disconnect(self):
        self.conn.close()
# -*- coding: utf-8 -*-
import os
import random
from dotenv import load_dotenv
from flask import Flask
from flask_cors import CORS
from src.user.user_routes import cons_user_blueprint
from src.transference.transf_routes import cons_transf_blueprint
from src.admin.admin_routes import cons_admin_blueprint
from src.subject.subject_routes import cons_subj_blueprint
#from homologation.homologation_routes import cons_hmlog_blueprint
from src.config.settings import getConfig
from werkzeug.security import generate_password_hash
from src.utils.notification_service import EmailSender

port = getConfig().get('port_http')
host = getConfig().get('host')

key_token = 'key token'

# Server Application
app = Flask(__name__)
app.config['CORS_HEADERS'] = 'Content-Type'
cors = CORS(app)

key_seed = 'developedbydbgroldan' + str(random.randint(1, 100000))
srtkey = generate_password_hash(key_seed)
app.secret_key = srtkey

email_sender = EmailSender(app)