--- /dev/null
+<table class="stats">
+ {% for country in countries %}
+ <tr>
+ <td class="key">
+ <img src="{{ static_url("images/flags/%s.png" % country.code) }}" />
+ {{ country.name }}
+ </td>
+ <td class="bar"><p style="{{ "width: %.2f%%" % country.value }}"> </p></td>
+ <td class="value">{{ "%.2f" % country.value }}%</td>
+ </tr>
+ {% end %}
+</table>
+<br class="clear" />
This chart shows us in which country IPFire is running.
</p>
{% end %}
- {{ modules.StasyTable(geo_locations, sortby="percentage", flags=True) }}
+ {{ modules.StasyGeoTable(geo_locations) }}
{% end block %}
"SidebarRelease" : SidebarReleaseModule,
"StasyTable" : StasyTableModule,
"StasyDeviceTable" : StasyDeviceTableModule,
+ "StasyGeoTable" : StasyGeoTableModule,
"TrackerPeerList": TrackerPeerListModule,
},
xsrf_cookies = True,
#!/usr/bin/python
+import re
+
from databases import Databases
from misc import Singleton
class GeoIP(object):
__metaclass__ = Singleton
+ def __init__(self):
+ self.__country_codes = self.db.query("SELECT code, name FROM iso3166_countries")
+
@property
def db(self):
return Databases().geoip
return self.db.get("SELECT * FROM locations WHERE id = %s", int(location))
+ def get_country_name(self, code):
+ name = "Unknown"
+
+ code = code.upper()
+ for country in self.__country_codes:
+ if country.code == code:
+ name = country.name
+ break
+
+ # Fix some weird strings
+ name = re.sub(r"(.*) (.* Republic of)", r"\2 \1", name)
+
+ return name
+
if __name__ == "__main__":
g = GeoIP()
count += geo_locations[geo_location]
+ for geo_location in geo_locations.keys():
+ geo_locations[geo_location] /= count
+
return geo_locations
def get_models_by_vendor(self, subsystem, vendor_id):
def releases(self):
return self.handler.releases
+ @property
+ def geoip(self):
+ return self.handler.geoip
+
class MenuModule(UIModule):
def render(self):
return self.render_string("modules/stasy-table-devices.html",
groups=groups.items())
+
+
+class StasyGeoTableModule(UIModule):
+ def render(self, items):
+ _ = self.locale.translate
+
+ # Sort all items by value
+ items = sorted(items.items(), key=operator.itemgetter(1), reverse=True)
+
+ countries = []
+ for code, value in items:
+ country = tornado.database.Row({
+ "code" : code.lower(),
+ "name" : _(self.geoip.get_country_name(code)),
+ "value" : value * 100,
+ })
+ countries.append(country)
+
+ return self.render_string("modules/stasy-table-geo.html", countries=countries)