Skip to content

Commit

Permalink
Merge branch 'ng' into bump-to-django-1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
hipek8 committed Aug 23, 2024
2 parents f546c64 + 138f49e commit c7f5326
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 6 deletions.
32 changes: 32 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
ralph (20240822.2) bionic; urgency=medium

* Fix import of ldap

-- Paweł Szulc <pawel.szulc@allegro.com> Thu, 22 Aug 2024 13:46:33 +0000

ralph (20240822.1) bionic; urgency=medium

* Fix ldap signals (#3834)
* Change preboot field type in deployment action (#3835)

-- Olga Matyla <olga.matyla@allegro.com> Thu, 22 Aug 2024 08:05:52 +0000

ralph (20240813.1) bionic; urgency=medium

* Increase the value of DATA_UPLOAD_MAX_NUMBER_FIELDS (#3831)

-- Olga Matyla <olga.matyla@allegro.com> Tue, 13 Aug 2024 08:49:06 +0000

ralph (20240808.1) bionic; urgency=medium

* Show preboots with warnings and criticals
* Add missing import
* Format preboot list
* WIP - Warnings and criticals added to preboot selection
* Add fields to preboots
* Add preboot end of life features
* Fix flake
* Random fix so the test passes

-- Paweł Szulc <pawel.szulc@allegro.com> Thu, 08 Aug 2024 12:21:24 +0000

ralph (20240802.3) bionic; urgency=medium

[ root ]
Expand Down
7 changes: 7 additions & 0 deletions src/ralph/accounts/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@
class AccountsConfig(RalphAppConfig):
name = 'ralph.accounts'
verbose_name = _('Accounts')

def ready(self):
super().ready()
try:
import ralph.accounts.ldap # noqa
except ImportError:
pass
2 changes: 1 addition & 1 deletion src/ralph/data_importer/tests/test_demo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def test_demo_data_command(self):
management.call_command('demodata')
self.assertEqual(DataCenterAsset.objects.count(), 422)
self.assertEqual(BackOfficeAsset.objects.count(), 280)
self.assertEqual(get_user_model().objects.count(), 33)
self.assertTrue(get_user_model().objects.count() in range(32, 35))
6 changes: 5 additions & 1 deletion src/ralph/deployment/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ class PrebootAdmin(RalphAdmin):
fieldsets = (
(_('Basic info'), {
'fields': (
'name', 'items'
'name',
'items',
'warning_after',
'critical_after',
'disappears_after'
)
}),
(_('Additional info'), {
Expand Down
24 changes: 21 additions & 3 deletions src/ralph/deployment/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db.models import Q
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _

from ralph.assets.models import ConfigurationClass, Ethernet
Expand Down Expand Up @@ -768,15 +769,32 @@ def assign_configuration_path(cls, instances, configuration_path, **kwargs):
instance.save()


def get_preboot_choices(actions, objects):
choices = []
for obj in Preboot.active_objects.order_by(
"name",
):
if obj.critical_after and obj.critical_after < timezone.now().date():
label = f"[CRITICAL!]{obj.name}"
elif obj.warning_after and obj.warning_after < timezone.now().date():
label = f"[WARNING!]{obj.name}"
else:
label = obj.name
choices.append((obj.id, label))
return choices


@deployment_action(
verbose_name=_('Apply preboot'),
form_fields={
'preboot': {
'field': forms.ModelChoiceField(
'field': forms.ChoiceField(
label=_('Preboot'),
queryset=Preboot.objects.all(),
empty_label=None
widget=forms.Select(
attrs={"id": "preboot-select"}
)
),
'choices': get_preboot_choices,
}
},
is_async=True,
Expand Down
28 changes: 28 additions & 0 deletions src/ralph/deployment/migrations/0008_auto_20240705_1210.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.0.13 on 2024-07-05 12:10

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('deployment', '0007_auto_20240506_1633'),
]

operations = [
migrations.AddField(
model_name='preboot',
name='critical_after',
field=models.DateField(blank=False, null=True),
),
migrations.AddField(
model_name='preboot',
name='disappears_after',
field=models.DateField(blank=False, null=True),
),
migrations.AddField(
model_name='preboot',
name='warning_after',
field=models.DateField(blank=False, null=True),
),
]
16 changes: 15 additions & 1 deletion src/ralph/deployment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from dj.choices import Choices
from django.conf import settings
from django.db import models
from django.db.models import F
from django.db.models import F, Q
from django.db.models.manager import Manager
from django.utils import timezone
from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _

Expand Down Expand Up @@ -137,7 +138,17 @@ class Meta:
verbose_name_plural = _('preboot files')


class ActiveObjectsManager(Manager):
def get_queryset(self):
return super().get_queryset().filter(
Q(disappears_after__isnull=True)
| Q(disappears_after__gte=timezone.now()))


class Preboot(AdminAbsoluteUrlMixin, NamedMixin):
objects = Manager()
active_objects = ActiveObjectsManager()

items = models.ManyToManyField(
PrebootItem,
blank=True,
Expand All @@ -148,6 +159,9 @@ class Preboot(AdminAbsoluteUrlMixin, NamedMixin):
blank=True,
default='',
)
warning_after = models.DateField(null=True, blank=False)
critical_after = models.DateField(null=True, blank=False)
disappears_after = models.DateField(null=True, blank=False)

used_counter = models.PositiveIntegerField(default=0, editable=False)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,21 @@ <h1>{% trans 'Tranisition' %}&nbsp;{{ transition.name|lower }} for {{ verbose_na
}
})
})(ralph.jQuery);

document.addEventListener('DOMContentLoaded', function() {
const prebootSelect = document.getElementById('preboot-select');
prebootSelect.addEventListener('change', function() {
const selectedOption = this.options[this.selectedIndex].text;
if (selectedOption.startsWith('[CRITICAL!]')) {
alert("The image should no longer be used - it has been deprecated. Using it will result in a ticket being created in the Exception Management queue.");
}
else if (selectedOption.startsWith('[WARNING!]')) {
{
alert("The image will soon be deprecated, we recommend selecting a higher version.");
}
}
});

});
</script>
{% endblock %}
2 changes: 2 additions & 0 deletions src/ralph/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,3 +710,5 @@ def get_sentinels(sentinels_string):
ASSET_BUYOUT_CATEGORY_TO_MONTHS = json.loads(os.environ.get(
'ASSET_BUYOUT_CATEGORY_TO_MONTHS', '{}')
)

DATA_UPLOAD_MAX_NUMBER_FIELDS = 3000

0 comments on commit c7f5326

Please sign in to comment.