Skip to content

Commit

Permalink
Format files using black
Browse files Browse the repository at this point in the history
- Silence bad-continuation and duplicate-code pylint errors
  • Loading branch information
DavisRayM committed Jan 20, 2020
1 parent 4c210a8 commit 18f1663
Show file tree
Hide file tree
Showing 68 changed files with 3,547 additions and 3,436 deletions.
2 changes: 1 addition & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

from django.core import management

os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings"
if __name__ == "__main__":
management.execute_from_command_line()
39 changes: 19 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@
from setuptools import setup, find_packages

setup(
name='ona-tasking',
version=__import__('tasking').__version__,
description='A Django app that provides adds tasking to your Django '
'project.',
license='Apache 2.0',
author='Ona Kenya',
author_email='[email protected]',
url='https://github.com/onaio/tasking',
packages=find_packages(exclude=['docs', 'tests']),
name="ona-tasking",
version=__import__("tasking").__version__,
description="A Django app that provides adds tasking to your Django " "project.",
license="Apache 2.0",
author="Ona Kenya",
author_email="[email protected]",
url="https://github.com/onaio/tasking",
packages=find_packages(exclude=["docs", "tests"]),
install_requires=[
'Django >= 1.11.19, < 2.1',
'python-dateutil',
'markdown', # adds markdown support for browsable REST API
'django-filter', # for filtering in the API
'djangorestframework-gis', # for location model
'django_countries', # for location model
'django-mptt', # For MPTT
"Django >= 1.11.19, < 2.1",
"python-dateutil",
"markdown", # adds markdown support for browsable REST API
"django-filter", # for filtering in the API
"djangorestframework-gis", # for location model
"django_countries", # for location model
"django-mptt", # For MPTT
],
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3.6',
'Framework :: Django',
'Framework :: Django :: 1.11',
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Framework :: Django",
"Framework :: Django :: 1.11",
],
)
4 changes: 2 additions & 2 deletions tasking/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"""

VERSION = (0, 3, 0)
__version__ = '.'.join(str(v) for v in VERSION)
__version__ = ".".join(str(v) for v in VERSION)
# pylint: disable=invalid-name
default_app_config = 'tasking.apps.TaskingConfig' # noqa
default_app_config = "tasking.apps.TaskingConfig" # noqa
4 changes: 3 additions & 1 deletion tasking/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class TaskingConfig(AppConfig):
"""
Tasking App Config Class
"""
name = 'tasking'

name = "tasking"
app_label = "tasking"
verbose_name = _("Tasking")

Expand All @@ -21,6 +22,7 @@ def ready(self):
# pylint: disable=import-outside-toplevel
from django.conf import settings
import tasking.settings as defaults

for name in dir(defaults):
if name.isupper() and not hasattr(settings, name):
setattr(settings, name, getattr(defaults, name))
32 changes: 17 additions & 15 deletions tasking/common_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
"""
from django.utils.translation import ugettext as _

TARGET_DOES_NOT_EXIST = _('The target content type does not exist.')
INVALID_TIMING_RULE = _('Invalid Timing Rule.')
RADIUS_MISSING = _('The Radius for Geopoint is missing.')
GEODETAILS_ONLY = _('Cannot Import Geopoint and Radius with Shapefile.')
SHAPEFILE_RADIUS = _('Cannot import Shapefile with radius.')
GEOPOINT_MISSING = _('The Geopoint for Radius is missing.')
CANT_EDIT_TASK = _('Cannot Change Task.')
NO_SHAPEFILE = _('Could not find the .shp in imported zip.')
MISSING_FILE = _('Either the .dbf , .shx or .shp file is missing.')
TARGET_DOES_NOT_EXIST = _("The target content type does not exist.")
INVALID_TIMING_RULE = _("Invalid Timing Rule.")
RADIUS_MISSING = _("The Radius for Geopoint is missing.")
GEODETAILS_ONLY = _("Cannot Import Geopoint and Radius with Shapefile.")
SHAPEFILE_RADIUS = _("Cannot import Shapefile with radius.")
GEOPOINT_MISSING = _("The Geopoint for Radius is missing.")
CANT_EDIT_TASK = _("Cannot Change Task.")
NO_SHAPEFILE = _("Could not find the .shp in imported zip.")
MISSING_FILE = _("Either the .dbf , .shx or .shp file is missing.")
UNNECESSARY_FILE = _(
'Uploaded an unnecessary file. Please make sure only a .shx , .shp and '
'.dbf file is being uploaded.'
"Uploaded an unnecessary file. Please make sure only a .shx , .shp and "
".dbf file is being uploaded."
)
INVALID_START_DATE = _("The start date cannnot be greater than the end date")
INVALID_END_DATE = _("The end date cannnot be lesser than the start date.")
MISSING_START_DATE = _(
"Cannot determine the start date. Please provide "
"either the start date or timing rule(s)"
)
INVALID_START_DATE = _('The start date cannnot be greater than the end date')
INVALID_END_DATE = _('The end date cannnot be lesser than the start date.')
MISSING_START_DATE = _('Cannot determine the start date. Please provide '
'either the start date or timing rule(s)')
INVALID_SHAPEFILE = _("Invalid shapefile")
NO_VALID_POLYGONS = _("No valid polygons in shapefile")
9 changes: 7 additions & 2 deletions tasking/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
"""
Custom exceptions for tasking
"""
from tasking.common_tags import (INVALID_SHAPEFILE, MISSING_FILE, NO_SHAPEFILE,
TARGET_DOES_NOT_EXIST, UNNECESSARY_FILE)
from tasking.common_tags import (
INVALID_SHAPEFILE,
MISSING_FILE,
NO_SHAPEFILE,
TARGET_DOES_NOT_EXIST,
UNNECESSARY_FILE,
)


