# Path: categories/models.py
# class Category(models.Model):
#     name = models.CharField(max_length=30)
#     active = models.BooleanField(default=True)
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def __str__(self):
#         return self.name
# 
# Path: categories/permissions.py
# class CategoryPermission(BasePermission):
# 
#     def has_permission(self, request, view):
# 
#         if view.action in ['list', 'metadata']:
#             return True
#         else:
#             return request.user.is_authenticated() and request.user.is_staff
# 
# Path: categories/serializers.py
# class CategorySerializer(serializers.ModelSerializer):
# 
#     class Meta:
#         model = Category
#         fields = ('id', 'name')


import datetime
from rest_framework import status
from categories.models import Category
from categories.permissions import CategoryPermission
from categories.serializers import CategorySerializer
from rest_framework.viewsets import GenericViewSet
from rest_framework.response import Response


class CategoryViewSet(GenericViewSet):

    permission_classes = [CategoryPermission]
    queryset = Category.objects.filter(active=1)

# Path: categories/models.py
# class Category(models.Model):
#     name = models.CharField(max_length=30)
#     active = models.BooleanField(default=True)
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def __str__(self):
#         return self.name
# 
# Path: categories/permissions.py
# class CategoryPermission(BasePermission):
# 
#     def has_permission(self, request, view):
# 
#         if view.action in ['list', 'metadata']:
#             return True
#         else:
#             return request.user.is_authenticated() and request.user.is_staff
# 
# Path: categories/serializers.py
# class CategorySerializer(serializers.ModelSerializer):
# 
#     class Meta:
#         model = Category
#         fields = ('id', 'name')


# Path: categories/api.py
import datetime
from rest_framework import status
from categories.models import Category
from categories.permissions import CategoryPermission
from categories.serializers import CategorySerializer
from rest_framework.viewsets import GenericViewSet
from rest_framework.response import Response



class CategoryViewSet(GenericViewSet):

    permission_classes = [CategoryPermission]
    queryset = Category.objects.filter(active=1)

    serializer_class = CategorySerializer