# Path: components/admin/api/models.py
# class Skill(models.Model):
#     id = models.AutoField(primary_key=True)
#     name = models.CharField(max_length=254)
#     title = models.CharField(max_length=254)
#     parent = models.CharField(max_length=254)
# 
#     def save(self, *args, **kwargs):
#         super(Skill, self).save(*args, **kwargs)  
# 
#     def __str__(self):
#         return self.name
# 
# class Interest(models.Model):
#     id = models.AutoField(primary_key=True)
#     name = models.CharField(max_length=254)
#     title = models.CharField(max_length=254)
#     parent = models.CharField(max_length=254)
# 
#     def save(self, *args, **kwargs):
#         super(Interest, self).save(*args, **kwargs)  
# 
#     def __str__(self):
#         return self.name
# 
# class Goal(models.Model):
#     id = models.AutoField(primary_key=True)
#     name = models.CharField(max_length=254)
#     title = models.CharField(max_length=254)
#     parent = models.CharField(max_length=254)
# 
#     def __str__(self):
#         return self.name
# 
#     def save(self, *args, **kwargs):
#         super(Goal, self).save(*args, **kwargs)  
# 
# class Project(models.Model):
#     id = models.AutoField(primary_key=True)
#     project_lead = models.ForeignKey(UserProfile, on_delete=models.CASCADE, null=True) 
#     preview = models.BooleanField(default=True) # project will only appear in Project List when set to False
#     
#     # UI properties
#     title = models.CharField(max_length=454, null=True)
#     summary = models.CharField(max_length=254)
#     skills_needed = models.ManyToManyField(Skill)
#     learning_opportunities = models.ManyToManyField(Goal)
#     civic_interests = models.ManyToManyField(Interest)
#     pending_tasks = models.CharField(max_length=454, null=True)
#     progress_made = models.CharField(max_length=454, null=True)
#     additional_info = models.CharField(max_length=454, null=True)  
#     slack_channel = models.CharField(max_length=200)
#     
#     # Admin properties
#     github_repository = models.CharField(max_length=454, null=True)
#     website = models.CharField(max_length=454, null=True)
#     twitter = models.CharField(max_length=454, null=True)
# 
#     def save(self, *args, **kwargs):
#         super(Project, self).save(*args, **kwargs)
# 
#     def __str__(self):
#         return self.title
# 
# Path: components/admin/api/serializers.py
# class SkillSerializer(serializers.ModelSerializer):
# 	owner = serializers.ReadOnlyField(source='owner.username')
# 	class Meta:
# 		model = Skill
# 		fields = ('_id', 'name', 'title', 'parent')
# 
# class InterestSerializer(serializers.ModelSerializer):
# 	owner = serializers.ReadOnlyField(source='owner.username')
# 	class Meta:
# 		model = Interest
# 		fields = ('_id', 'name', 'title', 'parent')
# 
# class GoalSerializer(serializers.ModelSerializer):
# 	owner = serializers.ReadOnlyField(source='owner.username')
# 	class Meta:
# 		model = Goal
# 		fields = ('_id', 'name', 'title', 'parent')
# 
# class ProjectSerializer(serializers.ModelSerializer):
# 	owner = serializers.ReadOnlyField(source='owner.username')
# 	class Meta:
# 		model = Project
# 		fields = ('_id', 'preview', 'title', 'summary', 'skills_needed', 'learning_opportunity', 'civic_interests', 'pending_tasks', 'progress_made', 'additional_info', 'slack_channel', 'github_repository')
# 
# Path: components/admin/api/permissions.py
# class IsOwnerOrReadOnly(permissions.BasePermission):
# 	def has_object_permission(self, request, view, obj):
# 	    if request.method in permissions.SAFE_METHODS:
# 	        return True
# 	    return obj.owner == request.user


from django.http import HttpResponse, Http404
from django.shortcuts import render
from rest_framework import generics, permissions, status, mixins
from .models import Skill, Interest, Goal, Project
from .serializers import SkillSerializer, InterestSerializer, GoalSerializer, ProjectSerializer
from .permissions import IsOwnerOrReadOnly
from django.contrib.auth.models import User
from django.views.generic import TemplateView
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.views import APIView


def index(request):
    return render(request, 'index.html',)

def create_project(request):
	return render(request, 'create_project/index.html',)

class SkillList(generics.ListCreateAPIView):
	queryset = Skill.objects.all()
	serializer_class = SkillSerializer
	permissions_classes = (permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly,)

class SkillDetail(generics.RetrieveUpdateDestroyAPIView):
	queryset = Skill.objects.all()
	serializer_class = SkillSerializer
	permissions_classes = (permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly,)

class InterestList(generics.ListCreateAPIView):
	queryset = Interest.objects.all()
	serializer_class = InterestSerializer
	permissions_classes = (permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly,)

class InterestDetail(generics.RetrieveUpdateDestroyAPIView):

