diff --git a/orochi/website/admin.py b/orochi/website/admin.py index 196d477a..f3ef4750 100644 --- a/orochi/website/admin.py +++ b/orochi/website/admin.py @@ -135,7 +135,7 @@ def get_form(self, request, obj=None, **kwargs): defaults = {} if obj is None: defaults["form"] = self.add_form - defaults.update(kwargs) + defaults |= kwargs return super().get_form(request, obj, **defaults) diff --git a/orochi/website/forms.py b/orochi/website/forms.py index 8108e7b2..a248575f 100644 --- a/orochi/website/forms.py +++ b/orochi/website/forms.py @@ -12,7 +12,11 @@ ) from orochi.utils.plugin_install import plugin_install -from orochi.website.defaults import RESULT_STATUS_NOT_STARTED +from orochi.website.defaults import ( + DUMP_STATUS_MISSING_SYMBOLS, + RESULT_STATUS_DISABLED, + RESULT_STATUS_NOT_STARTED, +) from orochi.website.models import Bookmark, Dump, Folder, Plugin, Result, UserPlugin @@ -223,29 +227,33 @@ class Meta: ] def save(self, commit=True): - plugin = self.cleaned_data["plugin"] - plugin_names = plugin_install(plugin.file.path) - first = None - for plugin_data in plugin_names: + plugin_zip = self.cleaned_data["plugin"] + if plugin_names := plugin_install(plugin_zip.file.path): + plugin_data = plugin_names[0] plugin_name, plugin_class = list(plugin_data.items())[0] - plugin = super(PluginCreateAdminForm, self).save(commit=commit) - plugin.comment = plugin_class.__doc__ - plugin.name = plugin_name - plugin.local = True - plugin.local_date = datetime.now() - plugin.save() + plugin_obj = super(PluginCreateAdminForm, self).save(commit=commit) + plugin_obj.comment = self.cleaned_data["comment"] or plugin_class.__doc__ + plugin_obj.name = plugin_name + plugin_obj.local = True + plugin_obj.local_date = datetime.now() + plugin_obj.save() for user in get_user_model().objects.all(): - UserPlugin.objects.get_or_create(user=user, plugin=plugin) - for dump in Dump.objects.all(): - if plugin.operating_system in [dump.operating_system, "Other"]: - Result.objects.update_or_create( - dump=dump, - plugin=plugin, - defaults={"result": RESULT_STATUS_NOT_STARTED}, - ) - if not first: - first = plugin - return first + UserPlugin.objects.get_or_create(user=user, plugin__id=plugin_obj.id) + for dump in Dump.objects.all(): + if plugin_obj.operating_system in [dump.operating_system, "Other"]: + Result.objects.update_or_create( + dump=dump, + plugin__id=plugin_obj.id, + defaults={ + "result": ( + RESULT_STATUS_NOT_STARTED + if dump.status != DUMP_STATUS_MISSING_SYMBOLS + else RESULT_STATUS_DISABLED + ) + }, + ) + self.save_m2m() + return plugin_obj class PluginEditAdminForm(FileFormMixin, forms.ModelForm):