- Author:
- shapiromatron
- Posted:
- October 29, 2015
- Language:
- Python
- Version:
- 3.2
- Score:
- 0 (after 0 ratings)
Hyperlinks to views requiring authentication in Microsoft Office (Word, Excel, Powerpoint) can fail based on how Office handles rendering. This middleware sends a refresh return to the client, which will allow the page to be opened as normal, instead of the "Unable to open ... Cannot download the information you requested."
This is a port from the ruby middleware project fix microsoft links.
To enable, add to your middleware stack in the django project settings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from django.http import HttpResponse import re class MicrosoftOfficeLinkMiddleware(object): # https://support.microsoft.com/en-us/kb/899927 # https://github.com/spilliton/fix_microsoft_links OFFICE_AGENTS = re.compile(r"(Word|Excel|PowerPoint|ms-office)") OUTLOOK_AGENTS = re.compile(r"(Microsoft Outlook)") RESPONSE_TEXT = """<html><head><meta http-equiv="refresh" content="0"/></head><body></body></html>""" def process_request(self, request): agent = request.META.get("HTTP_USER_AGENT", "") if (re.findall(self.OFFICE_AGENTS, agent) and not re.findall(self.OUTLOOK_AGENTS, agent)): return HttpResponse(self.RESPONSE_TEXT) |
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Please login first before commenting.