Skip to content

Black: run black over all the code base #10619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion common
2 changes: 1 addition & 1 deletion dockerfiles/settings/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@


class BuildDevSettings(DockerBaseSettings):

@property
def DATABASES(self): # noqa
return {}

DONT_HIT_DB = True


BuildDevSettings.load_settings(__name__)
2 changes: 1 addition & 1 deletion dockerfiles/settings/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CeleryDevSettings(DockerBaseSettings):
# http://storage:9000/... This setting fixes that.
# Once we can use CORS, we should define this setting in the
# ``docker_compose.py`` file instead.
S3_MEDIA_STORAGE_OVERRIDE_HOSTNAME = 'storage:9000'
S3_MEDIA_STORAGE_OVERRIDE_HOSTNAME = "storage:9000"


CeleryDevSettings.load_settings(__name__)
2 changes: 1 addition & 1 deletion dockerfiles/settings/proxito.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ProxitoDevSettings(CommunityProxitoSettingsMixin, DockerBaseSettings):
@property
def DEBUG_TOOLBAR_CONFIG(self):
return {
'SHOW_TOOLBAR_CALLBACK': lambda request: False,
"SHOW_TOOLBAR_CALLBACK": lambda request: False,
}


Expand Down
4 changes: 1 addition & 3 deletions dockerfiles/settings/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ class WebDevSettings(DockerBaseSettings):

# Router is useful from webs only because they have access to the database.
# Builders will use the same queue that was assigned the first time on retry
CELERY_ROUTES = (
'readthedocs.builds.tasks.TaskRouter',
)
CELERY_ROUTES = ("readthedocs.builds.tasks.TaskRouter",)


WebDevSettings.load_settings(__name__)
6 changes: 3 additions & 3 deletions docs/_ext/djangodocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def setup(app):
)

return {
'version': 'builtin',
'parallel_read_safe': True,
'parallel_write_safe': True,
"version": "builtin",
"parallel_read_safe": True,
"parallel_write_safe": True,
}
2 changes: 1 addition & 1 deletion readthedocs/acl/constants.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BACKEND_REQUEST_KEY = '_auth_request_key'
BACKEND_REQUEST_KEY = "_auth_request_key"
10 changes: 5 additions & 5 deletions readthedocs/analytics/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

@admin.register(PageView)
class PageViewAdmin(admin.ModelAdmin):
raw_id_fields = ('project', 'version')
list_display = ('project', 'version', 'path', 'view_count', 'date')
search_fields = ('project__slug', 'version__slug', 'path')
readonly_fields = ('date',)
list_select_related = ('project', 'version', 'version__project')
raw_id_fields = ("project", "version")
list_display = ("project", "version", "path", "view_count", "date")
search_fields = ("project__slug", "version__slug", "path")
readonly_fields = ("date",)
list_select_related = ("project", "version", "version__project")
4 changes: 2 additions & 2 deletions readthedocs/analytics/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ class AnalyticsAppConfig(AppConfig):
"""Analytics app init code."""

default_auto_field = "django.db.models.BigAutoField"
name = 'readthedocs.analytics'
verbose_name = 'Analytics'
name = "readthedocs.analytics"
verbose_name = "Analytics"
44 changes: 33 additions & 11 deletions readthedocs/analytics/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,49 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
('builds', '0022_migrate_protected_versions'),
('projects', '0048_remove_version_privacy_field'),
("builds", "0022_migrate_protected_versions"),
("projects", "0048_remove_version_privacy_field"),
]

operations = [
migrations.CreateModel(
name='PageView',
name="PageView",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('path', models.CharField(max_length=4096)),
('view_count', models.PositiveIntegerField(default=0)),
('date', models.DateField(db_index=True, default=datetime.date.today)),
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='page_views', to='projects.Project')),
('version', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='page_views', to='builds.Version', verbose_name='Version')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("path", models.CharField(max_length=4096)),
("view_count", models.PositiveIntegerField(default=0)),
("date", models.DateField(db_index=True, default=datetime.date.today)),
(
"project",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="page_views",
to="projects.Project",
),
),
(
"version",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="page_views",
to="builds.Version",
verbose_name="Version",
),
),
],
options={
'unique_together': {('project', 'version', 'path', 'date')},
"unique_together": {("project", "version", "path", "date")},
},
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("builds", "0041_track_task_id"),
("projects", "0087_use_booleanfield_null"),
Expand Down
1 change: 0 additions & 1 deletion readthedocs/analytics/migrations/0003_remove_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

