diff sat_website/views/whereami.py @ 150:b101828faa0e

split views.py in sub-modules
author souliane <souliane@mailoo.org>
date Tue, 17 Oct 2017 22:16:20 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sat_website/views/whereami.py	Tue Oct 17 22:16:20 2017 +0200
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+"""
+SàT website: Salut à Toi's presentation website
+Copyright (C) 2012  Jérôme Poisson (goffi@goffi.org)
+
+This file is part of SàT website.
+
+SàT website is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Foobar is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with SàT website.  If not, see <http://www.gnu.org/licenses/>.
+"""
+
+from django.views import View
+from django.http.response import HttpResponse
+
+
+class WhereAmIView(View):
+
+    def get(self, request):
+        """Return the client IP address"""
+        x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
+        if x_forwarded_for:
+            ip = x_forwarded_for.split(',')[0]
+        else:
+            ip = request.META.get('REMOTE_ADDR')
+        return HttpResponse(ip)