Skip to content

Commit

Permalink
Moved non-atomic logic into mixin class
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed May 31, 2016
1 parent 100a728 commit 9963c50
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
9 changes: 2 additions & 7 deletions casepro/cases/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
from dash.orgs.views import OrgPermsMixin, OrgObjPermsMixin
from datetime import date, timedelta
from django.core.cache import cache
from django.db import transaction
from django.db.models import Count
from django.http import HttpResponse, JsonResponse
from django.utils.decorators import method_decorator
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from django.views.generic import View
Expand All @@ -21,6 +19,7 @@
from casepro.utils import parse_csv, json_encode, datetime_to_microseconds, microseconds_to_datetime, JSONEncoder
from casepro.utils import month_range
from casepro.utils.export import BaseDownloadView
from casepro.utils.views import NonAtomicMixin

from . import MAX_MESSAGE_CHARS
from .forms import PartnerForm
Expand Down Expand Up @@ -267,11 +266,7 @@ class CaseExportCRUDL(SmartCRUDL):
model = CaseExport
actions = ('create', 'read')

class Create(OrgPermsMixin, CaseSearchMixin, SmartCreateView):
@method_decorator(transaction.non_atomic_requests)
def dispatch(self, request, *args, **kwargs):
return super(CaseExportCRUDL.Create, self).dispatch(request, *args, **kwargs)

class Create(NonAtomicMixin, OrgPermsMixin, CaseSearchMixin, SmartCreateView):
def post(self, request, *args, **kwargs):
search = self.derive_search()
export = self.model.create(self.request.org, self.request.user, search)
Expand Down
15 changes: 3 additions & 12 deletions casepro/msgs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

from collections import defaultdict
from dash.orgs.views import OrgPermsMixin, OrgObjPermsMixin
from django.db import transaction
from django.http import HttpResponse, HttpResponseBadRequest, JsonResponse
from django.utils.decorators import method_decorator
from django.utils.timesince import timesince
from django.utils.translation import ugettext_lazy as _
from el_pagination.paginators import LazyPaginator
Expand All @@ -17,6 +15,7 @@
from casepro.rules.models import ContainsTest, GroupsTest, Quantifier
from casepro.utils import parse_csv, str_to_bool, json_encode, JSONEncoder
from casepro.utils.export import BaseDownloadView
from casepro.utils.views import NonAtomicMixin

from .forms import LabelForm
from .models import Label, Message, MessageExport, MessageFolder, Outgoing, OutgoingFolder, ReplyExport
Expand Down Expand Up @@ -305,11 +304,7 @@ class MessageExportCRUDL(SmartCRUDL):
model = MessageExport
actions = ('create', 'read')

class Create(OrgPermsMixin, MessageSearchMixin, SmartCreateView):
@method_decorator(transaction.non_atomic_requests)
def dispatch(self, request, *args, **kwargs):
return super(MessageExportCRUDL.Create, self).dispatch(request, *args, **kwargs)

class Create(NonAtomicMixin, OrgPermsMixin, MessageSearchMixin, SmartCreateView):
def post(self, request, *args, **kwargs):
search = self.derive_search()
export = MessageExport.create(self.request.org, self.request.user, search)
Expand Down Expand Up @@ -411,11 +406,7 @@ class ReplyExportCRUDL(SmartCRUDL):
model = ReplyExport
actions = ('create', 'read')

class Create(OrgPermsMixin, ReplySearchMixin, SmartCreateView):
@method_decorator(transaction.non_atomic_requests)
def dispatch(self, request, *args, **kwargs):
return super(ReplyExportCRUDL.Create, self).dispatch(request, *args, **kwargs)

class Create(NonAtomicMixin, OrgPermsMixin, ReplySearchMixin, SmartCreateView):
def post(self, request, *args, **kwargs):
search = self.derive_search()
export = self.model.create(self.request.org, self.request.user, search)
Expand Down
13 changes: 13 additions & 0 deletions casepro/utils/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import unicode_literals

from django.db import transaction
from django.utils.decorators import method_decorator


class NonAtomicMixin(object):
"""
Mixin to configure a view to be handled without a transaction
"""
@method_decorator(transaction.non_atomic_requests)
def dispatch(self, request, *args, **kwargs):
return super(NonAtomicMixin, self).dispatch(request, *args, **kwargs)

0 comments on commit 9963c50

Please sign in to comment.