~ubuntu-branches/ubuntu/vivid/python-gevent/vivid

« back to all changes in this revision

Viewing changes to examples/webchat/chat/views.py

  • Committer: Bazaar Package Importer
  • Author(s): Örjan Persson
  • Date: 2011-05-17 16:43:20 UTC
  • mto: (14.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20110517164320-jyr5vamkqi3jfeab
Tags: upstream-0.13.6
Import upstream version 0.13.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
    def message_new(self, request):
23
23
        name = request.META.get('REMOTE_ADDR') or 'Anonymous'
 
24
        forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
 
25
        if forwarded_for and name == '127.0.0.1':
 
26
            name = forwarded_for
24
27
        msg = create_message(name, request.POST['body'])
25
28
        self.cache.append(msg)
26
29
        if len(self.cache) > self.cache_size:
37
40
        try:
38
41
            for index, m in enumerate(self.cache):
39
42
                if m['id'] == cursor:
40
 
                    return json_response({'messages': self.cache[index+1:]})
 
43
                    return json_response({'messages': self.cache[index + 1:]})
41
44
            return json_response({'messages': self.cache})
42
45
        finally:
43
46
            if self.cache:
60
63
def json_response(value, **kwargs):
61
64
    kwargs.setdefault('content_type', 'text/javascript; charset=UTF-8')
62
65
    return HttpResponse(simplejson.dumps(value), **kwargs)
63