Fleetup removal

This commit is contained in:
colcrunch 2020-01-16 03:54:18 +00:00
parent a5fe61eb15
commit 46d46ac90b
18 changed files with 23 additions and 1527 deletions

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
def remove_permission(apps, schema_editor):
User = apps.get_model('auth', 'User')
ContentType = apps.get_model('contenttypes', 'ContentType')
Permission = apps.get_model('auth', 'Permission')
ct = ContentType.objects.get_for_model(User)
Permission.objects.filter(codename="view_fleetup", content_type=ct, name="view_fleetup").delete()
class Migration(migrations.Migration):
dependencies = [
('authentication', '0016_ownershiprecord'),
]
operations = [
migrations.RunPython(remove_permission, migrations.RunPython.noop)
]

View File

@ -1 +0,0 @@
default_app_config = 'allianceauth.fleetup.apps.FleetupConfig'

View File

@ -1,6 +0,0 @@
from django.apps import AppConfig
class FleetupConfig(AppConfig):
name = 'allianceauth.fleetup'
label = 'fleetup'

View File

@ -1,27 +0,0 @@
from allianceauth.services.hooks import MenuItemHook, UrlHook
from allianceauth import hooks
from . import urls
class FleetUpMenu(MenuItemHook):
def __init__(self):
MenuItemHook.__init__(self, 'Fleet-Up',
'fa fa-arrow-up fa-fw',
'fleetup:view',
navactive=['fleetup:'])
def render(self, request):
if request.user.has_perm('auth.view_fleetup'):
return MenuItemHook.render(self, request)
return ''
@hooks.register('menu_item_hook')
def register_menu():
return FleetUpMenu()
@hooks.register('url_hook')
def register_url():
return UrlHook(urls, 'fleetup', r'^fleetup/')

View File

@ -1,189 +0,0 @@
from django.conf import settings
from django.core.cache import cache
from django.utils import timezone
from datetime import datetime
import logging
import requests
import hashlib
logger = logging.getLogger(__name__)
class FleetUpManager:
APP_KEY = settings.FLEETUP_APP_KEY
USER_ID = settings.FLEETUP_USER_ID
API_ID = settings.FLEETUP_API_ID
GROUP_ID = settings.FLEETUP_GROUP_ID
BASE_URL = "http://api.fleet-up.com/Api.svc/{}/{}/{}".format(APP_KEY, USER_ID, API_ID)
TZ = timezone.utc
def __init__(self):
pass
@classmethod
def _request_cache_key(cls, url):
h = hashlib.sha1()
h.update(url.encode('utf-8'))
return 'FLEETUP_ENDPOINT_' + h.hexdigest()
@classmethod
def _cache_until_seconds(cls, cache_until_json):
# Format comes in like "/Date(1493896236163)/"
try:
epoch_ms = int(cache_until_json[6:-2])
cache_delta = datetime.fromtimestamp(epoch_ms/1000) - datetime.now()
cache_delta_seconds = cache_delta.total_seconds()
if cache_delta_seconds < 0:
return 0
elif cache_delta_seconds > 3600:
return 3600
else:
return cache_delta_seconds
except TypeError:
logger.debug("Couldn't convert CachedUntil time, defaulting to 600 seconds")
return 600
@classmethod
def get_endpoint(cls, url):
try:
cache_key = cls._request_cache_key(url)
cached = cache.get(cache_key)
if cached:
return cached
r = requests.get(url)
r.raise_for_status()
json = r.json()
if json['Success']:
cache.set(cache_key, json, cls._cache_until_seconds(json['CachedUntilUTC']))
return json
except requests.exceptions.ConnectionError:
logger.warning("Can't connect to Fleet-Up API, is it offline?!")
except requests.HTTPError:
logger.exception("Error accessing Fleetup API")
return None
@classmethod
def get_fleetup_members(cls):
url = "{}/GroupCharacters/{}".format(cls.BASE_URL, cls.GROUP_ID)
try:
fmembers = cls.get_endpoint(url)
if not fmembers:
return None
return {row["UserId"]: {"user_id": row["UserId"],
"char_name": row["EveCharName"],
"char_id": row["EveCharId"],
"corporation": row["Corporation"]} for row in fmembers["Data"]}
except (ValueError, UnicodeDecodeError, TypeError):
logger.debug("No fleetup members retrieved.")
return {}
@classmethod
def get_fleetup_operations(cls):
url = "{}/Operations/{}".format(cls.BASE_URL, cls.GROUP_ID)
foperations = cls.get_endpoint(url)
if foperations is None:
return None
return {row["StartString"]: {"subject": row["Subject"],
"start": timezone.make_aware(
datetime.strptime(row["StartString"], "%Y-%m-%d %H:%M:%S"), cls.TZ),
"end": timezone.make_aware(
datetime.strptime(row["EndString"], "%Y-%m-%d %H:%M:%S"), cls.TZ),
"operation_id": row["OperationId"],
"location": row["Location"],
"location_info": row["LocationInfo"],
"details": row["Details"],
"url": row["Url"],
"doctrine": row["Doctrines"],
"organizer": row["Organizer"]} for row in foperations["Data"]}
@classmethod
def get_fleetup_timers(cls):
url = "{}/Timers/{}".format(cls.BASE_URL, cls.GROUP_ID)
ftimers = cls.get_endpoint(url)
if not ftimers:
return None
return {row["ExpiresString"]: {"solarsystem": row["SolarSystem"],
"planet": row["Planet"],
"moon": row["Moon"],
"owner": row["Owner"],
"type": row["Type"],
"timer_type": row["TimerType"],
"expires": timezone.make_aware(
datetime.strptime(row["ExpiresString"], "%Y-%m-%d %H:%M:%S"), cls.TZ),
"notes": row["Notes"]} for row in ftimers["Data"]}
@classmethod
def get_fleetup_doctrines(cls):
url = "{}/Doctrines/{}".format(cls.BASE_URL, cls.GROUP_ID)
fdoctrines = cls.get_endpoint(url)
if not fdoctrines:
return None
return {"fleetup_doctrines": fdoctrines["Data"]}
@classmethod
def get_fleetup_doctrine(cls, doctrinenumber):
url = "{}/DoctrineFittings/{}".format(cls.BASE_URL, doctrinenumber)
fdoctrine = cls.get_endpoint(url)
if not fdoctrine:
return None
return {"fitting_doctrine": fdoctrine}
@classmethod
def get_fleetup_fittings(cls):
url = "{}/Fittings/{}".format(cls.BASE_URL, cls.GROUP_ID)
ffittings = cls.get_endpoint(url)
if not ffittings:
return None
return {row["FittingId"]: {"fitting_id": row["FittingId"],
"name": row["Name"],
"icon_id": row["EveTypeId"],
"hull": row["HullType"],
"shiptype": row["ShipType"],
"estimated": row["EstPrice"],
"faction": row["Faction"],
"categories": row["Categories"],
"last_update":
timezone.make_aware(
datetime.strptime(row["LastUpdatedString"], "%Y-%m-%d %H:%M:%S"), cls.TZ)}
for row in ffittings["Data"]}
@classmethod
def get_fleetup_fitting(cls, fittingnumber):
url = "{}/Fitting/{}".format(cls.BASE_URL, fittingnumber)
try:
ffitting = cls.get_endpoint(url)
if not ffitting:
return None
return {"fitting_data": ffitting["Data"]}
except KeyError:
logger.warning("Failed to retrieve fleetup fitting number %s" % fittingnumber)
return {"fitting_data": {}}
@classmethod
def get_fleetup_doctrineid(cls, fittingnumber):
url = "{}/Fitting/{}".format(cls.BASE_URL, fittingnumber)
try:
fdoctrineid = cls.get_endpoint(url)
if not fdoctrineid:
return None
return fdoctrineid['Data']['Doctrines'][0]['DoctrineId']
except (KeyError, IndexError):
logger.debug("Fleetup fitting number %s not in a doctrine." % fittingnumber)
return {}
@classmethod
def get_fleetup_fitting_eft(cls, fittingnumber):
url = "{}/Fitting/{}/eft".format(cls.BASE_URL, fittingnumber)
try:
ffittingeft = cls.get_endpoint(url)
if not ffittingeft:
return None
return {"fitting_eft": ffittingeft["Data"]["FittingData"]}
except KeyError:
logger.warning("Fleetup fitting eft not found for fitting number %s" % fittingnumber)
return {"fitting_eft": {}}