class TargetDoesNotExist(Exception):
Expand Down
58 changes: 39 additions & 19 deletions tasking/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,28 @@
from tasking.models import Task, TaskOccurrence

DATETIME_LOOKUPS = [
'exact', 'gt', 'lt', 'gte', 'lte', 'year', 'year__gt', 'year__lt',
'year__gte', 'year__lte', 'month', 'month__gt', 'month__lt',
'month__gte', 'month__lte', 'day', 'day__gt', 'day__lt', 'day__gte',
'day__lte']
TIME_LOOKUPS = ['exact', 'gt', 'lt', 'gte', 'lte']
"exact",
"gt",
"lt",
"gte",
"lte",
"year",
"year__gt",
"year__lt",
"year__gte",
"year__lte",
"month",
"month__gt",
"month__lt",
"month__gte",
"month__lte",
"day",
"day__gt",
"day__lt",
"day__gte",
"day__lte",
]
TIME_LOOKUPS = ["exact", "gt", "lt", "gte", "lte"]


class TaskOccurrenceFilterSet(rest_filters.FilterSet):
Expand All @@ -24,42 +41,46 @@ class Meta:
"""
Meta options for TaskOccurrenceFilterSet
"""

model = TaskOccurrence
fields = {
'task': ['exact'],
'location': ['exact'],
'date': DATETIME_LOOKUPS,
'start_time': TIME_LOOKUPS,
'end_time': TIME_LOOKUPS
"task": ["exact"],
"location": ["exact"],
"date": DATETIME_LOOKUPS,
"start_time": TIME_LOOKUPS,
"end_time": TIME_LOOKUPS,
}


class TaskOccurenceFilter(filters.BaseFilterBackend):
"""
Task filter backend that filters the TaskOccurences
"""

def filter_queryset(self, request, queryset, view):
query_params = request.query_params
query_param_keys = query_params.keys()
filter_args = {}

for key in query_param_keys:
try:
name, lookup = key.split('__')
name, lookup = key.split("__")
except ValueError:
pass
else:
if lookup in DATETIME_LOOKUPS and name == 'date':
if lookup in DATETIME_LOOKUPS and name == "date":
filter_args[key] = query_params.get(key)

if lookup in TIME_LOOKUPS and name in [
'start_time', 'end_time']:
if lookup in TIME_LOOKUPS and name in ["start_time", "end_time"]:
filter_args[key] = query_params.get(key)

# pylint: disable=no-member
if filter_args:
task_ids = TaskOccurrence.objects.filter(
**filter_args).values_list('task_id', flat=True).distinct()
task_ids = (
TaskOccurrence.objects.filter(**filter_args)
.values_list("task_id", flat=True)
.distinct()
)
return queryset.filter(id__in=task_ids)

return queryset
Expand All @@ -75,7 +96,6 @@ class Meta:
"""
Meta options for TaskFilterSet
"""

model = Task
fields = [
'locations', 'status', 'project', 'parent'
]
fields = ["locations", "status", "project", "parent"]
Loading

0 comments on commit 18f1663

Please sign in to comment.