mirror of
https://github.com/dnlbauer/django-signposting.git
synced 2026-09-10 22:15:30 +00:00
use signposting package
This commit is contained in:
@@ -1,23 +1,17 @@
|
||||
from django.http import HttpResponse
|
||||
from signposting import Signpost
|
||||
|
||||
|
||||
def add_signposts(response: HttpResponse, **kwargs):
|
||||
def add_signposts(response: HttpResponse, *args: Signpost):
|
||||
""" Adds signposting headers to the responses.
|
||||
params:
|
||||
response - the response object
|
||||
kwargs - a map of relation types to a list of corresponding links. Each link can be a link or a tuple of link and media type.
|
||||
args - a list of signposts to add to this resposnse.
|
||||
"""
|
||||
|
||||
if not hasattr(response, '_signposts'):
|
||||
response._signposts = {}
|
||||
response._signposts = []
|
||||
|
||||
for key in kwargs.keys():
|
||||
|
||||
values = kwargs[key]
|
||||
if isinstance(values, str) or isinstance(values, tuple):
|
||||
values = [values]
|
||||
|
||||
if key not in response._signposts:
|
||||
response._signposts[key] = values
|
||||
else:
|
||||
response._signposts[key] += values
|
||||
for signpost in args:
|
||||
if not signpost in response._signposts:
|
||||
response._signposts.append(signpost)
|
||||
Reference in New Issue
Block a user