Skip to content

Commit

Permalink
Update relatorio and graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
devbaraus committed Apr 8, 2021
1 parent 32bfb63 commit 96e3d0d
Show file tree
Hide file tree
Showing 21 changed files with 689 additions and 44 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,4 @@ venv.bak/
.mypy_cache/

.idea/
static/
src/**/migrations
static/
4 changes: 3 additions & 1 deletion config/initdb/view_pergunta.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ from graph_participacaopergunta participacao
left join graph_dimensao dimensao on pergunta.dimensao_id = dimensao.id
left join graph_eixo eixo on dimensao.eixo_id = eixo.id;

refresh materialized view informacoes;
refresh materialized view informacoes;

update table
26 changes: 23 additions & 3 deletions config/requirements.pip
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
Django==2.2.0
aniso8601==7.0.0
appdirs==1.4.4
distlib==0.3.1
Django==2.2
django-cors-headers==3.1.1
djangorestframework==3.12.2
et-xmlfile==1.0.1
filelock==3.0.12
graphene==2.1.8
graphene-django==2.15.0
graphene-generator==0.1.2
graphql-core==2.3.2
graphql-relay==2.0.1
gunicorn==19.6.0
psycopg2>s=2.8.2
openpyxl==3.0.7
promise==2.3
psycopg2==2.8.6
pytz==2021.1
Rx==1.6.1
singledispatch==3.6.1
six==1.15.0
sqlparse==0.4.1
text-unidecode==1.3
virtualenv==20.4.3
xlrd==1.2.0
django-cors-headers==3.1.1
25 changes: 25 additions & 0 deletions config/requirements.pop
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
aniso8601==7.0.0
appdirs==1.4.4
distlib==0.3.1
Django==2.2
django-cors-headers==3.1.1
djangorestframework==3.12.2
et-xmlfile==1.0.1
filelock==3.0.12
graphene==2.1.8
graphene-django==2.15.0
graphene-generator==0.1.2
graphql-core==2.3.2
graphql-relay==2.0.1
gunicorn==19.6.0
openpyxl==3.0.7
promise==2.3
psycopg2==2.8.6
pytz==2021.1
Rx==1.6.1
singledispatch==3.6.1
six==1.15.0
sqlparse==0.4.1
text-unidecode==1.3
virtualenv==20.4.3
xlrd==1.2.0
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: "3.3"
services:
nginx:
cpanginx:
image: nginx:latest
container_name: cpa_nginx
ports:
Expand All @@ -16,7 +16,7 @@ services:
VIRTUAL_PORT: 8000
LETSENCRYPT_HOST: api.cpa.bcc.anapolis.ifg.edu.br
LETSENCRYPT_EMAIL: "[email protected]"
web:
cpaweb:
build: .
container_name: cpa_app
restart: always
Expand All @@ -33,7 +33,7 @@ services:
DATABASE_HOST: db2
DATABASE_PORT: 5432
DATABASE_NAME: cpadash
db2:
cpadb:
image: postgres:alpine
container_name: cpa_db
restart: always
Expand Down
3 changes: 0 additions & 3 deletions src/.vscode/settings.json

This file was deleted.

13 changes: 13 additions & 0 deletions src/cpadash/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import graphene
from graphene_generator.holder import QueriesHolder, MutationsHolder


class Query(QueriesHolder, graphene.ObjectType):
pass


class Mutation(MutationsHolder, graphene.ObjectType):
pass


schema = graphene.Schema(query=Query, mutation=MutationsHolder)
110 changes: 107 additions & 3 deletions src/cpadash/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*', 'web', 'cpa.localhost', 'localhost', '0.0.0.0', '127.0.0.1', 'api.cpa.bcc.anapolis.ifg.edu.br', 'cpa.bcc.anapolis.ifg.edu.br']
ALLOWED_HOSTS = ['*', 'web', 'cpa.localhost', 'localhost', '0.0.0.0', '127.0.0.1', 'api.cpa.bcc.anapolis.ifg.edu.br',
'cpa.bcc.anapolis.ifg.edu.br']
CORS_ALLOW_METHODS = [
'GET', 'POST'
'GET', 'POST', 'PUT'
]
CORS_ORIGIN_ALLOW_ALL = True # ativando o cors para o DJANGO
CORS_ALLOW_CREDENTIALS = True
Expand All @@ -40,8 +41,104 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'graph.apps.GraphConfig',

'rest_framework',
'rest_framework.authtoken',
'graphene_django',
'corsheaders',

'graph.apps.GraphConfig',
]

GRAPHENE = {
"SCHEMA": "cpadash.schema.schema"
}