View File

@ -1,48 +0,0 @@
{% extends "allianceauth/base.html" %}
{% load bootstrap %}
{% load staticfiles %}
{% load i18n %}
{% block page_title %}Characters - FleetUp{% endblock page_title %}
{% block content %}
<div class="col-lg-12">
{% if perms.auth.corp_stats %}
{% include "fleetup/menu.html" %}
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{% trans "Characters registered on Fleet-Up.com" %}</h3>
</div>
<div class="panel-body">
<div class="col-lg-6">
<div class="table-responsive">
<table class="table table-condensed table-hover table-striped">
<tr>
<th class="col-md-1"></th>
<th class="col-md-1">{% trans "Character" %}</th>
<th class="col-md-1">{% trans "Corporation" %}</th>
<th class="col-md-1">Fleet-Up(id)</th>
</tr>
{% for char_name, user_id in member_list %}
<tr>
<td>
<img src="https://imageserver.eveonline.com/Character/{{ user_id.char_id }}_32.jpg" class="img-circle">
</td>
<td>
<p>{{ user_id.char_name }}</p>
</td>
<td>
<p>{{ user_id.corporation }}</p>
</td>
<td>
<p>{{ user_id.user_id }}</p>
</td>
{% endfor %}
</table>
</div>
</div>
</div>
</div>
{% endif %}
</div>
{% endblock content %}

View File

@ -1,67 +0,0 @@
{% extends "allianceauth/base.html" %}
{% load bootstrap %}
{% load staticfiles %}
{% load i18n %}
{% block page_title %}Doctrine - FleetUp{% endblock page_title %}
{% block content %}
<div class="col-lg-12">
{% include "fleetup/menu.html" %}
<div>
{% for a, j in doctrine.items %}
{% regroup j.Data|dictsort:"Role" by Role as role_list %}
{% for Role in role_list %}
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><b>{{ Role.grouper }}</b></h3>
</div>
<div class="panel-body">
<table class="table table-condensed table-hover table-striped">
<tr>
<th class="col-md-1"></th>
<th class="col-md-1">{% trans "Name" %}</th>
<th class="col-md-1">{% trans "Role" %}</th>
<th class="col-md-1">{% trans "Hull type" %}</th>
<th class="col-md-1">{% trans "Ship type" %}</th>
<th class="col-md-1">{% trans "Estimated ISK" %}</th>
<th class="col-md-2">{% trans "Categories" %}</th>
</tr>
{% for item in Role.list %}
<tr>
<td>
<a href="{% url 'fleetup:fitting' item.FittingId %}"><img src="https://image.eveonline.com/InventoryType/{{ item.EveTypeId }}_32.png"></a>
</td>
<td>
{{ item.Name }}
</td>
<td>
{{ item.Role }}
</td>
<td>
{{ item.HullType }}
</td>
<td>
{{ item.ShipType }}
</td>
<td>
{% load humanize %}{{ item.EstPrice|intword }}
</td>
<td>
{% for categories in item.Categories %}
{{ categories }},
{% endfor %}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endblock content %}

View File

@ -1,62 +0,0 @@
{% extends "allianceauth/base.html" %}
{% load bootstrap %}
{% load staticfiles %}
{% load i18n %}
{% block page_title %}Doctrines - FleetUp{% endblock page_title %}
{% block content %}
<div class="col-lg-12">
{% include "fleetup/menu.html" %}
<div>
{% if doctrines_list %}
{% for a, j in doctrines_list.items %}
{% regroup j|dictsort:"FolderName" by FolderName as folder_list %}
{% for FolderName in folder_list %}
<div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><b>{{ FolderName.grouper }}</b></h3>
</div>
<div class="panel-body">
<table class="table table-condensed table-hover table-striped">
<tr>
<th class="col-lg-1"></th>
<th class="col-lg-4">{% trans "Name" %}</th>
<th class="col-lg-3">{% trans "Doctrine" %}</th>
<th class="col-lg-4">{% trans "Last updated" %}</th>
<!--<th class="col-lg-1">Owner</th>
<th class="col-lg-2">Note</th>-->
</tr>
{% for item in FolderName.list %}
<tr>
<td>
<a href="{% url 'fleetup:doctrine' item.DoctrineId %}"><img src="https://image.eveonline.com/InventoryType/{{ item.IconId }}_32.png"></a>
</td>
<td>
{{ item.Name }}
</td>
<td>
<a href="{% url 'fleetup:doctrine' item.DoctrineId %}" class="btn btn-info btn-sm">{{ item.FolderName }}</a>
</td>
<td>
{{ item.LastUpdatedString }}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
{% else %}
<h3>{% trans "There seems to be no Doctrines in here at the moment!" %}</h3>
{% endif %}
</div>
</div>
{% endblock content %}

View File

@ -1,131 +0,0 @@
{% extends "allianceauth/base.html" %}
{% load bootstrap %}
{% load staticfiles %}
{% load i18n %}
{% block page_title %}{% trans "Doctrine - FleetUp" %}{% endblock page_title %}
{% block content %}
<div class="col-lg-12">
{% include "fleetup/menu.html" %}
<div class="tab-content row">
<div id="fit" class="tab-pane fade in active">
<div class="col-lg-4">
{% for x, y in fitting_data.items %}
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{% trans "This fit is part of a doctrine" %}</h3>
</div>
<div class="panel-body">
{% for doctrin in y.Doctrines %}
<div class="clearfix">
<h4>{{ doctrin.Name }}</h4>
<div class="col-lg-12">
<p>{% trans "Role in doctrine:" %} {{ doctrin.Role }}</p>
</div>
<div class="col-lg-4">
<p>{% trans "Priority:" %}</p>
</div>
<div class="col-lg-8">
<div class="progress">
<div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="{{ doctrin.Priority }}" aria-valuemin="0" aria-valuemax="5" style="width: {% widthratio doctrin.Priority 5 100 %}%;">
{{ doctrin.Priority }}/5
</div>
</div>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{% url 'fleetup:doctrine' doctrin.DoctrineId %}">{% trans "See doctrine" %}</a>
</div>
</div>
{% endfor %}
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{% trans "Fit categories" %}</h3>
</div>
<div class="panel-body">
{% for category in y.Categories %}
<span class="label label-success">{{ category }}</span>
{% endfor %}
</div>
</div>
{% endfor %}
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{% trans "All fits in this Doctrine" %}</h3>
</div>
<div class="panel-body">
<div class="list-group">
{% for arbit, orbit in doctrines_list.items %}
{% for fitting in orbit.Data %}
<a href="{% url 'fleetup:fitting' fitting.FittingId %}" class="list-group-item">
<h4 class="list-group-item-heading">{{ fitting.Name }}<span class="pull-right"><img src="https://image.eveonline.com/InventoryType/{{ fitting.EveTypeId }}_32.png" class="img-circle"></span></h4>
<p class="list-group-item-heading">{{ fitting.Role }} - {{ fitting.ShipType }}</p>
</a>
{% endfor %}
{% endfor %}
</div>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">
{% for a, j in fitting_data.items %}
<h3 class="panel-title">{{ j.Name }}</h3>
</div>
<div class="panel-body">
<div class="col-lg-3">
<img src="https://image.eveonline.com/InventoryType/{{ j.EveTypeId }}_64.png" class="img-responsive">
</div>
<div class="col-lg-9">
<p>{% trans "Hull:" %} <b>{{ j.HullType }}</b></p>
<p>{% trans "Ship:" %} <b>{{ j.ShipType }}</b></p>
{% load humanize %}
<p>{% trans "Estimated price:" %} <b>{{ j.EstPrice|intword }} ISK</b></p>
</div>
{% regroup j.FittingData by Slot as fitting_list %}
<table class="table table-condensed table-hover">
<tr>
<th class="col-lg-1"></th>
<th class="col-lg-11"></th>
</tr>
{% for Slot in fitting_list %}
<tr class="info">
<td></td><td><b>{{ Slot.grouper }}</b></td>
</tr>
{% for item in Slot.list %}
<tr>
<td><img src="https://image.eveonline.com/InventoryType/{{ item.TypeId }}_32.png" class="img-responsive"></td>
<td> {{ item.Quantity }}x {{ item.TypeName }}</td>
</tr>
{% endfor %}
{% endfor %}
</table>
</div>
{% endfor %}
</div>
</div>
<div class="col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{% trans "EFT/Export" %}</h3>
</div>
<div class="panel-body">
{% for data in fitting_eft.items %}
{% autoescape off %}
<textarea class="form-control" rows="25" spellcheck="false" onclick="this.focus();this.select()" readonly>{{ fitting_eft.fitting_eft }}</textarea>
{% endautoescape %}
{% endfor %}
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock content %}

View File

