Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError "request" when load or send the JSON data via ajax. #67

Open
agusmakmun opened this issue Aug 26, 2021 · 0 comments
Open

KeyError "request" when load or send the JSON data via ajax. #67

agusmakmun opened this issue Aug 26, 2021 · 0 comments
Labels

Comments

@agusmakmun
Copy link
Collaborator

agusmakmun commented Aug 26, 2021

Screenshots

image

Desktop

  • OS: MacOSX, Windows, Linux
  • Browser Chrome
  • Version 92.0.4515

Solution:

I think we can just check whether request is filled.

def render(self, context):
    request = context.get('request', None)
    if request:
        qs = Announcement.objects.filter(
            publish_start__lte=timezone.now()
        ).filter(
            Q(publish_end__isnull=True) | Q(publish_end__gt=timezone.now())
        ).filter(
            site_wide=True
        )
        exclusions = request.session.get("excluded_announcements", [])
        exclusions = set(exclusions)
        if request.user.is_authenticated:
            for dismissal in request.user.announcement_dismissals.all():
                exclusions.add(dismissal.announcement.pk)
        else:
            qs = qs.exclude(members_only=True)
        context[self.as_var] = qs.exclude(pk__in=exclusions)
    return ""
@agusmakmun agusmakmun added the bug label Aug 26, 2021
@agusmakmun agusmakmun changed the title KeyError "request" when load the JSON data via ajax. KeyError "request" when load or send the JSON data via ajax. Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant