-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
105 lines (86 loc) · 3.47 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from django.db import models
from django.contrib.auth.models import User
class Organization(models.Model):
name = models.CharField(max_length=200)
description = models.TextField()
website = models.URLField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
class Project(models.Model):
STATUS_CHOICES = [
('OPEN', 'Open for Contributors'),
('IN_PROGRESS', 'In Progress'),
('COMPLETED', 'Completed'),
]
organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
title = models.CharField(max_length=200)
description = models.TextField()
requirements = models.TextField()
github_url = models.URLField()
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='OPEN')
created_at = models.DateTimeField(auto_now_add=True)
class Task(models.Model):
PRIORITY_CHOICES = [
('LOW', 'Low'),
('MEDIUM', 'Medium'),
('HIGH', 'High'),
]
STATUS_CHOICES = [
('OPEN', 'Open'),
('ASSIGNED', 'Assigned'),
('IN_PROGRESS', 'In Progress'),
('IN_REVIEW', 'In Review'),
('COMPLETED', 'Completed'),
]
project = models.ForeignKey(Project, on_delete=models.CASCADE)
title = models.CharField(max_length=200)
description = models.TextField()
priority = models.CharField(max_length=10, choices=PRIORITY_CHOICES)
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='OPEN')
assigned_to = models.ForeignKey(User, null=True, blank=True, on_delete=models.SET_NULL)
created_at = models.DateTimeField(auto_now_add=True)
class Contribution(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE)
contributor = models.ForeignKey(User, on_delete=models.CASCADE)
pull_request_url = models.URLField(blank=True)
status = models.CharField(max_length=20)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
# views.py
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
class ProjectViewSet(viewsets.ModelViewSet):
queryset = Project.objects.all()
serializer_class = ProjectSerializer
@action(detail=True, methods=['post'])
def volunteer(self, request, pk=None):
project = self.get_object()
task_id = request.data.get('task_id')
task = Task.objects.get(id=task_id, project=project)
task.assigned_to = request.user
task.status = 'ASSIGNED'
task.save()
return Response({'status': 'assigned'})
class TaskViewSet(viewsets.ModelViewSet):
queryset = Task.objects.all()
serializer_class = TaskSerializer
@action(detail=True, methods=['post'])
def submit_contribution(self, request, pk=None):
task = self.get_object()
contribution = Contribution.objects.create(
task=task,
contributor=request.user,
pull_request_url=request.data.get('pull_request_url'),
status='PENDING_REVIEW'
)
return Response({'status': 'contribution submitted'})
# urls.py
from django.urls import path, include
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
router.register(r'projects', ProjectViewSet)
router.register(r'tasks', TaskViewSet)
urlpatterns = [
path('api/', include(router.urls)),
]