@ -1,55 +0,0 @@
{% extends "allianceauth/base.html" %}
{% load bootstrap %}
{% load staticfiles %}
{% load i18n %}
{% block page_title %}Fittings - FleetUp{% endblock page_title %}
{% block content %}
<div class="col-lg-12">
{% include "fleetup/menu.html" %}
<div class="panel">
{% if fitting_list %}
<table class="table table-condensed table-hover table-striped">
<tr>
<th class="col-md-1"></th>
<th class="col-md-1">{% trans "Name" %}</th>
<th class="col-md-1">{% trans "Hull" %}</th>
<th class="col-md-1">{% trans "Ship type" %}</th>
<th class="col-md-1">{% trans "Estimated ISK" %}</th>
<th class="col-md-2">{% trans "Categories" %}</th>
</tr>
{% for id, fittings in fitting_list %}
<tr>
<td>
<a href="{% url 'fleetup:fitting' fittings.fitting_id %}"><img src="https://image.eveonline.com/InventoryType/{{ fittings.icon_id }}_32.png"></a>
</td>
<td>
{{ fittings.name }}
</td>
<td>
{{ fittings.hull }}
</td>
<td>
{{ fittings.shiptype }}
</td>
<td>
{% load humanize %}{{ fittings.estimated|intword }}
</td>
<td>
{% for categories in fittings.categories %}
{{ categories }},
{% endfor %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
<h3>{% trans "There seems to be no Fittings in here at the moment!" %}</h3>
{% endif %}
</div>
</div>
{% endblock content %}

View File

@ -1,254 +0,0 @@
{% extends "allianceauth/base.html" %}
{% load bootstrap %}
{% load staticfiles %}
{% load i18n %}
{% block page_title %}FleetUp{% endblock page_title %}
{% block content %}
<div class="col-lg-12">
{% include "fleetup/menu.html" %}
<div>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#operations">{% trans "Operations" %}</a></li>
<li><a data-toggle="tab" href="#timers">{% trans "Timers" %}</a></li>
</ul>
<div class="tab-content row">
<div id="operations" class="tab-pane fade in active">
<div class="col-lg-8">
{% if operations_list %}
{% for subject, start in operations_list %}
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><b>{{ start.subject }}</b></h3>
</div>
<div class="panel-body">
<table class="table table-condensed">
<tr>
<th class="col-md-6">{% trans "Start" %}</th>
<th class="col-md-6">{% trans "End" %}</th>
</tr>
<tr>
<td class="col-md-6">{{ start.start|date:"l d M H:i" }} <span class="label label-success">{% trans "Eve Time" %}</span></td>
<td class="col-md-6">{{ start.end|date:"l d M H:i" }} <span class="label label-success">{% trans "Eve Time" %}</span></td>
</tr>
<tr>
<td class="col-md-6">
<span id="localtime{{ start.operation_id }}"></span>&nbsp;<span class='label label-success'>Local time</span><br>
<div id="countdown{{ start.operation_id }}"></div>
</td>
<td class="col-md-6"></td>
</tr>
</table>
{{ start.details|linebreaks }}
<table class="table table-condensed table-striped">
<tr>
<th class="col-md-4">{% trans "Location" %}</th>
<th class="col-md-4">{% trans "Doctrine" %}</th>
<th class="col-md-2">{% trans "Organizer" %}</th>
<th class="col-md-2">{% trans "URL" %}</th>
</tr>
<tr>
<td>
{{ start.location }} - {{ start.location_info }} <a href="http://evemaps.dotlan.net/system/{{ start.location }}" target="_blank" class="label label-success">Dotlan</a>
</td>
<td>
{% if start.doctrine %}
{% for doctrine in start.doctrine %}
<a href="{% url 'fleetup:doctrine' doctrine.Id %}" class="label label-success">{{ doctrine.Name }}</a>
{% endfor %}
{% else %}
<span class="label label-danger">{% trans "TBA" %}</span>
{% endif %}
</td>
<td>
{{ start.organizer }}
</td>
<td>
{% ifequal start.url "" %}
<div class="label label-danger">{% trans "No link" %}</div>
{% else %}
<a href="{{ start.url }}" target="_blank" class="label label-success">{% trans "External link" %}</a>
{% endifequal %}
</td>
</tr>
</table>
</div>
</div>
{% endfor %}
{% else %}
<h3>{% trans "There seems to be no Operations in the near future." %}</h3>
{% endif %}
</div>
<div class="col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">{% trans "Current Eve Time:" %}</h2>
</div>
<div class="panel-body">
<div id="current-time"></div>
</div>
</div>
{% if timers_list %}
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">{% trans "Timers" %}</h2>
</div>
<div class="panel-body">
<table class="table table-condensed table-hover table-striped">
{% for notes, type in timers_list %}
<tr>
<td>
{{ type.solarsystem }}
</td>
<td>
{{ type.expires|date:"l d M H:i" }}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endif %}
</div>
</div>
<div id="timers" class="tab-pane fade in">
<div class="col-lg-12">
{% if timers_list %}
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">{% trans "Timers" %}</h2>
</div>
<div class="panel-body">
<div class="col-lg-12">
<table class="table table-condensed table-hover table-striped">
<tr>
<th class="col-lg-1">{% trans "Type" %}</th>
<th class="col-lg-1">{% trans "Structure" %}</th>
<th class="col-lg-2">{% trans "Location" %}</th>
<th class="col-lg-2">{% trans "Expires(EVE-time)" %}</th>
<th class="col-lg-1">{% trans "Owner" %}</th>
<th class="col-lg-2">{% trans "Note" %}</th>
</tr>
{% for notes, type in timers_list %}
<tr>
<td>
{% ifequal type.type "Final" %}
<span class="label label-danger">
{{ type.type }}</span>{% else %}{{ type.type }}{% endifequal %}
</td>
<td>
{{ type.timer_type }}
</td>
<td>
{{ type.solarsystem }} - Planet:{{ type.planet }} Moon:{{ type.moon }}
</td>
<td>
{{ type.expires|date:"l d M H:i" }}
</td>
<td>
{{ type.owner }}
</td>
<td>
{{ type.notes }}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% else %}
<h3>{% trans "There seems to be no Timers in the near future." %}</h3>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% include 'bundles/moment-js.html' with locale=True %}
<script src="{% static 'js/timers.js' %}"></script>
<script type="text/javascript">
// Data
var timers = [
{% for start, op in operations_list %}
{
'id': {{ op.operation_id }},
'start': moment("{{ op.start | date:"c" }}"),
'end': moment("{{ op.end | date:"c" }}"),
'expired': false
},
{% endfor %}
]
</script>
<script type="text/javascript">
timedUpdate();
setAllLocalTimes();
// Start timed updates
setInterval(timedUpdate, 1000);
function timedUpdate() {
updateClock();
updateAllTimers();
}
function updateAllTimers () {
var l = timers.length;
for (var i=0; i < l; ++i) {
if (timers[i].expired) continue;
updateTimer(timers[i]);
}
}
/**
* Update a timer
* @param timer Timer information
* @param timer.start Date of the timer
* @param timer.id Id number of the timer
* @param timer.expired
*/
function updateTimer(timer) {
if (timer.start.isAfter(Date.now())) {
var duration = moment.duration(timer.start - moment(), 'milliseconds');
document.getElementById("countdown" + timer.id).innerHTML = getDurationString(duration);
} else {
timer.expired = true;
document.getElementById("countdown" + timer.id).innerHTML = "";
}
}
/**
* Set all local time fields
*/
function setAllLocalTimes() {
var l = timers.length;
for (var i=0; i < l; ++i) {
setLocalTime(timers[i]);
}
}
/**
* Set the local time info for the timer
* @param timer Timer information
* @param timer.start Date of the timer
* @param timer.id Id number of the timer
*/
function setLocalTime(timer) {
document.getElementById("localtime" + timer.id).innerHTML = timer.start.format("ddd @ LT");
}
function updateClock() {
document.getElementById("current-time").innerHTML = "<b>" + moment.utc().format('ddd, ll HH:mm:ss z') + "</b>";
}
</script>
{% endblock content %}

