示例#1
0
文件: cache.py 项目: globocom/vault
def remove_from_cache(request, project):
    form = RemoveCacheForm(request.POST or None)

    if form.is_valid():
        urls = form.cleaned_data['urls'].splitlines()

        data = {'url': urls, 'user': request.user.username}

        api_url = '{host}/url/add'.format(host=settings.CACHESWEEP_API)
        req = requests.post(api_url, json=data)

        if req.status_code == 201:
            messages.add_message(
                request, messages.SUCCESS,
                _('URLs scheduled to be removed. Grab some coffee, it takes 2 to 3 minutes to remove.'
                  ))

            form = RemoveCacheForm(None)
            actionlog.log(request.user.username, "remove_cache", repr(urls))
        else:
            messages.add_message(request, messages.ERROR,
                                 _('Fail to schedule URLs to be removed.'))

    context = utils.update_default_context(request, {'form': form})

    return render(request, 'storage/cache_remove.html', context)
示例#2
0
def accountview(request, project):
    storage_url = get_storage_endpoint(request, 'adminURL')

    if not storage_url:
        return

    auth_token = request.session.get('auth_token')
    http_conn = client.http_connection(storage_url,
                                       insecure=settings.SWIFT_INSECURE)

    head_acc = {}
    try:
        head_acc = client.head_account(storage_url,
                                       auth_token,
                                       http_conn=http_conn)
    except Exception as err:
        log.exception(f'Exception: {err}')

    context = {
        'cloud': head_acc.get('x-account-meta-cloud'),
        'total_containers': head_acc.get('x-account-container-count'),
        'total_objects': head_acc.get('x-account-object-count'),
        'total_bytes': head_acc.get('x-account-bytes-used'),
        'account_domain_id': head_acc.get('x-account-project-domain-id'),
    }

    return render(request, 'storage/accountview.html',
                  update_default_context(request, context))
示例#3
0
    def get(self, request, *args, **kwargs):
        context = {}
        context['users'] = []
        context['groups'] = []

        try:
            all_groups_id = [group.id for group in Group.objects.all()]

            # Users without a team
            users = (User.objects.exclude(
                groups__in=all_groups_id).order_by('username'))

            for user in User.objects.all().order_by('username'):
                context['users'].append({
                    'id': int(user.id),
                    'name': user.username
                })

            for grp in request.user.groups.all():
                context['groups'].append({'id': int(grp.id), 'name': grp.name})

            context = update_default_context(request, context)

        except Exception as e:
            log.exception('{}{}'.format(_('Exception:').encode('UTF-8'), e))
            return self.render_to_response(context, status=500)

        return self.render_to_response(context)
示例#4
0
    def get(self, request, *args, **kwargs):

        context = update_default_context(
            request, {
                "project_name": request.session.get('project_name'),
                "project_id": request.session.get('project_id'),
                "has_team": request.user.groups.count() > 0,
                "last_login": str(request.user.last_login)
            })

        return self.render_to_response(context)
示例#5
0
    def get(self, request, *args, **kwargs):
        context = {}
        context["groups"] = []

        for index, group in enumerate(Group.objects.all()):

            context["groups"].append({"id": int(group.id), "name": group.name, "users": []})

            for user in group.user_set.all():
                context["groups"][index]["users"].append({"email": user.email})

        context = update_default_context(request, context)

        return self.render_to_response(context)
示例#6
0
    def get(self, request, *args, **kwargs):
        context = {}
        context['groups'] = []

        for index, group in enumerate(Group.objects.all()):

            context['groups'].append({
                'id': int(group.id),
                'name': group.name,
                'users': []
            })

            for user in group.user_set.all():
                context['groups'][index]['users'].append({'email': user.email})

        context = update_default_context(request, context)

        return self.render_to_response(context)
示例#7
0
    def get(self, request, *args, **kwargs):
        context = {}
        context["users"] = []
        context["groups"] = []

        try:
            all_groups_id = [group.id for group in Group.objects.all()]

            # Users without a team
            users = User.objects.exclude(groups__in=all_groups_id).order_by("username")

            for user in User.objects.all().order_by("username"):
                context["users"].append({"id": int(user.id), "name": user.username})

            for grp in request.user.groups.all():
                context["groups"].append({"id": int(grp.id), "name": grp.name})

            context = update_default_context(request, context)

        except Exception as e:
            log.exception("{}{}".format(_("Exception:").encode("UTF-8"), e))
            return self.render_to_response(context, status=500)

        return self.render_to_response(context)
示例#8
0
文件: views.py 项目: stormers/vault
    def get_context_data(self, **kwargs):
        context = super(LoginRequiredMixin, self).get_context_data(**kwargs)

        return update_default_context(self.request, context)