dependencies = [
("analytics", "0002_track_status_code"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def forwards_func(apps, schema_editor):


class Migration(migrations.Migration):

dependencies = [
("analytics", "0003_remove_index"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("analytics", "0004_merge_duplicate_records"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("analytics", "0005_add_unique_constraint"),
]
Expand Down
17 changes: 7 additions & 10 deletions readthedocs/analytics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ class PageView(models.Model):

project = models.ForeignKey(
Project,
related_name='page_views',
related_name="page_views",
on_delete=models.CASCADE,
)
# NOTE: this could potentially be removed,
# since isn't being used and not all page
# views (404s) are attached to a version.
version = models.ForeignKey(
Version,
verbose_name=_('Version'),
related_name='page_views',
verbose_name=_("Version"),
related_name="page_views",
on_delete=models.CASCADE,
null=True,
)
Expand Down Expand Up @@ -184,9 +184,7 @@ def page_views_by_date(cls, project_slug, since=None, status=200):
.order_by("date")
)

count_dict = dict(
queryset.order_by('date').values_list('date', 'total_views')
)
count_dict = dict(queryset.order_by("date").values_list("date", "total_views"))

# This fills in any dates where there is no data
# to make sure we have a full 30 days of dates
Expand All @@ -195,13 +193,12 @@ def page_views_by_date(cls, project_slug, since=None, status=200):
# format the date value to a more readable form
# Eg. `16 Jul`
last_30_days_str = [
timezone.datetime.strftime(date, '%d %b')
for date in _last_30_days_iter()
timezone.datetime.strftime(date, "%d %b") for date in _last_30_days_iter()
]

final_data = {
'labels': last_30_days_str,
'int_data': count_data,
"labels": last_30_days_str,
"int_data": count_data,
}

return final_data
9 changes: 4 additions & 5 deletions readthedocs/analytics/proxied_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ class BaseAnalyticsView(CDNCacheControlMixin, APIView):
# We always want to hit our analytics endpoint,
# so we capture all views/interactions.
cache_response = False
http_method_names = ['get']
http_method_names = ["get"]
permission_classes = [IsAuthorizedToViewVersion]

@lru_cache(maxsize=1)
def _get_project(self):
project_slug = self.request.GET.get('project')
project_slug = self.request.GET.get("project")
project = get_object_or_404(Project, slug=project_slug)
return project

@lru_cache(maxsize=1)
def _get_version(self):
version_slug = self.request.GET.get('version')
version_slug = self.request.GET.get("version")
project = self._get_project()
version = get_object_or_404(
project.versions.all(),
Expand All @@ -53,7 +53,7 @@ def _get_version(self):
def get(self, request, *args, **kwargs):
project = self._get_project()
version = self._get_version()
absolute_uri = self.request.GET.get('absolute_uri')
absolute_uri = self.request.GET.get("absolute_uri")
if not absolute_uri:
return JsonResponse(
{"error": "'absolute_uri' GET attribute is required"},
Expand Down Expand Up @@ -92,5 +92,4 @@ def increase_page_view_count(self, project, version, absolute_uri):


class AnalyticsView(SettingsOverrideObject):

_default_class = BaseAnalyticsView
41 changes: 19 additions & 22 deletions readthedocs/analytics/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@
from .utils import send_to_analytics

DEFAULT_PARAMETERS = {
'v': '1', # analytics version (always 1)
'aip': '1', # anonymize IP
'tid': settings.GLOBAL_ANALYTICS_CODE,

"v": "1", # analytics version (always 1)
"aip": "1", # anonymize IP
"tid": settings.GLOBAL_ANALYTICS_CODE,
# User data
'uip': '', # User IP address
'ua': '', # User agent

"uip": "", # User IP address
"ua": "", # User agent
# Application info
'an': 'Read the Docs',
'av': readthedocs.__version__, # App version
"an": "Read the Docs",
"av": readthedocs.__version__, # App version
}


@app.task(queue='web')
@app.task(queue="web")
def analytics_pageview(url, title=None, **kwargs):
"""
Send a pageview to Google Analytics.
Expand All @@ -35,19 +33,18 @@ def analytics_pageview(url, title=None, **kwargs):
:param kwargs: extra pageview parameters to send to GA
"""
data = {
't': 'pageview',
'dl': url, # URL of the pageview (required)
'dt': title, # Title of the page
"t": "pageview",
"dl": url, # URL of the pageview (required)
"dt": title, # Title of the page
}
data.update(DEFAULT_PARAMETERS)
data.update(kwargs)
send_to_analytics(data)


@app.task(queue='web')
@app.task(queue="web")
def analytics_event(
event_category, event_action, event_label=None, event_value=None,
**kwargs
event_category, event_action, event_label=None, event_value=None, **kwargs
):
"""
Send an analytics event to Google Analytics.
Expand All @@ -60,18 +57,18 @@ def analytics_event(
:param kwargs: extra event parameters to send to GA
"""
data = {
't': 'event', # GA event - don't change
'ec': event_category, # Event category (required)
'ea': event_action, # Event action (required)
'el': event_label, # Event label
'ev': event_value, # Event value (numeric)
"t": "event", # GA event - don't change
"ec": event_category, # Event category (required)
"ea": event_action, # Event action (required)
"el": event_label, # Event label
"ev": event_value, # Event value (numeric)
}
data.update(DEFAULT_PARAMETERS)
data.update(kwargs)
send_to_analytics(data)


@app.task(queue='web')
@app.task(queue="web")
def delete_old_page_counts():
"""
Delete page counts older than ``RTD_ANALYTICS_DEFAULT_RETENTION_DAYS``.
Expand Down
Loading