コード例 #1
0
    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)
        consumers = []

        try:
            urlpath = '/management/consumers'
            consumers = api.get(self.request, urlpath)
            consumers = FilterEnabled(context, self.request.GET)\
                .apply(consumers['list'])
            consumers = FilterAppType(context, self.request.GET)\
                .apply(consumers)
            consumers = FilterTime(context, self.request.GET, 'created')\
                .apply(consumers)
            consumers = self.scrub(consumers)
        except APIError as err:
            messages.error(self.request, err)

        sorted_consumers = sorted(consumers,
                                  key=lambda consumer: consumer['created'],
                                  reverse=True)
        context.update({
            'consumers': sorted_consumers,
            'statistics': self.compile_statistics(consumers),
        })
        return context
コード例 #2
0
    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)
        role_names = []
        users = []
        try:
            urlpath = '/users'
            users = api.get(self.request, urlpath)
            for user in users['users']:
                for entitlement in user['entitlements']['list']:
                    role_names.append(entitlement['role_name'])
            role_names = list(set(role_names))
            role_names.sort()
            users = FilterRoleName(context, self.request.GET)\
                .apply(users['users'])
            users = FilterEmail(context, self.request.GET)\
                .apply(users)
        except APIError as err:
            messages.error(self.request, err)

        context.update({
            'role_names': role_names,
            'statistics': {
                'users_num': len(users),
            },
            'users': users,
        })
        return context
コード例 #3
0
def api_username(request):
    """Returns the API username of the logged-in user"""
    if request.user.is_authenticated:
        data = api.get(request, '/users/current')
        username = data['username']
    else:
        username = '******'
    return {'API_USERNAME': username}
コード例 #4
0
def api_username(request):
    """Returns the API username of the logged-in user"""
    username = '******'
    if request.user.is_authenticated:
        try:
            data = api.get(request, '/users/current')
            username = data['username']
        except APIError as err:
            messages.error(request, err)
    return {'API_USERNAME': username}
コード例 #5
0
 def get_metrics(self, cleaned_data):
     """
     Gets the metrics from the API, using given cleaned form data.
     """
     metrics = []
     params = self.to_api(cleaned_data)
     urlpath = '{}?{}'.format(self.api_urlpath, params)
     try:
         metrics = api.get(self.request, urlpath)
         metrics = self.to_django(metrics['metrics'])
     except APIError as err:
         messages.error(self.request, err)
     return metrics
コード例 #6
0
ファイル: views.py プロジェクト: vdthatte/API-Manager
    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)
        try:
            urlpath = '/config'
            config = api.get(self.request, urlpath)
        except APIError as err:
            messages.error(self.request, err)
            config = {}

        context.update({
            'config_json': json.dumps(config, indent=4),
        })
        return context
コード例 #7
0
ファイル: views.py プロジェクト: kierstenbolton/API-Manager
    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)
        metrics = []
        params = self.get_params(self.request.GET)
        try:
            urlpath = '/management/metrics?{}'.format(params)
            metrics = api.get(self.request, urlpath)
            metrics = self.scrub(metrics['metrics'])
        except APIError as err:
            messages.error(self.request, err)

        context.update({'metrics': metrics, 'barchart_data': json.dumps({})})
        return context
コード例 #8
0
 def login_to_django(self):
     """
     Logs the user into Django
     Kind of faking it to establish if a user is authenticated later on
     """
     data = api.get(self.request, '/users/current')
     userid = data['user_id'] or data['email']
     username = hashlib.sha256(userid.encode('utf-8')).hexdigest()
     password = username
     user, _ = User.objects.get_or_create(
         username=username,
         password=password,
     )
     login(self.request, user)
コード例 #9
0
    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)

        try:
            urlpath = '/management/consumers/{}'.format(kwargs['consumer_id'])
            consumer = api.get(self.request, urlpath)
            consumer['created'] = datetime.strptime(
                consumer['created'], settings.API_DATETIMEFORMAT)
        except APIError as err:
            messages.error(self.request, err)

        context.update({
            'consumer': consumer,
        })
        return context
コード例 #10
0
ファイル: views.py プロジェクト: simonredfern/API-Manager
    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)

        # NOTE: assuming there is just one user with that email address
        # The API actually needs a 'get user by id'
        user = {}
        try:
            urlpath = '/users/{}'.format(kwargs['user_email'])
            users = api.get(self.request, urlpath)
            if len(users['users']) > 0:
                user = users['users'][0]
                try:
                    urlpath = '/users/{}/entitlements'.format(user['user_id'])
                    entitlements = api.get(self.request, urlpath)
                    user['entitlements'] = entitlements['list']
                except APIError as err:
                    messages.error(self.request, err)
        except APIError as err:
            messages.error(self.request, err)

        context.update({
            'apiuser': user,
        })
        return context
コード例 #11
0
    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)

        # NOTE: assuming there is just one user with that email address
        # The API needs a call 'get user by id'!
        user = {}
        try:
            urlpath = '/users/user_id/{}'.format(self.kwargs['user_id'])
            user = api.get(self.request, urlpath)
            context['form'].fields['user_id'].initial = user['user_id']
        except APIError as err:
            messages.error(self.request, err)

        context.update({
            'apiuser': user,  # 'user' is logged-in user in template context
        })
        return context