Example #1
0
    def post(self, *args, **kwargs):

        widgets = self.request.POST.getlist('widgets[]', [])

        widget_list = []

        try:
            for widget_id in widgets:
                widget = get_widget_from_id(widget_id)
                if widget:
                    widget_list.append(widget)
        except:
            messages.error(
                self.request, _('Error occured while sorting widgets.'))

        i = 0

        for widget in widget_list:
            widget.ordering = i
            widget.save()
            i += 1

        messages.success(self.request, _('Widget sorting success.'))

        return HttpResponse('ok')
    def post(self, *args, **kwargs):

        widgets = self.request.POST.getlist('widgets[]', [])

        widget_list = []

        try:
            for widget_id in widgets:
                widget = get_widget_from_id(widget_id)
                if widget:
                    widget_list.append(widget)
        except:
            messages.error(
                self.request, _('Error occured while sorting widgets.'))

        i = 0

        for widget in widget_list:
            widget.ordering = i
            widget.save()
            i += 1

        messages.success(self.request, _('Widget sorting success.'))

        return HttpResponse('ok')
Example #3
0
    def logout(self):
        messages.success(self.request, _('Logout complete'))
        auth_logout(self.request)

        self.request.session.flush()
        if hasattr(self.request, 'user'):
            from django.contrib.auth.models import AnonymousUser
            self.request.user = AnonymousUser()
Example #4
0
    def logout(self):
        messages.success(self.request, _('Logout complete'))
        auth_logout(self.request)

        self.request.session.flush()
        if hasattr(self.request, 'user'):
            from django.contrib.auth.models import AnonymousUser
            self.request.user = AnonymousUser()
    def post(self, *args, **kwargs):

        widget = self.object

        ordering = self.kwargs.get('ordering')

        if int(ordering) == 0:

            widget.ordering = 0
            widget.save()

            widgets = getattr(widget.parent.content, widget.region)
            widgets = [w for w in widgets if w.id != widget.id]

            for i, _widget in enumerate(widgets):
                _widget.ordering = i + 1
                _widget.save()

        elif int(ordering) == -1:
            next_ordering = widget.ordering - 1
            widgets = getattr(widget.parent.content, widget.region)
            for w in widgets:
                if w.ordering == next_ordering:
                    w.ordering = widget.ordering
                    w.save()
                    widget.ordering = next_ordering
                    widget.save()
        elif int(ordering) == 1:

            next_ordering = widget.ordering + 1
            widgets = getattr(widget.parent.content, widget.region)
            for w in widgets:
                if w.ordering == next_ordering:
                    w.ordering = widget.ordering
                    w.save()
                    widget.ordering = next_ordering
                    widget.save()

        else:
            widget.ordering = widget.next_ordering
            widget.save()
            widgets = getattr(widget.parent.content, widget.region)
            widgets = [w for w in widgets if w.id != widget.id]
            widgets.sort(key=lambda w: w.ordering)

            for i, _widget in enumerate(widgets):
                _widget.ordering = i
                _widget.save()

        messages.success(self.request, _('Widget was successfully moved.'))

        # TODO try HTTP_REFERER
        success_url = widget.parent.get_absolute_url()
        response = HttpResponseRedirect(success_url)
        response['X-Horizon-Location'] = success_url
        return response
    def form_valid(self, form):
        try:
            page = form.save()
            messages.success(self.request,
                             _('Page %s was successfully crated.' % page))
        except Exception as e:
            messages.error(self.request, str(e))
            return HttpResponseRedirect(self.object.get_absolute_url())

        return HttpResponseRedirect(page.get_absolute_url())
Example #7
0
    def form_valid(self, form):
        try:
            page = form.save()
            messages.success(
                self.request, _('Page %s was successfully crated.' % page))
        except Exception as e:
            messages.error(self.request, str(e))
            return HttpResponseRedirect(self.object.get_absolute_url())

        return HttpResponseRedirect(page.get_absolute_url())
Example #8
0
    def post(self, *args, **kwargs):

        widget = self.object
        widget.pk = None
        widget.save()

        messages.success(self.request, _('Widget was successfully cloned.'))

        # TODO try HTTP_REFERER
        success_url = self.get_success_url()
        response = HttpResponseRedirect(success_url)
        response['X-Horizon-Location'] = success_url
        return response
def server_restart_callback(request, delay=0, **kwargs):

    # time.sleep(delay)
    try:

        # from django.utils.autoreload import restart_with_reloader, reloader_thread
        # kill self
        os.kill(os.getpid(), 9)

        messages.success(
            request, _('Server was successfuly restarted !'))
    except Exception as e:
        messages.error(request, str(e))
    else:
        return True
    return False
Example #10
0
    def post(self, *args, **kwargs):

        widget = self.object
        widget.pk = None
        widget.save(created=False)
        # also copy dimensions
        for dimension in self.model.objects.get(
                id=self.kwargs["id"]).dimensions:
            dimension.pk = None
            dimension.widget_id = widget.id
            dimension.save()

        messages.success(self.request, _('Widget was successfully cloned.'))

        # TODO try HTTP_REFERER
        success_url = self.get_success_url()
        response = HttpResponseRedirect(success_url)
        response['X-Horizon-Location'] = success_url
        return response
Example #11
0
    def post(self, *args, **kwargs):

        widget = self.object
        widget.pk = None
        widget.save(created=False)
        # also copy dimensions
        for dimension in self.model.objects.get(
                id=self.kwargs["id"]).dimensions:
            dimension.pk = None
            dimension.widget_id = widget.id
            dimension.save()

        messages.success(self.request, _('Widget was successfully cloned.'))

        # TODO try HTTP_REFERER
        success_url = self.get_success_url()
        response = HttpResponseRedirect(success_url)
        response['X-Horizon-Location'] = success_url
        return response
Example #12
0
    def form_valid(self, form):

        # update values from actual parent
        parent = form.cleaned_data['parent']

        fields = ['color_scheme', 'layout', 'theme',
                  'site', 'in_navigation', 'template_key']

        changed_fields = form.changed_data
        for field_name, field in form.fields.items():
            if field_name not in changed_fields and field_name in fields:
                form.cleaned_data[field_name] = getattr(parent, field_name)

        try:
            page = form.save()
            messages.success(
                self.request, _('Page %s was successfully crated.' % page))
        except Exception as e:
            messages.error(self.request, str(e))
            return HttpResponseRedirect(self.object.get_absolute_url())

        return HttpResponseRedirect(page.get_absolute_url())
Example #13
0
def pip_install(packages, request=None, reload_server=False):
    """install packages from pip

    if request is provided, user messages is pushed out
    """

    if PIP:
        # install
        try:
            pip.main(['install', packages])
            if request:
                messages.success(request, _(
                    'Packages %s was successfully installed,\
                     please restart your server.' % packages))
        except Exception as e:
            if request:
                messages.error(request, _(
                    'Installing packages raised exception %s' % e))
            else:
                raise e
        else:
            if reload_server:
                # try self kill
                try:
                    import os
                    os.kill(os.getpid(), 9)
                except Exception as e:
                    if request:
                        messages.error(request, _(
                            'Run post install task fails with %s' % e))
                    else:
                        raise e

    else:
        if request:
            messages.error(request, _(
                'For this functionality please install pip package'))
Example #14
0
    def post(self, *args, **kwargs):

        widget = self.object

        ordering = self.kwargs.get('ordering')

        if int(ordering) == 0:

            widget.ordering = 0
            widget.save()

            widgets = getattr(widget.parent.content, widget.region)
            widgets = [w for w in widgets if w.id != widget.id]

            for i, _widget in enumerate(widgets):
                _widget.ordering = i + 1
                _widget.save()

        elif int(ordering) == -1:

            widgets = getattr(widget.parent.content, widget.region)
            widgets.sort(key=lambda w: w.ordering)

            for i, w in enumerate(widgets):
                if w.id == widget.id:
                    w.ordering = i - 1
                    w.save()
                    try:
                        next_widget = widgets[i - 1]
                    except IndexError:
                        pass
                    else:
                        next_widget.ordering += 1
                        next_widget.save()

        elif int(ordering) == 1:

            widgets = getattr(widget.parent.content, widget.region)
            widgets.sort(key=lambda w: w.ordering)

            for i, w in enumerate(widgets):
                if w.id == widget.id:
                    w.ordering = i + 1
                    w.save()
                    try:
                        next_widget = widgets[i + 1]
                    except IndexError:
                        pass
                    else:
                        next_widget.ordering -= 1
                        next_widget.save()

        else:
            widget.ordering = widget.next_ordering
            widget.save()
            widgets = getattr(widget.parent.content, widget.region)
            widgets = [w for w in widgets if w.id != widget.id]
            widgets.sort(key=lambda w: w.ordering)

            for i, _widget in enumerate(widgets):
                _widget.ordering = i
                _widget.save()

        widget.parent.invalidate_cache()

        messages.success(self.request, _('Widget was successfully moved.'))

        success_url = self.get_success_url()
        response = HttpResponseRedirect(success_url)
        response['X-Horizon-Location'] = success_url
        return response
Example #15
0
    def post(self, *args, **kwargs):

        widget = self.object

        ordering = self.kwargs.get('ordering')

        if int(ordering) == 0:

            widget.ordering = 0
            widget.save()

            widgets = getattr(widget.parent.content, widget.region)
            widgets = [w for w in widgets if w.id != widget.id]

            for i, _widget in enumerate(widgets):
                _widget.ordering = i + 1
                _widget.save()

        elif int(ordering) == -1:

            widgets = getattr(widget.parent.content, widget.region)
            widgets.sort(key=lambda w: w.ordering)

            for i, w in enumerate(widgets):
                if w.id == widget.id:
                    w.ordering = i - 1
                    w.save()
                    try:
                        next_widget = widgets[i - 1]
                    except IndexError:
                        pass
                    else:
                        next_widget.ordering += 1
                        next_widget.save()

        elif int(ordering) == 1:

            widgets = getattr(widget.parent.content, widget.region)
            widgets.sort(key=lambda w: w.ordering)

            for i, w in enumerate(widgets):
                if w.id == widget.id:
                    w.ordering = i + 1
                    w.save()
                    try:
                        next_widget = widgets[i + 1]
                    except IndexError:
                        pass
                    else:
                        next_widget.ordering -= 1
                        next_widget.save()

        else:
            widget.ordering = widget.next_ordering
            widget.save()
            widgets = getattr(widget.parent.content, widget.region)
            widgets = [w for w in widgets if w.id != widget.id]
            widgets.sort(key=lambda w: w.ordering)

            for i, _widget in enumerate(widgets):
                _widget.ordering = i
                _widget.save()

        widget.parent.invalidate_cache()

        messages.success(self.request, _('Widget was successfully moved.'))

        success_url = self.get_success_url()
        response = HttpResponseRedirect(success_url)
        response['X-Horizon-Location'] = success_url
        return response