def add_navlet(account, navlet, preferences=None): """Create new accountnavlet based on request data""" if preferences is None: preferences = {} accountnavlet = AccountNavlet(account=account, navlet=navlet) accountnavlet.column, accountnavlet.order = find_new_placement(account) default_preferences = get_default_preferences( get_navlet_from_name(navlet)) or {} accountnavlet.preferences = dict(preferences.items() + default_preferences.items()) accountnavlet.save() return accountnavlet
def add_navlet(account, navlet, preferences=None, dashboard=None): """Create new accountnavlet based on request data""" if preferences is None: preferences = {} if dashboard is None: dashboard = AccountDashboard.objects.get(account=account, is_default=True) accountnavlet = AccountNavlet(account=account, navlet=navlet, dashboard=dashboard) accountnavlet.column, accountnavlet.order = find_new_placement() accountnavlet.preferences = ( get_default_preferences(get_navlet_from_name(navlet)) or {} ) accountnavlet.preferences.update(preferences) accountnavlet.save() return accountnavlet
def remove_navlet(account, request): """Remove accountnavlet based on request data""" navlet_id = int(request.POST.get('navletid')) accountnavlet = AccountNavlet(pk=navlet_id, account=account) accountnavlet.delete()