pawamoy/django-suit-dashboard

Error en RefreshableDataView

Closed this issue ยท 3 comments

Hello, few days ago I was following django-suit-dashboard documentation to implement dashboard in my project admin (I use django-suit) and had an error when trying to implement updatable content (@refreshable), apparently do not find the dynamic route ( 'refreshable /' + regex). Could you please explain how I can to implement this functionality correctly. Here I attached a picture of error returned.
Excuse my English is not good.
image

Note: When I comment @refreshable decorator it's all OK.
image

Hi !
First I have to say that the documentation is maybe not in sync with the version released on PyPi (this is a side project and I don't have much time ๐Ÿ˜ž).

Did you install django-suit-dashboard through pip install or git clone?

Try to add persistent=True when creating the instance of the box, like in

class HomeView(DashboardView):
    template_name = 'dashboard/main.html'
    crumbs = (
        {'url': 'admin:index', 'name': _('Home')},
    )
    grid = Grid(Row(Column(BoxMachine(persistent=True))))

Explanation: by default, when you create a box, the get_items or get_context functions are not executed. They will be executed at rendering time. This is a problem with refreshable items because they need to be instanciated BEFORE rendering time (we need their dynamic urls to be generated before rendering). persistent=True will tell the box to immediately execute the functions and store the results in the object, so they don't have to be executed more than once.

This behavior is not intuitive and can be very confusing, I will try to improve this in the future.

Let me know if adding persistent=True helped.

Hi!!!
First of all, thanks for your quick response. Everything worked very well with persistent=True, here I attached a picture of how it looks running.
image
First use pip install, but I realized that was not up to date with the documentation and then use git clone and everything worked just missed the graph(persistent=True), again thanks and congratulations for this great job.

Just change a portion of code for me, in class BoxMachine (Box) -> get_items (self), I put you here if you is useful:

# Retrieve and format uptime (will not work on Windows)
with open('/proc/uptime') as f:
     s = timedelta(seconds=float(f.readline().split()[0])).total_seconds()
     uptime = _('%d days, %d hours, %d minutes, %d seconds') % (
                       s // 86400, s // 3600 % 24, s // 60 % 60, s % 60)

by:

p = psutil.Process(os.getpid())
uptime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(p.create_time()))    
# uptime = '2010-12-30 04:06:23'

It's cross platform and it served me, not only Linux.

By the way, I am a software developer in Cuba (AngularJS + Django), I develop on Windows and deploy on Ubuntu Server. Although my English is not good, if you ever need translated your documentation into Spanish, count me in.
Good luck

Alright, great !! Thank you for the cross-platform code ๐Ÿ˜„ You can send a Pull-Request if you want (or if you don't care I will include it myself). Your english seems good enough haha, it's not my native language either, but we understand each other sooooo...

Good luck to you too !