Esempio n. 1
0
def group_dashboard(request, group_id):
    # check user is allowed to access this
    user = request.user
    config_installed = 'config' in settings.INSTALLED_APPS
    user_level = user.userprofile.level
    machine_group = get_object_or_404(MachineGroup, pk=group_id)
    business_unit = machine_group.business_unit
    if business_unit not in user.businessunit_set.all():
        if user_level != 'GA':
            return redirect(index)
    if user_level == 'GA' or user_level == 'RW':
        is_editor = True
    else:
        is_editor = False
    machines = machine_group.machine_set.all()
    # Build the manager
    manager = PluginManager()
    # Tell it the default place(s) where to find plugins
    manager.setPluginPlaces([settings.PLUGIN_DIR, os.path.join(settings.PROJECT_DIR, 'server/plugins')])
    # Load all plugins
    manager.collectPlugins()
    output = []
    for plugin in manager.getAllPlugins():
        data = {}
        data['name'] = plugin.name
        (data['html'], data['width']) = plugin.plugin_object.show_widget('group_dashboard', machines, machine_group.id)
        output.append(data)
    output = utils.orderPluginOutput(output, 'group_dashboard', machine_group.id)
    c = {'user': request.user, 'machine_group': machine_group, 'user_level': user_level,  'is_editor': is_editor, 'business_unit': business_unit, 'output':output, 'config_installed':config_installed, 'request':request}
    return render_to_response('server/group_dashboard.html', c, context_instance=RequestContext(request))
Esempio n. 2
0
def index(request):
    # Get the current user's Business Units
    user = request.user
    # Count the number of users. If there is only one, they need to be made a GA
    if User.objects.count() == 1:
        # The first user created by syncdb won't have a profile. If there isn't one, make sure they get one.
        try:
            profile = UserProfile.objects.get(user=user)
        except UserProfile.DoesNotExist:
            profile = UserProfile(user=user)

        profile.level = "GA"
        profile.save()
    user_level = user.userprofile.level
    now = datetime.now()
    hour_ago = now - timedelta(hours=1)
    today = date.today()
    week_ago = today - timedelta(days=7)
    month_ago = today - timedelta(days=30)
    three_months_ago = today - timedelta(days=90)
    if user_level != "GA":
        # user has many BU's display them all in a friendly manner
        business_units = user.businessunit_set.all()
        if user.businessunit_set.count() == 1:
            # user only has one BU, redirect to it
            for bu in user.businessunit_set.all():
                return redirect("server.views.bu_dashboard", bu_id=bu.id)
                break
    else:
        machines = Machine.objects.all()
        # Build the manager
        manager = PluginManager()
        # Tell it the default place(s) where to find plugins
        manager.setPluginPlaces([settings.PLUGIN_DIR, os.path.join(settings.PROJECT_DIR, "server/plugins")])
        # Load all plugins
        manager.collectPlugins()
        output = []
        # Loop round the plugins and print their names.
        for plugin in manager.getAllPlugins():
            data = {}
            data["name"] = plugin.name
            (data["html"], data["width"]) = plugin.plugin_object.show_widget("front", machines)
            # output.append(plugin.plugin_object.show_widget('front'))
            output.append(data)
        output = utils.orderPluginOutput(output)

        # get the user level - if they're a global admin, show all of the machines. If not, show only the machines they have access to
        business_units = BusinessUnit.objects.all()
        config_installed = "config" in settings.INSTALLED_APPS

        c = {
            "user": request.user,
            "business_units": business_units,
            "output": output,
            "config_installed": config_installed,
        }
        return render_to_response("server/index.html", c, context_instance=RequestContext(request))
Esempio n. 3
0
def bu_dashboard(request, bu_id):
    user = request.user
    user_level = user.userprofile.level
    business_unit = get_object_or_404(BusinessUnit, pk=bu_id)
    bu = business_unit
    if business_unit not in user.businessunit_set.all() and user_level != "GA":
        print "not letting you in " + user_level
        return redirect(index)
    # Get the groups within the Business Unit
    machine_groups = business_unit.machinegroup_set.all()
    if user_level == "GA" or user_level == "RW":
        is_editor = True
    else:
        is_editor = False
    machines = utils.getBUmachines(bu_id)
    now = datetime.now()
    hour_ago = now - timedelta(hours=1)
    today = date.today()
    week_ago = today - timedelta(days=7)
    month_ago = today - timedelta(days=30)
    three_months_ago = today - timedelta(days=90)

    # Build the manager
    manager = PluginManager()
    # Tell it the default place(s) where to find plugins
    manager.setPluginPlaces([settings.PLUGIN_DIR, os.path.join(settings.PROJECT_DIR, "server/plugins")])
    # Load all plugins
    manager.collectPlugins()
    output = []

    # Loop round the plugins and print their names.
    for plugin in manager.getAllPlugins():
        data = {}
        data["name"] = plugin.name
        (data["html"], data["width"]) = plugin.plugin_object.show_widget("bu_dashboard", machines, bu.id)
        output.append(data)
    output = utils.orderPluginOutput(output, "bu_dashboard", bu.id)

    c = {
        "user": request.user,
        "machine_groups": machine_groups,
        "is_editor": is_editor,
        "business_unit": business_unit,
        "user_level": user_level,
        "output": output,
    }
    return render_to_response("server/bu_dashboard.html", c, context_instance=RequestContext(request))
Esempio n. 4
0
def bu_dashboard(request, bu_id):
    user = request.user
    user_level = user.userprofile.level
    business_unit = get_object_or_404(BusinessUnit, pk=bu_id)
    bu = business_unit
    config_installed = 'config' in settings.INSTALLED_APPS
    if business_unit not in user.businessunit_set.all() and user_level != 'GA':
        print 'not letting you in ' + user_level
        return redirect(index)
    # Get the groups within the Business Unit
    machine_groups = business_unit.machinegroup_set.all()
    if user_level == 'GA' or user_level == 'RW':
        is_editor = True
    else:
        is_editor = False
    machines = utils.getBUmachines(bu_id)
    now = datetime.now()
    hour_ago = now - timedelta(hours=1)
    today = date.today()
    week_ago = today - timedelta(days=7)
    month_ago = today - timedelta(days=30)
    three_months_ago = today - timedelta(days=90)

    # Build the manager
    manager = PluginManager()
    # Tell it the default place(s) where to find plugins
    manager.setPluginPlaces([settings.PLUGIN_DIR, os.path.join(settings.PROJECT_DIR, 'server/plugins')])
    # Load all plugins
    manager.collectPlugins()
    output = []
    # Get all the enabled plugins
    enabled_plugins = Plugin.objects.all().order_by('order')
    for enabled_plugin in enabled_plugins:
        # Loop round the plugins and print their names.
        for plugin in manager.getAllPlugins():
            if plugin.name == enabled_plugin.name:
                data = {}
                data['name'] = plugin.name
                (data['html'], data['width']) = plugin.plugin_object.show_widget('bu_dashboard', machines, bu.id)
                output.append(data)
                break

    output = utils.orderPluginOutput(output, 'bu_dashboard', bu.id)

    c = {'user': request.user, 'machine_groups': machine_groups, 'is_editor': is_editor, 'business_unit': business_unit, 'user_level': user_level, 'output':output, 'config_installed':config_installed }
    return render_to_response('server/bu_dashboard.html', c, context_instance=RequestContext(request))
