Commit 5e8e8669 authored by Yuri H. Salvador's avatar Yuri H. Salvador

Merge branch 'dev-models' into 'master'

Dev models

See merge request !4
parents e1158bb3 8b4dad25
[flake8]
max-line-length = 119
exclude = /*/migration/*.py
ignore = W503, E203
exclude = /*/migrations/*.py
ignore = W503,E203
per-file-ignores= */__init__.py:F401
......@@ -177,4 +177,6 @@ dmypy.json
# Ignore all local history of files
.history
# End of https://www.gitignore.io/api/django,python,visualstudiocode
\ No newline at end of file
### mongo-volume
mongo-volume/*
# End of https://www.gitignore.io/api/django,python,visualstudiocode
# evento-nosql
# eventos-nosql
Sistema de eventos utilizando MongoDB
<h2>BACKEND</h2>
Requisitos:
<ul>
<li><a href="https://docs.docker.com/engine/install/ubuntu/">Docker</a></li>
<li><a href="https://docs.docker.com/compose/install/">Docker-Compose</a></li>
<li><a href="https://python-poetry.org/docs/">Poetry</a></li>
</ul>
```
# Inicializar o banco de dados
sudo docker-compose up -d
# Instalar as dependências
poetry install
# Para inicializar a aplicação
./manage.py runserver
```
<b>Para fazer um commit, você deve estar dentro do virtualenv do backend</b>
Use o poetry para isso:
<blockquote>poetry shell</blockquote>
Configure os hooks de commit para executar verificaçãoes de código antes de fazer um commit:
<blockquote>pre-commit install</blockquote>
<h2>TEARDOWN</h2>
```
# Parar o banco de dados
sudo docker-compose down
```
......@@ -2,37 +2,18 @@
version: "3.7"
services:
mongo-express:
image: mongo-express
ports:
- "8081:8081"
environment:
ME_CONFIG_BASICAUTH_USERNAME: usereventos
ME_CONFIG_BASICAUTH_PASSWORD: 123
ME_CONFIG_MONGODB_PORT: 27017
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: eventos
links:
- mongo
networks:
- mongo-compose-network
mongo:
image: mongo
restart: always
database:
image: "mongo"
container_name: "eventos-nosql"
environment:
MONGO_INITDB_DATABASE: eventos
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: eventos
ports:
- "27017:27017"
volumes:
- db-data:/data/db
networks:
- mongo-compose-network
networks:
mongo-compose-network:
driver: bridge
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
- ./mongo-volume:/data/db
volumes:
db:
# from django.db import models
# Create your models here.
from eventos.core.models.certified import Certified
from eventos.core.models.event import Event
from eventos.core.models.event_ref import EventRef
from eventos.core.models.submission import Submission
from eventos.core.models.track import Track
from eventos.core.models.track_ref import TrackRef
from eventos.core.models.user import User
from eventos.core.models.user_ref import UserRef
from mongoengine import Document, fields
from eventos.core.models import EventRef, UserRef
class Certified(Document):
description = fields.StringField(max_length=255, required=True)
type = fields.StringField(max_length=255, required=True)
emission = fields.DateTimeField(required=True)
key = fields.StringField(max_length=255, required=True)
ref_user = fields.EmbeddedDocumentField(UserRef, required=True)
ref_event = fields.EmbeddedDocumentField(EventRef, required=True)
new_certified = fields.ReferenceField("self", required=False)
from mongoengine import Document, fields
from eventos.core.models import UserRef
class Event(Document):
name = fields.StringField(max_length=255, required=True)
name_english = fields.StringField(max_length=255, required=True)
starts_on = fields.DateTimeField(required=True)
ends_on = fields.DateTimeField(required=True)
local = fields.StringField(max_length=255, required=True)
description = fields.StringField(max_length=255, required=True)
owners = fields.EmbeddedDocumentListField(UserRef, required=False)
from mongoengine import EmbeddedDocument, fields
from eventos.core.models import Event
class EventRef(EmbeddedDocument):
id = fields.ReferenceField(Event, required=True)
name = fields.StringField(max_length=255, required=True)
name_english = fields.StringField(max_length=255, required=True)
from mongoengine import Document, fields
from eventos.core.models import EventRef, TrackRef, UserRef
class Submission(Document):
title = fields.StringField(max_length=255, required=True)
type = fields.StringField(max_length=255, required=True)
info = fields.StringField(max_length=255, required=True)
status = fields.BooleanField(default=False)
file = fields.FileField()
ref_track = fields.EmbeddedDocumentField(TrackRef, required=True)
owners = fields.EmbeddedDocumentListField(UserRef, required=True)
ref_event = fields.EmbeddedDocumentField(EventRef, required=True)
from mongoengine import Document, fields
from eventos.core.models import EventRef
class Track(Document):
starts_on = fields.DateTimeField()
ends_on = fields.DateTimeField()
ref_event = fields.EmbeddedDocumentField(EventRef)
from mongoengine import EmbeddedDocument, fields
from eventos.core.models import Track
class TrackRef(EmbeddedDocument):
id = fields.ReferenceField(Track, required=True)
starts_on = fields.DateTimeField()
ends_on = fields.DateTimeField()
from mongoengine import Document, fields
class User(Document):
first_name = fields.StringField(max_length=255, required=True)
last_name = fields.StringField(max_length=255, required=True)
email = fields.EmailField(max_length=255, required=True)
password = fields.StringField(max_length=255, required=True)
from mongoengine import EmbeddedDocument, fields
from eventos.core.models import User
class UserRef(EmbeddedDocument):
id = fields.ReferenceField(User, required=False)
first_name = fields.StringField(max_length=255, required=True)
last_name = fields.StringField(max_length=255, required=True)
email = fields.EmailField(max_length=255, required=True)
from rest_framework import routers
from rest_framework_mongoengine import routers
routers.SimpleRouter()
from eventos.core.views import CertifiedViewSet, EventViewSet, SubmissionViewSet, TrackViewSet, UserViewSet
router = routers.SimpleRouter()
router.register("user", UserViewSet)
router.register("event", EventViewSet)
router.register("submission", SubmissionViewSet)
router.register("certified", CertifiedViewSet)
router.register("track", TrackViewSet)
from eventos.core.serializers.certified import CertifiedSerializer
from eventos.core.serializers.embedded import EventRefSerializer, TrackRefSerializer, UserRefSerializer
from eventos.core.serializers.event import EventSerializer
from eventos.core.serializers.submission import SubmissionSerializer
from eventos.core.serializers.track import TrackSerializer
from eventos.core.serializers.user import UserSerializer
from rest_framework_mongoengine import serializers
from eventos.core.models import Certified
from eventos.core.serializers import EventRefSerializer, UserRefSerializer
class CertifiedSerializer(serializers.DocumentSerializer):
ref_event = EventRefSerializer(many=False)
ref_user = UserRefSerializer(many=False)
class Meta:
ref_name = "Certified"
model = Certified
from rest_framework_mongoengine import serializers
from eventos.core.models import EventRef, TrackRef, UserRef
class UserRefSerializer(serializers.EmbeddedDocumentSerializer):
class Meta:
ref_name = "ref_user"
model = UserRef
class EventRefSerializer(serializers.EmbeddedDocumentSerializer):
class Meta:
ref_name = "ref_event"
model = EventRef
class TrackRefSerializer(serializers.EmbeddedDocumentSerializer):
class Meta:
ref_name = "ref_track"
model = TrackRef
from rest_framework_mongoengine import serializers
from eventos.core.models import Event, UserRef
from eventos.core.serializers import UserRefSerializer
class EventSerializer(serializers.DocumentSerializer):
owners = UserRefSerializer(many=True)
class Meta:
ref_name = "Event"
model = Event
def create(self, validated_data):
owners_data = validated_data.pop("owners")
event = Event.objects.create(**validated_data)
event.owners = []
for owner_data in owners_data:
event.owners.append(UserRef(**owner_data))
event.save()
return event
def update(self, instance, validated_data):
owners_data = validated_data.pop("owners")
event = super(EventSerializer, self).update(instance, validated_data)
for owner_data in owners_data:
event.owners.append(UserRef(**owner_data))
event.save()
return event
from rest_framework_mongoengine import serializers
from eventos.core.models import Submission, UserRef
from eventos.core.serializers import EventRefSerializer, TrackRefSerializer, UserRefSerializer
class SubmissionSerializer(serializers.DocumentSerializer):
ref_track = TrackRefSerializer(many=False)
ref_event = EventRefSerializer(many=False)
owners = UserRefSerializer(many=True)
class Meta:
ref_name = "Submission"
model = Submission
def create(self, validated_data):
owners_data = validated_data.pop("owners")
submission = Submission.objects.create(**validated_data)
submission.owners = []
for owner_data in owners_data:
submission.owners.append(UserRef(**owner_data))
submission.save()
return submission
def update(self, instance, validated_data):
owners_data = validated_data.pop("owners")
submission = super(SubmissionSerializer, self).update(instance, validated_data)
for owner_data in owners_data:
submission.owners.append(UserRef(**owner_data))
submission.save()
return submission
from rest_framework_mongoengine import serializers
from eventos.core.models import Track
from eventos.core.serializers import EventRefSerializer
class TrackSerializer(serializers.DocumentSerializer):
ref_event = EventRefSerializer(many=False)
class Meta:
ref_name = "Track"
model = Track
from rest_framework_mongoengine import serializers
from eventos.core.models import User
class UserSerializer(serializers.DocumentSerializer):
class Meta:
ref_name = "User"
model = User
# from django.shortcuts import render
# Create your views here.
from eventos.core.views.certified import CertifiedViewSet
from eventos.core.views.event import EventViewSet
from eventos.core.views.submission import SubmissionViewSet
from eventos.core.views.track import TrackViewSet
from eventos.core.views.user import UserViewSet
from rest_framework_mongoengine import viewsets
from eventos.core.models import Certified
from eventos.core.serializers import CertifiedSerializer
class CertifiedViewSet(viewsets.ModelViewSet):
queryset = Certified.objects.all()
serializer_class = CertifiedSerializer
from rest_framework_mongoengine import viewsets
from eventos.core.models import Event
from eventos.core.serializers import EventSerializer
class EventViewSet(viewsets.ModelViewSet):
queryset = Event.objects.all()
serializer_class = EventSerializer
from rest_framework_mongoengine import viewsets
from eventos.core.models import Submission
from eventos.core.serializers import SubmissionSerializer
class SubmissionViewSet(viewsets.ModelViewSet):
queryset = Submission.objects.all()
serializer_class = SubmissionSerializer
from rest_framework_mongoengine import viewsets
from eventos.core.models import Track
from eventos.core.serializers import TrackSerializer
class TrackViewSet(viewsets.ModelViewSet):
queryset = Track.objects.all()
serializer_class = TrackSerializer
from rest_framework_mongoengine import viewsets
from eventos.core.models import User
from eventos.core.serializers import UserSerializer
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
from django.contrib import admin
from django.urls import path
from django.urls import include, path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
# from eventos.core.router import router as core_router
from eventos.core.router import router as core_router
schema_view = get_schema_view(openapi.Info(title="Eventos", default_version="v1"), public=True)
urlpatterns = [
# path("", include(core_router.urls)),
path("", include(core_router.urls)),
path("admin/", admin.site.urls),
path("swagger/", schema_view.with_ui()),
]
db.createUser({
user: "root",
pwd: "eventos",
roles: [
{
role: "readWrite",
db: "eventos",
},
],
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment