Skip to content

Instantly share code, notes, and snippets.

@Greymalkin
Created March 17, 2017 16:18
Show Gist options
  • Select an option

  • Save Greymalkin/8068568445fcfe415f15a796e0c58a7d to your computer and use it in GitHub Desktop.

Select an option

Save Greymalkin/8068568445fcfe415f15a796e0c58a7d to your computer and use it in GitHub Desktop.
get_request(): a way to pull request into places where it doesn't hook in naturally
# in requirements.txt
django-request-provider==1.0.2
# in settings.py
MIDDLEWARE_CLASSES += ['request_provider.middleware.RequestProvider',]
# in admin.py
from request_provider.signals import get_request
class MeetAdmin(admin.ModelAdmin):
list_display = ('short_name', 'host', 'date', 'is_current_meet',)
list_display = ('short_name', 'host', 'date', 'is_current_meet', 'set_meet')
actions = ['copy_meet']
def set_meet(self, obj):
request = get_request()
meet = request.session.get('meet', {})
if meet.get('id', '') == obj.id:
return "<strong>Active Meet</strong>"
return "<a class='setMeet' href='#' data-meet={}>Set Active Meet</a>".format(obj.id)
set_meet.short_description = "Active Meet"
set_meet.allow_tags = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment