mirror of
https://github.com/nikdoof/limetime.git
synced 2025-12-13 09:42:26 +00:00
Initial import of codebase
This commit is contained in:
1
app/limetime/__init__.py
Normal file
1
app/limetime/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__version__ = '0.1'
|
||||
0
app/limetime/conf/__init__.py
Normal file
0
app/limetime/conf/__init__.py
Normal file
131
app/limetime/conf/base.py
Normal file
131
app/limetime/conf/base.py
Normal file
@@ -0,0 +1,131 @@
|
||||
# Django settings for limetime project.
|
||||
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
ADMINS = (
|
||||
# ('Your Name', 'your_email@example.com'),
|
||||
)
|
||||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
# Hosts/domain names that are valid for this site; required if DEBUG is False
|
||||
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
# Local time zone for this installation. Choices can be found here:
|
||||
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
|
||||
# although not all choices may be available on all operating systems.
|
||||
# In a Windows environment this must be set to your system time zone.
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
# Language code for this installation. All choices can be found here:
|
||||
# http://www.i18nguy.com/unicode/language-identifiers.html
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
# If you set this to False, Django will make some optimizations so as not
|
||||
# to load the internationalization machinery.
|
||||
USE_I18N = True
|
||||
|
||||
# If you set this to False, Django will not format dates, numbers and
|
||||
# calendars according to the current locale.
|
||||
USE_L10N = True
|
||||
|
||||
# If you set this to False, Django will not use timezone-aware datetimes.
|
||||
USE_TZ = True
|
||||
|
||||
# Absolute filesystem path to the directory that will hold user-uploaded files.
|
||||
# Example: "/var/www/example.com/media/"
|
||||
MEDIA_ROOT = ''
|
||||
|
||||
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
||||
# trailing slash.
|
||||
# Examples: "http://example.com/media/", "http://media.example.com/"
|
||||
MEDIA_URL = ''
|
||||
|
||||
# Absolute path to the directory static files should be collected to.
|
||||
# Don't put anything in this directory yourself; store your static files
|
||||
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
|
||||
# Example: "/var/www/example.com/static/"
|
||||
STATIC_ROOT = ''
|
||||
|
||||
# URL prefix for static files.
|
||||
# Example: "http://example.com/static/", "http://static.example.com/"
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
# Additional locations of static files
|
||||
STATICFILES_DIRS = (
|
||||
# Put strings here, like "/home/html/static" or "C:/www/django/static".
|
||||
# Always use forward slashes, even on Windows.
|
||||
# Don't forget to use absolute paths, not relative paths.
|
||||
)
|
||||
|
||||
# List of finder classes that know how to find static files in
|
||||
# various locations.
|
||||
STATICFILES_FINDERS = (
|
||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||
)
|
||||
|
||||
# Make this unique, and don't share it with anybody.
|
||||
SECRET_KEY = '$+y3w%y3286wetd#tqhvqch$^ed)x=#s$we1c2)d1&lf9quktl'
|
||||
|
||||
# List of callables that know how to import templates from various sources.
|
||||
TEMPLATE_LOADERS = (
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'limetime.urls'
|
||||
|
||||
# Python dotted path to the WSGI application used by Django's runserver.
|
||||
WSGI_APPLICATION = 'limetime.wsgi.application'
|
||||
|
||||
import os
|
||||
TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), '../templates').replace('\\','/'),)
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.sites',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'django.contrib.admin',
|
||||
'gunicorn',
|
||||
'timer',
|
||||
)
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'filters': {
|
||||
'require_debug_false': {
|
||||
'()': 'django.utils.log.RequireDebugFalse'
|
||||
}
|
||||
},
|
||||
'handlers': {
|
||||
'mail_admins': {
|
||||
'level': 'ERROR',
|
||||
'filters': ['require_debug_false'],
|
||||
'class': 'django.utils.log.AdminEmailHandler'
|
||||
}
|
||||
},
|
||||
'loggers': {
|
||||
'django.request': {
|
||||
'handlers': ['mail_admins'],
|
||||
'level': 'ERROR',
|
||||
'propagate': True,
|
||||
},
|
||||
}
|
||||
}
|
||||
6
app/limetime/conf/development.py
Normal file
6
app/limetime/conf/development.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import os
|
||||
import dj_database_url
|
||||
from .base import *
|
||||
|
||||
default_db_url = 'sqlite:///%s' % os.path.join(os.path.dirname(__file__), '..', '..', '..', 'limetime.db3')
|
||||
DATABASES = {'default': dj_database_url.config(default=default_db_url)}
|
||||
10
app/limetime/urls.py
Normal file
10
app/limetime/urls.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.conf.urls import patterns, include, url
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^', include('timer.urls')),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
)
|
||||
32
app/limetime/wsgi.py
Normal file
32
app/limetime/wsgi.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
WSGI config for limetime project.
|
||||
|
||||
This module contains the WSGI application used by Django's development server
|
||||
and any production WSGI deployments. It should expose a module-level variable
|
||||
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
|
||||
this application via the ``WSGI_APPLICATION`` setting.
|
||||
|
||||
Usually you will have the standard Django WSGI application here, but it also
|
||||
might make sense to replace the whole Django WSGI application with a custom one
|
||||
that later delegates to the Django one. For example, you could introduce WSGI
|
||||
middleware here, or combine a Django application with an application of another
|
||||
framework.
|
||||
|
||||
"""
|
||||
import os
|
||||
|
||||
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
|
||||
# if running multiple sites in the same mod_wsgi process. To fix this, use
|
||||
# mod_wsgi daemon mode with each site in its own daemon process, or use
|
||||
# os.environ["DJANGO_SETTINGS_MODULE"] = "limetime.settings"
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "limetime.settings")
|
||||
|
||||
# This application object is used by any WSGI server configured to use this
|
||||
# file. This includes Django's development server, if the WSGI_APPLICATION
|
||||
# setting points here.
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
application = get_wsgi_application()
|
||||
|
||||
# Apply WSGI middleware here.
|
||||
# from helloworld.wsgi import HelloWorldApplication
|
||||
# application = HelloWorldApplication(application)
|
||||
10
app/manage.py
Executable file
10
app/manage.py
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "limetime.conf.development")
|
||||
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
execute_from_command_line(sys.argv)
|
||||
1
app/timer/__init__.py
Normal file
1
app/timer/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__version__ = '0.1'
|
||||
8
app/timer/admin.py
Normal file
8
app/timer/admin.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.contrib import admin
|
||||
from timer.models import Timer
|
||||
|
||||
|
||||
class TimerAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ['location']
|
||||
|
||||
admin.site.register(Timer, admin.ModelAdmin)
|
||||
0
app/timer/management/__init__.py
Normal file
0
app/timer/management/__init__.py
Normal file
0
app/timer/management/commands/__init__.py
Normal file
0
app/timer/management/commands/__init__.py
Normal file
23
app/timer/management/commands/import_alliances.py
Normal file
23
app/timer/management/commands/import_alliances.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import transaction
|
||||
from timer.models import Alliance, Corporation
|
||||
from eveapi import EVEAPIConnection
|
||||
|
||||
class Command(BaseCommand):
|
||||
args = ''
|
||||
help = 'Updates alliances from the EVE API'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
api = EVEAPIConnection()
|
||||
|
||||
alliance_list = api.eve.AllianceList().alliances
|
||||
print 'Updating %d alliances... ' % len(alliance_list)
|
||||
with transaction.commit_on_success():
|
||||
for alliance in alliance_list:
|
||||
allobj, created = Alliance.objects.get_or_create(pk=alliance.allianceID)
|
||||
allobj.name = alliance.name
|
||||
allobj.save()
|
||||
corp_ids = [x.corporationID for x in alliance.memberCorporations]
|
||||
Corporation.objects.exclude(pk__in=corp_ids).update(alliance=None)
|
||||
Corporation.objects.filter(pk__in=corp_ids).update(alliance=allobj)
|
||||
print 'Done'
|
||||
44
app/timer/management/commands/import_map.py
Normal file
44
app/timer/management/commands/import_map.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from __future__ import division
|
||||
import sqlite3
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import transaction
|
||||
from timer.models import Region, Constellation, System, Planet, Moon
|
||||
|
||||
class Command(BaseCommand):
|
||||
args = '<map csv>'
|
||||
help = 'Imports the EVE Map from a sqlite dump of the SDE table mapDenormalized'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
||||
# Connect to the sqlite3 DB
|
||||
db = sqlite3.connect(args[0])
|
||||
cur = db.cursor()
|
||||
|
||||
objs = []
|
||||
|
||||
# eveUnits
|
||||
print "Importing mapDenormalize..."
|
||||
cur.execute("""SELECT itemID, typeID, groupID, solarSystemID, constellationID, regionID, orbitID, x, y, z, itemName FROM mapDenormalize WHERE typeID in (3, 4, 5, 14) OR groupID = 7""")
|
||||
for row in cur.fetchall():
|
||||
id, type, group, solarid, constellationid, regionid, orbitid, x, y, z, name = row
|
||||
|
||||
if int(type) == 3:
|
||||
objs.append(Region(pk=id, name=name, x=0, y=0, z=0))
|
||||
elif int(type) == 4:
|
||||
objs.append(Constellation(pk=id, name=name, region_id=regionid, x=0, y=0, z=0))
|
||||
elif int(type) == 5:
|
||||
objs.append(System(pk=id, name=name, constellation_id=constellationid, x=0, y=0, z=0))
|
||||
elif int(group) == 7:
|
||||
objs.append(Planet(pk=id, name=name, system_id=solarid, x=x, y=y, z=z))
|
||||
elif int(type) == 14:
|
||||
objs.append(Moon(pk=id, name=name, planet_id=orbitid, x=x, y=y, z=z))
|
||||
print "Done"
|
||||
# Dump to DB
|
||||
|
||||
print 'Processing %d objects for commiting...' % len(objs)
|
||||
with transaction.commit_on_success():
|
||||
for i, x in enumerate(objs, start=1):
|
||||
if i % 1000 == 0: print "%d/%d (%d%%)" % (i, len(objs), round(i/len(objs) * 100))
|
||||
x.save()
|
||||
print 'Commited'
|
||||
24
app/timer/management/commands/import_stations.py
Normal file
24
app/timer/management/commands/import_stations.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db import transaction
|
||||
from timer.models import Station, System
|
||||
from eveapi import EVEAPIConnection
|
||||
|
||||
class Command(BaseCommand):
|
||||
args = ''
|
||||
help = 'Updates conquerable stations from the EVE API'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
api = EVEAPIConnection()
|
||||
|
||||
station_list = api.eve.ConquerableStationList().outposts
|
||||
print 'Updating %d stations... ' % len(station_list)
|
||||
with transaction.commit_on_success():
|
||||
for station in station_list:
|
||||
try:
|
||||
obj = Station.objects.get(pk=station.stationID)
|
||||
except Station.DoesNotExist:
|
||||
obj = Station(pk=station.stationID)
|
||||
obj.system, created = System.objects.get_or_create(pk=station.solarSystemID)
|
||||
obj.name = station.stationName
|
||||
obj.save()
|
||||
print 'Done'
|
||||
4
app/timer/models/__init__.py
Normal file
4
app/timer/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from .locations import *
|
||||
from .owners import *
|
||||
from .timer import *
|
||||
from .utils import *
|
||||
88
app/timer/models/locations.py
Normal file
88
app/timer/models/locations.py
Normal file
@@ -0,0 +1,88 @@
|
||||
from django.db import models
|
||||
from .utils import InheritanceQuerySet
|
||||
from .owners import Corporation
|
||||
|
||||
class LocationManager(models.Manager):
|
||||
|
||||
def all_subclassed(self):
|
||||
return InheritanceQuerySet(model=self.model).select_subclasses()
|
||||
|
||||
|
||||
class Location(models.Model):
|
||||
id = models.BigIntegerField('Location ID', primary_key=True)
|
||||
name = models.CharField('Location Name', max_length=200)
|
||||
x = models.BigIntegerField('X Location', null=True)
|
||||
y = models.BigIntegerField('Y Location', null=True)
|
||||
z = models.BigIntegerField('Z Location', null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return "%(name)s (%(id)d)" % self.__dict__
|
||||
|
||||
class Meta:
|
||||
app_label = 'timer'
|
||||
|
||||
|
||||
class Region(Location):
|
||||
|
||||
@property
|
||||
def systems(self):
|
||||
return System.objects.filter(constellation__in=self.constellations.all())
|
||||
|
||||
@property
|
||||
def planets(self):
|
||||
return Planet.objects.filter(system__constellation__in=self.constellations.all())
|
||||
|
||||
@property
|
||||
def moons(self):
|
||||
return Moon.objects.filter(planet__system__constellation__in=self.constellations.all())
|
||||
|
||||
class Meta:
|
||||
app_label = 'timer'
|
||||
|
||||
|
||||
class Constellation(Location):
|
||||
region = models.ForeignKey(Region, related_name='constellations')
|
||||
|
||||
@property
|
||||
def planets(self):
|
||||
return Planet.objects.filter(system__in=self.systems.all())
|
||||
|
||||
@property
|
||||
def moons(self):
|
||||
return Moon.objects.filter(planet__system__in=self.systems.all())
|
||||
|
||||
class Meta:
|
||||
app_label = 'timer'
|
||||
|
||||
|
||||
class System(Location):
|
||||
constellation = models.ForeignKey(Constellation, related_name='systems')
|
||||
owner = models.ForeignKey(Corporation, related_name='systems', null=True)
|
||||
|
||||
@property
|
||||
def moons(self):
|
||||
return Moon.objects.filter(planet__in=self.planets.all())
|
||||
|
||||
class Meta:
|
||||
app_label = 'timer'
|
||||
|
||||
|
||||
class Planet(Location):
|
||||
system = models.ForeignKey(System, related_name='planets')
|
||||
|
||||
class Meta:
|
||||
app_label = 'timer'
|
||||
|
||||
|
||||
class Moon(Location):
|
||||
planet = models.ForeignKey(Planet, related_name='moons')
|
||||
|
||||
class Meta:
|
||||
app_label = 'timer'
|
||||
|
||||
|
||||
class Station(Location):
|
||||
system = models.ForeignKey(System, related_name='stations')
|
||||
|
||||
class Meta:
|
||||
app_label = 'timer'
|
||||
24
app/timer/models/owners.py
Normal file
24
app/timer/models/owners.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Owner(models.Model):
|
||||
id = models.BigIntegerField('Owner ID', primary_key=True)
|
||||
name = models.CharField('Owner Name', max_length=200)
|
||||
|
||||
class Meta:
|
||||
app_label = 'timer'
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
class Alliance(Owner):
|
||||
|
||||
class Meta:
|
||||
app_label = 'timer'
|
||||
|
||||
class Corporation(Owner):
|
||||
"""Represents a EVE Corporation """
|
||||
alliance = models.ForeignKey(Alliance, related_name='corporations', null=True)
|
||||
|
||||
class Meta:
|
||||
app_label = 'timer'
|
||||
35
app/timer/models/timer.py
Normal file
35
app/timer/models/timer.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from django.db import models
|
||||
from django.utils.timezone import now
|
||||
|
||||
|
||||
class Timer(models.Model):
|
||||
|
||||
STATE_ACTIVE = 1
|
||||
STATE_EXPIRED = 2
|
||||
|
||||
STATE_CHOICES = (
|
||||
(STATE_ACTIVE, 'Active'),
|
||||
(STATE_EXPIRED, 'Expired'),
|
||||
)
|
||||
|
||||
TYPE_SHEILD_REENFORCEMENT = 1
|
||||
TYPE_ARMOR_REENFORCEMENT = 2
|
||||
|
||||
TYPE_CHOICES = (
|
||||
(TYPE_SHEILD_REENFORCEMENT, 'Sheild Reenforcement'),
|
||||
(TYPE_ARMOR_REENFORCEMENT, 'Armor Reenforcement'),
|
||||
)
|
||||
|
||||
location = models.ForeignKey('timer.Location', related_name='timers')
|
||||
expiration = models.DateTimeField('Timer Expiration')
|
||||
reenforcement_type = models.PositiveIntegerField('Timer Type', choices=TYPE_CHOICES)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
if self.expiration <= now():
|
||||
return self.STATE_EXPIRED
|
||||
return self.STATE_ACTIVE
|
||||
|
||||
class Meta:
|
||||
app_label = 'timer'
|
||||
ordering = ['-expiration']
|
||||
29
app/timer/models/utils.py
Normal file
29
app/timer/models/utils.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from django.db.models.fields.related import SingleRelatedObjectDescriptor
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
class InheritanceQuerySet(QuerySet):
|
||||
def select_subclasses(self, *subclasses):
|
||||
if not subclasses:
|
||||
subclasses = [o for o in dir(self.model)
|
||||
if isinstance(getattr(self.model, o), SingleRelatedObjectDescriptor)\
|
||||
and issubclass(getattr(self.model,o).related.model, self.model)]
|
||||
new_qs = self.select_related(*subclasses)
|
||||
new_qs.subclasses = subclasses
|
||||
return new_qs
|
||||
|
||||
def _clone(self, klass=None, setup=False, **kwargs):
|
||||
try:
|
||||
kwargs.update({'subclasses': self.subclasses})
|
||||
except AttributeError:
|
||||
pass
|
||||
return super(InheritanceQuerySet, self)._clone(klass, setup, **kwargs)
|
||||
|
||||
def iterator(self):
|
||||
iter = super(InheritanceQuerySet, self).iterator()
|
||||
if getattr(self, 'subclasses', False):
|
||||
for obj in iter:
|
||||
obj = [getattr(obj, s) for s in self.subclasses if getattr(obj, s)] or [obj]
|
||||
yield obj[0]
|
||||
else:
|
||||
for obj in iter:
|
||||
yield obj
|
||||
3
app/timer/templates/timer/timer_list.html
Normal file
3
app/timer/templates/timer/timer_list.html
Normal file
@@ -0,0 +1,3 @@
|
||||
{% for timer in timer_list %}
|
||||
{{ timer.location.name }} - {{ timer.expiration_datetime }}
|
||||
{% endfor %}
|
||||
16
app/timer/tests.py
Normal file
16
app/timer/tests.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
||||
6
app/timer/urls.py
Normal file
6
app/timer/urls.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.conf.urls import patterns, url
|
||||
from timer.views import TimerListView
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^$', TimerListView.as_view(), name='timer-list'),
|
||||
)
|
||||
14
app/timer/views.py
Normal file
14
app/timer/views.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from django.views.generic import ListView
|
||||
from django.utils.timezone import now
|
||||
from timer.models import Timer
|
||||
|
||||
|
||||
class TimerListView(ListView):
|
||||
model = Timer
|
||||
|
||||
def get_queryset(self):
|
||||
qs = super(TimerListView, self).get_queryset()
|
||||
if 'active' in self.kwargs:
|
||||
qs = qs.filter(expiry_datetime__gt=now())
|
||||
return qs
|
||||
|
||||
Reference in New Issue
Block a user