Skip to content

Commit

Permalink
fix admin upload plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Arcuri committed Mar 25, 2024
1 parent cf8d31b commit 174ba78
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion orochi/website/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
52 changes: 30 additions & 22 deletions orochi/website/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 174ba78

Please sign in to comment.