def display_open_tickets_for_plot(self, plot): """Displays unresolved requests for review for a plot""" tickets = plot.tickets.filter(status=Ticket.OPEN_STATUS) table = PrettyTable(["ID", "Title"]) for ticket in tickets: table.add_row([ticket.id, ticket.title]) self.msg("Open tickets for %s:\n%s" % (plot, table))
def create_table_view(self, templates): table = PrettyTable( ["Id", "Name", "Attribution", "Markup", "Access Level", "In Use"]) for template in templates: attribution = template.attribution if template.apply_attribution else "" access_level = "" for var in Template.ACCESS_LEVELS: if template.access_level == var[0]: access_level = var[1] in_use = "TRUE" if template.in_use() else "FALSE" if template.owner != self.caller.roster.current_account: in_use = "" table.add_row([ template.id, template.title, attribution, template.markup(), access_level, in_use, ]) return ArxCommandTest.format_returned_msg([str(table)], True)
def list(self, caller): table = PrettyTable([ "{wId{n", "{wName{n", "{wAttribution{n", "{wMarkup{n", "{wAccess Level{n", "{wIn Use{n", ]) for template in Template.objects.accessible_by(self.caller): attribution = template.attribution if template.apply_attribution else "" in_use = "TRUE" if template.in_use() else "FALSE" if template.owner != self.caller.roster.current_account: in_use = "" access_level = "" for var in Template.ACCESS_LEVELS: if template.access_level == var[0]: access_level = var[1] table.add_row([ template.id, template.title, attribution, template.markup(), access_level, in_use, ]) arx_more.msg(caller, str(table), justify_kwargs=False)
def view_outfits(self, archived=False): """Views elements of one outfit as table, or a table of outfits.""" if self.args: outfit = get_caller_outfit_from_args(self.caller, self.args) msg = outfit.table_display else: outfits = self.caller.dompc.fashion_outfits.filter( archived=archived ).order_by("name") if len(outfits) < 1: status = "archived " if archived else "" alt = ( "regular 'outfits'" if archived else "creating one, or 'outfits/archives'" ) raise FashionError( "No %soutfits to display! Try %s instead." % (status, alt) ) outfit_header = "%sOutfit" % ("Archived " if archived else "") # TODO: event & vote columns table = PrettyTable(("Created", outfit_header, "Appraisal/Buzz")) for outfit in outfits: date = outfit.db_date_created.strftime("%Y/%m/%d") table.add_row((date, outfit.name, outfit.appraisal_or_buzz)) msg = str(table) self.msg(msg)
def display_recipes(self, recipes): from server.utils import arx_more if not recipes: self.msg("(No recipes qualify.)") return known_list = CraftingRecipe.objects.filter( known_by__player__player=self.caller.player) table = PrettyTable( ["{wKnown{n", "{wName{n", "{wAbility{n", "{wLvl{n", "{wCost{n"]) def getter(a): return a.ability or "" recipes = sorted(recipes, key=getter) for recipe in recipes: known = "{wX{n" if recipe in known_list else "" table.add_row([ known, str(recipe), recipe.ability, recipe.difficulty, recipe.additional_cost, ]) arx_more.msg(self.caller, str(table), justify_kwargs=False)
def broker_display(self): """Displays items for sale on the broker""" qs = BrokeredSale.objects.filter(amount__gte=1) if "search" in self.switches and self.args: sale_type = self.get_sale_type() if sale_type in (BrokeredSale.ACTION_POINTS, BrokeredSale.ECONOMIC, BrokeredSale.SOCIAL, BrokeredSale.MILITARY): query = Q(sale_type=sale_type) else: if set(self.args.lower().split()) & { "materials", "mats", "crafting" }: query = Q(sale_type=BrokeredSale.CRAFTING_MATERIALS) elif "resource" in self.args.lower(): query = Q(sale_type__in=(BrokeredSale.ECONOMIC, BrokeredSale.SOCIAL, BrokeredSale.MILITARY)) else: query = ( Q(crafting_material_type__name__icontains=self.args) | Q(owner__player__username__iexact=self.args)) qs = qs.filter(query) table = PrettyTable(["ID", "Seller", "Type", "Price", "Amount"]) for deal in qs: table.add_row([ deal.id, str(deal.owner), str(deal.material_name), deal.price, deal.amount ]) self.msg(str(table))
def list_special_actions(self): """Gets string display of GM-defined special actions""" msg = "Current Actions:\n" table = PrettyTable(["#", "Name", "Stat", "Skill", "Difficulty"]) for num, action in enumerate(self.special_actions, 1): table.add_row([ num, action.name, action.stat, action.skill, action.difficulty ]) return msg + str(table)
def view_leaderboards(self): """Views table of fashion leaders""" from django.db.models import Sum, Count, Avg, F, IntegerField pretty_headers = ["Fashion Model", "Fame", "Items", "Avg Item Fame"] # default for top 20 models def get_queryset(manager, group_by_string, fame_divisor): """Teeny helper function for getting annotated queryset""" return (manager.values_list(group_by_string).annotate( total_fame=Sum(F('fame') / fame_divisor)).annotate( Count('id')).annotate(avg=Avg( F('fame') / fame_divisor, output_field=IntegerField())).order_by('-total_fame')) if "designer" in self.switches or "designers" in self.switches: if self.args: designer = self.caller.player.search(self.args) if not designer: return pretty_headers[0] = "%s Model" % designer designer = designer.Dominion qs = get_queryset(designer.designer_snapshots, 'fashion_model__player__username', Snapshot.DESIGNER_FAME_DIVISOR) else: pretty_headers[0] = "Designer" qs = get_queryset(Snapshot.objects, 'designer__player__username', Snapshot.DESIGNER_FAME_DIVISOR) elif "org" in self.switches or "orgs" in self.switches: if self.args: org = Organization.objects.get_public_org( self.args, self.caller) if not org: return pretty_headers[0] = "%s Model" % org qs = get_queryset(org.fashion_snapshots, 'fashion_model__player__username', Snapshot.ORG_FAME_DIVISOR) else: pretty_headers[0] = "Organization" qs = get_queryset(Snapshot.objects, 'org__name', Snapshot.ORG_FAME_DIVISOR) else: # Models by fame qs = get_queryset(Snapshot.objects, 'fashion_model__player__username', 1) qs = qs[:20] if "all" not in self.switches else qs if not qs: raise FashionError("Nothing was found.") table = PrettyTable(pretty_headers) for q in qs: # for lowercase names, we'll capitalize them if q[0] == q[0].lower(): q = list(q) q[0] = q[0].capitalize() table.add_row(q) self.msg(str(table))
def display_tickets(self, queryset): """Displays table of plot pitches""" table = PrettyTable(["ID", "Submitter", "Name", "Parent"]) for pitch in queryset: table.add_row([ pitch.id, str(pitch.submitting_player), pitch.plot.name, str(pitch.plot.parent_plot) ]) self.msg(str(table))
def display_available_plots(self): """Lists all plots available to caller""" qs = self.involvement_queryset.filter(plot__resolved="old" in self.switches).distinct() msg = "Plot Involvement:\n" table = PrettyTable(["Name/ID", "Involvement"]) for involvement in qs: name = "%s (#%s)" % (involvement.plot, involvement.plot.id) status = involvement.get_modified_status_display() table.add_row([name, status]) msg += str(table) self.msg(msg)
def list_petitions(self): """Lists petitions for org/player""" if ("search" in self.switches and self.rhs) or ( self.args and "search" not in self.switches ): if self.rhs: org = self.get_org_from_args(self.rhs) else: org = self.get_org_from_args(self.lhs) if not org.access(self.caller, "view_petition"): raise self.PetitionCommandError( "You do not have access to view petitions for %s." % org ) qs = org.petitions.all() else: orgs = Organization.objects.filter(members__deguilded=False).filter( members__player=self.caller.dompc ) orgs = [org for org in orgs if org.access(self.caller, "view_petition")] query = Q(organization__in=orgs) if "onlyorgs" not in self.switches: query = ( query | Q(organization__isnull=True) | Q(dompcs=self.caller.dompc) ) qs = Petition.objects.filter(query).order_by("-date_updated") if "old" in self.switches: qs = qs.filter(closed=True) else: qs = qs.filter(closed=False) if "search" in self.switches: qs = qs.filter( Q(topic__icontains=self.lhs) | Q(description__icontains=self.lhs) ) signed_up = list( self.caller.dompc.petitions.filter(petitionparticipation__signed_up=True) ) table = PrettyTable(["Updated", "ID", "Owner", "Topic", "Org", "On"]) for ob in qs.distinct(): signed_str = "X" if ob in signed_up else "" table.add_row( [ self.color_coder(ob, self.caller.dompc) + ob.date_updated.strftime("%m/%d/%y"), ob.id, str(ob.owner), ob.topic[:30], str(ob.organization), signed_str, ] ) self.msg(str(table)) self.display_petition_form()
def table_display(self): """A non-cached table of outfit items/locations, then model-info string.""" from server.utils.prettytable import PrettyTable table = PrettyTable((str(self), "Slot", "Location")) modi = self.modusornamenta_set.all() for mo in modi: table.add_row((str(mo.fashion_item), mo.slot or "", str(mo.fashion_item.location))) msg = str(table) if self.modeled: msg += "\n" + self.model_info # TODO: Include existing event info :) # TODO: Include existing fashion judge votes & comments! return msg
def list_rolls_for_special_actions(self): """Gets string display of all rolls players have made for GM-defined special actions""" actions = self.get_current_and_queued_actions() actions = [ ob for ob in actions if ob.special_action in self.special_actions ] table = PrettyTable(["Name", "Action", "Roll"]) for action in actions: table.add_row([ str(action.character), str(action.special_action), action.display_roll(), ]) return str(table)
def build_status_table(self): """Builds a table of the status of combatants""" combatants = sorted(self.ndb.combatants) table = PrettyTable([ "{wCombatant{n", "{wDamage{n", "{wFatigue{n", "{wAction{n", "{wReady?{n" ]) for state in combatants: name = state.combat_handler.name dmg = state.character.get_wound_descriptor(state.character.dmg) fatigue = str(state.fatigue_penalty) action = "None" if not state.queued_action else state.queued_action.table_str rdy = "yes" if state.ready else "{rno{n" table.add_row([name, dmg, fatigue, action, rdy]) self.ndb.status_table = table
def display_clue_table(self, attr): """ Returns a string of a PrettyTable of clues Args: attr(str): secrets or visions, the attribute we're fetching Returns: A string of a PrettyTable for those ClueDiscoveries """ from server.utils.prettytable import PrettyTable table = PrettyTable(["{w#", "{wName", "{wDate:"]) for ob in getattr(self, attr): name = ob.name if len(name) > 35: name = name[:32] + "..." table.add_row([ob.clue.id, name, ob.date.strftime("%x")]) return str(table)
def do_display(self): """Whatever text you want to display to characters when they just type 'pray' here.""" prayers = self.caller.prayers.all() if self.rhs: prayers = prayers.filter(entity__name__iexact=self.rhs) # list prayers table = PrettyTable( ["{w#", "{wEntity", "|wStatus|n", "{wDate|n", "|wPrayer|n"]) for prayer in prayers: table.add_row([ str(prayer.id), str(prayer.entity), str(prayer.status), prayer.db_date_created.strftime("%x"), prayer.text[:30], ]) self.msg(str(table))
def display_recipes(self, recipes): from server.utils import arx_more known_list = CraftingRecipe.objects.filter( known_by__player__player=self.caller.player) table = PrettyTable([ "{wKnown{n", "{wName{n", "{wAbility{n", "{wDifficulty{n", "{wCost{n" ]) from operator import attrgetter recipes = sorted(recipes, key=attrgetter('ability', 'difficulty', 'name')) for recipe in recipes: known = "{wX{n" if recipe in known_list else "" table.add_row([ known, recipe.name, recipe.ability, recipe.difficulty, recipe.additional_cost ]) arx_more.msg(self.caller, str(table), justify_kwargs=False)
def display_available_plots(self): """Lists all plots available to caller""" old = "old" in self.switches qs = self.involvement_queryset.filter(plot__resolved=old).distinct() table = PrettyTable( ["|w{}Plot (ID)|n".format("Resolved " if old else ""), "|wInvolvement|n"] ) for involvement in qs: if involvement.activity_status in ( involvement.INVITED, involvement.HAS_RP_HOOK, ): color = "|y" else: color = "" name = "{}{} (#{})|n".format(color, involvement.plot, involvement.plot.id) status = "{}{}|n".format(color, involvement.get_modified_status_display()) table.add_row([name, status]) self.msg(str(table))