Scott Baker | c7325a4 | 2014-05-30 16:06:46 -0700 | [diff] [blame] | 1 | from view_common import * |
| 2 | |
| 3 | class DashboardCustomize(View): |
| 4 | def post(self, request, *args, **kwargs):
|
| 5 | if request.user.isReadOnlyUser():
|
| 6 | return HttpResponseForbidden("User is in read-only mode")
|
| 7 |
|
| 8 | dashboards = request.POST.get("dashboards", None)
|
| 9 | if not dashboards:
|
| 10 | dashboards=[]
|
| 11 | else:
|
| 12 | dashboards = [x.strip() for x in dashboards.split(",")]
|
| 13 | dashboards = [DashboardView.objects.get(name=x) for x in dashboards]
|
| 14 |
|
Sapan Bhatia | 13d2db9 | 2014-11-11 21:47:45 -0500 | [diff] [blame] | 15 | request.user.userdashboardviews.all().delete()
|
Scott Baker | c7325a4 | 2014-05-30 16:06:46 -0700 | [diff] [blame] | 16 |
|
| 17 | for i,dashboard in enumerate(dashboards):
|
| 18 | udbv = UserDashboardView(user=request.user, dashboardView=dashboard, order=i)
|
| 19 | udbv.save()
|
| 20 |
|
Scott Baker | 823b721 | 2014-06-16 10:25:39 -0700 | [diff] [blame] | 21 | return HttpResponse(json.dumps("Success"), content_type='application/javascript') |
Scott Baker | c7325a4 | 2014-05-30 16:06:46 -0700 | [diff] [blame] | 22 | |