2018-01-16 08:32:06 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
2018-01-23 11:37:22 +00:00
|
|
|
from django.views.generic import TemplateView, CreateView, \
|
2018-01-16 08:32:06 +00:00
|
|
|
UpdateView, DeleteView, DetailView
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2018-01-23 11:37:22 +00:00
|
|
|
from django.urls import reverse_lazy
|
2018-01-16 08:32:06 +00:00
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
from common.permissions import PermissionsMixin, IsOrgAdmin
|
2018-01-26 07:32:23 +00:00
|
|
|
from common.const import create_success_msg, update_success_msg
|
|
|
|
from ..models import Label
|
2018-01-23 11:37:22 +00:00
|
|
|
from ..forms import LabelForm
|
2018-01-16 08:32:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
__all__ = (
|
|
|
|
"LabelListView", "LabelCreateView", "LabelUpdateView",
|
|
|
|
"LabelDetailView", "LabelDeleteView",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class LabelListView(PermissionsMixin, TemplateView):
|
2018-01-16 08:32:06 +00:00
|
|
|
template_name = 'assets/label_list.html'
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2018-01-16 08:32:06 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Assets'),
|
|
|
|
'action': _('Label list'),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class LabelCreateView(PermissionsMixin, CreateView):
|
2018-01-26 07:32:23 +00:00
|
|
|
model = Label
|
2018-01-23 11:37:22 +00:00
|
|
|
template_name = 'assets/label_create_update.html'
|
|
|
|
form_class = LabelForm
|
|
|
|
success_url = reverse_lazy('assets:label-list')
|
|
|
|
success_message = create_success_msg
|
2018-11-01 08:28:19 +00:00
|
|
|
disable_name = ['draw', 'search', 'limit', 'offset', '_']
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2018-01-23 11:37:22 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Assets'),
|
|
|
|
'action': _('Create label'),
|
2019-07-11 10:44:16 +00:00
|
|
|
'type': 'create'
|
2018-01-23 11:37:22 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
2018-01-16 08:32:06 +00:00
|
|
|
|
2018-11-01 08:28:19 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
name = form.cleaned_data.get('name')
|
|
|
|
if name in self.disable_name:
|
|
|
|
msg = _(
|
|
|
|
'Tips: Avoid using label names reserved internally: {}'
|
|
|
|
).format(', '.join(self.disable_name))
|
|
|
|
form.add_error("name", msg)
|
|
|
|
return self.form_invalid(form)
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
2018-01-16 08:32:06 +00:00
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class LabelUpdateView(PermissionsMixin, UpdateView):
|
2018-01-26 07:32:23 +00:00
|
|
|
model = Label
|
|
|
|
template_name = 'assets/label_create_update.html'
|
|
|
|
form_class = LabelForm
|
|
|
|
success_url = reverse_lazy('assets:label-list')
|
|
|
|
success_message = update_success_msg
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2018-01-26 07:32:23 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'app': _('Assets'),
|
|
|
|
'action': _('Update label'),
|
2019-07-11 10:44:16 +00:00
|
|
|
'type': 'update'
|
2018-01-26 07:32:23 +00:00
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
2018-01-16 08:32:06 +00:00
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class LabelDetailView(PermissionsMixin, DetailView):
|
2018-01-16 08:32:06 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class LabelDeleteView(PermissionsMixin, DeleteView):
|
2018-01-29 08:25:30 +00:00
|
|
|
model = Label
|
|
|
|
template_name = 'delete_confirm.html'
|
|
|
|
success_url = reverse_lazy('assets:label-list')
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|