Commit 15eb91b0 authored by Florent Chehab's avatar Florent Chehab
Browse files

New viewset for all modules

Cleaning and Optimizations, more to go
parent d08b29b3
...@@ -2,19 +2,21 @@ from .university import University # noqa: F401 ...@@ -2,19 +2,21 @@ from .university import University # noqa: F401
from .campus import Campus, CampusViewSet, CampusSerializer # noqa: F401 from .campus import Campus, CampusViewSet, CampusSerializer # noqa: F401
from .universityAPI import UniversitySerializer, UniversityViewSet # noqa: F401 from .universityAPI import UniversitySerializer, UniversityViewSet # noqa: F401
from .universityScholarship import UniversityScholarship, UniversityScholarshipViewSet # noqa: F401 from .universityScholarship import UniversityScholarship, UniversityScholarshipSerializer, UniversityScholarshipViewSet # noqa: F401
from .universityDri import UniversityDri, UniversityDriViewSet # noqa: F401 from .universityDri import UniversityDri, UniversityDriSerializer, UniversityDriViewSet # noqa: F401
from .universityInfo import UniversityInfo, UniversityInfoViewSet # noqa: F401 from .universityInfo import UniversityInfo, UniversityInfoSerializer, UniversityInfoViewSet # noqa: F401
from .universitySemestersDates import UniversitySemestersDates, UniversitySemestersDatesViewSet # noqa: F401 from .universitySemestersDates import UniversitySemestersDates, UniversitySemestersDatesSerializer, UniversitySemestersDatesViewSet # noqa: F401
from .universityBasicModules import UniversityInsurance, UniversityInsuranceViewSet # noqa: F401 from .universityBasicModules import UniversityInsurance, UniversityInsuranceSerializer, UniversityInsuranceViewSet # noqa: F401
from .universityBasicModules import UniversityCourses, UniversityCoursesViewSet # noqa: F401 from .universityBasicModules import UniversityCourses, UniversityCoursesSerializer, UniversityCoursesViewSet # noqa: F401
from .universityBasicModules import UniversityCulture, UniversityCultureViewSet # noqa: F401 from .universityBasicModules import UniversityCulture, UniversityCultureSerializer, UniversityCultureViewSet # noqa: F401
from .universityBasicModules import UniversityOtherStuff, UniversityOtherStuffViewSet # noqa: F401 from .universityBasicModules import UniversityOtherStuff, UniversityOtherStuffSerializer, UniversityOtherStuffViewSet # noqa: F401
from .universityBasicModules import UniversitySpecialOffer, UniversitySpecialOfferViewSet # noqa: F401 from .universityBasicModules import UniversitySpecialOffer, UniversitySpecialOfferSerializer, UniversitySpecialOfferViewSet # noqa: F401
from .campusBasicModules import CampusAccommodation, CampusAccommodationViewSet # noqa: F401 from .campusBasicModules import CampusAccommodation, CampusAccommodationSerializer, CampusAccommodationViewSet # noqa: F401
from .campusBasicModules import CampusTransport, CampusTransportViewSet # noqa: F401 from .campusBasicModules import CampusTransport, CampusTransportSerializer, CampusTransportViewSet # noqa: F401
from .campusBasicModules import CampusCultureAndStudentLife, CampusCultureAndStudentLifeViewSet # noqa: F401 from .campusBasicModules import CampusCultureAndStudentLife, CampusCultureAndStudentLifeSerializer, CampusCultureAndStudentLifeViewSet # noqa: F401
from .campusBasicModules import CampusOtherStuff, CampusOtherStuffViewSet # noqa: F401 from .campusBasicModules import CampusOtherStuff, CampusOtherStuffSerializer, CampusOtherStuffViewSet # noqa: F401
from .universityPhoto import UniversityPhoto, UniversityPhotoViewSet # noqa: F401 from .universityPhoto import UniversityPhoto, UniversityPhotoSerializer, UniversityPhotoViewSet # noqa: F401
from .universityModulesAPI import UniversityModulesViewSet # noqa: F401
...@@ -13,5 +13,5 @@ class UniversitySerializer(serializers.ModelSerializer): ...@@ -13,5 +13,5 @@ class UniversitySerializer(serializers.ModelSerializer):
class UniversityViewSet(viewsets.ModelViewSet): # TODO switch to dict class UniversityViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,) permission_classes = (permissions.DjangoModelPermissions,)
queryset = University.objects.all() # pylint: disable=E1101 queryset = University.objects.all().prefetch_related('univ_campus') # pylint: disable=E1101
serializer_class = UniversitySerializer serializer_class = UniversitySerializer
from backend.models.university import University
from rest_framework import serializers, viewsets, permissions
from backend.models.university.campus import CampusSerializer
from backend.models.university import UniversityDriSerializer
class UniversityModulesSerializer(serializers.ModelSerializer):
univ_campus = CampusSerializer(many=True, read_only=True)
university_dri = UniversityDriSerializer(many=True, read_only=True)
class Meta:
model = University
fields = '__all__'
class UniversityModulesViewSet(viewsets.ModelViewSet): # TODO switch to dict
serializer_class = UniversityModulesSerializer
def get_queryset(self):
univ_id = self.kwargs['univ_id']
return University.objects.filter(id=univ_id).prefetch_related('univ_campus', 'university_dri') # pylint: disable=E1101
permission_classes = (permissions.DjangoModelPermissions,)
# queryset = get_queryset()
...@@ -37,6 +37,7 @@ from backend.models.university import UniversityOtherStuffViewSet ...@@ -37,6 +37,7 @@ from backend.models.university import UniversityOtherStuffViewSet
from backend.models.university import UniversitySpecialOfferViewSet from backend.models.university import UniversitySpecialOfferViewSet
from backend.models.university import UniversityPhotoViewSet from backend.models.university import UniversityPhotoViewSet
from backend.models.university import UniversityDriViewSet from backend.models.university import UniversityDriViewSet
from backend.models.university import UniversityModulesViewSet
from backend.models.university import CampusTransportViewSet from backend.models.university import CampusTransportViewSet
from backend.models.university import CampusAccommodationViewSet from backend.models.university import CampusAccommodationViewSet
...@@ -84,6 +85,7 @@ router.register(r'city_more/other_stuff', CityOtherStuffViewSet) ...@@ -84,6 +85,7 @@ router.register(r'city_more/other_stuff', CityOtherStuffViewSet)
router.register(r'city_more/photos', CityPhotoViewSet) router.register(r'city_more/photos', CityPhotoViewSet)
router.register(r'university_more/all/(?P<univ_id>[0-9]+)', UniversityModulesViewSet, "university_details")
router.register(r'university_more/scholarship', UniversityScholarshipViewSet) router.register(r'university_more/scholarship', UniversityScholarshipViewSet)
router.register(r'university_more/info', UniversityInfoViewSet) router.register(r'university_more/info', UniversityInfoViewSet)
router.register(r'university_more/insurance', UniversityInsuranceViewSet) router.register(r'university_more/insurance', UniversityInsuranceViewSet)
......
...@@ -31,12 +31,13 @@ INSTALLED_APPS = [ ...@@ -31,12 +31,13 @@ INSTALLED_APPS = [
'reversion_compare', 'reversion_compare',
'rest_framework', 'rest_framework',
'rest_framework.authtoken', 'rest_framework.authtoken',
'main_website',
'backend', 'backend',
'frontend' 'frontend',
'debug_toolbar',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
...@@ -47,6 +48,8 @@ MIDDLEWARE = [ ...@@ -47,6 +48,8 @@ MIDDLEWARE = [
# 'general.middleware.LoginRequiredMiddleware', # 'general.middleware.LoginRequiredMiddleware',
] ]
INTERNAL_IPS = ['127.0.0.1']
LOGIN_URL = '/user/login' LOGIN_URL = '/user/login'
LOGIN_EXEMPT_URLS = [LOGIN_URL, LOGIN_EXEMPT_URLS = [LOGIN_URL,
'/admin/', '/admin/',
......
...@@ -5,7 +5,14 @@ from django.contrib import admin ...@@ -5,7 +5,14 @@ from django.contrib import admin
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
import django_cas_ng.views import django_cas_ng.views
urlpatterns = [
if settings.DEBUG:
import debug_toolbar
urlpatterns = [
url(r'^__debug__/', include(debug_toolbar.urls)),
]
urlpatterns += [
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^user/login$', url(r'^user/login$',
django_cas_ng.views.login, django_cas_ng.views.login,
......
from django.apps import AppConfig
class MainWebsiteConfig(AppConfig):
name = 'main_website'
<!DOCTYPE html>
<html>
<head>
<title>Python Getting Started on Heroku</title>
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<style type="text/css">
.jumbotron {
background: #532f8c;
color: white;
padding-bottom: 80px
}
.jumbotron .btn-primary {
background: #845ac7;
border-color: #845ac7
}
.jumbotron .btn-primary:hover {
background: #7646c1
}
.jumbotron p {
color: #d9ccee;
max-width: 75%;
margin: 1em auto 2em
}
.navbar+.jumbotron {
margin-top: -20px
}
.jumbotron .lang-logo {
display: block;
background: #b01302;
border-radius: 50%;
overflow: hidden;
width: 100px;
height: 100px;
margin: auto;
border: 2px solid white
}
.jumbotron .lang-logo img {
max-width: 100%
}
</style>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top navbar-inverse">
<div class="container">
<ul class="nav navbar-nav">
<li class="active">
<a href="/"><span class="glyphicon glyphicon-home"></span> Home</a>
</li>
<li>
<a href="https://devcenter.heroku.com/articles/how-heroku-works"><span class="glyphicon glyphicon-user"></span> How Heroku Works</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><span class="glyphicon glyphicon-info-sign"></span> Getting Started Guides <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="https://devcenter.heroku.com/articles/getting-started-with-ruby">Getting Started with Ruby on Heroku</a></li>
<li><a href="https://devcenter.heroku.com/articles/getting-started-with-nodejs">Getting Started with Node on Heroku</a></li>
<li><a href="https://devcenter.heroku.com/articles/getting-started-with-php">Getting Started with PHP on Heroku</a></li>
<li><a href="https://devcenter.heroku.com/articles/getting-started-with-python">Getting Started with Python on Heroku</a></li>
<li><a href="https://devcenter.heroku.com/articles/getting-started-with-java">Getting Started with Java on Heroku</a></li>
<li><a href="https://devcenter.heroku.com/articles/getting-started-with-clojure">Getting Started with Clojure on Heroku</a></li>
<li><a href="https://devcenter.heroku.com/articles/getting-started-with-scala">Getting Started with Scala on Heroku</a></li>
<li class="divider"></li>
<li><a href="https://devcenter.heroku.com/articles/getting-started-with-heroku-and-connect-without-local-dev">Getting Started on Heroku with Heroku Connect</a></li>
<li><a href="https://devcenter.heroku.com/articles/getting-started-with-jruby">Getting Started with Ruby on Heroku (Microsoft Windows)</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="navbar-right">
<a href="https://devcenter.heroku.com"><span class="glyphicon glyphicon-book"></span> Heroku Dev Center</a>
</li>
</ul>
</div>
</nav>
{% block content %}{% endblock %}
</body>
</html>
...@@ -15,3 +15,4 @@ django-reversion-compare==0.8.4 ...@@ -15,3 +15,4 @@ django-reversion-compare==0.8.4
reverse-geocoder==1.5.1 reverse-geocoder==1.5.1
coverage==4.5.1 coverage==4.5.1
flake8 flake8
django-debug-toolbar==1.9.1
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