Ejemplo n.º 1
0
class QdjangoProjectUpdateView(QdjangoProjectCUViewMixin, G3WGroupViewMixin, G3WRequestViewMixin, G3WACLViewMixin,
                               UpdateView):
    """Update project view."""

    model = Project
    form_class = QdjangoProjetForm

    editor_permission = 'change_project'
    viewer_permission = 'view_project'

    @method_decorator(permission_required('qdjango.change_project', (Project, 'slug', 'slug'), raise_exception=True))
    def dispatch(self, *args, **kwargs):
        return super(QdjangoProjectUpdateView, self).dispatch(*args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(QdjangoProjectUpdateView, self).get_context_data(**kwargs)
        if self.request.method == 'GET':
            context['pre_update_messages'] = []
            messages = pre_update_project.send(self, project=self.object, projectType='qdjango')
            for message in messages:
                if message[1]:
                    context['pre_update_messages'].append(message[1])
        return context

    def form_valid(self, form):
        res = super(QdjangoProjectUpdateView, self).form_valid(form)

        # send project update signal
        after_update_project.send(self, app_name='qdjango', project=form.instance)

        # clear cache
        if 'qdjango' in settings.CACHES:
            caches['qdjango'].delete(settings.QDJANGO_PRJ_CACHE_KEY.format(form.instance.pk))
        return res
Ejemplo n.º 2
0
class GroupSetProjectPanoramicView(View):
    '''
    Set panoramic project for this group
    '''

    # only user with change_group for this group can change overview map.
    @method_decorator(permission_required('core.change_group', (Group, 'slug', 'slug'), return_403=True))
    def dispatch(self, *args, **kwargs):
        return super(GroupSetProjectPanoramicView, self).dispatch(*args, **kwargs)

    def get(self, *args, **kwargs):
        # first remove current panoramic map
        group = Group.objects.get(slug=kwargs['slug'])
        groupProjectPanoramics = GroupProjectPanoramic.objects.filter(group_id=group.id)

        # case exists
        if groupProjectPanoramics:
            if kwargs['project_id'] == 'reset':
                groupProjectPanoramics.delete()
                return JsonResponse({'Saved': 'ok'})

            groupProjectPanoramic = groupProjectPanoramics[0]
            groupProjectPanoramic.project_type = kwargs['project_type']
            groupProjectPanoramic.project_id = kwargs['project_id']

        else:

            # case new one
            groupProjectPanoramic = GroupProjectPanoramic(group=group, project_type=kwargs['project_type'],
                                                          project_id=kwargs['project_id'])
        groupProjectPanoramic.save()
        return JsonResponse({'Saved': 'ok'})
Ejemplo n.º 3
0
class AdminFilterPosts(View):
    template_name = 'blog_admin/posts.html'

    @method_decorator(
        permission_required('main.add_post', accept_global_perms=True))
    def get(self, request):
        tag_id = request.GET.get('tag')
        category_id = request.GET.get('category')

        if tag_id:
            posts = filter_posts_by_tag(tag_id)
        elif category_id:
            posts = filter_posts_by_category(category_id)
        else:
            url = reverse('main:admin_posts')
            return redirect(url)

        if posts == None:
            raise Http404

        paginator = Paginator(posts, PER_PAGE_ADMIN)
        page = request.GET.get('page')
        try:
            posts = paginator.page(page)
        except PageNotAnInteger:
            posts = paginator.page(1)
        except EmptyPage:
            posts = paginator.page(paginator.num_pages)

        data = {'posts': posts}
        return render(request, self.template_name, data)
Ejemplo n.º 4
0
class QdjangoProjectCreateView(QdjangoProjectCUViewMixin, G3WGroupViewMixin,
                               G3WRequestViewMixin, CreateView):
    """Create group view."""

    model = Project
    form_class = QdjangoProjectForm

    @method_decorator(
        permission_required('core.add_project_to_group',
                            (Group, 'slug', 'group_slug'),
                            return_403=True))
    @method_decorator(
        permission_required('qdjango.add_project', return_403=True))
    @method_decorator(check_madd('MPC:XYamtBJA_JgFGmFvEa9x193rnLg', Project))
    def dispatch(self, *args, **kwargs):
        return super(QdjangoProjectCreateView, self).dispatch(*args, **kwargs)
Ejemplo n.º 5
0
class GroupUpdateView(G3WRequestViewMixin, G3WACLViewMixin, UpdateView):
    """Update view."""
    model = Group
    form_class = GroupForm

    editor_permission = ['change_group']
    editor2_permission = ['view_group']
    viewer_permission = 'view_group'

    @method_decorator(permission_required('core.change_group', (Group, 'slug', 'slug'), return_403=True))
    def dispatch(self, request, *args, **kwargs):
        return super(GroupUpdateView, self).dispatch(request, *args, **kwargs)

    def form_valid(self, form):
        res = super(GroupUpdateView, self).form_valid(form)

        # send after_save
        after_update_group.send(self, group=form.instance)

        # delete tempory file form files
        form.delete_temporary_files()
        return res

    def get_success_url(self):
        if self.request.session.get('http_referer', False):
            return self.request.session['http_referer']
        return reverse('group-list')
Ejemplo n.º 6
0
class QdjangoProjectFastUpdateView(QdjangoProjectCUViewMixin,
                                   G3WGroupViewMixin, G3WRequestViewMixin,
                                   View):
    """
    View for fast change project by ajaxfiler
    """
    @method_decorator(
        permission_required('qdjango.change_project',
                            (Project, 'slug', 'slug'),
                            raise_exception=True))
    def dispatch(self, *args, **kwargs):
        return super(QdjangoProjectFastUpdateView,
                     self).dispatch(*args, **kwargs)

    def post(self, request, *args, **kwargs):

        qgis_file = request.FILES['files[]'] if request.FILES else None
        qgskwargs = dict()
        qgskwargs['instance'] = Project.objects.get(slug=kwargs['slug'])
        qgskwargs['group'] = self.group
        qgis_project = QgisProject(qgis_file, **qgskwargs)
        try:
            qgis_project.clean()
        except Exception as e:
            raise ValidationError(e)

        qgis_project.save()

        return HttpResponse('Qgis project uploaded and updated')
Ejemplo n.º 7
0
class QdjangoProjectDeleteView(G3WAjaxDeleteViewMixin, SingleObjectMixin,
                               View):
    '''
    Delete Qdjango project Ajax view
    '''
    model = Project

    @method_decorator(
        permission_required('qdjango.delete_project',
                            (Project, 'slug', 'slug'),
                            raise_exception=True))
    def dispatch(self, *args, **kwargs):
        return super(QdjangoProjectDeleteView, self).dispatch(*args, **kwargs)

    def post(self, request, *args, **kwargs):

        # send before project delete signal
        self.object = self.get_object()
        before_delete_project.send(self,
                                   app_name='qdjango',
                                   project=self.object)

        # clear cache
        if 'qdjango' in settings.CACHES:
            caches['qdjango'].delete(
                settings.QDJANGO_PRJ_CACHE_KEY.format(self.object.pk))

        return super(QdjangoProjectDeleteView,
                     self).post(request, *args, **kwargs)
class DTMUpdateView(G3WRequestViewMixin, UpdateView):
    """
    Update view for DTM Layer and pth layers project
    """
    model = EleProDTM
    form_class = DTMForm
    template_name = 'eleprofile/dtm_form.html'

    @method_decorator(
        permission_required('eleprofile.change_eleproproject',
                            (EleProProject, 'pk', 'eleproproject_pk'),
                            return_403=True))
    def dispatch(self, *args, **kwargs):
        return super().dispatch(*args, **kwargs)

    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()

        # set 'initial' value fo eleproproject
        kwargs['initial']['elepro_project'] = self.kwargs['eleproproject_pk']

        return kwargs

    def get_success_url(self):
        """ Return correct url by Eleproproject instance"""

        return reverse('eleprofile-dtmlayer-list',
                       args=[self.kwargs['eleproproject_pk']])
Ejemplo n.º 9
0
class QdjangoProjectDownloadView(ObjectDownloadView):
    """
    Download Qgis project File
    """
    @method_decorator(permission_required('qdjango.change_project', (Project, 'slug', 'slug'), raise_exception=True))
    def dispatch(self, *args, **kwargs):
        return super(QdjangoProjectDownloadView, self).dispatch(*args, **kwargs)
Ejemplo n.º 10
0
class QdjangoLayerWidgetCreateView(QdjangoLayerWidgetsMixin, G3WRequestViewMixin, G3WGroupViewMixin, QdjangoProjectViewMixin,
                                   QdjangoLayerViewMixin, AjaxableFormResponseMixin, CreateView):

    form_class = QdjangoWidgetForm
    template_name = 'qdjango/ajax/widget_form.html'

    @method_decorator(permission_required('qdjango.add_widget', return_403=True))
    def dispatch(self, *args, **kwargs):
        return super(QdjangoLayerWidgetCreateView, self).dispatch(*args, **kwargs)

    def form_valid(self, form):
        self.object = form.save(commit=False)
        self.object.datasource = self.layer.datasource

        # to assign permissions the widget must be committed to DB
        ret = super(QdjangoLayerWidgetCreateView, self).form_valid(form)

        # add layer
        self.object.layers.add(self.layer)

        '''
        if not self.request.user.is_superuser:
            self.object.addPermissionsToEditor(self.request.user)
        else:
            editor_users = get_users_for_object(self.layer, 'change_layer', 'Editor Maps Groups')
            if editor_users:
                self.object.addPermissionsToEditor(editor_users[0])

        viewers = map(lambda o: o.id, get_users_for_object(self.layer, 'view_layer', 'Viewer Maps Groups'))
        self.object.addPermissionsToViewers(viewers)
        '''

        return ret
class DTMListView(ListView):
    """List DTM layer and path layers view."""

    template_name = 'eleprofile/dtms_list.html'
    model = EleProDTM

    @method_decorator(
        permission_required('eleprofile.change_eleproproject',
                            (EleProProject, 'pk', 'eleproproject_pk'),
                            return_403=True))
    def dispatch(self, *args, **kwargs):
        return super().dispatch(*args, **kwargs)

    def get_queryset(self):
        """ Get only EleProDTM elements filtered bu eleproproject pk"""

        return EleProDTM.objects.filter(
            elepro_project_id=self.kwargs['eleproproject_pk'])

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        # add eleproproject_instance
        context['eleproproject'] = EleProProject.objects.get(
            pk=self.kwargs['eleproproject_pk'])
        return context
Ejemplo n.º 12
0
class GroupDetailView(G3WRequestViewMixin, DetailView):
    """Detail view."""
    model = Group
    template_name = 'core/ajax/group_detail.html'

    @method_decorator(permission_required('core.view_group', (Group, 'slug', 'slug'), return_403=True))
    def dispatch(self, *args, **kwargs):
        return super(GroupDetailView, self).dispatch(*args, **kwargs)
Ejemplo n.º 13
0
class ProfileDetailView(DetailView):
    model = Profile
    slug_url_kwarg = 'username'
    slug_field = 'user__username'

    @method_decorator(permission_required('view_profile'))
    def dispatch(self, request, username):
        return super(ProfileDetailView, self).dispatch(request, username=username)
Ejemplo n.º 14
0
class QdjangoLayerDetailView(G3WRequestViewMixin, DetailView):
    """Detail view for qdjango layer object"""

    model = Layer
    template_name = 'qdjango/ajax/layer_detail.html'

    @method_decorator(permission_required('qdjango.change_project', (Project, 'slug', 'slug'), raise_exception=True))
    def dispatch(self, *args, **kwargs):
        return super(QdjangoLayerDetailView, self).dispatch(*args, **kwargs)
Ejemplo n.º 15
0
class ProjectsListView(ListView):
    """List projects view."""
    template_name = 'eleprofile/projects_list.html'
    model = EleProProject

    @method_decorator(
        permission_required('eleprofile.add_eleproproject', return_403=True))
    def dispatch(self, *args, **kwargs):
        return super().dispatch(*args, **kwargs)
Ejemplo n.º 16
0
class ActiveRasterTimeSeriesLayerView(AjaxableFormResponseMixin, G3WRequestViewMixin, FormView):
    """
    View for enabled raster time series layer form
    """

    form_class = ActiveRasterTimeSeriesLayerForm
    template_name = 'qtimeseries/raster_layer_active_form.html'

    @method_decorator(permission_required('qdjango.change_project', (Project, 'pk', 'project_id'),
                                          raise_exception=True))
    def dispatch(self, request, *args, **kwargs):
        self.layer_id = kwargs['layer_id']

        return super().dispatch(request, *args, **kwargs)

    def get_success_url(self):
        return None

    def get_form_kwargs(self):

        kwargs = super().get_form_kwargs()

        # get model by app
        self.layer = Layer.objects.get(pk=self.layer_id)
        # try to find notes config
        try:
            self.activated = QRasterTimeSeriesLayer.objects.get(layer=self.layer)
            kwargs['initial']['active'] = True
        except:
            self.activated = None
            kwargs['initial']['active'] = False

        return kwargs

    def form_valid(self, form):
        if form.cleaned_data['active']:
            if not self.activated:
                self.activated = QRasterTimeSeriesLayer.objects.create(layer=self.layer)
            else:
                self.activated.save()

            # Add start date and end date
            rts = RTS(get_qgis_layer(self.layer))
            dates = rts.dates()
            start_date = dates[0].toPyDate()
            end_date = dates[-1].toPyDate()

            self.activated.start_date = start_date
            self.activated.end_date = end_date
            self.activated.save()

        else:
            if self.activated:
                self.activated.delete()

        return super().form_valid(form)
Ejemplo n.º 17
0
class GroupsView(View):
    template_name = 'accounts/groups.html'

    @method_decorator(
        permission_required('main.change_user', accept_global_perms=True))
    def get(self, request):
        groups = Group.objects.all()
        data = {'groups': groups}

        return render(request, self.template_name, data)
Ejemplo n.º 18
0
class ProductCreateView(CreateView):
    model = Product
    template_name = 'crm/product_new.html'
    form_class = ProductForm

    def get_success_url(self):
        return reverse('products')

    @method_decorator(login_required())
    @method_decorator(
        permission_required('crm.add_product', accept_global_perms=True))
    def get(self, request, *args, **kwargs):
        translation.activate(request.user.salesperson.lang)
        return super().get(self, request, *args, **kwargs)

    @method_decorator(login_required())
    @method_decorator(
        permission_required('crm.add_product', accept_global_perms=True))
    def post(self, request, *args, **kwargs):
        return super().post(self, request, *args, **kwargs)
Ejemplo n.º 19
0
    def decorator(original_class):
        if not issubclass(original_class, View):
            raise TypeError('%(class)s is not a view class' % {
                'class': original_class
            })

        original_class.dispatch = method_decorator(
            permission_required(*args, **kwargs)
        )(original_class.dispatch)

        return original_class
Ejemplo n.º 20
0
class ProductUpdateView(UpdateView):
    model = Product
    form_class = ProductForm
    template_name = 'crm/product.html'

    def get_success_url(self):
        return reverse('product_page', kwargs={'pk': self.kwargs['pk']})

    @method_decorator(login_required())
    @method_decorator(
        permission_required('crm.change_product', accept_global_perms=True))
    def get(self, request, *args, **kwargs):
        translation.activate(request.user.salesperson.lang)
        return super().get(self, request, *args, **kwargs)

    @method_decorator(login_required())
    @method_decorator(
        permission_required('crm.change_product', accept_global_perms=True))
    def post(self, request, *args, **kwargs):
        return super().post(self, request, *args, **kwargs)
Ejemplo n.º 21
0
class AdminTags(View):
    template_name = 'blog_admin/tags.html'

    @method_decorator(
        permission_required('main.add_tag', accept_global_perms=True))
    def get(self, request, form=None):
        if not form:
            form = forms.TagForm()
        tags = models.Tag.objects.all()

        paginator = Paginator(tags, PER_PAGE_ADMIN)
        page = request.GET.get('page')

        try:
            tags = paginator.page(page)

        except PageNotAnInteger:
            tags = paginator.page(1)
        except EmptyPage:
            tags = paginator.page(paginator.num_pages)

        data = {'tags': tags, 'form': form}

        return render(request, self.template_name, data)

    @method_decorator(
        permission_required('main.add_tag', accept_global_perms=True))
    def post(self, request, form=None):
        form = forms.TagForm(request.POST)
        if form.is_valid():
            tags = form.cleaned_data['tags'].split(',')
            for tag in tags:
                tag_model, created = models.Tag.objects.get_or_create(
                    name=tag.strip())

            msg = 'Succeed to create tags'
            messages.add_message(request, messages.SUCCESS, msg)
            url = reverse('main:admin_tags')
            return redirect(url)
        else:
            return self.get(request, form=form)
Ejemplo n.º 22
0
class ProjectDeleteView(G3WAjaxDeleteViewMixin, SingleObjectMixin, View):
    """
    Delete EleProProject model Ajax view
    """
    model = EleProProject

    @method_decorator(
        permission_required('eleprofile.delete_eleproproject',
                            (EleProProject, 'pk', 'pk'),
                            return_403=True))
    def dispatch(self, *args, **kwargs):
        return super().dispatch(*args, **kwargs)
Ejemplo n.º 23
0
 def _wrapped_view(request, *args, **kwargs):
     if lookup_variables:
         try:
             return guardian.permission_required(perm, lookup_variables,
                 return_403=True)(view_func)(request, *args, **kwargs)
         except Http404:
             pass
     if request.user.has_perm(perm):
         return view_func(request, *args, **kwargs)
     else:
         return HttpResponseForbidden('You do not have permissions to'
                                      ' perform this action.')
Ejemplo n.º 24
0
class QdjangoLayerWidgetsView(G3WGroupViewMixin, QdjangoProjectViewMixin, QdjangoLayerViewMixin, ListView):

    model = Widget
    template_name = 'qdjango/ajax/layer_widgets.html'

    @method_decorator(permission_required('qdjango.view_project', (Project, 'slug', 'project_slug'),
                                          raise_exception=True))
    def dispatch(self, *args, **kwargs):
        return super(QdjangoLayerWidgetsView, self).dispatch(*args, **kwargs)

    def get_queryset(self):
        return Widget.objects.filter(datasource=self.layer.datasource)
Ejemplo n.º 25
0
class ProjectAddView(G3WRequestViewMixin, CreateView):
    """
    Create view for eleprofile project
    """
    form_class = ProjectForm
    template_name = 'eleprofile/project_form.html'
    success_url = reverse_lazy('eleprofile-project-list')

    @method_decorator(
        permission_required('eleprofile.add_eleproproject', return_403=True))
    def dispatch(self, *args, **kwargs):
        return super().dispatch(*args, **kwargs)
class DTMDeleteView(G3WAjaxDeleteViewMixin, SingleObjectMixin, View):
    """
    Delete Ajax view for DTM Layer and path layers project
    """
    model = EleProDTM

    @method_decorator(
        permission_required('eleprofile.change_eleproproject',
                            (EleProProject, 'pk', 'eleproproject_pk'),
                            return_403=True))
    def dispatch(self, *args, **kwargs):
        return super().dispatch(*args, **kwargs)
Ejemplo n.º 27
0
class QdjangoLayersListView(G3WRequestViewMixin, G3WGroupViewMixin, QdjangoProjectViewMixin, ListView):
    template_name = 'qdjango/layers_list.html'

    @method_decorator(permission_required('qdjango.change_project', (Project, 'slug', 'project_slug'),
                                          raise_exception=True))
    def dispatch(self, *args, **kwargs):
        return super(QdjangoLayersListView, self).dispatch(*args, **kwargs)

    def get_queryset(self):
        # get project by project_slug
        return Layer.objects.filter(project__slug=self.project_slug)

    def get_context_data(self, **kwargs):
        """Add current project_slug to context."""
        context = super(QdjangoLayersListView, self).get_context_data(**kwargs)

        # get project object
        project = Project.objects.get(slug=self.project_slug)

        # rebuild layers_tree for bootstrap tree view
        qlayers = self.get_queryset()
        layers = {l.qgs_layer_id: l for l in qlayers}

        layersTree = eval(project.layers_tree)
        layersTreeBoostrap = []

        def buildLeaf(layer):
            leaf = {}
            leaf['text'] = layer['name']
            if 'nodes' in layer:
                leaf['nodes'] = []
                for node in layer['nodes']:
                    leaf['nodes'].append(buildLeaf(node))
            return leaf

        for l in layersTree:
            layersTreeBoostrap.append(buildLeaf(l))

        context['project_slug'] = self.project_slug
        context['layers_tree'] = json.dumps(layersTreeBoostrap)

        context['type_layer_for_widget'] = (
            'postgres',
            'spatialite',
            'ogr'
        )

        context['type_layer_for_download'] = (
            'postgres',
            'spatialite'
        )
        return context
Ejemplo n.º 28
0
 def _wrapped_view(request, *args, **kwargs):
     if lookup_variables:
         try:
             return guardian.permission_required(
                 perm, lookup_variables,
                 return_403=True)(view_func)(request, *args, **kwargs)
         except Http404:
             pass
     if request.user.has_perm(perm):
         return view_func(request, *args, **kwargs)
     else:
         return HttpResponseForbidden('You do not have permissions to'
                                      ' perform this action.')
Ejemplo n.º 29
0
class SalesPersonDeleteView(DeleteView, SomeUtilsMixin):
    model = SalesPerson
    template_name = 'crm/salesperson_del.html'

    def get_success_url(self):
        return reverse('salespersons')

    @method_decorator(login_required())
    @method_decorator(
        permission_required('crm.delete_salesperson',
                            accept_global_perms=True))
    def get(self, request, *args, **kwargs):
        self.set_lang(request)
        return super().get(self, request, *args, **kwargs)
Ejemplo n.º 30
0
class QdjangoLayerDataView(G3WGroupViewMixin, QdjangoProjectViewMixin, View):
    @method_decorator(
        permission_required('qdjango.change_project',
                            (Project, 'slug', 'project_slug'),
                            raise_exception=True))
    def dispatch(self, *args, **kwargs):
        return super(QdjangoLayerDataView, self).dispatch(*args, **kwargs)

    def post(self, request, *args, **kwargs):

        layer = Layer.objects.get(pk=kwargs['layer_id'])
        layer.exclude_from_legend = int(request.POST['exclude_from_legend'])
        layer.save()
        return JsonResponse({'Saved': 'ok'})
Ejemplo n.º 31
0
class AdminCategory(View):
    template_name = 'blog_admin/category.html'

    @method_decorator(
        permission_required('main.add_category', accept_global_perms=True))
    def get(self, request, form=None):
        if not form:
            form = forms.CategoryForm()
        catagories = models.Category.objects.all()
        paginator = Paginator(catagories, PER_PAGE_ADMIN)
        page = request.GET.get('page')
        try:
            catagories = paginator.page(page)
        except PageNotAnInteger:
            catagories = paginator.page(1)
        except EmptyPage:
            catagories = paginator.page(paginator.num_pages)

        data = {'catagories': catagories, 'form': form}

        return render(request, self.template_name, data)

    @method_decorator(
        permission_required('main.add_category', accept_global_perms=True))
    def post(self, request, form=None):
        form = forms.CategoryForm(request.POST)
        if form.is_valid():
            category = models.Category()
            category.name = form.cleaned_data['name']
            category.save()

            msg = 'Succeed to create new category'
            messages.add_message(request, messages.SUCCESS, msg)
            url = reverse('main:admin_category')
            return redirect(url)
        else:
            return self.get(request, form=form)
class ProjectUpdateView(G3WRequestViewMixin, UpdateView):
    """
    Update view for EleProProject model
    """
    model = EleProProject
    form_class = ProjectForm
    template_name = 'eleprofile/project_form.html'
    success_url = reverse_lazy('eleprofile-project-list')

    @method_decorator(
        permission_required('eleprofile.change_eleproproject',
                            (EleProProject, 'pk', 'pk'),
                            return_403=True))
    def dispatch(self, *args, **kwargs):
        return super().dispatch(*args, **kwargs)
Ejemplo n.º 33
0
from django.contrib import messages
from django.conf import settings
from djing.lib.decorators import only_admins
from guardian.decorators import permission_required_or_403 as permission_required
from guardian.shortcuts import get_objects_for_user

from djing.global_base_views import OrderedFilteredList
from . import models
from . import forms


login_decs = login_required, only_admins


@method_decorator(login_decs, name='dispatch')
@method_decorator(permission_required('group_app.view_group'), name='dispatch')
class GroupListView(OrderedFilteredList):
    http_method_names = ('get',)
    paginate_by = getattr(settings, 'PAGINATION_ITEMS_PER_PAGE', 10)
    template_name = 'group_app/group_list.html'
    model = models.Group
    context_object_name = 'groups'

    def get_queryset(self):
        queryset = get_objects_for_user(self.request.user,
                                        'group_app.view_group', klass=self.model,
                                        accept_global_perms=False)
        return queryset


@method_decorator(login_decs, name='dispatch')
Ejemplo n.º 34
0
from django.utils.decorators import method_decorator
from django.utils.translation import gettext_lazy as _
from django.urls import reverse_lazy
from django.views.generic import ListView, CreateView, DeleteView, UpdateView
from guardian.decorators import permission_required_or_403 as permission_required
from guardian.shortcuts import assign_perm
from gw_app.forms import NasForm
from gw_app.models import NASModel
from djing.lib.decorators import only_admins


login_decs = login_required, only_admins


@method_decorator(login_decs, name='dispatch')
@method_decorator(permission_required('gw_app.view_nasmodel'), name='dispatch')
class NasListView(ListView):
    model = NASModel


@method_decorator(login_decs, name='dispatch')
@method_decorator(permission_required('gw_app.add_nasmodel'), name='dispatch')
class NasCreateView(CreateView):
    model = NASModel
    form_class = NasForm
    template_name = 'gw_app/nasmodel_add.html'
    success_url = reverse_lazy('gw_app:home')

    def form_valid(self, form):
        r = super(NasCreateView, self).form_valid(form)
        assign_perm("gw_app.change_nasmodel", self.request.user, self.object)
Ejemplo n.º 35
0
from django.contrib import messages
from django.shortcuts import render, redirect, get_object_or_404
from django.views.generic import ListView

from djing.lib.decorators import only_admins
from guardian.decorators import permission_required_or_403 as permission_required

from .models import Conversation, MessageError, Message
from .forms import ConversationForm, MessageForm


login_decs = login_required, only_admins


@method_decorator(login_decs, name='dispatch')
@method_decorator(permission_required('msg_app.view_conversation'), name='dispatch')
class ConversationsListView(ListView):
    context_object_name = 'conversations'
    template_name = 'msg_app/conversations.html'

    def get_queryset(self):
        # TODO: optimise queries
        return Conversation.objects.fetch(self.request.user)


@login_required
@only_admins
@permission_required('msg_app.add_conversation')
def new_conversation(request):
    try:
        frm = ConversationForm(request.POST or None)
Ejemplo n.º 36
0
from django.utils.decorators import method_decorator
from django.utils.translation import gettext_lazy as _
from django.views.generic import UpdateView, CreateView, DeleteView
from djing.lib.decorators import only_admins

from guardian.decorators import permission_required_or_403 as permission_required
from djing.global_base_views import OrderedFilteredList
from ip_pool import models, forms
from group_app.models import Group


login_decs = login_required, only_admins


@method_decorator(login_decs, name='dispatch')
@method_decorator(permission_required('ip_pool.view_networkmodel'), name='dispatch')
class NetworksListView(OrderedFilteredList):
    device_kind_code = None
    template_name = 'ip_pool/network_list.html'
    context_object_name = 'networks_list'
    model = models.NetworkModel

    def get_queryset(self):
        qs = super().get_queryset()
        if isinstance(self.device_kind_code, str):
            return qs.filter(kind=self.device_kind_code)
        return qs


@method_decorator(login_decs, name='dispatch')
@method_decorator(permission_required('ip_pool.change_networkmodel'), name='dispatch')