From 4ebca38d531653e285d58997b1b0695b26dc25a6 Mon Sep 17 00:00:00 2001 From: Michael Matloka Date: Tue, 28 Jul 2020 22:19:33 +0200 Subject: [PATCH] Sort imports with isort (#1272) * Add and configure isort * isort all the things! * Use local black and isort, and include json in prettier * Remove erroneous import * Delete isort.cfg and add isort options to lint-staged * isort all the things! (with Black-compatibile options) --- package.json | 9 +- posthog/admin.py | 13 +-- posthog/api/__init__.py | 19 ++-- posthog/api/action.py | 101 ++++++++---------- posthog/api/annotation.py | 12 ++- posthog/api/capture.py | 30 +++--- posthog/api/cohort.py | 8 +- posthog/api/dashboard.py | 24 +++-- posthog/api/decide.py | 18 ++-- posthog/api/element.py | 12 ++- posthog/api/event.py | 36 +++---- posthog/api/feature_flag.py | 16 +-- posthog/api/funnel.py | 14 +-- posthog/api/paths.py | 19 ++-- posthog/api/person.py | 19 ++-- posthog/api/test/base.py | 6 +- posthog/api/test/test_action.py | 21 +++- posthog/api/test/test_annotation.py | 7 +- posthog/api/test/test_capture.py | 18 ++-- posthog/api/test/test_cohort.py | 6 +- posthog/api/test/test_dashboard.py | 13 ++- posthog/api/test/test_decide.py | 9 +- posthog/api/test/test_element.py | 12 ++- posthog/api/test/test_event.py | 9 +- posthog/api/test/test_feature_flag.py | 3 +- posthog/api/test/test_funnel.py | 13 ++- posthog/api/test/test_paths.py | 8 +- posthog/api/test/test_person.py | 6 +- posthog/api/test/test_user.py | 3 +- posthog/api/user.py | 27 ++--- posthog/apps.py | 5 +- posthog/celery.py | 12 +-- posthog/decorators.py | 10 +- posthog/demo.py | 38 ++++--- .../management/commands/create_bulk_events.py | 32 +++--- posthog/management/commands/makemigrations.py | 2 +- .../commands/migrate_elementgroup.py | 17 ++- posthog/management/commands/partition.py | 3 +- posthog/middleware.py | 7 +- posthog/migrations/0001_initial.py | 4 +- posthog/migrations/0002_person.py | 2 +- posthog/migrations/0003_person_is_user.py | 2 +- posthog/migrations/0007_element.py | 2 +- posthog/migrations/0008_action_actionstep.py | 2 +- posthog/migrations/0010_funnel_funnelstep.py | 2 +- posthog/migrations/0011_auto_20200127_2105.py | 2 +- posthog/migrations/0014_auto_20200129_0703.py | 1 + posthog/migrations/0017_dashboarditem.py | 2 +- posthog/migrations/0020_auto_20200210_0212.py | 2 +- posthog/migrations/0021_user_distinct_id.py | 3 +- posthog/migrations/0025_cohort.py | 2 +- posthog/migrations/0026_auto_20200227_0804.py | 2 +- .../migrations/0027_move_elements_to_group.py | 7 +- posthog/migrations/0031_team_signup_token.py | 3 +- ..._migrate_actions_to_precalculate_events.py | 7 +- .../0042_add_type_dashboarditems.py | 1 + posthog/migrations/0044_auto_20200413_1936.py | 3 +- posthog/migrations/0050_dashboards.py | 2 +- .../migrations/0051_precalculate_cohorts.py | 4 +- posthog/migrations/0061_featureflag.py | 4 +- posthog/migrations/0068_auto_20200629_1322.py | 2 +- posthog/migrations/0069_auto_20200714_1642.py | 2 +- .../migrations/0071_cache_dashboard_items.py | 7 +- posthog/models/__init__.py | 4 +- posthog/models/action.py | 5 +- posthog/models/action_step.py | 2 +- posthog/models/cohort.py | 17 +-- posthog/models/dashboard_item.py | 6 +- posthog/models/element.py | 2 +- posthog/models/element_group.py | 12 ++- posthog/models/entity.py | 4 +- posthog/models/event.py | 77 +++++++------ posthog/models/feature_flag.py | 12 ++- posthog/models/filter.py | 22 ++-- posthog/models/funnel.py | 40 +++---- posthog/models/person.py | 5 +- posthog/models/property.py | 8 +- posthog/models/team.py | 13 ++- posthog/models/user.py | 11 +- posthog/settings.py | 7 +- posthog/tasks/calculate_action.py | 7 +- posthog/tasks/calculate_cohort.py | 14 +-- posthog/tasks/process_event.py | 10 +- posthog/tasks/slack.py | 2 +- posthog/tasks/test/test_process_event.py | 12 ++- posthog/tasks/test/test_update_cache.py | 18 ++-- posthog/tasks/update_cache.py | 25 ++--- posthog/test/test_cohort_model.py | 2 +- posthog/test/test_demo.py | 5 +- posthog/test/test_event_model.py | 15 +-- posthog/test/test_filter_model.py | 15 +-- posthog/test/test_middleware.py | 2 +- posthog/test/test_migration_0039.py | 9 +- posthog/test/test_signup.py | 9 +- posthog/test/test_utils.py | 7 +- posthog/urls.py | 41 +++---- posthog/utils.py | 29 +++-- posthog/views.py | 9 +- requirements/dev.in | 3 +- requirements/dev.txt | 3 +- 100 files changed, 634 insertions(+), 557 deletions(-) diff --git a/package.json b/package.json index 54b2102b363..fe345150eb2 100644 --- a/package.json +++ b/package.json @@ -104,11 +104,14 @@ } }, "lint-staged": { - "*.{js,ts,tsx,css,scss}": "prettier --write", + "*.{js,ts,tsx,json,css,scss}": "prettier --write", "*.{js,ts,tsx}": "eslint", - "*.py": "black -l 120" + "*.py": [ + "./env/bin/black -l 120", + "./env/bin/isort -m 3 --tc --fgw 8 --up -n -l 120" + ] }, "optionalDependencies": { "fsevents": "^2.1.2" } -} \ No newline at end of file +} diff --git a/posthog/admin.py b/posthog/admin.py index c521785ca21..478dafea835 100644 --- a/posthog/admin.py +++ b/posthog/admin.py @@ -1,17 +1,18 @@ from django.contrib import admin from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin from django.utils.translation import ugettext_lazy as _ + from posthog.models import ( - Event, - User, - Team, - Person, - Element, - Funnel, Action, ActionStep, DashboardItem, + Element, + Event, FeatureFlag, + Funnel, + Person, + Team, + User, ) admin.site.register(Team) diff --git a/posthog/api/__init__.py b/posthog/api/__init__.py index 4e999ed6170..094f182a4da 100644 --- a/posthog/api/__init__.py +++ b/posthog/api/__init__.py @@ -1,17 +1,18 @@ +from rest_framework import routers + from . import ( - event, - person, action, - funnel, - dashboard, - paths, - cohort, - element, - feature_flag, annotation, + cohort, + dashboard, + element, + event, + feature_flag, + funnel, + paths, + person, team, ) -from rest_framework import routers router = routers.DefaultRouter() router.register(r"annotation", annotation.AnnotationsViewSet) diff --git a/posthog/api/action.py b/posthog/api/action.py index cf51dc6080f..2355c0194f9 100644 --- a/posthog/api/action.py +++ b/posthog/api/action.py @@ -1,62 +1,55 @@ -from django.db.models.expressions import Subquery -from posthog.models import ( - Event, - Team, - Action, - ActionStep, - DashboardItem, - User, - Person, - Filter, - Entity, - Cohort, - CohortPeople, -) -from posthog.utils import ( - append_data, - get_compare_period_dates, - TemporaryTokenAuthentication, -) -from posthog.constants import ( - TREND_FILTER_TYPE_ACTIONS, - TREND_FILTER_TYPE_EVENTS, - TRENDS_CUMULATIVE, - TRENDS_STICKINESS, -) -from posthog.tasks.calculate_action import calculate_action -from rest_framework import request, serializers, viewsets, authentication -from rest_framework.response import Response -from rest_framework.decorators import action -from django.db.models import ( - Q, - Count, - Sum, - Avg, - Min, - Max, - Prefetch, - functions, - QuerySet, - OuterRef, - Exists, - Value, - BooleanField, - FloatField, -) -from django.db.models.expressions import RawSQL -from django.db.models.functions import Cast -from django.db import connection -from django.utils.timezone import now -from typing import Any, List, Dict, Optional, Tuple, Union -from datetime import timedelta -import pandas as pd +import copy import datetime import json -import copy +from datetime import timedelta +from typing import Any, Dict, List, Optional, Tuple, Union + import numpy as np +import pandas as pd from dateutil.relativedelta import relativedelta +from django.db import connection +from django.db.models import ( + Avg, + BooleanField, + Count, + Exists, + FloatField, + Max, + Min, + OuterRef, + Prefetch, + Q, + QuerySet, + Sum, + Value, + functions, +) +from django.db.models.expressions import RawSQL, Subquery +from django.db.models.functions import Cast +from django.utils.timezone import now +from rest_framework import authentication, request, serializers, viewsets +from rest_framework.decorators import action +from rest_framework.response import Response + +from posthog.constants import TREND_FILTER_TYPE_ACTIONS, TREND_FILTER_TYPE_EVENTS, TRENDS_CUMULATIVE, TRENDS_STICKINESS +from posthog.decorators import TRENDS_ENDPOINT, cached_function +from posthog.models import ( + Action, + ActionStep, + Cohort, + CohortPeople, + DashboardItem, + Entity, + Event, + Filter, + Person, + Team, + User, +) +from posthog.tasks.calculate_action import calculate_action +from posthog.utils import TemporaryTokenAuthentication, append_data, get_compare_period_dates + from .person import PersonSerializer -from posthog.decorators import cached_function, TRENDS_ENDPOINT FREQ_MAP = {"minute": "60S", "hour": "H", "day": "D", "week": "W", "month": "M"} diff --git a/posthog/api/annotation.py b/posthog/api/annotation.py index 0c5909add58..e007d40b6e9 100644 --- a/posthog/api/annotation.py +++ b/posthog/api/annotation.py @@ -1,9 +1,11 @@ -from django.db.models import QuerySet -from posthog.models import Annotation -from rest_framework import request, serializers, viewsets -from typing import Dict, Any -from posthog.api.user import UserSerializer from distutils.util import strtobool +from typing import Any, Dict + +from django.db.models import QuerySet +from rest_framework import request, serializers, viewsets + +from posthog.api.user import UserSerializer +from posthog.models import Annotation class AnnotationSerializer(serializers.ModelSerializer): diff --git a/posthog/api/capture.py b/posthog/api/capture.py index b68834c5798..f8aa112ebc7 100644 --- a/posthog/api/capture.py +++ b/posthog/api/capture.py @@ -1,19 +1,21 @@ -from django.http import HttpResponse, JsonResponse -from django.views.decorators.csrf import csrf_exempt -from django.utils import timezone -from posthog.models import Team -from posthog.utils import get_ip_address, cors_response -from typing import Dict, Union, Optional, List, Any -from posthog.tasks.process_event import process_event -from datetime import datetime -from dateutil import parser -from sentry_sdk import push_scope -import lzstring # type: ignore -import re -import json -import secrets import base64 import gzip +import json +import re +import secrets +from datetime import datetime +from typing import Any, Dict, List, Optional, Union + +import lzstring # type: ignore +from dateutil import parser +from django.http import HttpResponse, JsonResponse +from django.utils import timezone +from django.views.decorators.csrf import csrf_exempt +from sentry_sdk import push_scope + +from posthog.models import Team +from posthog.tasks.process_event import process_event +from posthog.utils import cors_response, get_ip_address def _load_data(request) -> Optional[Union[Dict, List]]: diff --git a/posthog/api/cohort.py b/posthog/api/cohort.py index 79534e3802d..0e33c04ddb8 100644 --- a/posthog/api/cohort.py +++ b/posthog/api/cohort.py @@ -1,9 +1,11 @@ +from typing import Any, Dict, Optional + +from django.db.models import Count, QuerySet from rest_framework import request, response, serializers, viewsets -from posthog.models import Cohort -from typing import Dict, Any, Optional + from posthog.api.user import UserSerializer +from posthog.models import Cohort from posthog.tasks.calculate_cohort import calculate_cohort -from django.db.models import QuerySet, Count class CohortSerializer(serializers.ModelSerializer): diff --git a/posthog/api/dashboard.py b/posthog/api/dashboard.py index c26d4fa2d04..ee57c731373 100644 --- a/posthog/api/dashboard.py +++ b/posthog/api/dashboard.py @@ -1,17 +1,19 @@ -from rest_framework import request, response, serializers, viewsets, authentication +import secrets +from datetime import datetime +from typing import Any, Dict, List + +from django.contrib.auth.models import AnonymousUser +from django.core.cache import cache +from django.db.models import Prefetch, QuerySet +from django.http import HttpRequest +from django.shortcuts import get_object_or_404 +from django.utils.timezone import now +from rest_framework import authentication, request, response, serializers, viewsets from rest_framework.decorators import action from rest_framework.exceptions import AuthenticationFailed + from posthog.models import Dashboard, DashboardItem, Filter -from typing import Dict, Any, List -from django.db.models import QuerySet, Prefetch -from django.shortcuts import get_object_or_404 -from datetime import datetime -from posthog.utils import render_template, generate_cache_key -from django.contrib.auth.models import AnonymousUser -from django.http import HttpRequest -from django.core.cache import cache -from django.utils.timezone import now -import secrets +from posthog.utils import generate_cache_key, render_template class PublicTokenAuthentication(authentication.BaseAuthentication): diff --git a/posthog/api/decide.py b/posthog/api/decide.py index c17344eb9a5..e5c8eadd3c9 100644 --- a/posthog/api/decide.py +++ b/posthog/api/decide.py @@ -1,13 +1,15 @@ -from django.conf import settings -from django.http import JsonResponse, HttpRequest -from django.views.decorators.csrf import csrf_exempt -from typing import Optional, List, Any, Dict -from posthog.utils import cors_response -from urllib.parse import urlparse -from posthog.models import FeatureFlag, Team -import json import base64 +import json import secrets +from typing import Any, Dict, List, Optional +from urllib.parse import urlparse + +from django.conf import settings +from django.http import HttpRequest, JsonResponse +from django.views.decorators.csrf import csrf_exempt + +from posthog.models import FeatureFlag, Team +from posthog.utils import cors_response def _load_data(data: str) -> Dict[str, Any]: diff --git a/posthog/api/element.py b/posthog/api/element.py index 6aab2c68488..3ed58d0b584 100644 --- a/posthog/api/element.py +++ b/posthog/api/element.py @@ -1,10 +1,12 @@ -from rest_framework import request, response, serializers, viewsets, authentication -from rest_framework.decorators import action -from posthog.models import Element, Team, Event, ElementGroup, Filter -from posthog.utils import TemporaryTokenAuthentication -from django.db.models import QuerySet, Count, Prefetch import json +from django.db.models import Count, Prefetch, QuerySet +from rest_framework import authentication, request, response, serializers, viewsets +from rest_framework.decorators import action + +from posthog.models import Element, ElementGroup, Event, Filter, Team +from posthog.utils import TemporaryTokenAuthentication + class ElementSerializer(serializers.ModelSerializer): class Meta: diff --git a/posthog/api/event.py b/posthog/api/event.py index cc3ccb3c21c..d0a198832ed 100644 --- a/posthog/api/event.py +++ b/posthog/api/event.py @@ -1,35 +1,35 @@ +import json from datetime import datetime, timedelta +from typing import Any, Dict, List, Optional, Tuple + +import pandas as pd from dateutil.relativedelta import relativedelta +from django.db import connection +from django.db.models import F, Prefetch, Q, QuerySet +from django.db.models.expressions import Window +from django.db.models.functions import Lag +from django.utils.timezone import now +from rest_framework import request, response, serializers, viewsets +from rest_framework.decorators import action + from posthog.models import ( - Event, - Person, - Element, Action, + Element, ElementGroup, + Event, Filter, + Person, PersonDistinctId, Team, ) from posthog.utils import ( - friendly_time, - request_to_date_query, append_data, convert_property_value, - get_compare_period_dates, dict_from_cursor_fetchall, + friendly_time, + get_compare_period_dates, + request_to_date_query, ) -from rest_framework import request, response, serializers, viewsets -from rest_framework.decorators import action -from django.db.models import QuerySet, F, Prefetch, Q -from django.db.models.functions import Lag -from django.db.models.expressions import Window -from django.db import connection -from django.utils.timezone import now -from typing import Any, Dict, List, Optional -from django.utils.timezone import now -import json -import pandas as pd -from typing import Tuple, Optional class ElementSerializer(serializers.ModelSerializer): diff --git a/posthog/api/feature_flag.py b/posthog/api/feature_flag.py index 2b4edead99c..3a33b3d3345 100644 --- a/posthog/api/feature_flag.py +++ b/posthog/api/feature_flag.py @@ -1,11 +1,13 @@ -from posthog.models import FeatureFlag -from posthog.api.user import UserSerializer -from rest_framework import request, serializers, viewsets -from django.db.models import QuerySet -from django.db import IntegrityError -from typing import List, Dict, Any -import posthoganalytics import json +from typing import Any, Dict, List + +import posthoganalytics +from django.db import IntegrityError +from django.db.models import QuerySet +from rest_framework import request, serializers, viewsets + +from posthog.api.user import UserSerializer +from posthog.models import FeatureFlag class FeatureFlagSerializer(serializers.HyperlinkedModelSerializer): diff --git a/posthog/api/funnel.py b/posthog/api/funnel.py index b7836c10e45..82e5bfd0088 100644 --- a/posthog/api/funnel.py +++ b/posthog/api/funnel.py @@ -1,11 +1,13 @@ -from posthog.models import Funnel, DashboardItem +import datetime +import json +from typing import Any, Dict, List + +from django.db.models import QuerySet from rest_framework import request, serializers, viewsets from rest_framework.response import Response -from django.db.models import QuerySet -from typing import List, Dict, Any -import json -from posthog.decorators import cached_function, FUNNEL_ENDPOINT -import datetime + +from posthog.decorators import FUNNEL_ENDPOINT, cached_function +from posthog.models import DashboardItem, Funnel class FunnelSerializer(serializers.HyperlinkedModelSerializer): diff --git a/posthog/api/paths.py b/posthog/api/paths.py index 5b9ba28f378..5a0a9b22e2b 100644 --- a/posthog/api/paths.py +++ b/posthog/api/paths.py @@ -1,18 +1,17 @@ -from rest_framework import viewsets, request -from rest_framework.response import Response -from rest_framework.decorators import action -from posthog.models import Event, Filter -from posthog.utils import request_to_date_query, dict_from_cursor_fetchall -from django.db.models import OuterRef -from django.db import connection +import json from typing import Optional +from django.db import connection +from django.db.models import F, OuterRef, Q from django.db.models.expressions import Window from django.db.models.functions import Lag -from django.db.models import F, Q -from django.db import connection +from rest_framework import request, viewsets +from rest_framework.decorators import action +from rest_framework.response import Response + +from posthog.models import Event, Filter +from posthog.utils import dict_from_cursor_fetchall, request_to_date_query -import json # At the moment, paths don't support users changing distinct_ids midway through. # See: https://github.com/PostHog/posthog/issues/185 diff --git a/posthog/api/person.py b/posthog/api/person.py index ce37858993b..1d0d6cebc90 100644 --- a/posthog/api/person.py +++ b/posthog/api/person.py @@ -1,15 +1,18 @@ -from posthog.models import Event, Team, Person, PersonDistinctId, Cohort, Filter -from posthog.utils import convert_property_value -from rest_framework import serializers, viewsets, response, request +import json +from typing import Union + +from django.core.cache import cache +from django.db.models import Count, Func, OuterRef, Prefetch, Q, QuerySet, Subquery +from rest_framework import request, response, serializers, viewsets from rest_framework.decorators import action from rest_framework.settings import api_settings from rest_framework_csv import renderers as csvrenderers # type: ignore -from django.db.models import Q, Prefetch, QuerySet, Subquery, OuterRef, Count, Func -from .event import EventSerializer -from typing import Union + +from posthog.models import Cohort, Event, Filter, Person, PersonDistinctId, Team +from posthog.utils import convert_property_value + from .base import CursorPagination as BaseCursorPagination -import json -from django.core.cache import cache +from .event import EventSerializer class PersonSerializer(serializers.HyperlinkedModelSerializer): diff --git a/posthog/api/test/base.py b/posthog/api/test/base.py index 79e913aa2f2..0a732bf086d 100644 --- a/posthog/api/test/base.py +++ b/posthog/api/test/base.py @@ -1,6 +1,6 @@ -from django.test import TransactionTestCase, TestCase -from posthog.models import User, Team -from django.test import Client +from django.test import Client, TestCase, TransactionTestCase + +from posthog.models import Team, User class BaseTest(TestCase): diff --git a/posthog/api/test/test_action.py b/posthog/api/test/test_action.py index 13de5243c29..6da30e9487b 100644 --- a/posthog/api/test/test_action.py +++ b/posthog/api/test/test_action.py @@ -1,13 +1,24 @@ +from datetime import datetime from json import dumps as jdumps +from unittest.mock import call, patch from freezegun import freeze_time -from unittest.mock import patch, call -from datetime import datetime -from posthog.models import Action, ActionStep, Element, Event, Filter, Person, Team, Cohort, Entity -from posthog.constants import TREND_FILTER_TYPE_ACTIONS, TREND_FILTER_TYPE_EVENTS -from .base import BaseTest, TransactionBaseTest from posthog.api.action import calculate_retention +from posthog.constants import TREND_FILTER_TYPE_ACTIONS, TREND_FILTER_TYPE_EVENTS +from posthog.models import ( + Action, + ActionStep, + Cohort, + Element, + Entity, + Event, + Filter, + Person, + Team, +) + +from .base import BaseTest, TransactionBaseTest @patch("posthog.tasks.calculate_action.calculate_action.delay") diff --git a/posthog/api/test/test_annotation.py b/posthog/api/test/test_annotation.py index c12c911352c..1dba8bfb4de 100644 --- a/posthog/api/test/test_annotation.py +++ b/posthog/api/test/test_annotation.py @@ -1,8 +1,11 @@ -from .base import BaseTest -from posthog.models import Annotation, Dashboard, DashboardItem from datetime import datetime + from freezegun import freeze_time +from posthog.models import Annotation, Dashboard, DashboardItem + +from .base import BaseTest + class TestAnnotation(BaseTest): TESTS_API = True diff --git a/posthog/api/test/test_capture.py b/posthog/api/test/test_capture.py index 443734a1dfd..c8a180779eb 100644 --- a/posthog/api/test/test_capture.py +++ b/posthog/api/test/test_capture.py @@ -1,14 +1,16 @@ -from .base import BaseTest +import base64 +import gzip +import json +from datetime import timedelta +from unittest.mock import call, patch +from urllib.parse import quote + +import lzstring # type: ignore from django.conf import settings from django.utils import timezone from freezegun import freeze_time -from unittest.mock import patch, call -from datetime import timedelta -from urllib.parse import quote -import base64 -import json -import gzip -import lzstring # type: ignore + +from .base import BaseTest class TestCapture(BaseTest): diff --git a/posthog/api/test/test_cohort.py b/posthog/api/test/test_cohort.py index 58181b31e02..0dba9d09c48 100644 --- a/posthog/api/test/test_cohort.py +++ b/posthog/api/test/test_cohort.py @@ -1,7 +1,9 @@ -from .base import BaseTest -from posthog.models import Cohort, Person from unittest.mock import patch +from posthog.models import Cohort, Person + +from .base import BaseTest + class TestCohort(BaseTest): TESTS_API = True diff --git a/posthog/api/test/test_dashboard.py b/posthog/api/test/test_dashboard.py index b93a8d9002a..53cdf71c5cc 100644 --- a/posthog/api/test/test_dashboard.py +++ b/posthog/api/test/test_dashboard.py @@ -1,11 +1,14 @@ -from .base import BaseTest, TransactionBaseTest -from posthog.models import Dashboard, Filter, DashboardItem -from posthog.api.action import calculate_trends -from posthog.decorators import TRENDS_ENDPOINT +import json + from django.core.cache import cache from django.utils.timezone import now from freezegun import freeze_time -import json + +from posthog.api.action import calculate_trends +from posthog.decorators import TRENDS_ENDPOINT +from posthog.models import Dashboard, DashboardItem, Filter + +from .base import BaseTest, TransactionBaseTest class TestDashboard(TransactionBaseTest): diff --git a/posthog/api/test/test_decide.py b/posthog/api/test/test_decide.py index e7bfc9217a4..11632b8ea8b 100644 --- a/posthog/api/test/test_decide.py +++ b/posthog/api/test/test_decide.py @@ -1,9 +1,10 @@ -from .base import BaseTest - -from posthog.models import Person, FeatureFlag -from unittest.mock import patch import base64 import json +from unittest.mock import patch + +from posthog.models import FeatureFlag, Person + +from .base import BaseTest class TestDecide(BaseTest): diff --git a/posthog/api/test/test_element.py b/posthog/api/test/test_element.py index 6923a2d2be9..8a246ca640c 100644 --- a/posthog/api/test/test_element.py +++ b/posthog/api/test/test_element.py @@ -1,10 +1,12 @@ -from .base import BaseTest -from posthog.models import Element, ElementGroup, Team, Event -from django.utils.timezone import now -from dateutil.relativedelta import relativedelta - import json +from dateutil.relativedelta import relativedelta +from django.utils.timezone import now + +from posthog.models import Element, ElementGroup, Event, Team + +from .base import BaseTest + class TestElement(BaseTest): TESTS_API = True diff --git a/posthog/api/test/test_event.py b/posthog/api/test/test_event.py index b42449acb21..6e0adb0e3e1 100644 --- a/posthog/api/test/test_event.py +++ b/posthog/api/test/test_event.py @@ -1,8 +1,11 @@ -from .base import BaseTest, TransactionBaseTest -from posthog.models import Event, Person, Element, Action, ActionStep, Team -from freezegun import freeze_time import json +from freezegun import freeze_time + +from posthog.models import Action, ActionStep, Element, Event, Person, Team + +from .base import BaseTest, TransactionBaseTest + class TestEvents(TransactionBaseTest): TESTS_API = True diff --git a/posthog/api/test/test_feature_flag.py b/posthog/api/test/test_feature_flag.py index 301b348a8b0..8749c419735 100644 --- a/posthog/api/test/test_feature_flag.py +++ b/posthog/api/test/test_feature_flag.py @@ -1,6 +1,7 @@ -from .base import BaseTest, TransactionBaseTest from posthog.models import FeatureFlag +from .base import BaseTest, TransactionBaseTest + class TestFeatureFlagApi(TransactionBaseTest): TESTS_API = True diff --git a/posthog/api/test/test_funnel.py b/posthog/api/test/test_funnel.py index e19b6bef374..98d6b71c1a0 100644 --- a/posthog/api/test/test_funnel.py +++ b/posthog/api/test/test_funnel.py @@ -1,10 +1,13 @@ -from posthog.models import Funnel, Action, ActionStep, Event, Element, Person -from posthog.tasks.update_cache import update_cache_item -from .base import BaseTest -from posthog.utils import generate_cache_key -from django.core.cache import cache from unittest.mock import patch +from django.core.cache import cache + +from posthog.models import Action, ActionStep, Element, Event, Funnel, Person +from posthog.tasks.update_cache import update_cache_item +from posthog.utils import generate_cache_key + +from .base import BaseTest + @patch("posthog.celery.update_cache_item_task.delay", update_cache_item) class TestCreateFunnel(BaseTest): diff --git a/posthog/api/test/test_paths.py b/posthog/api/test/test_paths.py index 0a53892e6dd..c970011d147 100644 --- a/posthog/api/test/test_paths.py +++ b/posthog/api/test/test_paths.py @@ -1,9 +1,11 @@ -from .base import BaseTest -from posthog.models import Person, Event, Element -from django.utils.timezone import now from dateutil.relativedelta import relativedelta +from django.utils.timezone import now from freezegun import freeze_time +from posthog.models import Element, Event, Person + +from .base import BaseTest + class TestPaths(BaseTest): TESTS_API = True diff --git a/posthog/api/test/test_person.py b/posthog/api/test/test_person.py index 6c3163704cb..fd74fc51e8c 100644 --- a/posthog/api/test/test_person.py +++ b/posthog/api/test/test_person.py @@ -1,7 +1,9 @@ -from .base import BaseTest -from posthog.models import Person, Event, Cohort import json +from posthog.models import Cohort, Event, Person + +from .base import BaseTest + class TestPerson(BaseTest): TESTS_API = True diff --git a/posthog/api/test/test_user.py b/posthog/api/test/test_user.py index 311ce6634f6..ca8f2862b02 100644 --- a/posthog/api/test/test_user.py +++ b/posthog/api/test/test_user.py @@ -1,5 +1,6 @@ +from posthog.models import Team, User + from .base import BaseTest -from posthog.models import User, Team class TestUser(BaseTest): diff --git a/posthog/api/user.py b/posthog/api/user.py index c40678bf708..7479e3850d7 100644 --- a/posthog/api/user.py +++ b/posthog/api/user.py @@ -1,19 +1,20 @@ -from django.http import HttpResponse, JsonResponse -from django.views.decorators.http import require_http_methods -from django.contrib.auth.password_validation import validate_password -from django.contrib.auth import update_session_auth_hash -from django.core.exceptions import ValidationError -from django.shortcuts import redirect -from django.conf import settings -from rest_framework import serializers -from posthog.models import Event, User -import requests - -import urllib.parse -import secrets import json import os +import secrets +import urllib.parse + import posthoganalytics +import requests +from django.conf import settings +from django.contrib.auth import update_session_auth_hash +from django.contrib.auth.password_validation import validate_password +from django.core.exceptions import ValidationError +from django.http import HttpResponse, JsonResponse +from django.shortcuts import redirect +from django.views.decorators.http import require_http_methods +from rest_framework import serializers + +from posthog.models import Event, User def user(request): diff --git a/posthog/apps.py b/posthog/apps.py index 1b957c0b7e5..c57a9b216ee 100644 --- a/posthog/apps.py +++ b/posthog/apps.py @@ -1,7 +1,8 @@ +import os + +import posthoganalytics from django.apps import AppConfig from django.conf import settings -import posthoganalytics -import os class PostHogConfig(AppConfig): diff --git a/posthog/celery.py b/posthog/celery.py index 96b74d976b8..254de051c26 100644 --- a/posthog/celery.py +++ b/posthog/celery.py @@ -1,14 +1,14 @@ import os +import time +from datetime import datetime +from typing import Optional + +import redis from celery import Celery, group from celery.schedules import crontab +from dateutil import parser from django.conf import settings from django.db import connection -import redis -import time -from typing import Optional -from datetime import datetime -from dateutil import parser - # set the default Django settings module for the 'celery' program. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "posthog.settings") diff --git a/posthog/decorators.py b/posthog/decorators.py index 808483954d3..84397e27e97 100644 --- a/posthog/decorators.py +++ b/posthog/decorators.py @@ -1,9 +1,11 @@ import json -from posthog.models import Filter, DashboardItem -from posthog.utils import generate_cache_key -from django.core.cache import cache -import json from datetime import datetime + +from django.core.cache import cache + +from posthog.models import DashboardItem, Filter +from posthog.utils import generate_cache_key + from .utils import generate_cache_key TRENDS_ENDPOINT = "Trends" diff --git a/posthog/demo.py b/posthog/demo.py index f95eca6039e..f489d4fa7e5 100644 --- a/posthog/demo.py +++ b/posthog/demo.py @@ -1,30 +1,28 @@ +import json +import random +import secrets +import uuid +from pathlib import Path +from typing import List + +from dateutil.relativedelta import relativedelta +from django.http import HttpResponseNotFound, JsonResponse +from django.utils.timezone import now + +from posthog.constants import TREND_FILTER_TYPE_ACTIONS from posthog.models import ( - Person, - PersonDistinctId, - Event, - Element, Action, ActionStep, - Funnel, - Team, Dashboard, DashboardItem, + Element, + Event, + Funnel, + Person, + PersonDistinctId, + Team, ) -from dateutil.relativedelta import relativedelta -from django.utils.timezone import now -from django.http import HttpResponseNotFound, JsonResponse - -from posthog.urls import render_template from posthog.utils import render_template -from posthog.constants import TREND_FILTER_TYPE_ACTIONS - -from typing import List -from pathlib import Path -import uuid - -import random -import json -import secrets def _create_anonymous_users(team: Team, base_url: str) -> None: diff --git a/posthog/management/commands/create_bulk_events.py b/posthog/management/commands/create_bulk_events.py index c0a1378511c..01e88c9e0e0 100644 --- a/posthog/management/commands/create_bulk_events.py +++ b/posthog/management/commands/create_bulk_events.py @@ -1,31 +1,29 @@ -import random +import io import json +import random +import time import uuid -import psycopg2 +from pathlib import Path +from typing import Iterator, List, Optional from urllib.parse import urlparse -from django.conf import settings +import psycopg2 +from dateutil.relativedelta import relativedelta +from django.conf import settings +from django.core import serializers from django.core.management.base import BaseCommand from django.utils.timezone import now -from django.core import serializers - -from dateutil.relativedelta import relativedelta -from pathlib import Path -from typing import List -import time -from typing import Iterator, Optional -import io from posthog.models import ( - Event, - Element, - Team, - Person, - PersonDistinctId, - Funnel, Action, ActionStep, + Element, + Event, + Funnel, FunnelStep, + Person, + PersonDistinctId, + Team, ) diff --git a/posthog/management/commands/makemigrations.py b/posthog/management/commands/makemigrations.py index 879e41e4aab..1e1fa44bec7 100644 --- a/posthog/management/commands/makemigrations.py +++ b/posthog/management/commands/makemigrations.py @@ -1,7 +1,7 @@ """Cause git to detect a merge conflict when two branches have migrations.""" -from django.db.migrations.loader import MigrationLoader from django.core.management.commands.makemigrations import Command as MakeMigrationsCommand +from django.db.migrations.loader import MigrationLoader class Command(MakeMigrationsCommand): diff --git a/posthog/management/commands/migrate_elementgroup.py b/posthog/management/commands/migrate_elementgroup.py index 467793f7b16..5324326efbf 100644 --- a/posthog/management/commands/migrate_elementgroup.py +++ b/posthog/management/commands/migrate_elementgroup.py @@ -1,14 +1,13 @@ -from django.core.management.base import BaseCommand, CommandError -from django.utils import timezone -from dateutil.relativedelta import relativedelta - -from django.forms.models import model_to_dict -from django.db import transaction, models - -import json import hashlib +import json -from posthog.models import Event, Element, ElementGroup +from dateutil.relativedelta import relativedelta +from django.core.management.base import BaseCommand, CommandError +from django.db import models, transaction +from django.forms.models import model_to_dict +from django.utils import timezone + +from posthog.models import Element, ElementGroup, Event class Command(BaseCommand): diff --git a/posthog/management/commands/partition.py b/posthog/management/commands/partition.py index a88f1baf143..865fc811682 100644 --- a/posthog/management/commands/partition.py +++ b/posthog/management/commands/partition.py @@ -1,5 +1,6 @@ -from django.core.management.base import BaseCommand import os + +from django.core.management.base import BaseCommand from django.db import connection diff --git a/posthog/middleware.py b/posthog/middleware.py index 14e3b2794bc..aae5cea82f7 100644 --- a/posthog/middleware.py +++ b/posthog/middleware.py @@ -1,8 +1,9 @@ -from django.conf import settings -from django.core.exceptions import MiddlewareNotUsed -from django.http import HttpResponse, HttpRequest from ipaddress import ip_address, ip_network + +from django.conf import settings from django.contrib.sessions.middleware import SessionMiddleware +from django.core.exceptions import MiddlewareNotUsed +from django.http import HttpRequest, HttpResponse class AllowIP(object): diff --git a/posthog/migrations/0001_initial.py b/posthog/migrations/0001_initial.py index ab319d32282..ae4919090b8 100644 --- a/posthog/migrations/0001_initial.py +++ b/posthog/migrations/0001_initial.py @@ -1,12 +1,12 @@ # Generated by Django 2.2.7 on 2020-01-23 22:38 -from django.conf import settings import django.contrib.auth.models import django.contrib.auth.validators import django.contrib.postgres.fields.jsonb -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/posthog/migrations/0002_person.py b/posthog/migrations/0002_person.py index ff17e5ca67e..f59f0d6d746 100644 --- a/posthog/migrations/0002_person.py +++ b/posthog/migrations/0002_person.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.7 on 2020-01-24 18:38 import django.contrib.postgres.fields.jsonb -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/posthog/migrations/0003_person_is_user.py b/posthog/migrations/0003_person_is_user.py index dfc016045ee..5706876c2e9 100644 --- a/posthog/migrations/0003_person_is_user.py +++ b/posthog/migrations/0003_person_is_user.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.7 on 2020-01-24 19:02 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/posthog/migrations/0007_element.py b/posthog/migrations/0007_element.py index ab6e79637fb..c749550779d 100644 --- a/posthog/migrations/0007_element.py +++ b/posthog/migrations/0007_element.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.7 on 2020-01-25 23:30 import django.contrib.postgres.fields.jsonb -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/posthog/migrations/0008_action_actionstep.py b/posthog/migrations/0008_action_actionstep.py index da38b5d6267..32430ca0596 100644 --- a/posthog/migrations/0008_action_actionstep.py +++ b/posthog/migrations/0008_action_actionstep.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.7 on 2020-01-26 21:16 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/posthog/migrations/0010_funnel_funnelstep.py b/posthog/migrations/0010_funnel_funnelstep.py index 66cef99ac70..009d3f24943 100644 --- a/posthog/migrations/0010_funnel_funnelstep.py +++ b/posthog/migrations/0010_funnel_funnelstep.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.7 on 2020-01-27 19:31 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/posthog/migrations/0011_auto_20200127_2105.py b/posthog/migrations/0011_auto_20200127_2105.py index c9eaac63819..231dbcffa14 100644 --- a/posthog/migrations/0011_auto_20200127_2105.py +++ b/posthog/migrations/0011_auto_20200127_2105.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.7 on 2020-01-27 21:05 -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/posthog/migrations/0014_auto_20200129_0703.py b/posthog/migrations/0014_auto_20200129_0703.py index ee79e00ca46..dc230906792 100644 --- a/posthog/migrations/0014_auto_20200129_0703.py +++ b/posthog/migrations/0014_auto_20200129_0703.py @@ -1,6 +1,7 @@ # Generated by Django 2.2.7 on 2020-01-29 07:03 from django.db import migrations, models + import posthog.models diff --git a/posthog/migrations/0017_dashboarditem.py b/posthog/migrations/0017_dashboarditem.py index 7b3f7294aae..bde518bf8ff 100644 --- a/posthog/migrations/0017_dashboarditem.py +++ b/posthog/migrations/0017_dashboarditem.py @@ -1,8 +1,8 @@ # Generated by Django 2.2.7 on 2020-02-06 22:07 import django.contrib.postgres.fields.jsonb -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/posthog/migrations/0020_auto_20200210_0212.py b/posthog/migrations/0020_auto_20200210_0212.py index 2803945bbfd..c5737413424 100644 --- a/posthog/migrations/0020_auto_20200210_0212.py +++ b/posthog/migrations/0020_auto_20200210_0212.py @@ -1,7 +1,7 @@ # Generated by Django 2.2.7 on 2020-02-10 02:12 -from django.db import migrations, models import django.utils.timezone +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/posthog/migrations/0021_user_distinct_id.py b/posthog/migrations/0021_user_distinct_id.py index 3efeba61033..5f7093f91d2 100644 --- a/posthog/migrations/0021_user_distinct_id.py +++ b/posthog/migrations/0021_user_distinct_id.py @@ -1,8 +1,9 @@ # Generated by Django 3.0.3 on 2020-02-10 18:30 -from django.db import migrations, models import secrets +from django.db import migrations, models + def forwards_func(apps, schema_editor): User = apps.get_model("posthog", "User") diff --git a/posthog/migrations/0025_cohort.py b/posthog/migrations/0025_cohort.py index 2e00863b84e..80bfd5fdfe7 100644 --- a/posthog/migrations/0025_cohort.py +++ b/posthog/migrations/0025_cohort.py @@ -1,8 +1,8 @@ # Generated by Django 3.0.3 on 2020-02-26 02:02 import django.contrib.postgres.fields.jsonb -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/posthog/migrations/0026_auto_20200227_0804.py b/posthog/migrations/0026_auto_20200227_0804.py index 21e59eb26e9..ca8df6a8ae3 100644 --- a/posthog/migrations/0026_auto_20200227_0804.py +++ b/posthog/migrations/0026_auto_20200227_0804.py @@ -1,7 +1,7 @@ # Generated by Django 3.0.3 on 2020-02-27 08:04 -from django.db import migrations, models, transaction import django.db.models.deletion +from django.db import migrations, models, transaction class Migration(migrations.Migration): diff --git a/posthog/migrations/0027_move_elements_to_group.py b/posthog/migrations/0027_move_elements_to_group.py index cd2675408f2..01f56724582 100644 --- a/posthog/migrations/0027_move_elements_to_group.py +++ b/posthog/migrations/0027_move_elements_to_group.py @@ -1,11 +1,10 @@ # Generated by Django 3.0.3 on 2020-02-27 18:13 +import hashlib +import json from typing import List -from django.db import migrations, transaction, models - +from django.db import migrations, models, transaction from django.forms.models import model_to_dict -import json -import hashlib def hash_elements(elements) -> str: diff --git a/posthog/migrations/0031_team_signup_token.py b/posthog/migrations/0031_team_signup_token.py index 2d415506671..cc6a0f5265e 100644 --- a/posthog/migrations/0031_team_signup_token.py +++ b/posthog/migrations/0031_team_signup_token.py @@ -1,8 +1,9 @@ # Generated by Django 3.0.3 on 2020-03-07 00:22 -from django.db import migrations, models import secrets +from django.db import migrations, models + def add_signup_tokens(apps, schema_editor): Team = apps.get_model("posthog", "Team") diff --git a/posthog/migrations/0038_migrate_actions_to_precalculate_events.py b/posthog/migrations/0038_migrate_actions_to_precalculate_events.py index f1fd8e2d016..3fd7c0bf4c4 100644 --- a/posthog/migrations/0038_migrate_actions_to_precalculate_events.py +++ b/posthog/migrations/0038_migrate_actions_to_precalculate_events.py @@ -1,9 +1,10 @@ # Generated by Django 3.0.3 on 2020-04-03 09:32 -from django.db import migrations, models, connection -from django.db.models import Exists, OuterRef, Q, Subquery, F import re -from typing import List, Dict, Union +from typing import Dict, List, Union + +from django.db import connection, migrations, models +from django.db.models import Exists, F, OuterRef, Q, Subquery attribute_regex = r"([a-zA-Z]*)\[(.*)=[\'|\"](.*)[\'|\"]\]" diff --git a/posthog/migrations/0042_add_type_dashboarditems.py b/posthog/migrations/0042_add_type_dashboarditems.py index 819a9ee679b..5e020de8e26 100644 --- a/posthog/migrations/0042_add_type_dashboarditems.py +++ b/posthog/migrations/0042_add_type_dashboarditems.py @@ -1,6 +1,7 @@ # Generated by Django 3.0.5 on 2020-04-09 10:55 from django.db import migrations + from posthog.constants import TREND_FILTER_TYPE_ACTIONS, TREND_FILTER_TYPE_EVENTS diff --git a/posthog/migrations/0044_auto_20200413_1936.py b/posthog/migrations/0044_auto_20200413_1936.py index a7ee95df4a6..66c5980cb81 100644 --- a/posthog/migrations/0044_auto_20200413_1936.py +++ b/posthog/migrations/0044_auto_20200413_1936.py @@ -1,8 +1,9 @@ # Generated by Django 3.0.3 on 2020-04-13 19:36 import django.contrib.postgres.fields.jsonb -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models + from posthog.constants import TREND_FILTER_TYPE_ACTIONS, TREND_FILTER_TYPE_EVENTS diff --git a/posthog/migrations/0050_dashboards.py b/posthog/migrations/0050_dashboards.py index 3442a06604c..6a3784bbf25 100644 --- a/posthog/migrations/0050_dashboards.py +++ b/posthog/migrations/0050_dashboards.py @@ -1,8 +1,8 @@ # Generated by Django 3.0.5 on 2020-05-07 09:12 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models, transaction -import django.db.models.deletion def forwards(apps, schema_editor): diff --git a/posthog/migrations/0051_precalculate_cohorts.py b/posthog/migrations/0051_precalculate_cohorts.py index b65fab1e272..627c681e420 100644 --- a/posthog/migrations/0051_precalculate_cohorts.py +++ b/posthog/migrations/0051_precalculate_cohorts.py @@ -1,9 +1,9 @@ # Generated by Django 3.0.5 on 2020-05-07 18:22 -from django.conf import settings -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/posthog/migrations/0061_featureflag.py b/posthog/migrations/0061_featureflag.py index d9e1f978168..232b283ebe7 100644 --- a/posthog/migrations/0061_featureflag.py +++ b/posthog/migrations/0061_featureflag.py @@ -1,10 +1,10 @@ # Generated by Django 3.0.6 on 2020-06-18 08:59 -from django.conf import settings import django.contrib.postgres.fields.jsonb -from django.db import migrations, models import django.db.models.deletion import django.utils.timezone +from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/posthog/migrations/0068_auto_20200629_1322.py b/posthog/migrations/0068_auto_20200629_1322.py index 67e0c0536be..73ea3313372 100644 --- a/posthog/migrations/0068_auto_20200629_1322.py +++ b/posthog/migrations/0068_auto_20200629_1322.py @@ -1,8 +1,8 @@ # Generated by Django 3.0.7 on 2020-06-29 13:22 +import django.db.models.deletion from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): diff --git a/posthog/migrations/0069_auto_20200714_1642.py b/posthog/migrations/0069_auto_20200714_1642.py index 33a9a2a9029..5e4515bd0a2 100644 --- a/posthog/migrations/0069_auto_20200714_1642.py +++ b/posthog/migrations/0069_auto_20200714_1642.py @@ -1,7 +1,7 @@ # Generated by Django 3.0.7 on 2020-07-14 16:42 -from django.db import migrations, models import django.utils.timezone +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/posthog/migrations/0071_cache_dashboard_items.py b/posthog/migrations/0071_cache_dashboard_items.py index a4ffa2b4bda..b50d04378f2 100644 --- a/posthog/migrations/0071_cache_dashboard_items.py +++ b/posthog/migrations/0071_cache_dashboard_items.py @@ -1,10 +1,11 @@ # Generated by Django 3.0.6 on 2020-06-25 10:24 -from django.db import migrations, models -from posthog.models import Filter - import secrets +from django.db import migrations, models + +from posthog.models import Filter + def forwards_func(apps, schema_editor): Dashboard = apps.get_model("posthog", "Dashboard") diff --git a/posthog/models/__init__.py b/posthog/models/__init__.py index 21f4d6d0c6a..66f7fb88ecf 100644 --- a/posthog/models/__init__.py +++ b/posthog/models/__init__.py @@ -1,8 +1,9 @@ from .action import Action from .action_step import ActionStep +from .annotation import Annotation +from .cohort import Cohort, CohortPeople from .dashboard import Dashboard from .dashboard_item import DashboardItem -from .cohort import Cohort, CohortPeople from .element import Element from .element_group import ElementGroup from .entity import Entity @@ -14,4 +15,3 @@ from .person import Person, PersonDistinctId from .property import Property from .team import Team from .user import User, UserManager -from .annotation import Annotation diff --git a/posthog/models/action.py b/posthog/models/action.py index 7796dc34aa5..7e7ab636490 100644 --- a/posthog/models/action.py +++ b/posthog/models/action.py @@ -1,11 +1,12 @@ import datetime -from django.db import models, connection, transaction from django.core.exceptions import EmptyResultSet +from django.db import connection, models, transaction from django.utils import timezone -from .user import User from sentry_sdk import capture_exception +from .user import User + class Action(models.Model): class Meta: diff --git a/posthog/models/action_step.py b/posthog/models/action_step.py index 73b06366777..c65e6d8bb2d 100644 --- a/posthog/models/action_step.py +++ b/posthog/models/action_step.py @@ -1,5 +1,5 @@ -from django.db import models, connection, transaction from django.contrib.postgres.fields import JSONField +from django.db import connection, models, transaction class ActionStep(models.Model): diff --git a/posthog/models/cohort.py b/posthog/models/cohort.py index 95cec942be8..4f41c3911d9 100644 --- a/posthog/models/cohort.py +++ b/posthog/models/cohort.py @@ -1,16 +1,17 @@ -from django.db import models, connection, transaction -from django.db.models import Q +import json +from typing import Any, Dict, Optional + +from dateutil.relativedelta import relativedelta from django.contrib.postgres.fields import JSONField +from django.db import connection, models, transaction +from django.db.models import Q from django.utils import timezone -from .person import Person +from sentry_sdk import capture_exception + from .action import Action from .event import Event from .filter import Filter -from dateutil.relativedelta import relativedelta -from sentry_sdk import capture_exception - -from typing import Any, Dict, Optional -import json +from .person import Person class Group(object): diff --git a/posthog/models/dashboard_item.py b/posthog/models/dashboard_item.py index e1e9f70582a..9629ec83d10 100644 --- a/posthog/models/dashboard_item.py +++ b/posthog/models/dashboard_item.py @@ -1,5 +1,5 @@ -from django.db import models from django.contrib.postgres.fields import JSONField +from django.db import models class DashboardItem(models.Model): @@ -16,6 +16,4 @@ class DashboardItem(models.Model): color: models.CharField = models.CharField(max_length=400, null=True, blank=True) last_refresh: models.DateTimeField = models.DateTimeField(blank=True, null=True) refreshing: models.BooleanField = models.BooleanField(default=False) - funnel: models.ForeignKey = models.ForeignKey( - "Funnel", on_delete=models.CASCADE, null=True, blank=True - ) + funnel: models.ForeignKey = models.ForeignKey("Funnel", on_delete=models.CASCADE, null=True, blank=True) diff --git a/posthog/models/element.py b/posthog/models/element.py index e3576884881..981009f6078 100644 --- a/posthog/models/element.py +++ b/posthog/models/element.py @@ -1,5 +1,5 @@ +from django.contrib.postgres.fields import ArrayField, JSONField from django.db import models -from django.contrib.postgres.fields import JSONField, ArrayField class Element(models.Model): diff --git a/posthog/models/element_group.py b/posthog/models/element_group.py index 04ee0bc6df1..85dca83261b 100644 --- a/posthog/models/element_group.py +++ b/posthog/models/element_group.py @@ -1,10 +1,12 @@ -from django.db import models, transaction -from django.forms.models import model_to_dict -from .element import Element -from .team import Team -from typing import List, Dict, Any import hashlib import json +from typing import Any, Dict, List + +from django.db import models, transaction +from django.forms.models import model_to_dict + +from .element import Element +from .team import Team class ElementGroupManager(models.Manager): diff --git a/posthog/models/entity.py b/posthog/models/entity.py index dcc0bcf894c..86f39070d20 100644 --- a/posthog/models/entity.py +++ b/posthog/models/entity.py @@ -1,5 +1,7 @@ +from typing import Any, Dict, List, Optional, Union + from posthog.constants import TREND_FILTER_TYPE_ACTIONS, TREND_FILTER_TYPE_EVENTS -from typing import Union, Dict, Any, Optional, List + from .property import Property, PropertyMixin diff --git a/posthog/models/event.py b/posthog/models/event.py index 7d946ffd587..cca98d7b51d 100644 --- a/posthog/models/event.py +++ b/posthog/models/event.py @@ -1,47 +1,44 @@ -from posthog.models.entity import Entity -from django.core.cache import cache -from django.conf import settings -from django.db import models, transaction -from django.db.models import ( - Exists, - OuterRef, - Q, - Subquery, - F, - signals, - Prefetch, - QuerySet, - Value, -) -from django.db import connection -from django.db.models.functions import TruncDay -from django.contrib.postgres.fields import JSONField -from django.utils import timezone -from django.forms.models import model_to_dict -from posthog.constants import TREND_FILTER_TYPE_ACTIONS, TREND_FILTER_TYPE_EVENTS - -from psycopg2 import sql # type: ignore - -from .element_group import ElementGroup -from .element import Element -from .action import Action -from .action_step import ActionStep -from .person import PersonDistinctId, Person -from .team import Team -from .filter import Filter -from .utils import namedtuplefetchall - -from posthog.utils import generate_cache_key - -from posthog.tasks.slack import post_event_to_slack -from typing import Dict, Union, List, Optional, Any, Tuple - -from collections import defaultdict import copy import datetime -import re import random +import re import string +from collections import defaultdict +from typing import Any, Dict, List, Optional, Tuple, Union + +from django.conf import settings +from django.contrib.postgres.fields import JSONField +from django.core.cache import cache +from django.db import connection, models, transaction +from django.db.models import ( + Exists, + F, + OuterRef, + Prefetch, + Q, + QuerySet, + Subquery, + Value, + signals, +) +from django.db.models.functions import TruncDay +from django.forms.models import model_to_dict +from django.utils import timezone +from psycopg2 import sql # type: ignore + +from posthog.constants import TREND_FILTER_TYPE_ACTIONS, TREND_FILTER_TYPE_EVENTS +from posthog.models.entity import Entity +from posthog.tasks.slack import post_event_to_slack +from posthog.utils import generate_cache_key + +from .action import Action +from .action_step import ActionStep +from .element import Element +from .element_group import ElementGroup +from .filter import Filter +from .person import Person, PersonDistinctId +from .team import Team +from .utils import namedtuplefetchall attribute_regex = r"([a-zA-Z]*)\[(.*)=[\'|\"](.*)[\'|\"]\]" diff --git a/posthog/models/feature_flag.py b/posthog/models/feature_flag.py index 9d5d0cd0f97..ef172a8a783 100644 --- a/posthog/models/feature_flag.py +++ b/posthog/models/feature_flag.py @@ -1,10 +1,12 @@ -from django.db import models -from django.contrib.postgres.fields import JSONField -from django.utils import timezone -from .person import Person -from .filter import Filter import hashlib +from django.contrib.postgres.fields import JSONField +from django.db import models +from django.utils import timezone + +from .filter import Filter +from .person import Person + __LONG_SCALE__ = float(0xFFFFFFFFFFFFFFF) diff --git a/posthog/models/filter.py b/posthog/models/filter.py index 4e373fb8ac1..d7d0301727e 100644 --- a/posthog/models/filter.py +++ b/posthog/models/filter.py @@ -1,15 +1,17 @@ -from dateutil.relativedelta import relativedelta -from django.utils import timezone -from django.db.models import Q -from django.http import HttpRequest -from posthog.constants import TREND_FILTER_TYPE_ACTIONS, TREND_FILTER_TYPE_EVENTS -from posthog.utils import relative_date_parse -from typing import Union, Dict, Any, List, Optional -from .entity import Entity -from .property import Property, PropertyMixin - import datetime import json +from typing import Any, Dict, List, Optional, Union + +from dateutil.relativedelta import relativedelta +from django.db.models import Q +from django.http import HttpRequest +from django.utils import timezone + +from posthog.constants import TREND_FILTER_TYPE_ACTIONS, TREND_FILTER_TYPE_EVENTS +from posthog.utils import relative_date_parse + +from .entity import Entity +from .property import Property, PropertyMixin class Filter(PropertyMixin): diff --git a/posthog/models/funnel.py b/posthog/models/funnel.py index ab8d065ca5c..6b31b56b8cf 100644 --- a/posthog/models/funnel.py +++ b/posthog/models/funnel.py @@ -1,27 +1,21 @@ -from collections import defaultdict import re +from collections import defaultdict +from datetime import timedelta +from typing import Any, Dict, List, Optional -from django.db import models from django.contrib.postgres.fields import JSONField -from django.db import connection -from django.db.models import ( - Min, - IntegerField, - Value, -) -from typing import List, Dict, Any, Optional - +from django.db import connection, models +from django.db.models import IntegerField, Min, Value +from django.utils import timezone from psycopg2 import sql # type: ignore -from .event import Event -from .action import Action -from .filter import Filter -from .entity import Entity -from .utils import namedtuplefetchall - from posthog.constants import TREND_FILTER_TYPE_ACTIONS, TREND_FILTER_TYPE_EVENTS -from datetime import timedelta -from django.utils import timezone + +from .action import Action +from .entity import Entity +from .event import Event +from .filter import Filter +from .utils import namedtuplefetchall class Funnel(models.Model): @@ -43,7 +37,15 @@ class Funnel(models.Model): **{filter_key: step.id}, team_id=team_id, **({"distinct_id": "1234321"} if index > 0 else {}), - **({"timestamp__gte": timezone.now().replace(year=2000, month=1, day=1, hour=0, minute=0, second=0, microsecond=0)} if index > 0 else {}), + **( + { + "timestamp__gte": timezone.now().replace( + year=2000, month=1, day=1, hour=0, minute=0, second=0, microsecond=0 + ) + } + if index > 0 + else {} + ), ) .filter(filter.properties_to_Q(team_id=team_id)) .filter(step.properties_to_Q(team_id=team_id)) diff --git a/posthog/models/person.py b/posthog/models/person.py index 0649aba6bb6..8f7a7e56c1e 100644 --- a/posthog/models/person.py +++ b/posthog/models/person.py @@ -1,7 +1,8 @@ -from django.db import models, transaction -from django.contrib.postgres.fields import JSONField from typing import Any, List +from django.contrib.postgres.fields import JSONField +from django.db import models, transaction + class PersonManager(models.Manager): def create(self, *args: Any, **kwargs: Any): diff --git a/posthog/models/property.py b/posthog/models/property.py index 519220216e6..a7c46635114 100644 --- a/posthog/models/property.py +++ b/posthog/models/property.py @@ -1,7 +1,9 @@ -from django.db.models import Q, Exists, OuterRef -from .person import Person import json -from typing import List, Optional, Union, Dict, Any +from typing import Any, Dict, List, Optional, Union + +from django.db.models import Exists, OuterRef, Q + +from .person import Person class Property: diff --git a/posthog/models/team.py b/posthog/models/team.py index 6e8eaced976..73cfd6bd11e 100644 --- a/posthog/models/team.py +++ b/posthog/models/team.py @@ -1,14 +1,17 @@ +import secrets +from datetime import datetime +from typing import Dict, List, Optional + +from django.contrib.postgres.fields import ArrayField, JSONField from django.db import models -from django.contrib.postgres.fields import JSONField, ArrayField + +from posthog.constants import TREND_FILTER_TYPE_EVENTS, TRENDS_LINEAR + from .action import Action from .action_step import ActionStep from .dashboard import Dashboard from .dashboard_item import DashboardItem from .user import User -from posthog.constants import TREND_FILTER_TYPE_EVENTS, TRENDS_LINEAR -from typing import Optional, List, Dict -from datetime import datetime -import secrets TEAM_CACHE: Dict[str, "Team"] = {} diff --git a/posthog/models/user.py b/posthog/models/user.py index 9e17dcb74d5..7069c622512 100644 --- a/posthog/models/user.py +++ b/posthog/models/user.py @@ -1,11 +1,10 @@ -from django.conf import settings -from django.db import models -from django.contrib.auth.models import AbstractUser, BaseUserManager -from typing import Union, Optional, List -from django.utils.translation import ugettext_lazy as _ - import secrets +from typing import List, Optional, Union +from django.conf import settings +from django.contrib.auth.models import AbstractUser, BaseUserManager +from django.db import models +from django.utils.translation import ugettext_lazy as _ from rest_framework.fields import BooleanField diff --git a/posthog/settings.py b/posthog/settings.py index 0056d609ae4..6d524ff5b9d 100644 --- a/posthog/settings.py +++ b/posthog/settings.py @@ -13,14 +13,13 @@ https://docs.djangoproject.com/en/2.2/ref/settings/ import ast import os import sys -from typing import List, Optional from distutils.util import strtobool - -import sentry_sdk -from sentry_sdk.integrations.django import DjangoIntegration +from typing import List, Optional import dj_database_url +import sentry_sdk from django.core.exceptions import ImproperlyConfigured +from sentry_sdk.integrations.django import DjangoIntegration VERSION = "1.11.0" diff --git a/posthog/tasks/calculate_action.py b/posthog/tasks/calculate_action.py index caa7ab22f29..43fa986bb78 100644 --- a/posthog/tasks/calculate_action.py +++ b/posthog/tasks/calculate_action.py @@ -1,9 +1,10 @@ -from celery import shared_task -from posthog.models import Action -from posthog.celery import app import logging import time +from celery import shared_task + +from posthog.celery import app +from posthog.models import Action logger = logging.getLogger(__name__) diff --git a/posthog/tasks/calculate_cohort.py b/posthog/tasks/calculate_cohort.py index 480bba83df8..493bac0d4f4 100644 --- a/posthog/tasks/calculate_cohort.py +++ b/posthog/tasks/calculate_cohort.py @@ -1,12 +1,14 @@ -from celery import shared_task -from posthog.models import Cohort -from posthog.celery import app -from django.utils import timezone -from django.db.models import Q -from dateutil.relativedelta import relativedelta import logging import time +from celery import shared_task +from dateutil.relativedelta import relativedelta +from django.db.models import Q +from django.utils import timezone + +from posthog.celery import app +from posthog.models import Cohort + logger = logging.getLogger(__name__) diff --git a/posthog/tasks/process_event.py b/posthog/tasks/process_event.py index 76bddd3b963..5fb3c492bb8 100644 --- a/posthog/tasks/process_event.py +++ b/posthog/tasks/process_event.py @@ -1,17 +1,15 @@ -from numbers import Number -from celery import shared_task -from django.core import serializers -from posthog.models import Person, Element, Event, Team, PersonDistinctId import datetime -from typing import Union, Dict, Optional +from numbers import Number +from typing import Dict, Optional, Union from celery import shared_task from dateutil import parser from dateutil.relativedelta import relativedelta +from django.core import serializers from django.db import IntegrityError from sentry_sdk import capture_exception -from posthog.models import Person, Element, Event, Team, PersonDistinctId +from posthog.models import Element, Event, Person, PersonDistinctId, Team def _alias(previous_distinct_id: str, distinct_id: str, team_id: int, retry_if_failed: bool = True,) -> None: diff --git a/posthog/tasks/slack.py b/posthog/tasks/slack.py index 7c39434fd62..b133f1f748a 100644 --- a/posthog/tasks/slack.py +++ b/posthog/tasks/slack.py @@ -1,7 +1,7 @@ +import requests from celery import shared_task from django.apps import apps from django.conf import settings -import requests @shared_task diff --git a/posthog/tasks/test/test_process_event.py b/posthog/tasks/test/test_process_event.py index 86a897351f7..583cd0b4e93 100644 --- a/posthog/tasks/test/test_process_event.py +++ b/posthog/tasks/test/test_process_event.py @@ -1,20 +1,22 @@ +from datetime import timedelta +from unittest.mock import call, patch + from django.test import TransactionTestCase from django.utils.timezone import now -from datetime import timedelta from freezegun import freeze_time + from posthog.api.test.base import BaseTest from posthog.models import ( - Event, Action, ActionStep, - Person, + Element, ElementGroup, + Event, + Person, Team, User, - Element, ) from posthog.tasks.process_event import process_event -from unittest.mock import patch, call class ProcessEvent(BaseTest): diff --git a/posthog/tasks/test/test_update_cache.py b/posthog/tasks/test/test_update_cache.py index 11a17e1b39a..3db910fb24d 100644 --- a/posthog/tasks/test/test_update_cache.py +++ b/posthog/tasks/test/test_update_cache.py @@ -1,12 +1,14 @@ -from posthog.tasks.update_cache import update_cache_item, update_cached_items -from posthog.api.test.base import BaseTest -from posthog.models import Filter, DashboardItem, Dashboard, Funnel -from posthog.utils import generate_cache_key -from django.core.cache import cache -from freezegun import freeze_time -from unittest.mock import patch, MagicMock -from django.utils.timezone import now import json +from unittest.mock import MagicMock, patch + +from django.core.cache import cache +from django.utils.timezone import now +from freezegun import freeze_time + +from posthog.api.test.base import BaseTest +from posthog.models import Dashboard, DashboardItem, Filter, Funnel +from posthog.tasks.update_cache import update_cache_item, update_cached_items +from posthog.utils import generate_cache_key class TestUpdateCache(BaseTest): diff --git a/posthog/tasks/update_cache.py b/posthog/tasks/update_cache.py index 63c08114d22..f13ba9ebda5 100644 --- a/posthog/tasks/update_cache.py +++ b/posthog/tasks/update_cache.py @@ -1,19 +1,20 @@ -from celery import shared_task, group +import datetime +import json +import logging +from typing import Any, Dict, List, Optional, Union + +from celery import group, shared_task +from dateutil.relativedelta import relativedelta +from django.core.cache import cache +from django.db.models import Prefetch, Q +from django.utils import timezone + from posthog.api.action import calculate_trends, get_actions from posthog.api.funnel import FunnelSerializer -from posthog.models import Filter, Action, Funnel, Entity, DashboardItem, ActionStep +from posthog.celery import app, update_cache_item_task from posthog.decorators import FUNNEL_ENDPOINT, TRENDS_ENDPOINT +from posthog.models import Action, ActionStep, DashboardItem, Entity, Filter, Funnel from posthog.utils import generate_cache_key -from posthog.celery import update_cache_item_task -from django.db.models import Prefetch, Q -from django.core.cache import cache -from django.utils import timezone -from dateutil.relativedelta import relativedelta -import logging -from typing import List, Dict, Any, Union, Optional -import json -import datetime -from posthog.celery import app logger = logging.getLogger(__name__) diff --git a/posthog/test/test_cohort_model.py b/posthog/test/test_cohort_model.py index c7201c9a255..b0b44234a66 100644 --- a/posthog/test/test_cohort_model.py +++ b/posthog/test/test_cohort_model.py @@ -1,5 +1,5 @@ -from posthog.models import Event, Element, Action, ActionStep, Person, Team, Cohort from posthog.api.test.base import BaseTest +from posthog.models import Action, ActionStep, Cohort, Element, Event, Person, Team class TestCohort(BaseTest): diff --git a/posthog/test/test_demo.py b/posthog/test/test_demo.py index 37c190c4abe..6d058727982 100644 --- a/posthog/test/test_demo.py +++ b/posthog/test/test_demo.py @@ -1,6 +1,7 @@ -from django.test import TestCase, Client -from posthog.models import User, DashboardItem, Action, Person, Event, Funnel, Team +from django.test import Client, TestCase + from posthog.api.test.base import BaseTest +from posthog.models import Action, DashboardItem, Event, Funnel, Person, Team, User class TestDemo(BaseTest): diff --git a/posthog/test/test_event_model.py b/posthog/test/test_event_model.py index 05aa118c576..664609f394e 100644 --- a/posthog/test/test_event_model.py +++ b/posthog/test/test_event_model.py @@ -1,15 +1,8 @@ -from posthog.models import ( - Event, - Element, - Action, - ActionStep, - Person, - Team, - ElementGroup, -) -from posthog.models.event import Selector, SelectorPart +from unittest.mock import call, patch + from posthog.api.test.base import BaseTest -from unittest.mock import patch, call +from posthog.models import Action, ActionStep, Element, ElementGroup, Event, Person, Team +from posthog.models.event import Selector, SelectorPart class TestFilterByActions(BaseTest): diff --git a/posthog/test/test_filter_model.py b/posthog/test/test_filter_model.py index f16943eea4d..051b6425097 100644 --- a/posthog/test/test_filter_model.py +++ b/posthog/test/test_filter_model.py @@ -1,10 +1,12 @@ -from posthog.api.test.base import BaseTest -from posthog.models import Filter, Property, Event, Person, Element -from django.db.models import Q -from dateutil.relativedelta import relativedelta -from django.utils import timezone import json +from dateutil.relativedelta import relativedelta +from django.db.models import Q +from django.utils import timezone + +from posthog.api.test.base import BaseTest +from posthog.models import Element, Event, Filter, Person, Property + class TestFilter(BaseTest): def test_old_style_properties(self): @@ -167,6 +169,7 @@ class TestPropertiesToQ(BaseTest): self.assertEqual(events[0], event1) self.assertEqual(len(events), 1) + class TestDateFilterQ(BaseTest): def test_filter_by_all(self): filter = Filter( @@ -178,7 +181,7 @@ class TestDateFilterQ(BaseTest): "type": "person", } ], - "date_from": "all" + "date_from": "all", } ) date_filter_query = filter.date_filter_Q diff --git a/posthog/test/test_middleware.py b/posthog/test/test_middleware.py index 64000714570..85fd6104370 100644 --- a/posthog/test/test_middleware.py +++ b/posthog/test/test_middleware.py @@ -1,4 +1,4 @@ -from django.test import TestCase, Client +from django.test import Client, TestCase class TestSignup(TestCase): diff --git a/posthog/test/test_migration_0039.py b/posthog/test/test_migration_0039.py index f154b04612a..84ff5ab7c2a 100644 --- a/posthog/test/test_migration_0039.py +++ b/posthog/test/test_migration_0039.py @@ -1,9 +1,10 @@ -from django.apps import apps -from django.test import TestCase -from django.db.migrations.executor import MigrationExecutor -from django.db import connection from typing import Optional +from django.apps import apps +from django.db import connection +from django.db.migrations.executor import MigrationExecutor +from django.test import TestCase + class TestMigrations(TestCase): @property diff --git a/posthog/test/test_signup.py b/posthog/test/test_signup.py index 2de57e52c30..51e42faf53c 100644 --- a/posthog/test/test_signup.py +++ b/posthog/test/test_signup.py @@ -1,8 +1,9 @@ -from django.test import TestCase, Client -from posthog.models import User, Dashboard, DashboardItem, Action, Person, Event, Team -from social_django.strategy import DjangoStrategy -from social_django.models import DjangoStorage +from django.test import Client, TestCase from social_core.utils import module_member +from social_django.models import DjangoStorage +from social_django.strategy import DjangoStrategy + +from posthog.models import Action, Dashboard, DashboardItem, Event, Person, Team, User from posthog.urls import social_create_user diff --git a/posthog/test/test_utils.py b/posthog/test/test_utils.py index 41bac135fcc..cf822bf1aab 100644 --- a/posthog/test/test_utils.py +++ b/posthog/test/test_utils.py @@ -1,9 +1,10 @@ from django.test import TestCase -from posthog.models import Event -from posthog.api.test.base import BaseTest -from posthog.utils import relative_date_parse from freezegun import freeze_time +from posthog.api.test.base import BaseTest +from posthog.models import Event +from posthog.utils import relative_date_parse + class TestRelativeDateParse(TestCase): @freeze_time("2020-01-31T12:22:23") diff --git a/posthog/urls.py b/posthog/urls.py index d8cde3016c7..75a1d73c5ef 100644 --- a/posthog/urls.py +++ b/posthog/urls.py @@ -1,27 +1,28 @@ -from typing import cast, Optional -from django.contrib import admin -from django.urls import path, include, re_path -from django.views.generic.base import TemplateView -from django.http import HttpResponse, JsonResponse -from django.shortcuts import redirect -from django.contrib.auth import authenticate, login, views as auth_views, decorators -from django.conf import settings -from django.views.decorators.csrf import csrf_exempt, csrf_protect -from django.template.loader import render_to_string -from django.template.exceptions import TemplateDoesNotExist +import json +import os +from typing import Optional, cast from urllib.parse import urlparse -from .api import router, capture, user, decide, dashboard -from .models import Team, User, Event +import posthoganalytics +from django.conf import settings +from django.contrib import admin +from django.contrib.auth import authenticate, decorators, login +from django.contrib.auth import views as auth_views +from django.http import HttpResponse, JsonResponse +from django.shortcuts import redirect +from django.template.exceptions import TemplateDoesNotExist +from django.template.loader import render_to_string +from django.urls import include, path, re_path +from django.views.decorators.csrf import csrf_exempt, csrf_protect +from django.views.generic.base import TemplateView +from rest_framework import permissions + +from posthog.demo import delete_demo_data, demo + +from .api import capture, dashboard, decide, router, user +from .models import Event, Team, User from .utils import render_template from .views import health, stats -from posthog.demo import demo, delete_demo_data -import json -import posthoganalytics -import os - - -from rest_framework import permissions def home(request, **kwargs): diff --git a/posthog/utils.py b/posthog/utils.py index 77cfcac3d3c..cf2f4f40f45 100644 --- a/posthog/utils.py +++ b/posthog/utils.py @@ -1,23 +1,22 @@ +import datetime +import hashlib +import json +import os +import re +from typing import Any, Dict, List, Optional, Tuple, Union +from urllib.parse import urlparse, urlsplit + +import pytz +from dateutil import parser from dateutil.relativedelta import relativedelta -from django.utils.timezone import now +from django.apps import apps from django.conf import settings from django.db.models import Q -from typing import Dict, Any, List, Union, Tuple +from django.http import HttpRequest, HttpResponse, JsonResponse from django.template.loader import get_template -from django.http import HttpResponse, JsonResponse, HttpRequest -from dateutil import parser -from typing import Tuple, Optional -from rest_framework import request, authentication +from django.utils.timezone import now +from rest_framework import authentication, request from rest_framework.exceptions import AuthenticationFailed -from urllib.parse import urlsplit, urlparse -from django.apps import apps - -import datetime -import json -import re -import os -import pytz -import hashlib def relative_date_parse(input: str) -> datetime.datetime: diff --git a/posthog/views.py b/posthog/views.py index a912693f318..b4043bcf110 100644 --- a/posthog/views.py +++ b/posthog/views.py @@ -1,9 +1,10 @@ -from typing import Dict, Union -from django.http import HttpResponse -from django.conf import settings import json -import redis import time +from typing import Dict, Union + +import redis +from django.conf import settings +from django.http import HttpResponse if settings.REDIS_URL: redis_instance = redis.from_url(settings.REDIS_URL, db=0) diff --git a/requirements/dev.in b/requirements/dev.in index 0d50bf220c7..03e9f6417c7 100644 --- a/requirements/dev.in +++ b/requirements/dev.in @@ -19,4 +19,5 @@ djangorestframework-stubs django-stubs freezegun packaging -black \ No newline at end of file +black +isort diff --git a/requirements/dev.txt b/requirements/dev.txt index c2fd615943d..06dba5dd413 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -26,10 +26,10 @@ flake8-logging-format==0.6.0 # via -r requirements/dev.in flake8-print==3.1.4 # via -r requirements/dev.in flake8==3.7.9 # via -r requirements/dev.in, flake8-bugbear, flake8-colors, flake8-commas, flake8-comprehensions, flake8-print freezegun==0.3.15 # via -r requirements/dev.in -importlib-metadata==1.6.0 # via flake8-comprehensions ipdb==0.13.2 # via -r requirements/dev.in ipython-genutils==0.2.0 # via traitlets ipython==7.14.0 # via ipdb +isort==5.1.4 # via -r requirements/dev.in jedi==0.17.0 # via ipython mccabe==0.6.1 # via flake8 mypy-extensions==0.4.3 # via -r requirements/dev.in, mypy @@ -57,7 +57,6 @@ traitlets==4.3.3 # via ipython typed-ast==1.4.1 # via black, mypy typing-extensions==3.7.4.2 # via django-stubs, djangorestframework-stubs, mypy wcwidth==0.1.9 # via prompt-toolkit -zipp==3.1.0 # via importlib-metadata # The following packages are considered to be unsafe in a requirements file: # pip