Esempio n. 5
0
def group_dashboard(request, group_id):
    # check user is allowed to access this
    user = request.user
    user_level = user.userprofile.level
    machine_group = get_object_or_404(MachineGroup, pk=group_id)
    business_unit = machine_group.business_unit
    if business_unit not in user.businessunit_set.all():
        if user_level != "GA":
            return redirect(index)
    if user_level == "GA" or user_level == "RW":
        is_editor = True
    else:
        is_editor = False
    machines = machine_group.machine_set.all()
    # Build the manager
    manager = PluginManager()
    # Tell it the default place(s) where to find plugins
    manager.setPluginPlaces([settings.PLUGIN_DIR, os.path.join(settings.PROJECT_DIR, "server/plugins")])
    # Load all plugins
    manager.collectPlugins()
    output = []
    for plugin in manager.getAllPlugins():
        data = {}
        data["name"] = plugin.name
        (data["html"], data["width"]) = plugin.plugin_object.show_widget("group_dashboard", machines, machine_group.id)
        output.append(data)
    output = utils.orderPluginOutput(output, "group_dashboard", machine_group.id)
    c = {
        "user": request.user,
        "machine_group": machine_group,
        "user_level": user_level,
        "is_editor": is_editor,
        "business_unit": business_unit,
        "output": output,
    }
    return render_to_response("server/group_dashboard.html", c, context_instance=RequestContext(request))
Esempio n. 6
0
def index(request):
    # Get the current user's Business Units
    user = request.user
    # Count the number of users. If there is only one, they need to be made a GA
    if User.objects.count() == 1:
        # The first user created by syncdb won't have a profile. If there isn't one, make sure they get one.
        try:
            profile = UserProfile.objects.get(user=user)
        except UserProfile.DoesNotExist:
            profile = UserProfile(user=user)

        profile.level = 'GA'
        profile.save()
    user_level = user.userprofile.level
    now = datetime.now()
    hour_ago = now - timedelta(hours=1)
    today = date.today()
    week_ago = today - timedelta(days=7)
    month_ago = today - timedelta(days=30)
    three_months_ago = today - timedelta(days=90)
    config_installed = 'config' in settings.INSTALLED_APPS
    if user_level != 'GA':
        # user has many BU's display them all in a friendly manner
        business_units = user.businessunit_set.all()
        if user.businessunit_set.count() == 0:
            c = {'user': request.user, }
            return render_to_response('server/no_access.html', c, context_instance=RequestContext(request))
        if user.businessunit_set.count() == 1:
            # user only has one BU, redirect to it
            for bu in user.businessunit_set.all():
                return redirect('server.views.bu_dashboard', bu_id=bu.id)
                break

    if user_level == 'GA':
        machines = Machine.objects.all()
    else:
        machines = Machine.objects.none()
        for business_unit in user.businessunit_set.all():
            for group in business_unit.machinegroup_set.all():
                machines = machines | group.machine_set.all()

    # Load in the default plugins if needed
    utils.loadDefaultPlugins()
    # Build the manager
    manager = PluginManager()
    # Tell it the default place(s) where to find plugins
    manager.setPluginPlaces([settings.PLUGIN_DIR, os.path.join(settings.PROJECT_DIR, 'server/plugins')])
    # Load all plugins
    manager.collectPlugins()
    output = []
    # Get all the enabled plugins
    enabled_plugins = Plugin.objects.all().order_by('order')
    for enabled_plugin in enabled_plugins:
        # Loop round the plugins and print their names.
        for plugin in manager.getAllPlugins():
            if plugin.name == enabled_plugin.name:
                data = {}
                data['name'] = plugin.name
                (data['html'], data['width']) = plugin.plugin_object.show_widget('front', machines)
                output.append(data)
                break

    output = utils.orderPluginOutput(output)

    # get the user level - if they're a global admin, show all of the machines. If not, show only the machines they have access to
    if user_level == 'GA':
        business_units = BusinessUnit.objects.all()
    else:
        business_units = user.businessunit_set.all()

    c = {'user': request.user, 'business_units': business_units, 'output': output, }
    return render_to_response('server/index.html', c, context_instance=RequestContext(request))