Example #1
0
 def broadcast(self, content, category, link=None):
     new_turn_message = shortcuts.create_message(content,
                                                 self,
                                                 category,
                                                 link=link)
     for character in self.character_set.all():
         shortcuts.add_character_recipient(new_turn_message, character)
Example #2
0
 def add_notification(self, template, title, template_context=None):
     if template_context is None:
         template_context = {}
     message = shortcuts.create_message(
         template=template,
         world=self.world,
         title=title,
         template_context=template_context
     )
     shortcuts.add_character_recipient(message, self)
    def broadcast(self, template, title, context=None, link=None):
        if context is None:
            context = {}

        message = shortcuts.create_message(
            template=template,
            world=self,
            title=title,
            template_context=context,
            link=link,
        )
        for character in self.character_set.all():
            shortcuts.add_character_recipient(message, character)
Example #4
0
    def create_recipients_from_post_data(self, request, message):
        raw_recipients = request.POST.getlist('recipient')
        organization_count = 0
        character_count = 0

        for raw_recipient in raw_recipients:
            split = raw_recipient.split('_')

            if split[0] == 'settlement':
                for character in request.hero.location.character_set.all():
                    character_count += 1
                    add_character_recipient(message, character)
            elif split[0] == 'region':
                for character in Character.objects.filter(
                        location__tile=request.hero.location.tile):
                    character_count += 1
                    add_character_recipient(message, character)
            elif split[0] == 'organization':
                organization_count += 1
                organization = get_object_or_404(Organization, id=split[1])
                add_organization_recipient(message, organization)
            elif split[0] == 'character':
                character_count += 1
                character = get_object_or_404(Character, id=split[1])
                add_character_recipient(message, character)
            else:
                message.delete()
                raise ComposeView.RecipientBuildingException(
                    "Invalid recipient.")

        if organization_count > 4 or character_count > 40:
            message.delete()
            raise ComposeView.RecipientBuildingException(
                "Too many recipients.")
def transfer_cash(request):
    transfer_cash_amount = int(request.POST.get('transfer_cash_amount'))

    to_character = get_object_or_404(Character,
                                     pk=request.POST.get('to_character_id'))

    if request.hero.location != to_character.location:
        messages.error(
            request, "You need to be in the same location to transfer money.",
            "danger")
        return redirect('character:inventory')

    if transfer_cash_amount > request.hero.cash:
        messages.error(request, "You have not enough cash.", "danger")
        return redirect('character:inventory')

    if transfer_cash_amount < 1:
        messages.error(request, "That is not a valid cash amount.", "danger")
        return redirect('character:inventory')

    request.hero.cash = request.hero.cash - transfer_cash_amount
    to_character.cash = to_character.cash + transfer_cash_amount

    request.hero.save()
    to_character.save()

    messages.success(request, "The transaction was successful.", "success")

    message = shortcuts.create_message(
        'messaging/messages/cash_received.html', request.hero.world,
        "You receive {} coins".format(transfer_cash_amount), {
            'sender': request.hero,
            'amount': transfer_cash_amount
        })
    shortcuts.add_character_recipient(message, to_character)

    return redirect('character:inventory')