Exemplo n.º 1
0
    def render_to_response(self, context, **response_kwargs):
        """
        If the request is Ajax, it adds the needed headers to the response
        """

        response = super(AjaxTemplateResponseMixin, self) \
            .render_to_response(context, **response_kwargs)
        if is_ajax(self.request):
            response['Cache-Control'] = 'no-cache'
            response['Vary'] = 'Accept'
        return response
Exemplo n.º 2
0
    def get_template_names(self):
        """
        Returns a list of template names to be used for the request. Must
        return a list. May not be called if render_to_response is overridden.
        """

        template_names = None
        if is_ajax(self.request) and self.ajax_template_name is not None:
            template_names = [self.ajax_template_name, self.template_name]

        if template_names is None:
            template_names = super(AjaxTemplateResponseMixin, self) \
                .get_template_names()

        return template_names
Exemplo n.º 3
0
def export_users(request):

    ordering, users = utils.get_paginated_users(request)
    for user in users:
        try:
            user.apiKey = user.api_key.key
        except ApiKey.DoesNotExist:
            # if the user doesn't have an apiKey yet, generate it
            user.apiKey = ApiKey.objects.create(user=user).key

    template = 'export-users.html'
    if is_ajax(request):
        template = 'users-paginated-list.html'

    return render(request, 'profile/' + template, {
        'page_obj': users,
        'object_list': users.object_list,
        'page_ordering': ordering,
        'users_list_template': 'export'})