コード例 #1
0
ファイル: api.py プロジェクト: flavio342/nave_mae_backend
    def post(self):

        form = RegisterForm()

        if form.validate_on_submit():

            photo = upload_file(request.files['photo'])

            obj = Relative(name=form.name.data,
                           cpf=form.cpf.data,
                           phone=form.phone.data,
                           email=form.email.data,
                           password=bcrypt.generate_password_hash(
                               form.password.data).decode('utf-8'),
                           photo=photo,
                           active=True)

            db.session.add(obj)
            db.session.commit()
            """token = relative_token_serializer.dumps(form.email.data, salt='confirm-email')
            
            msg = Message(
                '82Hack - Confirmação de Cadastro',
                sender=app.config['MAIL_USERNAME'],
                recipients=[form.email.data]
            )
            msg.html = "<a href='" + API_URL + "confirm_email/" + \
                token + "'>Clique aqui para confirmar seu cadastro!</a>"
            mail.send(msg)"""

            return {'success': True}

        else:
            print(form.errors)
            return {'success': False, "errors": form.errors}
コード例 #2
0
ファイル: api.py プロジェクト: flavio342/nave_mae_backend
    def post(self):

        form = RegisterForm()

        if form.validate_on_submit():

            photo = upload_file(request.files['photo'])

            obj = Class(name=form.name.data, photo=photo)

            institution_obj = get_institution_by_id(form.institution_id.data)
            if institution_obj:

                institution_obj.classes.append(obj)

                db.session.add(obj)
                db.session.add(institution_obj)
                db.session.commit()

                return {'success': True}

            else:

                return {
                    'success': False,
                    "errors": {
                        "institution_id": ["Instituição não existe"]
                    }
                }

        else:

            return {'success': False, "errors": form.errors}
コード例 #3
0
    def post(self):

        form = RegisterForm()

        if form.validate_on_submit():

            photo = upload_file(request.files['photo'])

            obj = Student(name=form.name.data,
                          cpf=form.cpf.data,
                          phone=form.phone.data,
                          email=form.email.data,
                          photo=photo)

            db.session.add(obj)
            db.session.commit()

            return {'success': True, 'id': obj.id}

        else:

            return {'success': False, "errors": form.errors}
コード例 #4
0
    def post(self):

        form = RegisterForm()

        if form.validate_on_submit():

            photo = upload_file(request.files['photo'])

            obj = Event(name=form.name.data,
                        date=form.date.data,
                        description=form.description.data,
                        photo=photo)

            class_obj = get_class_by_id(form.class_id.data)
            if class_obj:

                print(class_obj.events)

                class_obj.events.append(obj)

                db.session.add_all([class_obj, obj])
                db.session.commit()

                return {'success': True}

            else:
                return {
                    'success': False,
                    "errors": {
                        "class_id": ["Turma não existe"]
                    }
                }

        else:

            return {'success': False, "errors": form.errors}