Skip to content
Snippets Groups Projects
Commit 805c4faf authored by Carlos Vega's avatar Carlos Vega
Browse files

added decorators properly in class-based views

parent 6037223b
No related branches found
No related tags found
1 merge request!192Feature/add way to change password and PERMISSIONS
...@@ -15,7 +15,10 @@ class LanguageListView(ListView, WrappedView): ...@@ -15,7 +15,10 @@ class LanguageListView(ListView, WrappedView):
context_object_name = "languages" context_object_name = "languages"
template_name = 'languages/list.html' template_name = 'languages/list.html'
@PermissionDecorator('change_language', 'configuration') @PermissionDecorator('change_language', 'configuration')
def dispatch(self, *args, **kwargs):
return super(LanguageListView, self).dispatch(*args, **kwargs)
class LanguageCreateView(CreateView, WrappedView): class LanguageCreateView(CreateView, WrappedView):
model = Language model = Language
template_name = "languages/add.html" template_name = "languages/add.html"
...@@ -23,7 +26,10 @@ class LanguageCreateView(CreateView, WrappedView): ...@@ -23,7 +26,10 @@ class LanguageCreateView(CreateView, WrappedView):
success_url = reverse_lazy('web.views.languages') success_url = reverse_lazy('web.views.languages')
success_message = "Language created" success_message = "Language created"
@PermissionDecorator('change_language', 'configuration') @PermissionDecorator('change_language', 'configuration')
def dispatch(self, *args, **kwargs):
return super(LanguageCreateView, self).dispatch(*args, **kwargs)
class LanguageDeleteView(DeleteView, WrappedView): class LanguageDeleteView(DeleteView, WrappedView):
model = Language model = Language
success_url = reverse_lazy('web.views.languages') success_url = reverse_lazy('web.views.languages')
...@@ -33,7 +39,10 @@ class LanguageDeleteView(DeleteView, WrappedView): ...@@ -33,7 +39,10 @@ class LanguageDeleteView(DeleteView, WrappedView):
messages.success(request, "Language deleted") messages.success(request, "Language deleted")
return super(LanguageDeleteView, self).delete(request, *args, **kwargs) return super(LanguageDeleteView, self).delete(request, *args, **kwargs)
@PermissionDecorator('change_language', 'configuration') @PermissionDecorator('change_language', 'configuration')
def dispatch(self, *args, **kwargs):
return super(LanguageDeleteView, self).dispatch(*args, **kwargs)
class LanguageEditView(UpdateView, WrappedView): class LanguageEditView(UpdateView, WrappedView):
model = Language model = Language
success_url = reverse_lazy('web.views.languages') success_url = reverse_lazy('web.views.languages')
...@@ -41,3 +50,7 @@ class LanguageEditView(UpdateView, WrappedView): ...@@ -41,3 +50,7 @@ class LanguageEditView(UpdateView, WrappedView):
success_message = "Language edited" success_message = "Language edited"
template_name = "languages/edit.html" template_name = "languages/edit.html"
context_object_name = "language" context_object_name = "language"
@PermissionDecorator('change_language', 'configuration')
def dispatch(self, *args, **kwargs):
return super(LanguageEditView, self).dispatch(*args, **kwargs)
\ No newline at end of file
...@@ -11,7 +11,7 @@ from web.decorators import PermissionDecorator ...@@ -11,7 +11,7 @@ from web.decorators import PermissionDecorator
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
PermissionDecorator('change_study', 'configuration') @PermissionDecorator('change_study', 'configuration')
def study_edit(request, study_id): def study_edit(request, study_id):
study = get_object_or_404(Study, id=study_id) study = get_object_or_404(Study, id=study_id)
if request.method == 'POST': if request.method == 'POST':
......
...@@ -24,11 +24,14 @@ class VoucherListView(ListView, WrappedView): ...@@ -24,11 +24,14 @@ class VoucherListView(ListView, WrappedView):
context_object_name = "vouchers" context_object_name = "vouchers"
template_name = 'vouchers/list.html' template_name = 'vouchers/list.html'
@PermissionDecorator('change_voucher', 'configuration')
def dispatch(self, *args, **kwargs):
return super(VoucherListView, self).dispatch(*args, **kwargs)
def voucher_types_for_study_subject(study_subject_id): def voucher_types_for_study_subject(study_subject_id):
return StudySubject.objects.get(id=study_subject_id).voucher_types.all() return StudySubject.objects.get(id=study_subject_id).voucher_types.all()
PermissionDecorator('change_voucher', 'configuration')
class VoucherCreateView(CreateView, WrappedView): class VoucherCreateView(CreateView, WrappedView):
form_class = VoucherForm form_class = VoucherForm
model = Voucher model = Voucher
...@@ -61,7 +64,10 @@ class VoucherCreateView(CreateView, WrappedView): ...@@ -61,7 +64,10 @@ class VoucherCreateView(CreateView, WrappedView):
kwargs['voucher_types'] = voucher_types_for_study_subject(self.request.GET.get("study_subject_id", -1)) kwargs['voucher_types'] = voucher_types_for_study_subject(self.request.GET.get("study_subject_id", -1))
return kwargs return kwargs
PermissionDecorator('change_voucher', 'configuration') @PermissionDecorator('change_voucher', 'configuration')
def dispatch(self, *args, **kwargs):
return super(VoucherCreateView, self).dispatch(*args, **kwargs)
class VoucherEditView(SuccessMessageMixin, UpdateView, WrappedView): class VoucherEditView(SuccessMessageMixin, UpdateView, WrappedView):
form_class = VoucherForm form_class = VoucherForm
model = Voucher model = Voucher
...@@ -83,6 +89,10 @@ class VoucherEditView(SuccessMessageMixin, UpdateView, WrappedView): ...@@ -83,6 +89,10 @@ class VoucherEditView(SuccessMessageMixin, UpdateView, WrappedView):
context['mail_templates'] = MailTemplate.get_voucher_mail_templates([]) context['mail_templates'] = MailTemplate.get_voucher_mail_templates([])
return context return context
@PermissionDecorator('change_voucher', 'configuration')
def dispatch(self, *args, **kwargs):
return super(VoucherEditView, self).dispatch(*args, **kwargs)
class ExpireVouchersJob(CronJobBase): class ExpireVouchersJob(CronJobBase):
RUN_EVERY_MINUTES = 120 RUN_EVERY_MINUTES = 120
......
...@@ -15,7 +15,10 @@ class VoucherTypeListView(ListView, WrappedView): ...@@ -15,7 +15,10 @@ class VoucherTypeListView(ListView, WrappedView):
context_object_name = "voucher_types" context_object_name = "voucher_types"
template_name = 'voucher_types/list.html' template_name = 'voucher_types/list.html'
PermissionDecorator('change_vouchertype', 'configuration') @PermissionDecorator('change_vouchertype', 'configuration')
def dispatch(self, *args, **kwargs):
return super(VoucherTypeListView, self).dispatch(*args, **kwargs)
class VoucherTypeCreateView(CreateView, WrappedView): class VoucherTypeCreateView(CreateView, WrappedView):
form_class = VoucherTypeForm form_class = VoucherTypeForm
model = VoucherType model = VoucherType
...@@ -28,7 +31,11 @@ class VoucherTypeCreateView(CreateView, WrappedView): ...@@ -28,7 +31,11 @@ class VoucherTypeCreateView(CreateView, WrappedView):
form.instance.study_id = GLOBAL_STUDY_ID form.instance.study_id = GLOBAL_STUDY_ID
return super(VoucherTypeCreateView, self).form_valid(form) return super(VoucherTypeCreateView, self).form_valid(form)
PermissionDecorator('change_vouchertype', 'configuration') @PermissionDecorator('change_vouchertype', 'configuration')
def dispatch(self, *args, **kwargs):
return super(VoucherTypeCreateView, self).dispatch(*args, **kwargs)
#@PermissionDecorator('change_vouchertype', 'configuration')
class VoucherTypeEditView(UpdateView, WrappedView): class VoucherTypeEditView(UpdateView, WrappedView):
form_class = VoucherTypeForm form_class = VoucherTypeForm
model = VoucherType model = VoucherType
...@@ -37,3 +44,7 @@ class VoucherTypeEditView(UpdateView, WrappedView): ...@@ -37,3 +44,7 @@ class VoucherTypeEditView(UpdateView, WrappedView):
success_message = "Voucher type edited" success_message = "Voucher type edited"
template_name = "voucher_types/edit.html" template_name = "voucher_types/edit.html"
context_object_name = "voucher_type" context_object_name = "voucher_type"
@PermissionDecorator('change_vouchertype', 'configuration')
def dispatch(self, *args, **kwargs):
return super(VoucherTypeEditView, self).dispatch(*args, **kwargs)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment