コード例 #1
0
 def post(self, request):
     node_ids = [int(id) for id in request.POST.getlist('node_ids')]
     print node_ids
     # Rearrange all nodes in the group following
     # the order set by node_ids.
     if request.POST.get('group_id'):
         group = Group.objects.get(pk=int(request.POST.get('group_id')))
         nodes_in_group = group.nodes.all()
     else:
         group = None
         nodes_in_group = Node.objects.filter(group_id__isnull=True)
     for node in nodes_in_group:
         try:
             node.weight = node_ids.index(node.id) + 1
         except ValueError:
             node.weight = 0
         node.save()
     # Add to the group any other given node that was not yet on it.
     node_ids_in_group = [node.id for node in nodes_in_group]
     print node_ids_in_group
     for node_id in node_ids:
         if node_id not in node_ids_in_group:
             node = Node.objects.get(pk=node_id)
             node.group = group
             node.weight = node_ids.index(node.id) + 1
             node.save()
     return HttpResponseAjax()
コード例 #2
0
 def process_response(self, request, response):
     if request.is_ajax():
         if isinstance(response, HttpResponseRedirect) or \
            isinstance(response, HttpResponsePermanentRedirect):
             return HttpResponseAjax(
                 [commands.redirect(response['Location'])])
     return response
コード例 #3
0
ファイル: task.py プロジェクト: wAaron/varnish-bans-manager
 def get(self, request, token):
     async_result = tasks.find(request, token)
     if async_result:
         if async_result.successful():
             cmds = [commands.hide_progress()]
             if 'callback' in async_result.result:
                 fn = async_result.result['callback']['fn']
                 # Transform 'fn' in a callable.
                 if isinstance(fn, tuple) and len(fn) == 2:
                     (path, static_method) = fn
                     index = path.rfind('.')
                     classname = path[index + 1:len(path)]
                     module = __import__(
                         path[0:index], fromlist=[classname])
                     klass = getattr(module, classname)
                     callable = getattr(klass, static_method)
                 else:
                     callable = None
                 # Call callable.
                 if callable:
                     cmds.extend(callable.__call__(
                         request,
                         async_result.result['result'],
                         async_result.result['callback']['context']
                     ))
             async_result.forget()
             return HttpResponseAjax(cmds, request)
         elif async_result.failed():
             async_result.forget()
             messages.error(request, DEFAULT_ERROR_MESSAGE)
             return HttpResponseAjax([
                 commands.hide_progress(),
             ], request)
         elif async_result.status == 'PROGRESS':
             return HttpResponseAjax([
                 commands.update_progress(async_result.result['value']),
             ], request)
         else:
             return HttpResponseAjax([
                 commands.update_progress(),
             ], request)
     else:
         messages.error(request, DEFAULT_ERROR_MESSAGE)
         return HttpResponseAjax([
             commands.hide_progress(),
         ], request)
コード例 #4
0
 def post(self, request, node):
     try:
         node.delete()
         messages.success(request, _('The node has been deleted.'))
     except:
         messages.error(request, DEFAULT_ERROR_MESSAGE)
     return HttpResponseAjax([
         commands.navigate(reverse('caches-browse')),
     ], request)
コード例 #5
0
ファイル: groups.py プロジェクト: wAaron/varnish-bans-manager
 def post(self, request):
     ids = [int(id) for id in request.POST.getlist('ids')]
     for group in Group.objects.all():
         try:
             group.weight = ids.index(group.id) + 1
         except ValueError:
             group.weight = 0
         group.save()
     return HttpResponseAjax()
コード例 #6
0
ファイル: task.py プロジェクト: wAaron/varnish-bans-manager
 def post(self, request, token):
     async_result = tasks.find(request, token)
     if async_result and async_result.task_id:
         revoke(async_result.task_id, terminate=True, signal='SIGKILL')
         messages.info(request, _('The task execution has been aborted.'))
     else:
         messages.error(request, DEFAULT_ERROR_MESSAGE)
     return HttpResponseAjax([
         commands.hide_progress(),
     ], request)
コード例 #7
0
ファイル: user.py プロジェクト: wAaron/varnish-bans-manager
 def post(self, request):
     form = PasswordChangeForm(request.user, data=request.POST)
     if form.is_valid():
         form.save()
         messages.success(request, _('Your password has been updated.'))
         return HttpResponseAjax([
             commands.reload(request),
         ], request)
     else:
         messages.error(request, DEFAULT_FORM_ERROR_MESSAGE)
         return self._render(form)
コード例 #8
0
 def post(self, request, node):
     form = UpdateForm(data=request.POST, instance=node)
     if form.is_valid():
         form.save()
         messages.success(request, DEFAULT_SUCCESS_MESSAGE)
         return HttpResponseAjax([
             commands.navigate(reverse('caches-browse')),
         ], request)
     else:
         messages.error(request, DEFAULT_FORM_ERROR_MESSAGE)
         return self._render(form)
コード例 #9
0
 def post(self, request):
     form = GeneralForm(data=request.POST)
     if form.is_valid():
         form.save()
         messages.success(request, DEFAULT_SUCCESS_MESSAGE)
         return HttpResponseAjax([
             commands.navigate(reverse('settings-general')),
         ], request)
     else:
         messages.error(request, DEFAULT_FORM_ERROR_MESSAGE)
         return self._render(form=form)
コード例 #10
0
ファイル: users.py プロジェクト: wAaron/varnish-bans-manager
 def post(self, request, user):
     form = UpdateForm(user, data=request.POST, files=request.FILES)
     if form.is_valid():
         form.save()
         messages.success(request, DEFAULT_SUCCESS_MESSAGE)
         return HttpResponseAjax([
             commands.navigate(reverse('users-browse')),
         ], request)
     else:
         messages.error(request, DEFAULT_FORM_ERROR_MESSAGE)
         return self._render(form, user)
コード例 #11
0
ファイル: groups.py プロジェクト: wAaron/varnish-bans-manager
 def post(self, request, group):
     try:
         group.delete()
         messages.success(
             request,
             _('The group has been deleted. Its nodes are no longer assigned '
               'to any group.'))
     except:
         messages.error(request, DEFAULT_ERROR_MESSAGE)
     return HttpResponseAjax([
         commands.navigate(reverse('caches-browse')),
     ], request)
コード例 #12
0
ファイル: user.py プロジェクト: wAaron/varnish-bans-manager
    def post(self, request):
        form = LoginForm(data=request.POST)
        if form.is_valid():
            # Log user in.
            auth.login(request, form.user)

            # Done!
            messages.info(request, _('Welcome back!'))
            return HttpResponseAjax([
                commands.redirect(form.cleaned_data.get('destination')),
            ], request)
        else:
            return self._render(form)
コード例 #13
0
ファイル: user.py プロジェクト: wAaron/varnish-bans-manager
 def post(self, request):
     form = ProfilePreferencesForm(request.user,
                                   data=request.POST,
                                   files=request.FILES)
     if form.is_valid():
         form.save()
         messages.success(request, DEFAULT_SUCCESS_MESSAGE)
         return HttpResponseAjax([
             commands.reload(request),
         ], request)
     else:
         messages.error(request, DEFAULT_FORM_ERROR_MESSAGE)
         return self._render(form)
コード例 #14
0
ファイル: user.py プロジェクト: wAaron/varnish-bans-manager
    def post(self, request, user):
        form = PasswordResetConfirmationForm(user, data=request.POST)
        if form.is_valid():
            # Save.
            form.save()

            # Done!
            messages.success(request, _('Your password has been updated.'))
            return HttpResponseAjax([
                commands.navigate(reverse('user-login')),
            ], request)
        else:
            return self._render(form, request)
コード例 #15
0
 def _redirect(self, request, secure):
     protocol = secure and "https" or "http"
     url = "%s://%s%s" % (protocol, request.get_host(),
                          request.get_full_path())
     if settings.DEBUG and request.method == 'POST':
         raise RuntimeError(
             '''Django can't perform a redirect while maintaining POST data.
             Please structure your views so that redirects only occur during
             GETs.''')
     if request.is_ajax():
         return HttpResponseAjax([commands.redirect(url)])
     else:
         return HttpResponseRedirect(url)
コード例 #16
0
ファイル: users.py プロジェクト: wAaron/varnish-bans-manager
 def post(self, request, user):
     token = tasks.enqueue(
         request,
         DeleteTask(), [user.id],
         callback={
             'fn': (
                 'varnish_bans_manager.core.views.users.Delete',
                 'callback',
             ),
             'context': {
                 'destination': reverse('users-browse'),
             }
         })
     return HttpResponseAjax([
         commands.show_progress(token, title=_('Removing user...')),
     ], request)
コード例 #17
0
ファイル: users.py プロジェクト: wAaron/varnish-bans-manager
 def _launch_task(self, request, form, task, title, destination):
     token = tasks.enqueue(
         request,
         task,
         form.ids,
         callback={
             'fn': (
                 'varnish_bans_manager.core.views.users.Bulk',
                 '%s_callback' % form.cleaned_data.get('op'),
             ),
             'context': {
                 'destination': destination,
             }
         })
     return HttpResponseAjax([
         commands.show_progress(token, title=title),
     ], request)
コード例 #18
0
ファイル: user.py プロジェクト: wAaron/varnish-bans-manager
    def post(self, request):
        form = PasswordResetForm(data=request.POST)
        if form.is_valid():
            # Save.
            form.save(request)

            # Done!
            messages.success(
                request,
                _('An e-mail with password reset instructions has been '
                  'delivered to %(email)s. Please, check your inbox and '
                  'follow the instructions.') % {'email': form.user.email})
            return HttpResponseAjax([
                commands.navigate(reverse('user-login')),
            ], request)
        else:
            return self._render(form)
コード例 #19
0
ファイル: views.py プロジェクト: wAaron/varnish-bans-manager
 def wrapped(request, *args, **kwargs):
     result = fn(request, *args, **kwargs)
     if isinstance(result, HttpResponse):
         return result
     else:
         if request.is_ajax():
             contents = render_to_string(
                 result['template'],
                 result['context'],
                 context_instance=RequestContext(request))
             return HttpResponseAjax([
                 set_content(contents),
             ], request)
         else:
             return render_to_response(
                 result['template'],
                 result['context'],
                 context_instance=RequestContext(request))
コード例 #20
0
 def post(self, request):
     form = StatusForm(data=request.POST)
     if form.is_valid():
         token = tasks.enqueue(
             request,
             StatusTask(),
             form.cleaned_data.get('cache'),
             callback={
                 'fn': (
                     'varnish_bans_manager.core.views.bans.Status',
                     'callback',
                 ),
                 'context': {},
             })
         return HttpResponseAjax([
             commands.show_progress(token,
                                    title=_('Fetching lists of bans...')),
         ], request)
     else:
         messages.error(request, DEFAULT_FORM_ERROR_MESSAGE)
         return self._render(form=form)
コード例 #21
0
 def post(self, request):
     form = self._form(request.user, data=request.POST)
     if form.is_valid():
         token = tasks.enqueue(
             request,
             SubmitTask(),
             form.ban_submission,
             callback={
                 'fn': (
                     'varnish_bans_manager.core.views.bans.Submit',
                     'callback',
                 ),
                 'context': {
                     'expression': form.expression,
                     'destination': self.destination,
                 }
             })
         return HttpResponseAjax([
             commands.show_progress(token, title=_('Submitting ban...')),
         ], request)
     else:
         messages.error(request, DEFAULT_FORM_ERROR_MESSAGE)
         return self._render(form=form)