6 from xml.dom.minidom import parse, parseString
7 from xml.parsers.expat import ExpatError
8 from forum.modules import ui, decorate
9 from forum.settings import VCS_REVISION
10 from django.contrib.auth.middleware import AuthenticationMiddleware
11 from django.core.exceptions import ObjectDoesNotExist
12 from django.utils.encoding import smart_str
14 from base import update_trigger
16 # Update the user messages
17 @decorate.result(AuthenticationMiddleware.process_request, needs_params=True)
18 def process_request(result, self, request):
19 # Call the update trigger on every request
23 messages_dom = parseString(smart_str(settings.UPDATE_MESSAGES_XML.value))
24 messages = messages_dom.getElementsByTagName('message')
26 for message in messages:
27 # Get the SVN Revision
29 svn_revision = int(VCS_REVISION.replace('SVN-', ''))
31 # Here we'll have to find another way of getting the SVN revision
34 message_body = message.getElementsByTagName('body')[0].firstChild.nodeValue
35 message_revision = int(message.getElementsByTagName('revision')[0].firstChild.nodeValue)
37 # Add the message to the user messages set only if the Message Revision number is greater than the
38 # current installation SVN Revision number and only if the current user is a super user.
39 if message_revision >= svn_revision and request.user.is_superuser:
40 # We do not want to repeat ourselves. If the message already exists in the message list, we're not going to
41 # add it. That's why first of all we're going the check if it is there.
43 # If the message doesn't exist in the RelatedManager ObjectsDoesNotExist is going to be raised.
44 request.user.message_set.all().get(message=message_body)
45 except ObjectDoesNotExist:
46 # Let's create the message.
47 request.user.message_set.create(message=message_body)