def policy(request):
    policies = []
    for i in range(0,10):
        policy = PolicyModel(name="TestPolicy" + str(i), enabled="false", source="")
        policy.pk = i
        policyForm = PolicyModelForm(instance=policy)
        policies.append({ "policy" : policy, "policyForm" : policyForm })
    blank_policy_form = PolicyModelForm()
    return render_to_response('celerymanagementapp/policy.html',
            { "load_test_data" : "true",
            "policies" : policies,
            "blank_policy_form": blank_policy_form},
            context_instance=RequestContext(request))
Beispiel #2
0
def create_policy(name, source=None, schedule_src=None, condition_srcs=None, 
                  apply_src=None, enabled=True):
    """ Creates a new policy model object to the database.  If it doesn't 
        compile, an exception will be thrown.
    """
    assert isinstance(name, basestring)  # TODO: make this an exception
    source = policy.combine_sources(source, schedule_src, condition_srcs, 
                                    apply_src)
    # The following method should throw an exception if it fails, so the 
    # following 'raise' statement should never get called.  It is here for 
    # explanatory purposes.
    if not policy.check_source(source):
        msg = 'Invariant error:  policy.check_source() returned False.'
        raise RuntimeError(msg)
    model = PolicyModel(name=name, source=source, enabled=enabled)
    model.modified = datetime.datetime.now()
    model.save()
    return model