Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
継承元の変更とリファクタ
Browse files Browse the repository at this point in the history
  • Loading branch information
okwrtdsh committed Dec 7, 2016
1 parent 7218917 commit e0282b3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
1 change: 0 additions & 1 deletion django_cbv_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
VERSION = (0, 1, 0)

# Dynamically calculate the version based on VERSION tuple
Expand Down
5 changes: 1 addition & 4 deletions django_cbv_utils/forms/clean.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from django import forms


class RequiredMixin(forms.Form):
class RequiredMixin(object):
multiple_required_list = []
chain_required_list = []

Expand Down
22 changes: 9 additions & 13 deletions django_cbv_utils/forms/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@
NumericWidget, TimePickerWidget)


class SetFromControlMixin(forms.Form):
class SetFromControlMixin(forms.BaseForm):

def __init__(self, *args, **kwargs):
super(SetFromControlMixin, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
for field in self.fields:
if not isinstance(self.fields[field].widget, (
forms.CheckboxInput, forms.RadioSelect,
CalendarCheckboxSelectMultiple)):
forms.CheckboxInput, forms.RadioSelect)):
self.fields[field].widget.attrs.update(
{'class': "form-control"})


class SetDateTimePickerMixin(forms.Form):
class SetDateTimePickerMixin(forms.BaseForm):

def __init__(self, *args, **kwargs):
super(SetDateTimePickerMixin, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
for field in self.fields:
if isinstance(self.fields[field].widget, (
DateTimePickerWidget,
DatePickerWidget,
TimePickerWidget)):
DateTimePickerWidget, DatePickerWidget, TimePickerWidget)):
continue
if isinstance(self.fields[field].widget, forms.DateTimeInput):
self.fields[field].widget = DateTimePickerWidget()
Expand All @@ -37,14 +34,13 @@ def __init__(self, *args, **kwargs):
self.fields[field].widget = TimePickerWidget()


class SetPositiveIntegerMixin(forms.Form):
class SetPositiveIntegerMixin(forms.BaseForm):

def __init__(self, *args, **kwargs):
super(SetPositiveIntegerMixin, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
for field in self.fields:
if isinstance(self.fields[field].widget, (
NumericWidget,
NumericIntegerWidget,
NumericWidget, NumericIntegerWidget,
NumericPositiveIntegerWidget)):
continue
if isinstance(self.fields[field].widget, forms.NumberInput):
Expand Down
12 changes: 6 additions & 6 deletions django_cbv_utils/forms/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Meta:
fields = []

def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request", None)
super(SearchForm, self).__init__(*args, **kwargs)
self.request = kwargs.pop('request', None)
super().__init__(*args, **kwargs)
for field in self.fields:
self.fields[field].required = False

Expand Down Expand Up @@ -100,7 +100,7 @@ def _get_queries(self, queryset_filter):
q = Q()
for target in target_list:
q |= Q(**{'{0}__{1}'.format(target, attr): getattr(
data, attr) for attr in ("year", "month", "day")})
data, attr) for attr in ('year', 'month', 'day')})
queries &= q
continue

Expand All @@ -111,12 +111,12 @@ def _get_queries(self, queryset_filter):
for i, v in enumerate(data):
if v is not None:
_q &= Q(**{'{0}__{1}'.format(
target, operator.split("_")[i]): v})
target, operator.split('_')[i]): v})
q |= _q
queries &= q
continue

if operator == "icontains_or":
if operator == 'icontains_or':
if not isinstance(data, str) or not data:
continue
q = Q()
Expand All @@ -126,7 +126,7 @@ def _get_queries(self, queryset_filter):
queries &= q
continue

if operator == "icontains_and":
if operator == 'icontains_and':
if not isinstance(data, str) or not data:
continue
q = Q()
Expand Down
13 changes: 4 additions & 9 deletions django_cbv_utils/views/event.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from django.views.generic.base import View


class GETBindEventMixin(View):
class GETBindEventMixin(object):
"""
get_key = "action"
get_events = {"myevent": "myfunc"}
Expand All @@ -14,14 +11,13 @@ def myfunc(self, request, *args, **kwargs):

def get(self, request, *args, **kwargs):
key = request.GET.get(self.get_key)
handler = getattr(
super(GETBindEventMixin, self), "get", self.http_method_not_allowed)
handler = getattr(super(), "get", self.http_method_not_allowed)
if key is not None and self.get_events.get(key):
handler = getattr(self, self.get_events[key], handler)
return handler(request, *args, **kwargs)


class POSTBindEventMixin(View):
class POSTBindEventMixin(object):
"""
post_key = "action"
post_events = {"myevent": "myfunc"}
Expand All @@ -34,8 +30,7 @@ def myfunc(self, request, *args, **kwargs):

def post(self, request, *args, **kwargs):
key = request.POST.get(self.post_key)
handler = getattr(
super(POSTBindEventMixin, self), "post", self.http_method_not_allowed)
handler = getattr(super(), "post", self.http_method_not_allowed)
if key is not None and self.post_events.get(key):
handler = getattr(self, self.post_events[key], handler)
return handler(request, *args, **kwargs)

0 comments on commit e0282b3

Please sign in to comment.