Esempio n. 1
0
def save_data(userId, columns, tableName, searchTerm="", objType="", sortBy=None, 
              tableId=None, isDefaultOnDashboard=False, maxRows=0,
              dashboard=None, clone=False, row=0, grid_col=0, sizex=0,
              sizey=0):
    """
    Saves the customized table in the dashboard. Called by save_search and
    save_new_dashboard via ajax in views.py.
    """
    try:
        if searchTerm:
            searchTerm = HTMLParser.HTMLParser().unescape(searchTerm)
        #if user is editing a table
        if tableId :
            newSavedSearch = SavedSearch.objects(id=tableId).first()
            if not newSavedSearch:
                raise Exception("Cannot find Table")
            elif clone:
                clonedSavedSearch = cloneSavedSearch(newSavedSearch, dashboard.id)
        else:
            newSavedSearch = SavedSearch()
        cols = []
        for col in columns:
            if "field" not in col or "caption" not in col:
                continue
            cols.append(col)
        if not cols:
            raise("There are no columns to save")
        newSavedSearch.tableColumns = cols
        newSavedSearch.name = tableName
        oldDashId = None
        if dashboard and newSavedSearch.dashboard != dashboard.id:
            newSavedSearch.dashboard= dashboard.id
        #if it is not a deault dashboard table, it must have a searchterm and objtype
        if searchTerm:
            newSavedSearch.searchTerm = searchTerm
        if objType:
            newSavedSearch.objType = objType
        #this is to identify the default tables on every user dashboard
        newSavedSearch.isDefaultOnDashboard = isDefaultOnDashboard
        if sortBy:
            newSavedSearch.sortBy = sortBy
        if sizex:
            newSavedSearch.sizex = sizex
        elif not newSavedSearch.sizex:
            newSavedSearch.sizex = 50
        if sizey:
            newSavedSearch.sizey = sizey
        elif maxRows and maxRows != newSavedSearch.maxRows:
            newSavedSearch.sizey = int(maxRows)+1
        elif not newSavedSearch.sizey:
            newSavedSearch.sizey = 7
        if row:
            newSavedSearch.row = row
        elif not newSavedSearch.row:
            newSavedSearch.row = 1
        if grid_col:
            newSavedSearch.col = grid_col
        elif not newSavedSearch.col:
            newSavedSearch.col = 1
        if maxRows:
            newSavedSearch.maxRows = maxRows;
        newSavedSearch.save()
        #if the old dashboard is empty, delete it
        if oldDashId:
            deleteDashboardIfEmpty(oldDashId)
    except Exception as e:
        print "ERROR: "
        print e
        return {'success': False,
                'message': "An unexpected error occurred while saving table. Please refresh and try again"}
    return {'success': True,'message': tableName+" Saved Successfully!"}
Esempio n. 2
0
def save_data(userId, columns, tableName, searchTerm="", objType="", sortBy=None, 
              tableId=None, top=None, left=None, width=0,
              isDefaultOnDashboard=False, maxRows=0, dashboardWidth=0,
              dashboard=None, clone=False):
    """
    Saves the customized table in the dashboard. Called by save_search and
    save_new_dashboard via ajax in views.py.
    width - css style used on dashboard
    tableWidth - width of table on edit page in order to calculate percentage width of columns
    """
    try:
        if searchTerm:
            searchTerm = HTMLParser.HTMLParser().unescape(searchTerm)
        #if user is editing a table
        if tableId :
            newSavedSearch = SavedSearch.objects(id=tableId).first()
            if not newSavedSearch:
                raise Exception("Cannot find Table")
            elif clone:
                clonedSavedSearch = cloneSavedSearch(newSavedSearch, dashboard.id)
        else:
            newSavedSearch = SavedSearch()
        cols = []
        for col in columns:
            if "field" not in col or "caption" not in col:
                continue
            cols.append(col)
        if not cols:
            raise("There are no columns to save")
        newSavedSearch.tableColumns = cols
        newSavedSearch.name = tableName
        oldDashId = None
        if dashboard:
            if newSavedSearch.dashboard != dashboard.id:
                newSavedSearch.left = -1
                newSavedSearch.top = -1
                newSavedSearch.dashboard= dashboard.id
        #if it is not a deault dashboard table, it must have a searchterm and objtype
        if searchTerm:
            newSavedSearch.searchTerm = searchTerm
        if objType:
            newSavedSearch.objType = objType
        #this is to identify the default tables on every user dashboard
        newSavedSearch.isDefaultOnDashboard = isDefaultOnDashboard
        if sortBy:
            newSavedSearch.sortBy = sortBy
        if (top or left) and dashboardWidth:
            newSavedSearch.top = top
            leftAsPercent = float(left)/float(dashboardWidth)*100
            #if the new left value is within 2 of previous, dont change.
            #This is because rounding issues in the HTML were constantly 
            #shifting the tables over by 1% every save
            if newSavedSearch.left==-1 or not (leftAsPercent >= newSavedSearch.left-2 and leftAsPercent <= newSavedSearch.left+2):
                newSavedSearch.left = leftAsPercent
        if maxRows:
            #if the table is growing in height, reset it's position so it doesnt
            #overlap with other tables
            if int(maxRows) > newSavedSearch.maxRows:
                newSavedSearch.top=-1
            newSavedSearch.maxRows = maxRows;
        if width:
            width = float(width)
            if not dashboardWidth and newSavedSearch.width and (width > newSavedSearch.width+2 or width < newSavedSearch.width-2):
                newSavedSearch.top=-1
            newSavedSearch.width = float(width)
        newSavedSearch.save()
        #if the old dashboard is empty, delete it
        if oldDashId:
            deleteDashboardIfEmpty(oldDashId)
    except Exception as e:
        print e
        return {'success': False,
                'message': "An unexpected error occurred while saving table. Please refresh and try again"}
    return {'success': True,'message': tableName+" Saved Successfully!"}
Esempio n. 3
0
def save_data(userId,
              columns,
              tableName,
              searchTerm="",
              objType="",
              sortBy=None,
              tableId=None,
              isDefaultOnDashboard=False,
              maxRows=0,
              dashboard=None,
              clone=False,
              row=0,
              grid_col=0,
              sizex=0,
              sizey=0):
    """
    Saves the customized table in the dashboard. Called by save_search and
    save_new_dashboard via ajax in views.py.
    """
    try:
        if searchTerm:
            searchTerm = HTMLParser.HTMLParser().unescape(searchTerm)
        #if user is editing a table
        if tableId:
            newSavedSearch = SavedSearch.objects(id=tableId).first()
            if not newSavedSearch:
                raise Exception("Cannot find Table")
            elif clone:
                clonedSavedSearch = cloneSavedSearch(newSavedSearch,
                                                     dashboard.id)
        else:
            newSavedSearch = SavedSearch()
        cols = []
        for col in columns:
            if "field" not in col or "caption" not in col:
                continue
            cols.append(col)
        if not cols:
            raise ("There are no columns to save")
        newSavedSearch.tableColumns = cols
        newSavedSearch.name = tableName
        oldDashId = None
        if dashboard and newSavedSearch.dashboard != dashboard.id:
            newSavedSearch.dashboard = dashboard.id
        #if it is not a deault dashboard table, it must have a searchterm and objtype
        if searchTerm:
            newSavedSearch.searchTerm = searchTerm
        if objType:
            newSavedSearch.objType = objType
        #this is to identify the default tables on every user dashboard
        newSavedSearch.isDefaultOnDashboard = isDefaultOnDashboard
        if sortBy:
            newSavedSearch.sortBy = sortBy
        if sizex:
            newSavedSearch.sizex = sizex
        elif not newSavedSearch.sizex:
            newSavedSearch.sizex = 50
        if sizey:
            newSavedSearch.sizey = sizey
        elif maxRows and maxRows != newSavedSearch.maxRows:
            newSavedSearch.sizey = int(maxRows) + 1
        elif not newSavedSearch.sizey:
            newSavedSearch.sizey = 7
        if row:
            newSavedSearch.row = row
        elif not newSavedSearch.row:
            newSavedSearch.row = 1
        if grid_col:
            newSavedSearch.col = grid_col
        elif not newSavedSearch.col:
            newSavedSearch.col = 1
        if maxRows:
            newSavedSearch.maxRows = maxRows
        newSavedSearch.save()
        #if the old dashboard is empty, delete it
        if oldDashId:
            deleteDashboardIfEmpty(oldDashId)
    except Exception as e:
        print "ERROR: "
        print e
        return {
            'success':
            False,
            'message':
            "An unexpected error occurred while saving table. Please refresh and try again"
        }
    return {'success': True, 'message': tableName + " Saved Successfully!"}
