6 from xml.dom.minidom import parse, parseString
8 from forum.modules import ui, decorate
9 from forum.settings import SVN_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 # Trigger the update process
15 now = datetime.datetime.now()
16 if (now - settings.LATEST_UPDATE_DATETIME) > datetime.timedelta(days=1):
19 # Update the user messages
20 @decorate.result(AuthenticationMiddleware.process_request, needs_params=True)
21 def process_request(result, self, request):
22 messages_dom = parseString(smart_str(settings.UPDATE_MESSAGES_XML.value))
23 messages = messages_dom.getElementsByTagName('message')
25 for message in messages:
26 # Get the SVN Revision
28 svn_revision = int(SVN_REVISION.replace('SVN-', ''))
30 # Here we'll have to find another way of getting the SVN revision
33 message_body = message.getElementsByTagName('body')[0].firstChild.nodeValue
34 message_revision = int(message.getElementsByTagName('revision')[0].firstChild.nodeValue)
36 # Add the message to the user messages set only if the Message Revision number is greater than the
37 # current installation SVN Revision number and only if the current user is a super user.
38 if message_revision >= svn_revision and request.user.is_superuser:
39 # We do not want to repeat ourselves. If the message already exists in the message list, we're not going to
40 # add it. That's why first of all we're going the check if it is there.
42 # If the message doesn't exist in the RelatedManager ObjectsDoesNotExist is going to be raised.
43 request.user.message_set.all().get(message=message_body)
44 except ObjectDoesNotExist:
45 # Let's create the message.
46 request.user.message_set.create(message=message_body)