Change default filtering system to more simple method.
parent
1a052a080c
commit
fe0cbbc6e1
|
@ -4,6 +4,34 @@ from greenmine.scrum.serializers import *
|
||||||
from greenmine.scrum.models import *
|
from greenmine.scrum.models import *
|
||||||
|
|
||||||
|
|
||||||
|
class SimpleFilterMixin(object):
|
||||||
|
filter_fields = []
|
||||||
|
filter_special_fields = []
|
||||||
|
|
||||||
|
_special_values_dict = {
|
||||||
|
'true': True,
|
||||||
|
'false': False,
|
||||||
|
'null': None,
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
queryset = super(SimpleFilterMixin, self).get_queryset()
|
||||||
|
query_params = {}
|
||||||
|
|
||||||
|
for field_name in self.filter_fields:
|
||||||
|
if field_name in self.request.QUERY_PARAMS:
|
||||||
|
field_data = self.request.QUERY_PARAMS[field_name]
|
||||||
|
if field_data in self._special_values_dict:
|
||||||
|
query_params[field_name] = self._special_values_dict[field_data]
|
||||||
|
else:
|
||||||
|
query_params[field_name] = field_data
|
||||||
|
|
||||||
|
if query_params:
|
||||||
|
queryset = queryset.filter(**query_params)
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
class ProjectList(generics.ListCreateAPIView):
|
class ProjectList(generics.ListCreateAPIView):
|
||||||
model = Project
|
model = Project
|
||||||
serializer_class = ProjectSerializer
|
serializer_class = ProjectSerializer
|
||||||
|
@ -14,7 +42,7 @@ class ProjectDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
serializer_class = ProjectSerializer
|
serializer_class = ProjectSerializer
|
||||||
|
|
||||||
|
|
||||||
class MilestoneList(generics.ListCreateAPIView):
|
class MilestoneList(SimpleFilterMixin, generics.ListCreateAPIView):
|
||||||
model = Milestone
|
model = Milestone
|
||||||
serializer_class = MilestoneSerializer
|
serializer_class = MilestoneSerializer
|
||||||
filter_fields = ('project',)
|
filter_fields = ('project',)
|
||||||
|
@ -25,7 +53,7 @@ class MilestoneDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
serializer_class = MilestoneSerializer
|
serializer_class = MilestoneSerializer
|
||||||
|
|
||||||
|
|
||||||
class UserStoryList(generics.ListCreateAPIView):
|
class UserStoryList(SimpleFilterMixin, generics.ListCreateAPIView):
|
||||||
model = UserStory
|
model = UserStory
|
||||||
serializer_class = UserStorySerializer
|
serializer_class = UserStorySerializer
|
||||||
filter_fields = ('project', 'milestone')
|
filter_fields = ('project', 'milestone')
|
||||||
|
@ -89,7 +117,7 @@ class IssueStatusDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
serializer_class = IssueStatusSerializer
|
serializer_class = IssueStatusSerializer
|
||||||
|
|
||||||
|
|
||||||
class TaskStatusList(generics.ListCreateAPIView):
|
class TaskStatusList(SimpleFilterMixin, generics.ListCreateAPIView):
|
||||||
model = TaskStatus
|
model = TaskStatus
|
||||||
serializer_class = TaskStatusSerializer
|
serializer_class = TaskStatusSerializer
|
||||||
filter_fields = ('project',)
|
filter_fields = ('project',)
|
||||||
|
|
|
@ -29,22 +29,22 @@ subjects = [
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
def create_user(self, counter):
|
||||||
|
user = User.objects.create(
|
||||||
|
username='user%d' % (counter),
|
||||||
|
first_name='user%d' % (counter),
|
||||||
|
email='foouser%d@domain.com' % (counter),
|
||||||
|
)
|
||||||
|
|
||||||
|
user.set_password('user%d' % (counter))
|
||||||
|
user.save()
|
||||||
|
return user
|
||||||
|
|
||||||
@transaction.commit_on_success
|
@transaction.commit_on_success
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
def create_user(counter):
|
|
||||||
user = User(
|
|
||||||
username='user%d' % (counter),
|
|
||||||
first_name='user%d' % (counter),
|
|
||||||
email='foouser%d@domain.com' % (counter),
|
|
||||||
)
|
|
||||||
|
|
||||||
user.set_password('user%d' % (counter))
|
|
||||||
user.save()
|
|
||||||
return user
|
|
||||||
|
|
||||||
users = []
|
users = []
|
||||||
for x in range(10):
|
for x in range(10):
|
||||||
users.append(create_user(x))
|
users.append(self.create_user(x))
|
||||||
|
|
||||||
# projects
|
# projects
|
||||||
for x in xrange(3):
|
for x in xrange(3):
|
||||||
|
@ -128,12 +128,13 @@ class Command(BaseCommand):
|
||||||
for y in xrange(20):
|
for y in xrange(20):
|
||||||
bug = Issue.objects.create(
|
bug = Issue.objects.create(
|
||||||
project=project,
|
project=project,
|
||||||
severity=Severity.objects.get(project=project, order=2),
|
|
||||||
priority=Priority.objects.get(project=project, order=3),
|
|
||||||
type=IssueType.objects.get(project=project, order=1),
|
|
||||||
subject=lorem_ipsum.words(random.randint(1, 5), common=False),
|
subject=lorem_ipsum.words(random.randint(1, 5), common=False),
|
||||||
description=lorem_ipsum.words(random.randint(1, 15), common=False),
|
description=lorem_ipsum.words(random.randint(1, 15), common=False),
|
||||||
owner=project.owner,
|
owner=project.owner,
|
||||||
|
severity=Severity.objects.get(project=project, order=2),
|
||||||
|
status=IssueStatus.objects.get(project=project, order=4),
|
||||||
|
priority=Priority.objects.get(project=project, order=2),
|
||||||
|
type=IssueType.objects.get(project=project, order=1),
|
||||||
tags=[],
|
tags=[],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ class UserStorySerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserStory
|
model = UserStory
|
||||||
fields = ()
|
fields = ()
|
||||||
|
depth = 0
|
||||||
|
|
||||||
|
|
||||||
class ChangeSerializer(serializers.ModelSerializer):
|
class ChangeSerializer(serializers.ModelSerializer):
|
||||||
|
|
Loading…
Reference in New Issue