2019-05-20 11:39:53 +00:00
|
|
|
# coding: utf-8
|
|
|
|
#
|
|
|
|
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.views.generic import TemplateView
|
|
|
|
from django.views.generic.edit import CreateView, UpdateView
|
|
|
|
from django.views.generic.detail import DetailView
|
|
|
|
from django.contrib.messages.views import SuccessMessageMixin
|
|
|
|
from django.urls import reverse_lazy
|
|
|
|
|
|
|
|
|
2019-06-19 03:31:38 +00:00
|
|
|
from common.permissions import PermissionsMixin, IsOrgAdmin, IsValidUser
|
2019-05-20 11:39:53 +00:00
|
|
|
from common.const import create_success_msg, update_success_msg
|
|
|
|
|
|
|
|
from ..models import RemoteApp
|
|
|
|
from .. import forms
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'RemoteAppListView', 'RemoteAppCreateView', 'RemoteAppUpdateView',
|
|
|
|
'RemoteAppDetailView', 'UserRemoteAppListView',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class RemoteAppListView(PermissionsMixin, TemplateView):
|
2019-05-20 11:39:53 +00:00
|
|
|
template_name = 'applications/remote_app_list.html'
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2019-05-20 11:39:53 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2019-06-20 10:10:44 +00:00
|
|
|
'app': _('Applications'),
|
2019-05-20 11:39:53 +00:00
|
|
|
'action': _('RemoteApp list'),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class RemoteAppCreateView(PermissionsMixin, SuccessMessageMixin, CreateView):
|
2019-05-20 11:39:53 +00:00
|
|
|
template_name = 'applications/remote_app_create_update.html'
|
|
|
|
model = RemoteApp
|
|
|
|
form_class = forms.RemoteAppCreateUpdateForm
|
|
|
|
success_url = reverse_lazy('applications:remote-app-list')
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2019-05-20 11:39:53 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2019-06-20 10:10:44 +00:00
|
|
|
'app': _('Applications'),
|
2019-05-20 11:39:53 +00:00
|
|
|
'action': _('Create RemoteApp'),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
def get_success_message(self, cleaned_data):
|
|
|
|
return create_success_msg % ({'name': cleaned_data['name']})
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class RemoteAppUpdateView(PermissionsMixin, SuccessMessageMixin, UpdateView):
|
2019-05-20 11:39:53 +00:00
|
|
|
template_name = 'applications/remote_app_create_update.html'
|
|
|
|
model = RemoteApp
|
|
|
|
form_class = forms.RemoteAppCreateUpdateForm
|
|
|
|
success_url = reverse_lazy('applications:remote-app-list')
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2019-05-20 11:39:53 +00:00
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
return {k: v for k, v in self.object.params.items()}
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2019-06-20 10:10:44 +00:00
|
|
|
'app': _('Applications'),
|
2019-05-20 11:39:53 +00:00
|
|
|
'action': _('Update RemoteApp'),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
def get_success_message(self, cleaned_data):
|
|
|
|
return update_success_msg % ({'name': cleaned_data['name']})
|
|
|
|
|
|
|
|
|
2019-06-19 02:47:26 +00:00
|
|
|
class RemoteAppDetailView(PermissionsMixin, DetailView):
|
2019-05-20 11:39:53 +00:00
|
|
|
template_name = 'applications/remote_app_detail.html'
|
|
|
|
model = RemoteApp
|
|
|
|
context_object_name = 'remote_app'
|
2019-06-19 02:47:26 +00:00
|
|
|
permission_classes = [IsOrgAdmin]
|
2019-05-20 11:39:53 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
2019-06-20 10:10:44 +00:00
|
|
|
'app': _('Applications'),
|
2019-05-20 11:39:53 +00:00
|
|
|
'action': _('RemoteApp detail'),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|
|
|
|
|
|
|
|
|
2019-06-19 03:31:38 +00:00
|
|
|
class UserRemoteAppListView(PermissionsMixin, TemplateView):
|
2019-05-20 11:39:53 +00:00
|
|
|
template_name = 'applications/user_remote_app_list.html'
|
2019-06-19 03:31:38 +00:00
|
|
|
permission_classes = [IsValidUser]
|
2019-05-20 11:39:53 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = {
|
|
|
|
'action': _('My RemoteApp'),
|
|
|
|
}
|
|
|
|
kwargs.update(context)
|
|
|
|
return super().get_context_data(**kwargs)
|