Skip to content

Commit

Permalink
Use black for code auto formatting fixes #410
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlockhart committed May 28, 2018
1 parent 219169b commit 6613413
Show file tree
Hide file tree
Showing 44 changed files with 1,807 additions and 1,444 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ test: compose_build
lint: compose_build
docker-compose run app flake8 .

check: compose_build lint test
black: compose_build
docker-compose run app black -l 79 .

check: compose_build lint black test
echo "Success"

makemigrations: compose_build
Expand Down
143 changes: 75 additions & 68 deletions app/experimenter/experiments/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
class BaseVariantInlineAdmin(admin.StackedInline):
max_num = 1
model = ExperimentVariant
prepopulated_fields = {
'slug': ('name',)
}
prepopulated_fields = {"slug": ("name",)}

def has_delete_permission(self, request, obj=None):
return False
Expand All @@ -32,34 +30,34 @@ class Meta:


class ControlVariantInlineAdmin(BaseVariantInlineAdmin):
fields = ("name", "slug", "ratio", "description", "value")
form = ControlVariantModelForm
verbose_name = 'Control Variant'
verbose_name_plural = 'Control Variant'
fields = ('name', 'slug', 'ratio', 'description', 'value')
verbose_name = "Control Variant"
verbose_name_plural = "Control Variant"

def get_queryset(self, request):
return super().get_queryset(request).filter(is_control=True)


class ExperimentVariantInlineAdmin(BaseVariantInlineAdmin):
verbose_name = 'Experiment Variant'
verbose_name_plural = 'Experiment Variant'
fields = ('name', 'slug', 'ratio', 'description', 'value')
fields = ("name", "slug", "ratio", "description", "value")
verbose_name = "Experiment Variant"
verbose_name_plural = "Experiment Variant"

def get_queryset(self, request):
return super().get_queryset(request).filter(is_control=False)


class ExperimentChangeLogInlineAdmin(admin.TabularInline):
model = ExperimentChangeLog
extra = 1
model = ExperimentChangeLog

fields = (
'changed_by',
'changed_on',
'old_status',
'new_status',
'message',
"changed_by",
"changed_on",
"old_status",
"new_status",
"message",
)


Expand All @@ -69,61 +67,68 @@ class ExperimentAdmin(admin.ModelAdmin):
ExperimentVariantInlineAdmin,
ExperimentChangeLogInlineAdmin,
)
list_display = (
'name', 'project', 'status')
list_display = ("name", "project", "status")

fieldsets = (
('Overview', {
'fields': (
'archived',
'owner',
'project',
'status',
'name',
'slug',
'short_description',
'proposed_start_date',
'proposed_end_date',
),
}),
('Client Config', {
'fields': (
'pref_key',
'pref_type',
'pref_branch',
'firefox_channel',
'firefox_version',
'population_percent',
'client_matching',
),
}),
('Notes', {
'fields': ('objectives', 'analysis'),
}),
('Risks & Testing', {
'fields': (
'risk_partner_related',
'risk_brand',
'risk_fast_shipped',
'risk_confidential',
'risk_release_population',
'risks',
'testing',
),
}),
('Telemetry', {
'fields': (
'dashboard_url',
'dashboard_image_url',
'enrollment_dashboard_url',
'total_users',
),
}),
(
"Overview",
{
"fields": (
"archived",
"owner",
"project",
"status",
"name",
"slug",
"short_description",
"proposed_start_date",
"proposed_end_date",
)
},
),
(
"Client Config",
{
"fields": (
"pref_key",
"pref_type",
"pref_branch",
"firefox_channel",
"firefox_version",
"population_percent",
"client_matching",
)
},
),
("Notes", {"fields": ("objectives", "analysis")}),
(
"Risks & Testing",
{
"fields": (
"risk_partner_related",
"risk_brand",
"risk_fast_shipped",
"risk_confidential",
"risk_release_population",
"risks",
"testing",
)
},
),
(
"Telemetry",
{
"fields": (
"dashboard_url",
"dashboard_image_url",
"enrollment_dashboard_url",
"total_users",
)
},
),
)

prepopulated_fields = {
'slug': ('name',)
}
prepopulated_fields = {"slug": ("name",)}

def get_actions(self, request):
return []
Expand All @@ -134,9 +139,11 @@ def has_delete_permission(self, request, obj=None):
def show_dashboard_url(self, obj):
return format_html(
'<a href="{url}" target="_blank">{url}</a>'.format(
url=obj.dashboard_url))
url=obj.dashboard_url
)
)

show_dashboard_url.short_description = 'Dashboard URL'
show_dashboard_url.short_description = "Dashboard URL"


admin.site.register(Experiment, ExperimentAdmin)
14 changes: 5 additions & 9 deletions app/experimenter/experiments/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@


urlpatterns = [
url(r"^$", ExperimentListView.as_view(), name="experiments-api-list"),
url(
r'^$',
ExperimentListView.as_view(),
name='experiments-api-list',
),
url(
r'^(?P<slug>[\w-]+)/accept/$',
r"^(?P<slug>[\w-]+)/accept/$",
ExperimentAcceptView.as_view(),
name='experiments-api-accept',
name="experiments-api-accept",
),
url(
r'^(?P<slug>[\w-]+)/reject/$',
r"^(?P<slug>[\w-]+)/reject/$",
ExperimentRejectView.as_view(),
name='experiments-api-reject',
name="experiments-api-reject",
),
]
12 changes: 5 additions & 7 deletions app/experimenter/experiments/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
from rest_framework.response import Response

from experimenter.experiments.models import Experiment, ExperimentChangeLog
from experimenter.experiments.serializers import (
ExperimentSerializer,
)
from experimenter.experiments.serializers import ExperimentSerializer


class ExperimentListView(ListAPIView):
filter_fields = ('project__slug', 'status')
filter_fields = ("project__slug", "status")
queryset = Experiment.objects.all()
serializer_class = ExperimentSerializer


class ExperimentAcceptView(UpdateAPIView):
lookup_field = "slug"
queryset = Experiment.objects.filter(status=Experiment.STATUS_REVIEW)
lookup_field = 'slug'

def update(self, request, *args, **kwargs):
experiment = self.get_object()
Expand All @@ -36,8 +34,8 @@ def update(self, request, *args, **kwargs):


class ExperimentRejectView(UpdateAPIView):
lookup_field = "slug"
queryset = Experiment.objects.filter(status=Experiment.STATUS_REVIEW)
lookup_field = 'slug'

def update(self, request, *args, **kwargs):
experiment = self.get_object()
Expand All @@ -52,7 +50,7 @@ def update(self, request, *args, **kwargs):
old_status=old_status,
new_status=experiment.status,
changed_by=self.request.user,
message=self.request.data.get('message', ''),
message=self.request.data.get("message", ""),
)

return Response()
Loading

0 comments on commit 6613413

Please sign in to comment.