# Path: horarios/views.py
# class ProfessionList(generics.ListAPIView):
#     queryset = Profession.objects.all()
#     serializer_class = ProfessionSerializer
# 
# class SessionList(generics.ListCreateAPIView):
#     queryset = Session.objects.all()
#     serializer_class = SessionSerializer
# 
# class SessionDetail(generics.RetrieveUpdateAPIView):
#     permission_classes = (AllowAny,)
#     queryset = Session.objects.all()
#     serializer_class = SessionSerializer
# 
# class SubjectList(generics.ListAPIView):
#     queryset = Subject.objects.all()
#     serializer_class = SubjectSerializer
#     permission_classes = (IsAdminUser,)
# 
# class SubjectDetail(generics.RetrieveAPIView):
#     queryset = Subject.objects.all()
#     serializer_class = SubjectSerializer
# 
# class SubjectProfessionAutocompleteView(APIView):
#     def get(self, request, *args , **kw):
#         import json
#         search_term = kw['search_term']
#         try:
#             profession  = int(kw['profession'])
#         except:
#             profession = ""
#         try:
#             subject_type = json.loads(kw['subject_type'])
#         except:
#             subject_type = []
#         queryset = Subject.autocomplete(search_term,profession,subject_type)
#         print queryset
#         serializer = SubjectSimpleSerializer(queryset, many=True)
#         return Response(serializer.data)


from django.conf.urls import patterns, include, url
from horarios.views import ProfessionList, SessionList, SessionDetail, SubjectList, SubjectDetail, SubjectProfessionAutocompleteView
from django.contrib import admin

urlpatterns = patterns('',
    url(r'^$', 'horarios.views.home', name='home'),
    url(r'^deploy/$', 'horarios.views.do_deploy', name='deploy'),
    url(r'^api/v1.0/subjects/autocomplete/search_term=(?P<search_term>[^&]*)&profession=(?P<profession>[^&]*)&subject_type=(?P<subject_type>[^/]*)[/]?$', SubjectProfessionAutocompleteView.as_view()),
    url(r'^api/v1.0/subjects/$', SubjectList.as_view()),
    url(r'^api/v1.0/subjects/(?P<pk>\w+)$',SubjectDetail.as_view()),
    url(r'^api/v1.0/professions/$', ProfessionList.as_view()),
    url(r'^api/v1.0/sessions/$',SessionList.as_view()),
    url(r'^api/v1.0/sessions/(?P<pk>\w+)$',SessionDetail.as_view()),
    url(r'^admin/', include(admin.site.urls)),

# Path: horarios/views.py
# class ProfessionList(generics.ListAPIView):
#     queryset = Profession.objects.all()
#     serializer_class = ProfessionSerializer
# 
# class SessionList(generics.ListCreateAPIView):
#     queryset = Session.objects.all()
#     serializer_class = SessionSerializer
# 
# class SessionDetail(generics.RetrieveUpdateAPIView):
#     permission_classes = (AllowAny,)
#     queryset = Session.objects.all()
#     serializer_class = SessionSerializer
# 
# class SubjectList(generics.ListAPIView):
#     queryset = Subject.objects.all()
#     serializer_class = SubjectSerializer
#     permission_classes = (IsAdminUser,)
# 
# class SubjectDetail(generics.RetrieveAPIView):
#     queryset = Subject.objects.all()
#     serializer_class = SubjectSerializer
# 
# class SubjectProfessionAutocompleteView(APIView):
#     def get(self, request, *args , **kw):
#         import json
#         search_term = kw['search_term']
#         try:
#             profession  = int(kw['profession'])
#         except:
#             profession = ""
#         try:
#             subject_type = json.loads(kw['subject_type'])
#         except:
#             subject_type = []
#         queryset = Subject.autocomplete(search_term,profession,subject_type)
#         print queryset
#         serializer = SubjectSimpleSerializer(queryset, many=True)
#         return Response(serializer.data)


# Path: horarios/urls.py
from django.conf.urls import patterns, include, url
from horarios.views import ProfessionList, SessionList, SessionDetail, SubjectList, SubjectDetail, SubjectProfessionAutocompleteView
from django.contrib import admin


urlpatterns = patterns('',
    url(r'^$', 'horarios.views.home', name='home'),
    url(r'^deploy/$', 'horarios.views.do_deploy', name='deploy'),
    url(r'^api/v1.0/subjects/autocomplete/search_term=(?P<search_term>[^&]*)&profession=(?P<profession>[^&]*)&subject_type=(?P<subject_type>[^/]*)[/]?$', SubjectProfessionAutocompleteView.as_view()),
    url(r'^api/v1.0/subjects/$', SubjectList.as_view()),
    url(r'^api/v1.0/subjects/(?P<pk>\w+)$',SubjectDetail.as_view()),
    url(r'^api/v1.0/professions/$', ProfessionList.as_view()),
    url(r'^api/v1.0/sessions/$',SessionList.as_view()),
    url(r'^api/v1.0/sessions/(?P<pk>\w+)$',SessionDetail.as_view()),
    url(r'^admin/', include(admin.site.urls)),

)