Skip to content

Commit

Permalink
Merge branch 'mt5-filtrar-tasas-tipo-titulacion' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jcabala14 committed Feb 1, 2018
2 parents 7c21506 + 44c3869 commit e5f6314
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
18 changes: 11 additions & 7 deletions mapa/static/mapa/js/mapa.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var cargarGrado = function(d){
$('#bootstrap_lista_units').html('');

// Llamada a la API
d3.json("/api/provincias/"+ d.id, function (error, universidades) {
d3.json("/api/provincias/"+ d.id + '?tipo_titulacion=0', function (error, universidades) {
//TODO: Handle error
if(universidades.length == 0){
$('#bootstrap_lista_units').html('<p>No se han encontrado universidades en la provincia de '
Expand Down Expand Up @@ -144,12 +144,16 @@ function createGraph(universidad, media){
var media_nacional = ['Media nacional'];
var cursos = new Set();
universidad.tasas.forEach(function(tasa){
x.push(new Date(tasa.curso.toString()));
cursos.add(tasa.curso.toString());
primera_matricula.push(tasa.tasas1.toFixed(2));
segunda_matricula.push(tasa.tasas2.toFixed(2));
tercera_matricula.push(tasa.tasas3.toFixed(2));
cuarta_matricula.push(tasa.tasas4.toFixed(2));
// TODO: Se incluye una condición para así poder mostrar sólo las tasas de grado.
// NOTE: Retocarlo cuando se haga la parte de máster
if (tasa.tipo_titulacion === 0){
x.push(new Date(tasa.curso.toString()));
cursos.add(tasa.curso.toString());
primera_matricula.push(tasa.tasas1.toFixed(2));
segunda_matricula.push(tasa.tasas2.toFixed(2));
tercera_matricula.push(tasa.tasas3.toFixed(2));
cuarta_matricula.push(tasa.tasas4.toFixed(2));
}
});

Object.keys(media).sort().forEach(function(curso){
Expand Down
25 changes: 16 additions & 9 deletions tasas/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ def __init__(self, *args, **kwargs):

class UniversidadSerializer(DynamicFieldsMixin, ModelSerializer):
logo_thumbnail = SerializerMethodField()
tasas = TasaSerializer(many=True, read_only=True)
#tasas = TasaSerializer(many=True, read_only=True)
tasas = SerializerMethodField()
tipo_verbose = SerializerMethodField(read_only=True)

class Meta:
model = Universidad
exclude = ('id',)
depth = 1
def __init__(self, *args, **kwargs):
self.filtro_tipo_tasas = kwargs.pop("filtro_tipo_tasas", None)
super().__init__(*args, **kwargs)

@staticmethod
def get_tasas(obj):
if obj.tasas:
return obj.tasas
def get_tasas(self, obj):
if self.filtro_tipo_tasas is not None:
tasas = obj.tasas.filter(tipo_titulacion=self.filtro_tipo_tasas)
else:
tasas = obj.tasas
return TasaSerializer(tasas, many=True).data

def get_logo_thumbnail(self, obj):
if obj.logo:
Expand All @@ -72,3 +74,8 @@ def get_logo_thumbnail(self, obj):
def get_tipo_verbose(self, obj):
if obj.tipo is not None:
return obj.get_tipo_universidad_verbose(obj.tipo)

class Meta:
model = Universidad
exclude = ('id',)
depth = 1
4 changes: 3 additions & 1 deletion tasas/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ def list(self, request, *args, **kwargs):
# TODO
pass

tipo_titulacion = request.query_params.get('tipo_titulacion', None)

unis = queryset.filter(provincia__iexact=provincia) # get_list_or_404(queryset, provincia__iexact=provincia)
serializer = self.serializer_class(unis, many=True)
serializer = self.serializer_class(unis, filtro_tipo_tasas=tipo_titulacion, many=True)

return Response(serializer.data)

Expand Down

0 comments on commit e5f6314

Please sign in to comment.