View File

@ -1,26 +0,0 @@
{% load i18n %}
{% load navactive %}
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">{% trans "Toggle navigation" %}</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Fleet-Up</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="{% navactive request 'fleetup:view' %}"><a href="{% url 'fleetup:view' %}">{% trans "Ops and Timers" %}</a></li>
<li class="{% navactive request 'fleetup:doctrines fleetup:doctrine' %}"><a href="{% url 'fleetup:doctrines' %}">{% trans "Doctrines" %}</a></li>
<li class="{% navactive request 'fleetup:fittings fleetup:fitting' %}"><a href="{% url 'fleetup:fittings' %}">{% trans "Fittings" %}</a></li>
{% if perms.auth.corp_stats %}
<li class="{% navactive request 'fleetup:characters' %}"><a href="{% url 'fleetup:characters' %}">{% trans "Characters" %}</a></li>
{% endif %}
</ul>
</div>
</div>
</nav>

View File

@ -1,503 +0,0 @@
from unittest import mock
import requests_mock
import json
import datetime
from django.test import TestCase
from django.utils.timezone import make_aware, utc
from allianceauth.fleetup.managers import FleetUpManager
class FleetupManagerTestCase(TestCase):
def setUp(self):
pass
def test__request_cache_key(self):
cache_key = FleetUpManager._request_cache_key('testurl')
self.assertEqual('FLEETUP_ENDPOINT_a39562b6ef5b858220be13d2adb61d3f10cf8d61',
cache_key)
@mock.patch('allianceauth.fleetup.managers.cache')
@requests_mock.Mocker()
def test_get_endpoint(self, cache, m):
url = "http://example.com/test/endpoint/"
json_data = {'data': "123456", 'CachedUntilUTC': '/Date(1493896236163)/', 'Success': True}
m.register_uri('GET', url,
text=json.dumps(json_data))
cache.get.return_value = None # No cached value
# Act
result = FleetUpManager.get_endpoint(url)
# Assert
self.assertTrue(cache.get.called)
self.assertTrue(cache.set.called)
args, kwargs = cache.set.call_args
self.assertDictEqual(json_data, args[1])
self.assertDictEqual(json_data, result)
@mock.patch('allianceauth.fleetup.managers.cache')
@requests_mock.Mocker()
def test_get_endpoint_error(self, cache, m):
url = "http://example.com/test/endpoint/"
json_data = {'data': [], 'Success': False}
m.register_uri('GET', url,
text=json.dumps(json_data),
status_code=400)
cache.get.return_value = None # No cached value
# Act
result = FleetUpManager.get_endpoint(url)
# Assert
self.assertTrue(cache.get.called)
self.assertFalse(cache.set.called)
self.assertIsNone(result)
@mock.patch('allianceauth.fleetup.managers.FleetUpManager.get_endpoint')
def test_get_fleetup_members(self, get_endpoint):
get_endpoint.return_value = {"Data": [
{
'UserId': 1234,
'EveCharName': 'test_name',
'EveCharId': 5678,
'Corporation': 'test_corporation',
}
]}
# Act
result = FleetUpManager.get_fleetup_members()
# Asset
self.assertTrue(get_endpoint.called)
args, kwargs = get_endpoint.call_args
self.assertEqual(args[0],
FleetUpManager.BASE_URL + '/GroupCharacters/' +
FleetUpManager.GROUP_ID)
expected_result = {
1234: {
'user_id': 1234,
'char_name': 'test_name',
'char_id': 5678,
'corporation': 'test_corporation',
}
}
self.assertDictEqual(expected_result, result)
# Test None response
# Arrange
get_endpoint.return_value = None
# Act
result = FleetUpManager.get_fleetup_members()
# Assert
self.assertIsNone(result)
# Test Empty response
# Arrange
get_endpoint.return_value = {'Data': []}
# Act
result = FleetUpManager.get_fleetup_members()
# Assert
self.assertDictEqual({}, result)
@mock.patch('allianceauth.fleetup.managers.FleetUpManager.get_endpoint')
def test_get_fleetup_operations(self, get_endpoint):
get_endpoint.return_value = {"Data": [
{
'Subject': 'test_operation',
'StartString': '2017-05-06 11:11:11',
'EndString': '2017-05-06 12:12:12',
'OperationId': 1234,
'Location': 'Jita',
'LocationInfo': '4-4',
'Details': 'This is a test operation',
'Url': 'http://example.com/1234',
'Doctrines': 'Foxcats',
'Organizer': 'Example FC'
}
]}
# Act
result = FleetUpManager.get_fleetup_operations()
self.maxDiff = None
# Asset
self.assertTrue(get_endpoint.called)
args, kwargs = get_endpoint.call_args
self.assertEqual(args[0],
FleetUpManager.BASE_URL + '/Operations/' +
FleetUpManager.GROUP_ID)
expected_result = {
'2017-05-06 11:11:11': {
'subject': 'test_operation',
'start': make_aware(datetime.datetime(2017, 5, 6, 11, 11, 11), utc),
'end': make_aware(datetime.datetime(2017, 5, 6, 12, 12, 12), utc),
'operation_id': 1234,
'location': 'Jita',
'location_info': '4-4',
'details': 'This is a test operation',
'url': 'http://example.com/1234',
'doctrine': 'Foxcats',
'organizer': 'Example FC'
}
}
self.assertDictEqual(expected_result, result)
# Test None response
# Arrange
get_endpoint.return_value = None
# Act
result = FleetUpManager.get_fleetup_operations()
# Assert
self.assertIsNone(result)
# Test Empty response
# Arrange
get_endpoint.return_value = {'Data': []}
# Act
result = FleetUpManager.get_fleetup_operations()
# Assert
self.assertDictEqual({}, result)
@mock.patch('allianceauth.fleetup.managers.FleetUpManager.get_endpoint')
def test_get_fleetup_timers(self, get_endpoint):
get_endpoint.return_value = {"Data": [
{
'ExpiresString': '2017-05-06 11:11:11',
'SolarSystem': 'Jita',
'Planet': '4',
'Moon': '4',
'Owner': 'Caldari Navy',
'Type': 'Caldari Station',
'TimerType': 'Armor',
'Notes': 'Burn Jita?'
}
]}
# Act
result = FleetUpManager.get_fleetup_timers()
# Asset
self.assertTrue(get_endpoint.called)
args, kwargs = get_endpoint.call_args
self.assertEqual(args[0],
FleetUpManager.BASE_URL + '/Timers/' +
FleetUpManager.GROUP_ID)
expected_result = {
'2017-05-06 11:11:11': {
'expires': make_aware(datetime.datetime(2017, 5, 6, 11, 11, 11), utc),
'solarsystem': 'Jita',
'planet': '4',
'moon': '4',
'owner': 'Caldari Navy',
'type': 'Caldari Station',
'timer_type': 'Armor',
'notes': 'Burn Jita?'
}
}
self.assertDictEqual(expected_result, result)
# Test None response
# Arrange
get_endpoint.return_value = None
# Act
result = FleetUpManager.get_fleetup_timers()
# Assert
self.assertIsNone(result)
# Test Empty response
# Arrange
get_endpoint.return_value = {'Data': []}
# Act
result = FleetUpManager.get_fleetup_timers()
# Assert
self.assertDictEqual({}, result)
@mock.patch('allianceauth.fleetup.managers.FleetUpManager.get_endpoint')
def test_get_fleetup_doctrines(self, get_endpoint):
get_endpoint.return_value = {"Data": [
{
'TestData': True
}
]}
# Act
result = FleetUpManager.get_fleetup_doctrines()
# Asset
self.assertTrue(get_endpoint.called)
args, kwargs = get_endpoint.call_args
self.assertEqual(args[0],
FleetUpManager.BASE_URL + '/Doctrines/' +
FleetUpManager.GROUP_ID)
expected_result = {
'fleetup_doctrines': [{
'TestData': True
}]
}
self.assertDictEqual(expected_result, result)
# Test None response
# Arrange
get_endpoint.return_value = None
# Act
result = FleetUpManager.get_fleetup_doctrines()
# Assert
self.assertIsNone(result)
# Test Empty response
# Arrange
get_endpoint.return_value = {'Data': []}
# Act
result = FleetUpManager.get_fleetup_doctrines()
# Assert
self.assertDictEqual({"fleetup_doctrines": []}, result)
@mock.patch('allianceauth.fleetup.managers.FleetUpManager.get_endpoint')
def test_get_fleetup_doctrine(self, get_endpoint):
get_endpoint.return_value = {"Data": [
{
'TestData': True
}
]}
# Act
result = FleetUpManager.get_fleetup_doctrine(1234)
# Asset
self.assertTrue(get_endpoint.called)
args, kwargs = get_endpoint.call_args
self.assertEqual(args[0],
FleetUpManager.BASE_URL + '/DoctrineFittings/1234')
expected_result = {
'fitting_doctrine': {'Data': [{
'TestData': True
}]}
}
self.assertDictEqual(expected_result, result)
# Test None response
# Arrange
get_endpoint.return_value = None
# Act
result = FleetUpManager.get_fleetup_doctrine(1234)
# Assert
self.assertIsNone(result)
# Test Empty response
# Arrange
get_endpoint.return_value = {'Data': []}
# Act
result = FleetUpManager.get_fleetup_doctrine(1234)
# Assert
self.assertDictEqual({"fitting_doctrine": {'Data': []}}, result)
@mock.patch('allianceauth.fleetup.managers.FleetUpManager.get_endpoint')
def test_get_fleetup_fittings(self, get_endpoint):
get_endpoint.return_value = {"Data": [
{
'FittingId': 1234,
'Name': 'Foxcat',
'EveTypeId': 17726,
'HullType': 'Battleship',
'ShipType': 'Apocalypse Navy Issue',
'EstPrice': 500000000,
'Faction': 'Amarr',
'Categories': ["Armor", "Laser"],
'LastUpdatedString': '2017-05-06 11:11:11',
}
]}
# Act
result = FleetUpManager.get_fleetup_fittings()
# Asset
self.assertTrue(get_endpoint.called)
expected_result = {
1234: {
'fitting_id': 1234,
'name': 'Foxcat',
'icon_id': 17726,
'hull': 'Battleship',
'shiptype': 'Apocalypse Navy Issue',
'estimated': 500000000,
'faction': 'Amarr',
'categories': ["Armor", "Laser"],
'last_update': make_aware(datetime.datetime(2017, 5, 6, 11, 11, 11), utc)
}
}
self.assertDictEqual(expected_result, result)
# Test None response
# Arrange
get_endpoint.return_value = None
# Act
result = FleetUpManager.get_fleetup_fittings()
# Assert
self.assertIsNone(result)
# Test Empty response
# Arrange
get_endpoint.return_value = {'Data': []}
# Act
result = FleetUpManager.get_fleetup_fittings()
# Assert
self.assertDictEqual({}, result)
@mock.patch('allianceauth.fleetup.managers.FleetUpManager.get_endpoint')
def test_get_fleetup_fitting(self, get_endpoint):
get_endpoint.return_value = {"Data":
{
'FittingData': [{}]
}
}
# Act
result = FleetUpManager.get_fleetup_fitting(1234)
# Asset
self.assertTrue(get_endpoint.called)
args, kwargs = get_endpoint.call_args
self.assertEqual(args[0], FleetUpManager.BASE_URL + '/Fitting/1234')
expected_result = {
'fitting_data': {
'FittingData': [{}]
}
}
self.assertDictEqual(expected_result, result)
# Test None response
# Arrange
get_endpoint.return_value = None
# Act
result = FleetUpManager.get_fleetup_fitting(1234)
# Assert
self.assertIsNone(result)
# Test Empty response
# Arrange
get_endpoint.return_value = {'Data': {}}
# Act
result = FleetUpManager.get_fleetup_fitting(1234)
# Assert
self.assertDictEqual({"fitting_data": {}}, result)
@mock.patch('allianceauth.fleetup.managers.FleetUpManager.get_endpoint')
def test_get_fleetup_doctrineid(self, get_endpoint):
get_endpoint.return_value = {
"Data": {
'Doctrines': [{'DoctrineId': 4567}]
}
}
# Act
result = FleetUpManager.get_fleetup_doctrineid(1234)
# Asset
self.assertTrue(get_endpoint.called)
args, kwargs = get_endpoint.call_args
self.assertEqual(args[0], FleetUpManager.BASE_URL + '/Fitting/1234')
self.assertEqual(4567, result)
# Test None response
# Arrange
get_endpoint.return_value = None
# Act
result = FleetUpManager.get_fleetup_doctrineid(1234)
# Assert
self.assertIsNone(result)
# Test Empty response
# Arrange
get_endpoint.return_value = {'Data': {}}
# Act
result = FleetUpManager.get_fleetup_doctrineid(1234)
# Assert
self.assertDictEqual({}, result)
@mock.patch('allianceauth.fleetup.managers.FleetUpManager.get_endpoint')
def test_get_fleetup_fitting_eft(self, get_endpoint):
get_endpoint.return_value = {
"Data": {
'FittingData': '[Apocalypse Navy Issue, Foxcat]'
}
}
# Act
result = FleetUpManager.get_fleetup_fitting_eft(1234)
# Asset
self.assertTrue(get_endpoint.called)
args, kwargs = get_endpoint.call_args
self.assertEqual(args[0], FleetUpManager.BASE_URL + '/Fitting/1234/eft')
self.assertDictEqual({"fitting_eft": '[Apocalypse Navy Issue, Foxcat]'},
result)
# Test None response
# Arrange
get_endpoint.return_value = None
# Act
result = FleetUpManager.get_fleetup_fitting_eft(1234)
# Assert
self.assertIsNone(result)
# Test Empty response
# Arrange
get_endpoint.return_value = {'Data': {}}
# Act
result = FleetUpManager.get_fleetup_fitting_eft(1234)
# Assert
self.assertDictEqual({"fitting_eft": {}}, result)

