mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-08 20:10:17 +02:00
Merge branch 'structure-timer-updates' into 'master'
Timerboard Updates See merge request allianceauth/allianceauth!1674
This commit is contained in:
commit
a5971314f5
@ -0,0 +1,45 @@
|
||||
# Generated by Django 4.2.17 on 2025-01-06 17:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("timerboard", "0006_alter_timer_objective_alter_timer_structure_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="timer",
|
||||
name="structure",
|
||||
field=models.CharField(
|
||||
choices=[
|
||||
("POCO", "POCO"),
|
||||
("Orbital Skyhook", "Orbital Skyhook"),
|
||||
("I-HUB", "Sovereignty Hub"),
|
||||
("TCU", "TCU"),
|
||||
("POS[S]", "POS [S]"),
|
||||
("POS[M]", "POS [M]"),
|
||||
("POS[L]", "POS [L]"),
|
||||
("Astrahus", "Astrahus"),
|
||||
("Fortizar", "Fortizar"),
|
||||
("Keepstar", "Keepstar"),
|
||||
("Raitaru", "Raitaru"),
|
||||
("Azbel", "Azbel"),
|
||||
("Sotiyo", "Sotiyo"),
|
||||
("Athanor", "Athanor"),
|
||||
("Tatara", "Tatara"),
|
||||
("Pharolux Cyno Beacon", "Cyno Beacon"),
|
||||
("Tenebrex Cyno Jammer", "Cyno Jammer"),
|
||||
("Ansiblex Jump Gate", "Ansiblex Jump Gate"),
|
||||
("Mercenary Den", "Mercenary Den"),
|
||||
("Moon Mining Cycle", "Moon Mining Cycle"),
|
||||
("Metenox Moon Drill", "Metenox Moon Drill"),
|
||||
("Other", "Other"),
|
||||
],
|
||||
default="Other",
|
||||
max_length=254,
|
||||
),
|
||||
),
|
||||
]
|
@ -1,6 +1,6 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from allianceauth.eveonline.models import EveCharacter
|
||||
from allianceauth.eveonline.models import EveCorporationInfo
|
||||
@ -23,7 +23,7 @@ class Timer(models.Model):
|
||||
|
||||
POCO = "POCO", _("POCO")
|
||||
ORBITALSKYHOOK = "Orbital Skyhook", _("Orbital Skyhook")
|
||||
IHUB = "I-HUB", _("I-HUB")
|
||||
IHUB = "I-HUB", _("Sovereignty Hub")
|
||||
TCU = "TCU", _("TCU") # Pending Remval
|
||||
POSS = "POS[S]", _("POS [S]")
|
||||
POSM = "POS[M]", _("POS [M]")
|
||||
@ -36,9 +36,10 @@ class Timer(models.Model):
|
||||
SOTIYO = "Sotiyo", _("Sotiyo")
|
||||
ATHANOR = "Athanor", _("Athanor")
|
||||
TATARA = "Tatara", _("Tatara")
|
||||
PHAROLUX = "Pharolux Cyno Beacon", _("Pharolux Cyno Beacon")
|
||||
TENEBREX = "Tenebrex Cyno Jammer", _("Tenebrex Cyno Jammer")
|
||||
PHAROLUX = "Pharolux Cyno Beacon", _("Cyno Beacon")
|
||||
TENEBREX = "Tenebrex Cyno Jammer", _("Cyno Jammer")
|
||||
ANSIBLEX = "Ansiblex Jump Gate", _("Ansiblex Jump Gate")
|
||||
MERCDEN = "Mercenary Den", _("Mercenary Den")
|
||||
MOONPOP = "Moon Mining Cycle", _("Moon Mining Cycle")
|
||||
METENOX = "Metenox Moon Drill", _("Metenox Moon Drill")
|
||||
OTHER = "Other", _("Other")
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
{% for timer in timers %}
|
||||
<tr class="{% if timer.important == True %}bg-danger bg-opacity-25{% else %}bg-info bg-opacity-25{% endif %}">
|
||||
|
||||
<td style="width: 150px;" class="text-center">
|
||||
{{ timer.details }}
|
||||
|
||||
@ -30,13 +29,21 @@
|
||||
</td>
|
||||
|
||||
<td class="text-center">
|
||||
{% comment %} Objective: Hostile (BG: Danger) {% endcomment %}
|
||||
{% if timer.objective == "Hostile" %}
|
||||
<div class="badge bg-danger">{% translate "Hostile" %}</div>
|
||||
<div class="badge bg-danger">
|
||||
|
||||
{% comment %} Objective: Friendly (BG: Primare) {% endcomment %}
|
||||
{% elif timer.objective == "Friendly" %}
|
||||
<div class="badge bg-primary">{% translate "Friendly" %}</div>
|
||||
<div class="badge bg-primary">
|
||||
|
||||
{% comment %} Objective: Neutral (BG: Secondary) {% endcomment %}
|
||||
{% elif timer.objective == "Neutral" %}
|
||||
<div class="badge bg-secondary">{% translate "Neutral" %}</div>
|
||||
<div class="badge bg-secondary">
|
||||
{% endif %}
|
||||
|
||||
{{ timer.get_objective_display }}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="text-center">
|
||||
@ -44,49 +51,9 @@
|
||||
</td>
|
||||
|
||||
<td class="text-center">
|
||||
{% if timer.structure == "POCO" %}
|
||||
<div class="badge bg-info">{% translate "POCO" %}</div>
|
||||
{% elif timer.structure == "Orbital Skyhook" %}
|
||||
<div class="badge bg-warning">{% translate "Orbital Skyhook" %}</div>
|
||||
{% elif timer.structure == "I-HUB" %}
|
||||
<div class="badge bg-warning">{% translate "I-HUB" %}</div>
|
||||
{% elif timer.structure == "TCU" %} {% comment %} Pending Removal {% endcomment %}
|
||||
<div class="badge bg-secondary">{% translate "TCU" %}</div>
|
||||
{% elif timer.structure == "POS[S]" %}
|
||||
<div class="badge bg-info">{% translate "POS [S]" %}</div>
|
||||
{% elif timer.structure == "POS[M]" %}
|
||||
<div class="badge bg-info">{% translate "POS [M]" %}</div>
|
||||
{% elif timer.structure == "POS[L]" %}
|
||||
<div class="badge bg-info">{% translate "POS [L]" %}</div>
|
||||
{% elif timer.structure == "Citadel[M]" or timer.structure == "Astrahus" %}
|
||||
<div class="badge bg-danger">{% translate "Astrahus" %}</div>
|
||||
{% elif timer.structure == "Citadel[L]" or timer.structure == "Fortizar" %}
|
||||
<div class="badge bg-danger">{% translate "Fortizar" %}</div>
|
||||
{% elif timer.structure == "Citadel[XL]" or timer.structure == "Keepstar" %}
|
||||
<div class="badge bg-danger">{% translate "Keepstar" %}</div>
|
||||
{% elif timer.structure == "Engineering Complex[M]" or timer.structure == "Raitaru" %}
|
||||
<div class="badge bg-warning">{% translate "Raitaru" %}</div>
|
||||
{% elif timer.structure == "Engineering Complex[L]" or timer.structure == "Azbel" %}
|
||||
<div class="badge bg-warning">{% translate "Azbel" %}</div>
|
||||
{% elif timer.structure == "Engineering Complex[XL]" or timer.structure == "Sotiyo" %}
|
||||
<div class="badge bg-danger">{% translate "Sotiyo" %}</div>
|
||||
{% elif timer.structure == "Refinery[M]" or timer.structure == "Athanor" %}
|
||||
<div class="badge bg-warning">{% translate "Athanor" %}</div>
|
||||
{% elif timer.structure == "Refinery[L]" or timer.structure == "Tatara" %}
|
||||
<div class="badge bg-warning">{% translate "Tatara" %}</div>
|
||||
{% elif timer.structure == "Cyno Beacon" or timer.structure == "Pharolux Cyno Beacon" %}
|
||||
<div class="badge bg-warning">{% translate "Cyno Beacon" %}</div>
|
||||
{% elif timer.structure == "Cyno Jammer" or timer.structure == "Tenebrex Cyno Jammer" %}
|
||||
<div class="badge bg-warning">{% translate "Cyno Jammer" %}</div>
|
||||
{% elif timer.structure == "Jump Gate" or timer.structure == "Ansiblex Jump Gate" %}
|
||||
<div class="badge bg-warning">{% translate "Ansiblex Jump Gate" %}</div>
|
||||
{% elif timer.structure == "Moon Mining Cycle" %}
|
||||
<div class="badge bg-success">{% translate "Moon Mining Cycle" %}</div>
|
||||
{% elif timer.structure == "Metenox Moon Drill" %}
|
||||
<div class="badge bg-warning">{% translate "Metenox Moon Drill" %}</div>
|
||||
{% elif timer.structure == "Other" %}
|
||||
<div class="badge bg-secondary">{% translate "Other" %}</div>
|
||||
{% endif %}
|
||||
<div class="badge bg-{{ timer.bg_modifier }}">
|
||||
{{ timer.get_structure_display }}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="text-center" nowrap>{{ timer.eve_time | date:"Y-m-d H:i" }}</td>
|
||||
|
@ -1,12 +1,12 @@
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import (
|
||||
LoginRequiredMixin, PermissionRequiredMixin,
|
||||
LoginRequiredMixin,
|
||||
PermissionRequiredMixin,
|
||||
)
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils import timezone
|
||||
@ -20,8 +20,8 @@ from allianceauth.timerboard.models import Timer
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
TIMER_VIEW_PERMISSION = 'auth.timer_view'
|
||||
TIMER_MANAGE_PERMISSION = 'auth.timer_management'
|
||||
TIMER_VIEW_PERMISSION = "auth.timer_view"
|
||||
TIMER_MANAGE_PERMISSION = "auth.timer_management"
|
||||
|
||||
|
||||
class BaseTimerView(LoginRequiredMixin, PermissionRequiredMixin, View):
|
||||
@ -29,22 +29,112 @@ class BaseTimerView(LoginRequiredMixin, PermissionRequiredMixin, View):
|
||||
|
||||
|
||||
class TimerView(BaseTimerView):
|
||||
template_name = 'timerboard/view.html'
|
||||
template_name = "timerboard/view.html"
|
||||
permission_required = TIMER_VIEW_PERMISSION
|
||||
|
||||
def get(self, request):
|
||||
"""
|
||||
Renders the timer view
|
||||
|
||||
:param request:
|
||||
:type request:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
def get_bg_modifier(structure):
|
||||
"""
|
||||
Returns the bootstrap bg modifier for the given structure
|
||||
|
||||
:param structure:
|
||||
:type structure:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
|
||||
if structure in bg_info:
|
||||
return "info"
|
||||
elif structure in bg_warning:
|
||||
return "warning"
|
||||
elif structure in bg_danger:
|
||||
return "danger"
|
||||
elif structure in bg_secondary:
|
||||
return "secondary"
|
||||
|
||||
return "primary"
|
||||
|
||||
logger.debug(f"timer_view called by user {request.user}")
|
||||
char = request.user.profile.main_character
|
||||
|
||||
if char:
|
||||
corp = char.corporation
|
||||
else:
|
||||
corp = None
|
||||
base_query = Timer.objects.select_related('eve_character')
|
||||
|
||||
base_query = Timer.objects.select_related("eve_character")
|
||||
|
||||
timers = []
|
||||
corp_timers = []
|
||||
future_timers = []
|
||||
past_timers = []
|
||||
|
||||
bg_info = [
|
||||
Timer.Structure.POCO.value, # POCO
|
||||
Timer.Structure.POSS.value, # POS[S]
|
||||
Timer.Structure.POSM.value, # POS[M]
|
||||
Timer.Structure.POSL.value, # POS[L]
|
||||
]
|
||||
bg_warning = [
|
||||
Timer.Structure.ANSIBLEX.value, # Ansiblex Jump Gate
|
||||
Timer.Structure.ATHANOR.value, # Athanor
|
||||
Timer.Structure.AZBEL.value, # Azbel
|
||||
Timer.Structure.MERCDEN.value, # Mercenary Den
|
||||
Timer.Structure.METENOX.value, # Metenox Moon Drill
|
||||
Timer.Structure.ORBITALSKYHOOK.value, # Orbital Skyhook
|
||||
Timer.Structure.PHAROLUX.value, # Pharolux Cyno Beacon
|
||||
Timer.Structure.RAITARU.value, # Raitaru
|
||||
"Station", # Legacy structure, remove in future update
|
||||
Timer.Structure.TATARA.value, # Tatara
|
||||
Timer.Structure.TENEBREX.value, # Tenebrex Cyno Jammer
|
||||
]
|
||||
bg_danger = [
|
||||
Timer.Structure.ASTRAHUS.value, # Astrahus
|
||||
Timer.Structure.FORTIZAR.value, # Fortizar
|
||||
Timer.Structure.IHUB.value, # I-HUB
|
||||
Timer.Structure.KEEPSTAR.value, # Keepstar
|
||||
Timer.Structure.SOTIYO.value, # Sotiyo
|
||||
Timer.Structure.TCU.value, # TCU (Legacy structure, remove in future update)
|
||||
]
|
||||
bg_secondary = [
|
||||
Timer.Structure.MOONPOP.value, # Moon Mining Cycle
|
||||
Timer.Structure.OTHER.value, # Other
|
||||
]
|
||||
|
||||
# Timers
|
||||
for timer in base_query.filter(corp_timer=False):
|
||||
timer.bg_modifier = get_bg_modifier(timer.structure)
|
||||
timers.append(timer)
|
||||
|
||||
# Corp Timers
|
||||
for timer in base_query.filter(corp_timer=True, eve_corp=corp):
|
||||
timer.bg_modifier = get_bg_modifier(timer.structure)
|
||||
corp_timers.append(timer)
|
||||
|
||||
# Future Timers
|
||||
for timer in base_query.filter(corp_timer=False, eve_time__gte=timezone.now()):
|
||||
timer.bg_modifier = get_bg_modifier(timer.structure)
|
||||
future_timers.append(timer)
|
||||
|
||||
# Past Timers
|
||||
for timer in base_query.filter(corp_timer=False, eve_time__lt=timezone.now()):
|
||||
timer.bg_modifier = get_bg_modifier(timer.structure)
|
||||
past_timers.append(timer)
|
||||
|
||||
render_items = {
|
||||
'timers': base_query.filter(corp_timer=False),
|
||||
'corp_timers': base_query.filter(corp_timer=True, eve_corp=corp),
|
||||
'future_timers': base_query.filter(corp_timer=False, eve_time__gte=timezone.now()),
|
||||
'past_timers': base_query.filter(corp_timer=False, eve_time__lt=timezone.now()),
|
||||
"timers": timers,
|
||||
"corp_timers": corp_timers,
|
||||
"future_timers": future_timers,
|
||||
"past_timers": past_timers,
|
||||
}
|
||||
|
||||
return render(request, self.template_name, context=render_items)
|
||||
@ -52,7 +142,7 @@ class TimerView(BaseTimerView):
|
||||
|
||||
class TimerManagementView(BaseTimerView):
|
||||
permission_required = TIMER_MANAGE_PERMISSION
|
||||
index_redirect = 'timerboard:view'
|
||||
index_redirect = "timerboard:view"
|
||||
success_url = reverse_lazy(index_redirect)
|
||||
model = Timer
|
||||
|
||||
@ -66,12 +156,12 @@ class AddUpdateMixin:
|
||||
Inject the request user into the kwargs passed to the form
|
||||
"""
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs.update({'user': self.request.user})
|
||||
kwargs.update({"user": self.request.user})
|
||||
return kwargs
|
||||
|
||||
|
||||
class AddTimerView(TimerManagementView, AddUpdateMixin, CreateView):
|
||||
template_name_suffix = '_create_form'
|
||||
template_name_suffix = "_create_form"
|
||||
form_class = TimerForm
|
||||
|
||||
def form_valid(self, form):
|
||||
@ -82,17 +172,18 @@ class AddTimerView(TimerManagementView, AddUpdateMixin, CreateView):
|
||||
)
|
||||
messages.success(
|
||||
self.request,
|
||||
_('Added new timer in %(system)s at %(time)s.') % {"system": timer.system, "time": timer.eve_time}
|
||||
_("Added new timer in %(system)s at %(time)s.")
|
||||
% {"system": timer.system, "time": timer.eve_time},
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
class EditTimerView(TimerManagementView, AddUpdateMixin, UpdateView):
|
||||
template_name_suffix = '_update_form'
|
||||
template_name_suffix = "_update_form"
|
||||
form_class = TimerForm
|
||||
|
||||
def form_valid(self, form):
|
||||
messages.success(self.request, _('Saved changes to the timer.'))
|
||||
messages.success(self.request, _("Saved changes to the timer."))
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
@ -107,21 +198,20 @@ def dashboard_timers(request):
|
||||
except (EveCorporationInfo.DoesNotExist, AttributeError):
|
||||
return ""
|
||||
|
||||
timers = Timer.objects.select_related(
|
||||
'eve_character'
|
||||
).filter(
|
||||
timers = Timer.objects.select_related("eve_character").filter(
|
||||
(Q(corp_timer=True) & Q(eve_corp=corp)) | Q(corp_timer=False),
|
||||
eve_time__gte=timezone.now()
|
||||
eve_time__gte=timezone.now(),
|
||||
)[:5]
|
||||
|
||||
if timers.count():
|
||||
context = {
|
||||
'timers': timers,
|
||||
"timers": timers,
|
||||
}
|
||||
|
||||
return render_to_string(
|
||||
template_name='timerboard/dashboard.timers.html',
|
||||
context=context, request=request
|
||||
template_name="timerboard/dashboard.timers.html",
|
||||
context=context,
|
||||
request=request,
|
||||
)
|
||||
else:
|
||||
return ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user