Esempio n. 4
0
def save_data(userId,
              columns,
              tableName,
              searchTerm="",
              objType="",
              sortBy=None,
              tableId=None,
              top=None,
              left=None,
              width=0,
              isDefaultOnDashboard=False,
              maxRows=0,
              dashboardWidth=0,
              dashboard=None,
              clone=False):
    """
    Saves the customized table in the dashboard. Called by save_search and
    save_new_dashboard via ajax in views.py.
    width - css style used on dashboard
    tableWidth - width of table on edit page in order to calculate percentage width of columns
    """
    try:
        if searchTerm:
            searchTerm = HTMLParser.HTMLParser().unescape(searchTerm)
        #if user is editing a table
        if tableId:
            newSavedSearch = SavedSearch.objects(id=tableId).first()
            if not newSavedSearch:
                raise Exception("Cannot find Table")
            elif clone:
                clonedSavedSearch = cloneSavedSearch(newSavedSearch,
                                                     dashboard.id)
        else:
            newSavedSearch = SavedSearch()
        cols = []
        for col in columns:
            if "field" not in col or "caption" not in col:
                continue
            cols.append(col)
        if not cols:
            raise ("There are no columns to save")
        newSavedSearch.tableColumns = cols
        newSavedSearch.name = tableName
        oldDashId = None
        if dashboard:
            if newSavedSearch.dashboard != dashboard.id:
                newSavedSearch.left = -1
                newSavedSearch.top = -1
                newSavedSearch.dashboard = dashboard.id
        #if it is not a deault dashboard table, it must have a searchterm and objtype
        if searchTerm:
            newSavedSearch.searchTerm = searchTerm
        if objType:
            newSavedSearch.objType = objType
        #this is to identify the default tables on every user dashboard
        newSavedSearch.isDefaultOnDashboard = isDefaultOnDashboard
        if sortBy:
            newSavedSearch.sortBy = sortBy
        if (top or left) and dashboardWidth:
            newSavedSearch.top = top
            leftAsPercent = float(left) / float(dashboardWidth) * 100
            #if the new left value is within 2 of previous, dont change.
            #This is because rounding issues in the HTML were constantly
            #shifting the tables over by 1% every save
            if newSavedSearch.left == -1 or not (
                    leftAsPercent >= newSavedSearch.left - 2
                    and leftAsPercent <= newSavedSearch.left + 2):
                newSavedSearch.left = leftAsPercent
        if maxRows:
            #if the table is growing in height, reset it's position so it doesnt
            #overlap with other tables
            if int(maxRows) > newSavedSearch.maxRows:
                newSavedSearch.top = -1
            newSavedSearch.maxRows = maxRows
        if width:
            width = float(width)
            if not dashboardWidth and newSavedSearch.width and (
                    width > newSavedSearch.width + 2
                    or width < newSavedSearch.width - 2):
                newSavedSearch.top = -1
            newSavedSearch.width = float(width)
        newSavedSearch.save()
        #if the old dashboard is empty, delete it
        if oldDashId:
            deleteDashboardIfEmpty(oldDashId)
    except Exception as e:
        print e
        return {
            'success':
            False,
            'message':
            "An unexpected error occurred while saving table. Please refresh and try again"
        }
    return {'success': True, 'message': tableName + " Saved Successfully!"}