Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
Serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
rcotrina94 committed May 22, 2015
1 parent 5144af1 commit 6301a5a
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ target/
*.sqlite3

# Node.js modules
platforms/desktop/src/clients/admin/node_modules
platforms/desktop/src/clients/admin/static/assets/components
# platforms/desktop/src/clients/admin/static/assets/components

# Electron builder
platforms/desktop/src/clients/electron


# Platform builds
# platforms/desktop/dist
# platforms/mobiles/dist
Binary file added assets/calendar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/citas.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icon.png
Binary file not shown.
2 changes: 1 addition & 1 deletion platforms/desktop/src/clients/admin/disk.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"accessToken":"534eef8b5dc1661dc1f38602b6db2c92974f3b12"}
{"accessToken":"b5f31ebe9064fa125b8b1ff103739741170696b3","loginData":{"password":"medico","username":"medico"}}
8 changes: 6 additions & 2 deletions platforms/desktop/src/clients/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
},
"author": "Richard Cotrina <[email protected]>",
"license": "ISC",
"devDependencies": {},
"devDependencies": {
"asar": "^0.6.1",
"grunt": "^0.4.5",
"grunt-electron-installer": "^0.31.0"
},
"dependencies": {}
}
}
22 changes: 11 additions & 11 deletions src/citasalud/apps/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
# coding=utf-8

from rest_framework import serializers
from citasalud.apps.main.models import PerfilUsuario, Medico, Especialidad
from citasalud.apps.main.models import Perfil, Medico, Especialidad
from django.contrib.auth.models import User


class PerfilUsuarioSerializer(serializers.ModelSerializer):
""" Serializador para Perfil de Usuario """

class Meta:
model = PerfilUsuario
model = Perfil


class MedicoSerializer(serializers.ModelSerializer):
""" Serializador para Médico """

class Meta:
model = Medico


class UsuarioSerializer(serializers.ModelSerializer):
profile = PerfilUsuarioSerializer()

class Meta:
model = User
fields = ('username', 'email', 'profile', 'is_active')
# fields = ('id', 'username', 'profile','is_superuser')

def create(self, validated_data):
profile_data = validated_data.pop('profile')
user = User.objects.create(**validated_data)
Profile.objects.create(user=user, **profile_data)
return user

class MedicoSerializer(serializers.ModelSerializer):
""" Serializador para Médico """

class Meta:
model = Medico
# extra_kwargs = {'password': {'write_only': True}}


class EspecialidadSerializer(serializers.ModelSerializer):
""" Serializador para Especialidad """
Expand Down
2 changes: 1 addition & 1 deletion src/citasalud/apps/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class CurrentUserView(APIView):

def get(self, request):
serializer = UsuarioSerializer(request.user)
return Response(serializer.data)
return Response(serializer.data)
4 changes: 2 additions & 2 deletions src/citasalud/apps/main/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding=utf-8

from django.contrib import admin
from .models import PerfilUsuario, Especialidad, CitaMedica, Medico, Paciente, Personal
from .models import Perfil, Especialidad, CitaMedica, Medico, Paciente, Personal
# from django.contrib.auth.admin import UserAdmin


Expand All @@ -12,7 +12,7 @@
# (None, {'fields': ("dni", "nombre", "apellidos", "fecha_nacimiento", "telefono", "ciudad",)}),
# )
# ordering = []
admin.site.register(PerfilUsuario)
admin.site.register(Perfil)
admin.site.register(Paciente)
admin.site.register(Personal)
admin.site.register(Medico)
Expand Down
43 changes: 19 additions & 24 deletions src/citasalud/apps/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,26 @@
from django.contrib.auth.models import User


class PerfilUsuario(models.Model):
class Perfil(models.Model):
usuario = models.OneToOneField(User, related_name="profile", null=True, blank=True)
activado = models.BooleanField("Usuario activado")

dni = DNIField("DNI", unique=True)
nombre = models.CharField("Nombre", max_length=32)
apellido_paterno = models.CharField("Ap. Paterno", max_length=16)
apellido_materno = models.CharField("Ap. Materno", max_length=16)

fecha_nacimiento = models.DateField("Fecha de Nacimiento")
telefono = models.CharField("Teléfono", max_length=9, blank=True)

ciudad = models.CharField("Ciudad de origen", max_length=128)

email = models.EmailField("E-mail", unique=True, blank=True)
avatar = models.ImageField("Imagen", upload_to="avatar", null=False, default="/media/avatar/sin_imagen.png", blank=True)

def get_name(self):
return self.nombre.split(" ")[0]

def get_full_name(self):
return "%s %s %s" % (self.nombre, self.apellido_paterno, self.apellido_materno)

def get_short_name(self):
return "%s %s" % (self.get_name(), self.apellido_paterno)

# def get_name(self):
# return self.nombre.split(" ")[0]
#
# def get_full_name(self):
# return "%s %s" % (self.usuario.first_name, self.usuario.last_name)
#
# def get_short_name(self):
# return "%s %s" % (self.get_name(), self.apellido_paterno)
#
def __unicode__(self):
return "[%s] %s" % (self.dni, self.get_full_name())
return "[%s] %s" % (self.dni, self.usuario.get_full_name())

# def has_perm(self, perm, obj=None):
# return True
Expand All @@ -42,7 +34,7 @@ def __unicode__(self):


class Paciente(models.Model):
usuario = models.OneToOneField('PerfilUsuario')
usuario = models.ForeignKey(User, unique=True, related_name="paciente")
nss = PrimaryNumberField("NSS", digits=9)

def __unicode__(self):
Expand All @@ -54,18 +46,21 @@ class Meta:


class Personal(models.Model):
usuario = models.OneToOneField('PerfilUsuario')
usuario = models.ForeignKey(User, unique=True, related_name="personal")
nregistropersonal = PrimaryNumberField("N° Registro personal")
departamento = models.CharField("Departamento", max_length=32)

# class Meta:
# proxy = True


class Medico(Personal):
ncolegiado = PrimaryNumberField("N° Colegiado")
especialidades = models.ManyToManyField("Especialidad", blank=True, related_name='especialidades')

@property
def tipo(self):
def _tipo(self):
return TIPO_MEDICO.ESPECIALISTA if self.especialidades else TIPO_MEDICO.GENERAL
tipo = property(_tipo)

def __unicode__(self):
return "%s (%s)" % (self.usuario.get_short_name(), self.ncolegiado)
Expand Down Expand Up @@ -101,4 +96,4 @@ class Meta:


class HistoriaClinica(models.Model):
paciente = models.OneToOneField("Paciente")
paciente = models.ForeignKey("Paciente", unique=True)
13 changes: 10 additions & 3 deletions src/citasalud/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# coding=utf-8
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin

from citasalud.apps.api.viewsets import MedicoViewSet, EspecialidadViewSet, UsuarioViewSet

from rest_framework.routers import DefaultRouter
Expand All @@ -18,9 +22,12 @@
# Examples:
# url(r'^$', 'citasalud.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^api/currentuser', CurrentUserView.as_view() ),
url(r'^api/', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^api-auth-token/', views.obtain_auth_token),
url(r'^api/auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^api/auth/usuario/', CurrentUserView.as_view() ),
url(r'^api/auth/token/', views.obtain_auth_token),
url(r'^admin/', include(admin.site.urls)),
]

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

0 comments on commit 6301a5a

Please sign in to comment.