increase calendar url length, add import action in admin backend
This commit is contained in:
parent
03163c1899
commit
7e4ff4366b
|
@ -3,6 +3,12 @@ from django.contrib import admin
|
||||||
from .models import Calendar
|
from .models import Calendar
|
||||||
|
|
||||||
|
|
||||||
|
def update_calendar(modeladmin, request, queryset):
|
||||||
|
for calendar in queryset:
|
||||||
|
calendar.update()
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Calendar)
|
@admin.register(Calendar)
|
||||||
class CalendarAdmin(admin.ModelAdmin):
|
class CalendarAdmin(admin.ModelAdmin):
|
||||||
list_display = ("url", "needs_fallback", "has_errors")
|
list_display = ("url", "needs_fallback", "has_errors")
|
||||||
|
actions = (update_calendar,)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 5.0.4 on 2025-05-12 22:16
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("importer", "0002_calendar_needs_fallback"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="calendar",
|
||||||
|
name="url",
|
||||||
|
field=models.URLField(max_length=1000, primary_key=True, serialize=False),
|
||||||
|
),
|
||||||
|
]
|
|
@ -4,10 +4,17 @@ from shiftregister.app.models import *
|
||||||
|
|
||||||
|
|
||||||
class Calendar(models.Model):
|
class Calendar(models.Model):
|
||||||
url = models.URLField(primary_key=True)
|
url = models.URLField(primary_key=True, max_length=1000)
|
||||||
needs_fallback = models.BooleanField(default=False, editable=True)
|
needs_fallback = models.BooleanField(default=False, editable=True)
|
||||||
has_errors = models.BooleanField(default=False, editable=False)
|
has_errors = models.BooleanField(default=False, editable=False)
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
# break circular import
|
||||||
|
from .importer import import_calendar
|
||||||
|
|
||||||
|
self.has_errors = not import_calendar(self)
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
|
||||||
class Event(Shift):
|
class Event(Shift):
|
||||||
uuid = models.UUIDField(primary_key=True, editable=False)
|
uuid = models.UUIDField(primary_key=True, editable=False)
|
||||||
|
|
|
@ -7,5 +7,4 @@ from .models import Calendar
|
||||||
@shared_task
|
@shared_task
|
||||||
def import_shifts():
|
def import_shifts():
|
||||||
for calendar in Calendar.objects.all():
|
for calendar in Calendar.objects.all():
|
||||||
calendar.has_errors = not import_calendar(calendar)
|
calendar.update()
|
||||||
calendar.save()
|
|
||||||
|
|
Loading…
Reference in New Issue