Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard doesn't update unless i press reset button #26

Open
Ajeetlakhani opened this issue Nov 27, 2015 · 11 comments
Open

Dashboard doesn't update unless i press reset button #26

Ajeetlakhani opened this issue Nov 27, 2015 · 11 comments

Comments

@Ajeetlakhani
Copy link

When i do some changes in my custom dashboard file it does not reflect changes in browser unless i press reset button. When i looked into jet's dashboard file i found that

    def load_modules(self):
        module_models = UserDashboardModule.objects.filter(
            app_label=self.app_label,
            user=self.context['request'].user.pk
        ).all()

        if len(module_models) == 0:
            module_models = self.create_initial_module_models(self.context['request'].user)

        loaded_modules = []

        for module_model in module_models:
            module_cls = module_model.load_module()
            if module_cls is not None:
                module = module_cls(model=module_model, context=self.context)
                loaded_modules.append(module)

        self.modules = loaded_modules

This function loads module from UserDashboardModule model not from my custom dashboard file. I guess model should only store the position and some setting for respective modules instead of storing all the modules in db. It never happened with me when i used admin-tools.

@ShubhamBadal
Copy link

I am also facing exactly the same issue since many months.

@f1nality
Copy link
Contributor

This is made mainly for storing widget's settings (title, some settings). What changes you do to dashboard file you don't want to be loaded from database?

@Ajeetlakhani
Copy link
Author

I need a multi-level dashboard so i am extending jet and making it hierarchial. So i would prefer loading it from file. Also in development its difficult to add more module and check because this function create new entry in database only when module_models is'nt there or its length is 0.

@SalahAdDin
Copy link
Contributor

Man, why put you a JET_INDEX_DASHBOARD if django-jet doesn't charge a custom dashboard by default? It's crazy. I think that this are a bug mine, but isn't it, it's a Django-Jet Bug

👍

@Ajeetlakhani Ajeetlakhani changed the title Dashboard does'nt update unless i press reset button Dashboard doesn't update unless i press reset button Jan 21, 2016
@ohad-G
Copy link

ohad-G commented Feb 29, 2016

HI, this bug is a pain for me too,
Reset button ?
sql Command for reset on sqlite3 would be nice,
Thanks

@SalahAdDin
Copy link
Contributor

SalahAdDin commented May 27, 2016

@f1nality what's about this man?

I think that a possible solution will be use the same methos with this form:

class ResetDashboardForm(forms.Form):
    app_label = forms.CharField(required=False)

    def __init__(self, request, *args, **kwargs):
        self.request = request
        super(ResetDashboardForm, self).__init__(*args, **kwargs)

    class Meta:
        model = UserDashboardModule
        fields = []

    def clean(self):
        data = super(ResetDashboardForm, self).clean()
        data['app_label'] = data['app_label'] if data['app_label'] else None

        if not self.request.user.is_authenticated():
            raise ValidationError('error')

        return data

    def save(self, commit=True):
        if commit:
            UserDashboardModule.objects.filter(
                user=self.request.user.pk,
                app_label=self.cleaned_data['app_label']
            ).delete()

Use some this methods when load the custom template.

I think that when you use migrate on dashboard you load first default dashboard and it is set in database first. So, when you use reset, this function clean default dashboard sets in database and save the new dashboard, right?

@nryoung
Copy link

nryoung commented Jun 20, 2017

@Ajeetlakhani what do you mean by pressing the "reset" button here? Does this mean wiping out the database and starting fresh?

@f1nality This is rough bug to figure out. What is the work around to getting your dashboard to update with different modules? Wiping out the database isn't really an option for me. (I bought the license if that matters at all)

@nryoung
Copy link

nryoung commented Jun 20, 2017

I actually implemented a workaround for this. It involves overriding load_modules method on the Dashboard object. It now calls a new method called get_or_create_module_models every time which either gets that specific module from the DB if it exists, otherwise it creates it. This allows you to modify the Dashboard and it will update as you would expect it to.

from jet.dashboard.dashboard import Dashboard
from jet.dashboard.models import UserDashboardModule


class CustomIndexDashboard(Dashboard):
    columns = 3
    # Moderator Tools

    def init_with_context(self, context):
        self.available_children.append(modules.LinkList)

    def get_or_create_module_models(self, user):
        module_models = []

        i = 0

        for module in self.children:
            column = module.column if module.column is not None else i % self.columns
            order = module.order if module.order is not None else int(i / self.columns)

            obj, created = UserDashboardModule.objects.get_or_create(
                title=module.title,
                app_label=self.app_label,
                user=user.pk,
                module=module.fullname(),
                column=column,
                order=order,
                settings=module.dump_settings(),
                children=module.dump_children()
            )
            module_models.append(obj)
            i += 1

        return module_models

    def load_modules(self):
        module_models = self.get_or_create_module_models(self.context['request'].user)

        loaded_modules = []

        for module_model in module_models:
            module_cls = module_model.load_module()
            if module_cls is not None:
                module = module_cls(model=module_model, context=self.context)
                loaded_modules.append(module)

        self.modules = loaded_modules

@SalahAdDin
Copy link
Contributor

@nryoung good man, i think you should make a pull request: this feature have to be in this package by default. @f1nality isn't it?

@Ismael-VC
Copy link

Please come to the django-jet Discord server so we can organize if you like:

Welcome! 😄

@SalahAdDin
Copy link
Contributor

@Ismael-VC , what's about this? Did you test it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants