def do_creation_switches(self): """Handles creation of a new petition""" form = self.caller.db.petition_form if "submit" in self.switches: if not form: raise self.PetitionCommandError( "You must create a form first.") form = PetitionForm(form, owner=self.caller.dompc) if not form.is_valid(): raise self.PetitionCommandError(form.display_errors()) petition = form.save() self.msg("Successfully created petition %s." % petition.id) self.caller.attributes.remove("petition_form") else: if "create" in self.switches: if form: self.display_petition_form() raise self.PetitionCommandError( "You already are creating a petition.") self.caller.db.petition_form = { 'topic': self.lhs or None, 'description': self.rhs } elif form is None: raise self.PetitionCommandError("You must use /create first.") elif "topic" in self.switches: form['topic'] = self.args elif "desc" in self.switches: form['description'] = self.args elif "org" in self.switches: from world.dominion.models import Organization if not self.args: form['organization'] = None else: try: form['organization'] = Organization.objects.get( name__iexact=self.args).id except (Organization.DoesNotExist, ValueError, TypeError): raise self.PetitionCommandError( "No organization by that name.") elif "cancel" in self.switches: self.caller.attributes.remove("petition_form") self.msg("Petition form cancelled.") self.display_petition_form()
def display_petition_form(self): """Displays petition information""" form = self.caller.db.petition_form if not form: return self.msg(PetitionForm(form, owner=self.caller.dompc).display())
def do_creation_switches(self): """Handles creation of a new petition""" form = self.caller.db.petition_form if "submit" in self.switches: if not form: raise self.PetitionCommandError( "You must create a form first.") form = PetitionForm(form, owner=self.caller.dompc) if not form.is_valid(): raise self.PetitionCommandError(form.display_errors()) petition = form.save() self.msg("Successfully created petition %s." % petition.id) self.caller.attributes.remove("petition_form") if petition.organization is not None: targets = PetitionSettings.objects.all().exclude( ignored_organizations=petition.organization).exclude( inform=False) for target in targets: target.owner.player.msg( "{wA new petition was posted by %s to %s.{n" % (petition.owner, petition.organization)) target.owner.player.inform( "{wA new petition was posted by %s to %s.{n|/|/%s" % (petition.owner, petition.organization, petition.display()), category="Petition", append=True) else: targets = PetitionSettings.objects.all().exclude( inform=False).exclude(ignore_general=True) for target in targets: target.owner.player.msg( "{wA new petition was posted by %s{n" % (petition.owner)) target.owner.player.inform( "{wA new petition was posted by %s{n|/|/%s" % (petition.owner, petition.display()), category="Petition", append=True) else: if "create" in self.switches: if form: self.display_petition_form() raise self.PetitionCommandError( "You already are creating a petition.") self.caller.db.petition_form = { 'topic': self.lhs or None, 'description': self.rhs } elif form is None: raise self.PetitionCommandError("You must use /create first.") elif "topic" in self.switches: form['topic'] = self.args elif "desc" in self.switches: form['description'] = self.args elif "org" in self.switches: from world.dominion.models import Organization if not self.args: form['organization'] = None else: try: form['organization'] = Organization.objects.get( name__iexact=self.args).id except (Organization.DoesNotExist, ValueError, TypeError): raise self.PetitionCommandError( "No organization by that name.") elif "cancel" in self.switches: self.caller.attributes.remove("petition_form") self.msg("Petition form cancelled.") self.display_petition_form()