# Path: djangozik/models.py
# class Album(models.Model):
#     name = models.CharField(max_length=250)
#     date = models.DateField('date released', null=True)
#     picture = models.CharField(max_length=256, null=True)
#     slug = models.SlugField(db_index=True)
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.name)
#         super(Album, self).save(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']
# 
# class Artist(models.Model):
#     name = models.CharField(max_length=250)
#     picture = models.CharField(max_length=256, null=True)
#     text = models.TextField(null=True)
#     slug = models.SlugField(db_index=True)
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.name)
#         super(Artist, self).save(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']
# 
# class Song(models.Model):
#     title = models.CharField(max_length=250)
#     artist = models.ForeignKey(Artist, related_name="song")
#     style = models.ForeignKey(Style, related_name="song")
#     album = models.ForeignKey(Album, related_name="song")
#     filepath = models.CharField(max_length=256)
#     slug = models.SlugField(db_index=True)
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.title)
#         super(Song, self).save(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.title
# 
#     class Meta:
#         ordering = ['title']
# 
# class Style(models.Model):
#     name = models.CharField(max_length=250)
#     slug = models.SlugField(db_index=True)
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.name)
#         super(Style, self).save(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']
# 
# Path: api/models.py
# class ApiKey(models.Model):
#     name = models.CharField(max_length=250)
#     key = models.TextField(null=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']


from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import status
from django.shortcuts import get_object_or_404
from djangozik.models import Album, Artist, Song, Style
from api.models import ApiKey
from rest_framework_extensions.cache.decorators import cache_response
from django.utils.text import slugify
import json


class DjangoZikAPIView(APIView):
    def calculate_cache_key(self, view_instance, view_method,
                            request, args, kwargs):
        get_params = request.query_params.copy()
        del get_params['key']
        get_params = json.dumps(get_params)
        get_params = slugify(u'%s' % get_params)
        return '.'.join([
            get_params,
            request.path
        ])


class ArtistApiView(DjangoZikAPIView):
    @cache_response(60 * 15, key_func='calculate_cache_key')
    def get(self, request):
        get_object_or_404(ApiKey, key=request.GET.get('key', None))
        api_response = ApiResponse()
        content = {}
        try:
            style = request.GET.get('style', None)
            if style is not None:

# Path: djangozik/models.py
# class Album(models.Model):
#     name = models.CharField(max_length=250)
#     date = models.DateField('date released', null=True)
#     picture = models.CharField(max_length=256, null=True)
#     slug = models.SlugField(db_index=True)
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.name)
#         super(Album, self).save(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']
# 
# class Artist(models.Model):
#     name = models.CharField(max_length=250)
#     picture = models.CharField(max_length=256, null=True)
#     text = models.TextField(null=True)
#     slug = models.SlugField(db_index=True)
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.name)
#         super(Artist, self).save(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']
# 
# class Song(models.Model):
#     title = models.CharField(max_length=250)
#     artist = models.ForeignKey(Artist, related_name="song")
#     style = models.ForeignKey(Style, related_name="song")
#     album = models.ForeignKey(Album, related_name="song")
#     filepath = models.CharField(max_length=256)
#     slug = models.SlugField(db_index=True)
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.title)
#         super(Song, self).save(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.title
# 
#     class Meta:
#         ordering = ['title']
# 
# class Style(models.Model):
#     name = models.CharField(max_length=250)
#     slug = models.SlugField(db_index=True)
# 
#     def save(self, *args, **kwargs):
#         self.slug = slugify(self.name)
#         super(Style, self).save(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']
# 
# Path: api/models.py
# class ApiKey(models.Model):
#     name = models.CharField(max_length=250)
#     key = models.TextField(null=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']


# Path: api/views.py
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import status
from django.shortcuts import get_object_or_404
from djangozik.models import Album, Artist, Song, Style
from api.models import ApiKey
from rest_framework_extensions.cache.decorators import cache_response
from django.utils.text import slugify
import json



class DjangoZikAPIView(APIView):
    def calculate_cache_key(self, view_instance, view_method,
                            request, args, kwargs):
        get_params = request.query_params.copy()
        del get_params['key']
        get_params = json.dumps(get_params)
        get_params = slugify(u'%s' % get_params)
        return '.'.join([
            get_params,
            request.path
        ])


class ArtistApiView(DjangoZikAPIView):
    @cache_response(60 * 15, key_func='calculate_cache_key')
    def get(self, request):
        get_object_or_404(ApiKey, key=request.GET.get('key', None))
        api_response = ApiResponse()
        content = {}
        try:
            style = request.GET.get('style', None)
            if style is not None:

                content['artists'] = Artist.objects.filter(