View File

@ -1,14 +0,0 @@
from django.conf.urls import url
from . import views
app_name = 'fleetup'
urlpatterns = [
url(r'^$', views.fleetup_view, name='view'),
url(r'^fittings/$', views.fleetup_fittings, name='fittings'),
url(r'^fittings/(?P<fittingnumber>[0-9]+)/$', views.fleetup_fitting, name='fitting'),
url(r'^doctrines/$', views.fleetup_doctrines, name='doctrines'),
url(r'^characters/$', views.fleetup_characters, name='characters'),
url(r'^doctrines/(?P<doctrinenumber>[0-9]+)/$', views.fleetup_doctrine, name='doctrine'),
]

View File

@ -1,112 +0,0 @@
import datetime
import logging
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import permission_required
from django.shortcuts import render
from django.template.defaulttags import register
from django.utils.translation import ugettext_lazy as _
from .managers import FleetUpManager
logger = logging.getLogger(__name__)
@register.filter
def get_item(dictionary, key):
return dictionary.get(key)
@login_required
@permission_required('auth.view_fleetup')
def fleetup_view(request):
logger.debug("fleetup_view called by user %s" % request.user)
operations_list = FleetUpManager.get_fleetup_operations()
if operations_list is None:
messages.add_message(request, messages.ERROR, _("Failed to get operations list, contact your administrator"))
operations_list = {}
timers_list = FleetUpManager.get_fleetup_timers()
if timers_list is None:
messages.add_message(request, messages.ERROR, _("Failed to get timers list, contact your administrator"))
timers_list = {}
now = datetime.datetime.now().strftime('%H:%M:%S')
context = {"timers_list": sorted(timers_list.items()),
"operations_list": sorted(operations_list.items()),
"now": now}
return render(request, 'fleetup/index.html', context=context)
@login_required
@permission_required('auth.human_resources')
@permission_required('auth.view_fleetup')
def fleetup_characters(request):
logger.debug("fleetup_characters called by user %s" % request.user)
member_list = FleetUpManager.get_fleetup_members()
if member_list is None:
messages.add_message(request, messages.ERROR, _("Failed to get member list, contact your administrator"))
member_list = {}
context = {"member_list": sorted(member_list.items())}
return render(request, 'fleetup/characters.html', context=context)
@login_required
@permission_required('auth.view_fleetup')
def fleetup_fittings(request):
logger.debug("fleetup_fittings called by user %s" % request.user)
fitting_list = FleetUpManager.get_fleetup_fittings()
if fitting_list is None:
messages.add_message(request, messages.ERROR, _("Failed to get fitting list, contact your administrator"))
fitting_list = {}
context = {"fitting_list": sorted(fitting_list.items())}
return render(request, 'fleetup/fittingsview.html', context=context)
@login_required
@permission_required('auth.view_fleetup')
def fleetup_fitting(request, fittingnumber):
logger.debug("fleetup_fitting called by user %s" % request.user)
fitting_eft = FleetUpManager.get_fleetup_fitting_eft(fittingnumber)
fitting_data = FleetUpManager.get_fleetup_fitting(fittingnumber)
doctrinenumber = FleetUpManager.get_fleetup_doctrineid(fittingnumber)
doctrines_list = FleetUpManager.get_fleetup_doctrine(doctrinenumber)
if fitting_eft is None or fitting_data is None or doctrinenumber is None:
messages.add_message(request, messages.ERROR, _("There was an error getting some of the data for this fitting. "
"Contact your administrator"))
context = {"fitting_eft": fitting_eft,
"fitting_data": fitting_data,
"doctrines_list": doctrines_list}
return render(request, 'fleetup/fitting.html', context=context)
@login_required
@permission_required('auth.view_fleetup')
def fleetup_doctrines(request):
logger.debug("fleetup_doctrines called by user %s" % request.user)
doctrines_list = FleetUpManager.get_fleetup_doctrines()
if doctrines_list is None:
messages.add_message(request, messages.ERROR, _("Failed to get doctrines list, contact your administrator"))
context = {"doctrines_list": doctrines_list}
return render(request, 'fleetup/doctrinesview.html', context=context)
@login_required
@permission_required('auth.view_fleetup')
def fleetup_doctrine(request, doctrinenumber):
logger.debug("fleetup_doctrine called by user %s" % request.user)
doctrine = FleetUpManager.get_fleetup_doctrine(doctrinenumber)
if doctrine is None:
messages.add_message(request, messages.ERROR, _("Failed to get doctine, contact your administrator"))
context = {"doctrine": doctrine}
return render(request, 'fleetup/doctrine.html', context=context)

