# Path: apps/core/models.py
# class Task(models.Model):
#     uid = models.CharField("Task ID", max_length=12, unique=True)
#     recipe = models.ForeignKey(Recipe, related_name="tasks")
#     test = models.ForeignKey(Test)
#     result = models.SmallIntegerField(choices=RESULT_CHOICES,
#                                       default=UNKNOW, db_index=True)
#     status = models.SmallIntegerField(
#         choices=Recipe.STATUS_CHOICES, default=UNKNOW)
#     duration = models.FloatField(default=-1.)
#     datestart = models.DateTimeField(null=True, blank=True)
#     statusbyuser = models.SmallIntegerField(
#         choices=USERSTATUS_CHOICES, default=NONE)
#     alias = models.CharField(max_length=32, blank=True, null=True)
# 
#     def __unicode__(self):
#         return self.uid
# 
#     def logfiles(self):
#         return list(FileLog.objects.filter(task=self).values("path"))
# 
#     def set_result(self, value):
#         try:
#             self.result = [it[0]
#                            for it in RESULT_CHOICES if it[1] == value.lower()][0]
#         except IndexError:
#             logger.error("IndexError: Task result %s %s %s" %
#                          (value, self.result, RESULT_CHOICES))
# 
#     def get_result(self):
#         if self.statusbyuser == WAIVED:
#             return [it[1] for it in USERSTATUS_CHOICES if it[0] == WAIVED][0]
#         return [it[1] for it in RESULT_CHOICES if it[0] == self.result][0]
# 
#     def set_status(self, value):
#         try:
#             self.status = [it[0]
#                            for it in Recipe.STATUS_CHOICES if it[1].lower() == value.lower()][0]
#         except IndexError:
#             logger.error("IndexError: Task status %s %s %s" %
#                          (value, self.status, Recipe.STATUS_CHOICES))
# 
#     def is_completed(self):
#         return (self.status == Recipe.COMPLETED)
# 
#     def set_waived(self):
#         self.statusbyuser = WAIVED
#         self.save()
#         self.recipe.recount_result()
#         self.recipe.save()
# 
#     def get_uid(self):
#         return self.uid.replace("T:", "")


from django_filters import Filter, FilterSet, NumberFilter
from apps.core.models import Task
from django_filters.fields import Lookup
#!/bin/python
# -*- coding: utf-8 -*-

# Author: Martin Korbel
# Email: mkorbel@redhat.com
# Date: 4.4.2016




class ListFilter(Filter):

    def filter(self, qs, value):
        if not value:
            return qs

# Path: apps/core/models.py
# class Task(models.Model):
#     uid = models.CharField("Task ID", max_length=12, unique=True)
#     recipe = models.ForeignKey(Recipe, related_name="tasks")
#     test = models.ForeignKey(Test)
#     result = models.SmallIntegerField(choices=RESULT_CHOICES,
#                                       default=UNKNOW, db_index=True)
#     status = models.SmallIntegerField(
#         choices=Recipe.STATUS_CHOICES, default=UNKNOW)
#     duration = models.FloatField(default=-1.)
#     datestart = models.DateTimeField(null=True, blank=True)
#     statusbyuser = models.SmallIntegerField(
#         choices=USERSTATUS_CHOICES, default=NONE)
#     alias = models.CharField(max_length=32, blank=True, null=True)
# 
#     def __unicode__(self):
#         return self.uid
# 
#     def logfiles(self):
#         return list(FileLog.objects.filter(task=self).values("path"))
# 
#     def set_result(self, value):
#         try:
#             self.result = [it[0]
#                            for it in RESULT_CHOICES if it[1] == value.lower()][0]
#         except IndexError:
#             logger.error("IndexError: Task result %s %s %s" %
#                          (value, self.result, RESULT_CHOICES))
# 
#     def get_result(self):
#         if self.statusbyuser == WAIVED:
#             return [it[1] for it in USERSTATUS_CHOICES if it[0] == WAIVED][0]
#         return [it[1] for it in RESULT_CHOICES if it[0] == self.result][0]
# 
#     def set_status(self, value):
#         try:
#             self.status = [it[0]
#                            for it in Recipe.STATUS_CHOICES if it[1].lower() == value.lower()][0]
#         except IndexError:
#             logger.error("IndexError: Task status %s %s %s" %
#                          (value, self.status, Recipe.STATUS_CHOICES))
# 
#     def is_completed(self):
#         return (self.status == Recipe.COMPLETED)
# 
#     def set_waived(self):
#         self.statusbyuser = WAIVED
#         self.save()
#         self.recipe.recount_result()
#         self.recipe.save()
# 
#     def get_uid(self):
#         return self.uid.replace("T:", "")


# Path: apps/api/filters.py
from django_filters import Filter, FilterSet, NumberFilter
from apps.core.models import Task
from django_filters.fields import Lookup

#!/bin/python
# -*- coding: utf-8 -*-

# Author: Martin Korbel
# Email: mkorbel@redhat.com
# Date: 4.4.2016




class ListFilter(Filter):

    def filter(self, qs, value):
        if not value:
            return qs

        value_list = [int(x) for x in value.split(',')]