Skip to content

Commit

Permalink
Merge pull request #86 from ppfeufer/development
Browse files Browse the repository at this point in the history
[RELEASE] v1.17.0
  • Loading branch information
ppfeufer authored Mar 6, 2023
2 parents 0bc713e + 6c17b98 commit 28199ce
Show file tree
Hide file tree
Showing 18 changed files with 358 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/automated-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
DB_PASSWORD: temp_password_aa_tox_tests

- name: Upload Coverage Artifacts
if: ${{ github.event_name == 'pull_request' && matrix.python-version == '3.10' && matrix.django-version == '4.0' }}
if: ${{ (github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/master')) && matrix.python-version == '3.10' && matrix.django-version == '4.0' }}
uses: actions/upload-artifact@v3
with:
name: coverage-${{ github.event_name }}-${{ github.sha }}
Expand Down Expand Up @@ -219,7 +219,7 @@ jobs:

# Coverage upload to Codecov and Codacy
upload-coverage:
if: ${{ github.event_name == 'pull_request' }}
if: ${{ github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/master') }}
needs: [ test-coverage-aa-stable ]
# needs: [ test-coverage-aa-stable, test-coverage-aa-dev ]
name: Upload Coverage
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pypi-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@main

- name: Set up Python 3.8
uses: actions/setup-python@v2
Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repos:
- id: check-merge-conflict

- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 2.6.1
rev: 2.7.1
hooks:
- id: editorconfig-checker
exclude: |
Expand All @@ -50,7 +50,7 @@ repos:
)
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
rev: v1.10.0
hooks:
- id: python-check-mock-methods
- id: python-no-log-warn
Expand All @@ -64,7 +64,7 @@ repos:
args: [ --target-version=4.0 ]

- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
rev: v3.3.1
hooks:
- id: pyupgrade
args: [ --py38-plus ]
Expand All @@ -85,16 +85,16 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 22.10.0
rev: 22.12.0
hooks:
- id: black
args: [ --target-version=py38 ]

- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
rev: 1.13.0
hooks:
- id: blacken-docs
additional_dependencies: [ black==22.10.0 ]
additional_dependencies: [ black==22.12.0 ]
args: [ --target-version=py38 ]

- repo: https://github.com/asottile/setup-cfg-fmt
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ and this project adheres to [Semantic Versioning]
## [In Development] - Unreleased


## [1.17.0] - 2023-03-06

### Added

- Fleet type to SRP links (optional) ([#83])
- SRP details to SRP request form ([#84])

[#83]: https://github.com/ppfeufer/aa-srp/issues/83 "[Feature Request] Add Fleet Types to SRP Links"
[#84]: https://github.com/ppfeufer/aa-srp/issues/84 "[Feature Request] Add ARP Link Details to Request Form"


## [1.16.4] - 2022-11-26

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion aasrp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
A couple of variable to use throughout the app
"""

__version__ = "1.16.4"
__version__ = "1.17.0"
__title__ = "Ship Replacement"
126 changes: 124 additions & 2 deletions aasrp/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"""

# Django
from django.contrib import admin
from django.contrib import admin, messages

# AA SRP
from aasrp.models import AaSrpLink, AaSrpRequest, AaSrpRequestComment
from aasrp.models import AaSrpLink, AaSrpRequest, AaSrpRequestComment, FleetType


def custom_filter(title):
Expand All @@ -21,6 +21,26 @@ class Wrapper(admin.FieldListFilter):
Custom_filter :: wrapper
"""

def expected_parameters(self):
"""
Expected parameters
:return:
:rtype:
"""

pass

def choices(self, changelist):
"""
Choices
:param changelist:
:type changelist:
:return:
:rtype:
"""

pass

def __new__(cls, *args, **kwargs):
instance = admin.FieldListFilter.create(*args, **kwargs)
instance.title = title
Expand Down Expand Up @@ -108,3 +128,105 @@ class AaSrpRequestCommentAdmin(admin.ModelAdmin):
list_display = ("srp_request", "comment_type", "creator")
ordering = ("srp_request",)
list_filter = ("comment_type",)


@admin.register(FleetType)
class FleetTypeAdmin(admin.ModelAdmin):
"""
Config for fleet type model
"""

list_display = ("id", "_name", "_is_enabled")
list_filter = ("is_enabled",)
ordering = ("name",)

@admin.display(description="Fleet Type", ordering="name")
def _name(self, obj):
"""
Rewrite name
:param obj:
:type obj:
:return:
:rtype:
"""

return obj.name

@admin.display(description="Is Enabled", boolean=True, ordering="is_enabled")
def _is_enabled(self, obj):
"""
Rewrite is_enabled
:param obj:
:type obj:
:return:
:rtype:
"""

return obj.is_enabled

actions = (
"activate",
"deactivate",
)

@admin.action(description="Activate selected fleet type(s)")
def activate(self, request, queryset):
"""
Mark fleet type as active
:param request:
:type request:
:param queryset:
:type queryset:
:return:
:rtype:
"""

notifications_count = 0
failed = 0

for obj in queryset:
try:
obj.is_enabled = True
obj.save()

notifications_count += 1
except Exception:
failed += 1

if failed:
messages.error(request, f"Failed to activate {failed} fleet types")

if queryset.count() - failed > 0:
messages.success(request, f"Activated {notifications_count} fleet type(s)")

@admin.action(description="Deactivate selected fleet type(s)")
def deactivate(self, request, queryset):
"""
Mark fleet type as inactive
:param request:
:type request:
:param queryset:
:type queryset:
:return:
:rtype:
"""

notifications_count = 0
failed = 0

for obj in queryset:
try:
obj.is_enabled = False
obj.save()

notifications_count += 1
except Exception:
failed += 1

if failed:
messages.error(request, f"Failed to deactivate {failed} fleet types")

if queryset.count() - failed > 0:
messages.success(
request, f"Deactivated {notifications_count} fleet type(s)"
)
10 changes: 8 additions & 2 deletions aasrp/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ZKILLBOARD_KILLMAIL_URL_REGEX,
)
from aasrp.managers import AaSrpManager
from aasrp.models import AaSrpLink, AaSrpRequest, AaSrpUserSettings
from aasrp.models import AaSrpLink, AaSrpRequest, AaSrpUserSettings, FleetType


def get_mandatory_form_label_text(text: str) -> str:
Expand Down Expand Up @@ -56,6 +56,12 @@ class AaSrpLinkForm(ModelForm):
label=get_mandatory_form_label_text(_("Fleet Time")),
widget=forms.DateTimeInput(attrs={"autocomplete": "off"}),
)
fleet_type = forms.ModelChoiceField(
required=False,
label=_("Fleet Type (optional)"),
queryset=FleetType.objects.filter(is_enabled=True),
# empty_label=_("Please select a fleet type"),
)
fleet_doctrine = forms.CharField(
required=True, label=get_mandatory_form_label_text(_("Fleet Doctrine"))
)
Expand All @@ -67,7 +73,7 @@ class Meta: # pylint: disable=too-few-public-methods
"""

model = AaSrpLink
fields = ["srp_name", "fleet_time", "fleet_doctrine", "aar_link"]
fields = ["srp_name", "fleet_time", "fleet_type", "fleet_doctrine", "aar_link"]


class AaSrpLinkUpdateForm(ModelForm):
Expand Down
52 changes: 52 additions & 0 deletions aasrp/migrations/0009_add_fleet_type_to_srp_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 4.0.10 on 2023-03-06 09:09

# Django
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("aasrp", "0008_aasrprequestcomment_new_status_and_more"),
]

operations = [
migrations.CreateModel(
name="FleetType",
fields=[
("id", models.AutoField(primary_key=True, serialize=False)),
(
"name",
models.CharField(
help_text="Descriptive name of your fleet type", max_length=254
),
),
(
"is_enabled",
models.BooleanField(
db_index=True,
default=True,
help_text="Whether this fleet type is active or not",
),
),
],
options={
"verbose_name": "SRP Link Fleet Type",
"verbose_name_plural": "SRP Link Fleet Types",
"default_permissions": (),
},
),
migrations.AddField(
model_name="aasrplink",
name="fleet_type",
field=models.ForeignKey(
blank=True,
default=None,
help_text="The SRP link fleet type, if it's set",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="aasrp.fleettype",
),
),
]
47 changes: 47 additions & 0 deletions aasrp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,42 @@ class Meta: # pylint: disable=too-few-public-methods
)


class FleetType(models.Model):
"""
FleetType
"""

id = models.AutoField(primary_key=True)

name = models.CharField(
max_length=254, help_text="Descriptive name of your fleet type"
)

is_enabled = models.BooleanField(
default=True,
db_index=True,
help_text="Whether this fleet type is active or not",
)

class Meta: # pylint: disable=too-few-public-methods
"""
AFatLinkType :: Meta
"""

default_permissions = ()
verbose_name = "SRP Link Fleet Type"
verbose_name_plural = "SRP Link Fleet Types"

def __str__(self) -> str:
"""
Return the objects string name
:return:
:rtype:
"""

return str(self.name)


class AaSrpLink(models.Model):
"""
SRP link model
Expand Down Expand Up @@ -77,6 +113,17 @@ class Status(models.TextChoices):
on_delete=models.SET_NULL,
)
fleet_doctrine = models.CharField(max_length=254, default="")

fleet_type = models.ForeignKey(
FleetType,
related_name="+",
on_delete=models.SET_NULL,
null=True,
blank=True,
default=None,
help_text="The SRP link fleet type, if it's set",
)

fleet_time = models.DateTimeField()
aar_link = models.CharField(max_length=254, blank=True, default="")

Expand Down
Loading

0 comments on commit 28199ce

Please sign in to comment.