Ejemplo n.º 1
0
 def get_serializer_context(self):
     context = RetrieveAPIView.get_serializer_context(self)
     user_id = self.kwargs.get('id')
     user = User.objects.filter(id=user_id).first()
     context.update(dict(user=user))
     return context
Ejemplo n.º 2
0
from enhydris.api import serializers

_urls = [
    'enhydris.api.views',
    url(r'^$', 'api_root'),
    url(r'^tsdata/(?P<pk>\d+)/$', Tsdata.as_view(), name='tsdata')
]
all_models = dict((x, models.__dict__[x]) for x in models.__dict__)
all_models.update(
    dict((x, iwidget_models.__dict__[x]) for x in iwidget_models.__dict__))
for _x in modelnames:
    model = all_models[_x]
    serializer_class = None
    if _x == 'Station':
        serializer_class = serializers.StationSerializer
    detail_view = RetrieveAPIView.as_view(model=model,
                                          serializer_class=serializer_class)
    list_view = ListAPIView.as_view(model=model,
                                    serializer_class=serializer_class)
    if _x == 'Timeseries':
        list_view = TimeseriesList.as_view()
        detail_view = TimeseriesDetail.as_view()
    _urls.append(url(r'^{0}/$'.format(_x), list_view, name=_x + '-list'))
    _urls.append(
        url(r'^{0}/modified_after/(?P<modified_after>.*)/$'.format(_x),
            list_view,
            name=_x + '-list'))
    _urls.append(
        url(r'^{0}/(?P<pk>\d+)/$'.format(_x), detail_view,
            name=_x + '-detail'))

urlpatterns = format_suffix_patterns(patterns(*_urls))
Ejemplo n.º 3
0
from enhydris.hcore import models
from iwidget import models as iwidget_models
from enhydris.api.views import modelnames, TimeseriesList, TimeseriesDetail,\
    Tsdata, ListAPIView
from enhydris.api import serializers

_urls = ['enhydris.api.views',
         url(r'^$', 'api_root'),
         url(r'^tsdata/(?P<pk>\d+)/$', Tsdata.as_view(), name='tsdata')]
all_models = dict((x, models.__dict__[x]) for x in models.__dict__)
all_models.update(dict((x, iwidget_models.__dict__[x]) for x in iwidget_models.__dict__))
for _x in modelnames:
    model = all_models[_x]
    serializer_class = None
    if _x == 'Station':
        serializer_class = serializers.StationSerializer
    detail_view = RetrieveAPIView.as_view(model=model,
                                          serializer_class=serializer_class)
    list_view = ListAPIView.as_view(model=model,
                                    serializer_class=serializer_class)
    if _x == 'Timeseries':
        list_view = TimeseriesList.as_view()
        detail_view = TimeseriesDetail.as_view()
    _urls.append(url(r'^{0}/$'.format(_x), list_view, name=_x + '-list'))
    _urls.append(url(r'^{0}/modified_after/(?P<modified_after>.*)/$'
                     .format(_x), list_view, name=_x + '-list'))
    _urls.append(url(r'^{0}/(?P<pk>\d+)/$'.format(_x), detail_view,
                     name=_x + '-detail'))

urlpatterns = format_suffix_patterns(patterns(*_urls))
Ejemplo n.º 4
0
         OwnProfileView.as_view(),
         name="profile_edit_view"),
    path(
        'view/all',
        ListAPIView.as_view(
            authentication_classes=settings.AUTH_CLASSES,
            permission_classes=settings.PERM_CLASSES,
            serializer_class=QuickUserSerializer,
            queryset=User.objects.all(),
        )),
    path(
        'view/<str:username>',
        RetrieveAPIView.as_view(
            authentication_classes=settings.AUTH_CLASSES,
            permission_classes=settings.PERM_CLASSES,
            serializer_class=QuickUserSerializer,
            lookup_field="username",
            queryset=User.objects.all(),
        )),
    path('validate',
         views.ValidateUserData.as_view(),
         name="validate_username"),
    path('activate/<uidb64>/<token>',
         views.Activate.as_view(),
         name='activate'),
    path('search', views.UserSearch.as_view(), name="user_search"),
    path('color/<str:username>',
         views.UserColorView.as_view(),
         name="user_colors"),
]
Ejemplo n.º 5
0
 def get(self, request, *args, **kwargs):
     return RetrieveAPIView.get(self, request, *args, **kwargs) \
         if 'pk' in kwargs else ListAPIView.get(self, request, *args, **kwargs)
Ejemplo n.º 6
0
from django.urls import path, include
from course import views
from rest_framework.generics import RetrieveAPIView
from course.serializers import CourseSerializer

from course.models import *

urlpatterns = [
    path('api/1', views.api1),
    path('courses/', views.CourseList.as_view(), name='course-list'),
    # path('courses/<int:pk>', views.CourseDetail.as_view()),
    path(
        'courses/<int:pk>',
        RetrieveAPIView.as_view(queryset=Course.objects.all(),
                                serializer_class=CourseSerializer)),
]
Ejemplo n.º 7
0
from enhydris.hcore import models
from enhydris.api.views import modelnames, TimeseriesList, TimeseriesDetail,\
    Tsdata, ListAPIView, StationList, StationDetail

_urls = ['enhydris.api.views',
         url(r'^$', 'api_root'),
         url(r'^tsdata/(?P<pk>\d+)/$', Tsdata.as_view(), name='tsdata')]
for _x in modelnames:
    model = models.__dict__[_x]
    if _x == 'Station':
        list_view = StationList.as_view()
        detail_view = StationDetail.as_view()
    elif _x == 'Timeseries':
        list_view = TimeseriesList.as_view()
        detail_view = TimeseriesDetail.as_view()
    else:
        class serializer(serializers.ModelSerializer):
            class Meta:
                model = model
                exclude = ()
        detail_view = RetrieveAPIView.as_view(queryset=model.objects.all())
        list_view = ListAPIView.as_view(queryset=model.objects.all(),
                                        serializer_class=serializer)
    _urls.append(url(r'^{0}/$'.format(_x), list_view, name=_x + '-list'))
    _urls.append(url(r'^{0}/modified_after/(?P<modified_after>.*)/$'
                     .format(_x), list_view, name=_x + '-list'))
    _urls.append(url(r'^{0}/(?P<pk>\d+)/$'.format(_x), detail_view,
                     name=_x + '-detail'))

urlpatterns = format_suffix_patterns(patterns(*_urls))