def Start(self):
    # We are already running.
    if self.flow_obj.Get(self.flow_obj.Schema.STATE) == "STARTED":
      return

    # Check the permissions for the hunt here. Note that self.args.token is the
    # original creators's token, while the aff4 object was created with the
    # caller's token. This check therefore ensures that the caller to this
    # method has permissions to start the hunt (not necessarily the original
    # creator of the hunt).
    data_store.DB.security_manager.CheckHuntAccess(
        self.flow_obj.token, self.session_id)

    # Determine when this hunt will expire.
    self.context.expires = self.args.expiry_time.Expiry()

    # When the next client can be scheduled. Implements gradual client
    # recruitment rate according to the client_rate.
    self.context.next_client_due = rdfvalue.RDFDatetime().Now()

    self._CreateAuditEvent("HUNT_STARTED")

    # Start the hunt.
    self.flow_obj.Set(self.flow_obj.Schema.STATE("STARTED"))
    self.flow_obj.Flush()

    if not self.args.add_foreman_rules:
      return

    # Add a new rule to the foreman
    foreman_rule = rdf_foreman.ForemanRule(
        created=rdfvalue.RDFDatetime().Now(),
        expires=self.context.expires,
        description="Hunt %s %s" % (self.session_id,
                                    self.args.hunt_name),
        regex_rules=self.args.regex_rules,
        integer_rules=self.args.integer_rules,
        client_rule_set=self.args.client_rule_set)

    foreman_rule.actions.Append(hunt_id=self.session_id,
                                hunt_name=self.args.hunt_name,
                                client_limit=self.args.client_limit)

    # Make sure the rule makes sense.
    foreman_rule.Validate()

    with aff4.FACTORY.Open("aff4:/foreman", mode="rw", token=self.token,
                           aff4_type="GRRForeman",
                           ignore_cache=True) as foreman:
      foreman_rules = foreman.Get(foreman.Schema.RULES,
                                  default=foreman.Schema.RULES())
      foreman_rules.Append(foreman_rule)
      foreman.Set(foreman_rules)
The 'change' admin view for this model.
dataset/ETHPy150Open google/grr/grr/lib/hunts/implementation.py/HuntRunner.Start--crossover with--dataset/ETHPy150Open Tivix/django-common/django_common/admin.py/NestedModelAdmin.change_view