View File

@ -1,18 +0,0 @@
# Fleetup
## Installation
Add `'allianceauth.fleetup',` to your auth project's `INSTALLED_APPS` list.
Additional settings are required. Append the following settings to the end of your auth project's settings file and fill them out.
FLEETUP_APP_KEY = '' # The app key from http://fleet-up.com/Api/MyApps
FLEETUP_USER_ID = '' # The user id from http://fleet-up.com/Api/MyKeys
FLEETUP_API_ID = '' # The API id from http://fleet-up.com/Api/MyKeys
FLEETUP_GROUP_ID = '' # The id of the group you want to pull data from, see http://fleet-up.com/Api/Endpoints#groups_mygroupmemberships
Once filled out restart Gunicorn and Celery.
## Permissions
The Fleetup module is only visible to users with the `auth | user | view_fleeup` permission.

View File

@ -24,7 +24,6 @@ INSTALLED_APPS += [
'allianceauth.optimer',
'allianceauth.corputils',
'allianceauth.fleetactivitytracking',
'allianceauth.fleetup',
'allianceauth.permissions_tool',
'allianceauth.services.modules.mumble',
'allianceauth.services.modules.discord',
@ -174,19 +173,6 @@ SEAT_XTOKEN = 'tokentokentoken'
######################################
SMF_URL = ''
######################################
# Fleet-Up Configuration
######################################
# FLEETUP_APP_KEY - The app key from http://fleet-up.com/Api/MyApps
# FLEETUP_USER_ID - The user id from http://fleet-up.com/Api/MyKeys
# FLEETUP_API_ID - The API id from http://fleet-up.com/Api/MyKeys
# FLEETUP_GROUP_ID - The id of the group you want to pull data from, see http://fleet-up.com/Api/Endpoints#groups_mygroupmemberships
######################################
FLEETUP_APP_KEY = ''
FLEETUP_USER_ID = ''
FLEETUP_API_ID = ''
FLEETUP_GROUP_ID = ''
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.MD5PasswordHasher',
]