# Path: components/admin/api/models.py
# class Skill(models.Model):
#     id = models.AutoField(primary_key=True)
#     name = models.CharField(max_length=254)
#     title = models.CharField(max_length=254)
#     parent = models.CharField(max_length=254)
# 
#     def save(self, *args, **kwargs):
#         super(Skill, self).save(*args, **kwargs)  
# 
#     def __str__(self):
#         return self.name
# 
# class Interest(models.Model):
#     id = models.AutoField(primary_key=True)
#     name = models.CharField(max_length=254)
#     title = models.CharField(max_length=254)
#     parent = models.CharField(max_length=254)
# 
#     def save(self, *args, **kwargs):
#         super(Interest, self).save(*args, **kwargs)  
# 
#     def __str__(self):
#         return self.name
# 
# class Goal(models.Model):
#     id = models.AutoField(primary_key=True)
#     name = models.CharField(max_length=254)
#     title = models.CharField(max_length=254)
#     parent = models.CharField(max_length=254)
# 
#     def __str__(self):
#         return self.name
# 
#     def save(self, *args, **kwargs):
#         super(Goal, self).save(*args, **kwargs)  
# 
# class Project(models.Model):
#     id = models.AutoField(primary_key=True)
#     project_lead = models.ForeignKey(UserProfile, on_delete=models.CASCADE, null=True) 
#     preview = models.BooleanField(default=True) # project will only appear in Project List when set to False
#     
#     # UI properties
#     title = models.CharField(max_length=454, null=True)
#     summary = models.CharField(max_length=254)
#     skills_needed = models.ManyToManyField(Skill)
#     learning_opportunities = models.ManyToManyField(Goal)
#     civic_interests = models.ManyToManyField(Interest)
#     pending_tasks = models.CharField(max_length=454, null=True)
#     progress_made = models.CharField(max_length=454, null=True)
#     additional_info = models.CharField(max_length=454, null=True)  
#     slack_channel = models.CharField(max_length=200)
#     
#     # Admin properties
#     github_repository = models.CharField(max_length=454, null=True)
#     website = models.CharField(max_length=454, null=True)
#     twitter = models.CharField(max_length=454, null=True)
# 
#     def save(self, *args, **kwargs):
#         super(Project, self).save(*args, **kwargs)
# 
#     def __str__(self):
#         return self.title
# 
# Path: components/admin/api/serializers.py
# class SkillSerializer(serializers.ModelSerializer):
# 	owner = serializers.ReadOnlyField(source='owner.username')
# 	class Meta:
# 		model = Skill
# 		fields = ('_id', 'name', 'title', 'parent')
# 
# class InterestSerializer(serializers.ModelSerializer):
# 	owner = serializers.ReadOnlyField(source='owner.username')
# 	class Meta:
# 		model = Interest
# 		fields = ('_id', 'name', 'title', 'parent')
# 
# class GoalSerializer(serializers.ModelSerializer):
# 	owner = serializers.ReadOnlyField(source='owner.username')
# 	class Meta:
# 		model = Goal
# 		fields = ('_id', 'name', 'title', 'parent')
# 
# class ProjectSerializer(serializers.ModelSerializer):
# 	owner = serializers.ReadOnlyField(source='owner.username')
# 	class Meta:
# 		model = Project
# 		fields = ('_id', 'preview', 'title', 'summary', 'skills_needed', 'learning_opportunity', 'civic_interests', 'pending_tasks', 'progress_made', 'additional_info', 'slack_channel', 'github_repository')
# 
# Path: components/admin/api/permissions.py
# class IsOwnerOrReadOnly(permissions.BasePermission):
# 	def has_object_permission(self, request, view, obj):
# 	    if request.method in permissions.SAFE_METHODS:
# 	        return True
# 	    return obj.owner == request.user


# Path: components/admin/api/views.py
from django.http import HttpResponse, Http404
from django.shortcuts import render
from rest_framework import generics, permissions, status, mixins
from .models import Skill, Interest, Goal, Project
from .serializers import SkillSerializer, InterestSerializer, GoalSerializer, ProjectSerializer
from .permissions import IsOwnerOrReadOnly
from django.contrib.auth.models import User
from django.views.generic import TemplateView
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.views import APIView



def index(request):
    return render(request, 'index.html',)

def create_project(request):
	return render(request, 'create_project/index.html',)

class SkillList(generics.ListCreateAPIView):
	queryset = Skill.objects.all()
	serializer_class = SkillSerializer
	permissions_classes = (permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly,)

class SkillDetail(generics.RetrieveUpdateDestroyAPIView):
	queryset = Skill.objects.all()
	serializer_class = SkillSerializer
	permissions_classes = (permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly,)

class InterestList(generics.ListCreateAPIView):
	queryset = Interest.objects.all()
	serializer_class = InterestSerializer
	permissions_classes = (permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly,)

class InterestDetail(generics.RetrieveUpdateDestroyAPIView):

	queryset = Interest.objects.all()