GRAPHENE_GENERATOR_MODELS = [
{
'name': 'questionario',
'path': 'graph.models.Questionario',
'require_auth': {
'mutations': ["create", 'update', 'delete']
}
},
{
'name': 'eixo',
'path': 'graph.models.Eixo',
'require_auth': {
'mutations': ["create", 'update', 'delete']
}
},
{
'name': 'dimensao',
'path': 'graph.models.Dimensao',
'require_auth': {
'mutations': ["create", 'update', 'delete']
}
},
{
'name': 'segmento',
'path': 'graph.models.Segmento',
'require_auth': {
'mutations': ["create", 'update', 'delete']
}
},
{
'name': 'atuacao',
'path': 'graph.models.Atuacao',
'require_auth': {
'mutations': ["create", 'update', 'delete']
}
},
{
'name': 'lotacao',
'path': 'graph.models.Lotacao',
'require_auth': {
'mutations': ["create", 'update', 'delete']
}
},
{
'name': 'campus',
'path': 'graph.models.Campus',
'require_auth': {
'mutations': ["create", 'update', 'delete']
}
},
{
'name': 'curso',
'path': 'graph.models.Curso',
'require_auth': {
'mutations': ["create", 'update', 'delete']
}
},
{
'name': 'pergunta',
'path': 'graph.models.Pergunta',
'require_auth': {
'mutations': ["create", 'update', 'delete']
}
},
{
'name': 'pergunta_segmento',
'path': 'graph.models.PerguntaSegmento',
'require_auth': {
'mutations': ["create", 'update', 'delete']
}
},
{
'name': 'resposta_objetiva',
'path': 'graph.models.RespostaObjetiva',
'require_auth': {
'mutations': ["create", 'update', 'delete']
}
},
{
'name': 'participacao',
'path': 'graph.models.ParticipacaoPergunta',
'require_auth': {
'mutations': ["create", 'update', 'delete']
}
},
]

MIDDLEWARE = [
Expand All @@ -55,7 +152,14 @@
'corsheaders.middleware.CorsMiddleware',
]

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication', # <-- And here
],
}

ROOT_URLCONF = 'cpadash.urls'
APPEND_SLASH = False

TEMPLATES = [
{
Expand Down
10 changes: 7 additions & 3 deletions src/cpadash/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
"""
from django.contrib import admin
from django.urls import path, include
from django.views.decorators.csrf import csrf_exempt
from graph.views import index

from src.graph.authenticated.views import DRFAuthenticatedGraphQLView

urlpatterns = [
path('*', index , name='home'),
path('admin/', admin.site.urls),
path('', include('graph.urls'))
path('*', index, name='home'),
path(r'admin', admin.site.urls),
path(r'graphql', csrf_exempt(DRFAuthenticatedGraphQLView.as_view(graphiql=True))),
path(r'', include('graph.urls')),
]
5 changes: 3 additions & 2 deletions src/graph/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin
from .models import Pessoa, Curso, Campus, Eixo, Pergunta, Segmento, Atuacao, Dimensao, ParticipacaoPergunta, \
CursoCampus, PerguntaSegmento, RespostaObjetiva, Lotacao
CursoCampus, PerguntaSegmento, RespostaObjetiva, Lotacao, Questionario

# Register your models here.
admin.site.register(Pessoa)
Expand All @@ -15,4 +15,5 @@
admin.site.register(ParticipacaoPergunta)
admin.site.register(CursoCampus)
admin.site.register(PerguntaSegmento)
admin.site.register(RespostaObjetiva)
admin.site.register(RespostaObjetiva)
admin.site.register(Questionario)
67 changes: 67 additions & 0 deletions src/graph/authenticated/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from django.contrib.auth.models import User
from django.forms.models import model_to_dict
from graphene_django.views import GraphQLView
import rest_framework
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import authentication_classes, permission_classes, api_view
from rest_framework.settings import api_settings


class DRFAuthenticatedGraphQLView(GraphQLView):
def parse_body(self, request):
if isinstance(request, rest_framework.request.Request):
return request.data
return super(DRFAuthenticatedGraphQLView, self).parse_body(request)

@classmethod
def as_view(cls, *args, **kwargs):
view = super(DRFAuthenticatedGraphQLView, cls).as_view(*args, **kwargs)
view = permission_classes((IsAuthenticated,))(view)
view = authentication_classes(api_settings.DEFAULT_AUTHENTICATION_CLASSES)(view)
view = api_view(['GET', 'POST'])(view)
return view

class AuthView(APIView):
permission_classes = (IsAuthenticated,) # <-- And here

def get(self, request):
content = {
"username": f'{request.user}'
}

return Response(content)


class UserView(APIView):
permission_classes = (IsAuthenticated,) # <-- And here

def get(self, request):
user = User.objects.get(username=request.user)
user = model_to_dict(user)
user.pop('password')
user.pop('groups')
user.pop('user_permissions')

return Response(user)

def put(self, request):
updated_user = request.data

user = User.objects.get(username=request.user)

if updated_user['first_name'] is not None:
user.first_name = updated_user['first_name']

if updated_user['last_name'] is not None:
user.last_name = updated_user['last_name']

if updated_user['email'] is not None:
user.email = updated_user['email']

user.save()

content = model_to_dict(user)

return Response(content)
Loading

0 comments on commit 96e3d0d

Please sign in to comment.