Exemple #1
0
def overview(request, template="territory/territory.html"):
    somalia = ",".join([
        "[%s,%s]" % (x[0], x[1]) for x in Territory.convert_points(somalia_pts)
    ])
    user = gtc(request)
    if not Line.objects.filter(lineorder__character=user).exclude(
            faction=None).exists():
        messages.error(request, "You're not a member of any wargame factions.")
        return redirect('/')
    try:
        faction = Line.objects.filter(lineorder__character=user).exclude(
            faction=None)[0].faction
    except IndexError:
        raise Http404
    #    units = Unit.live_units().filter(faction=faction)
    territories = Territory.objects.all()
    owned_terrs = faction.territory_set.all()
    builds = BuildOrder.objects.filter(faction=faction,
                                       turn=GameBoard.get_turn())
    context = {
        'faction': faction,
        'gameboard': GameBoard,
        'w_turn': GameBoard.get_turn(),
        'last_w_turn': GameBoard.get_turn() - 1,  #ugh
        'orders': json.dumps(get_orders(faction.code)),
        'builds': builds,
        'somalia': somalia,
        'territories': territories,
        'owned_terrs': owned_terrs
    }
    return render(request, template, context)
Exemple #2
0
def overview(request, template="territory/territory.html"):
    somalia = ",".join(["[%s,%s]" % (x[0], x[1]) for x in Territory.convert_points(somalia_pts)])
    user = gtc(request)
    if not Line.objects.filter(lineorder__character=user).exclude(faction=None).exists():
        messages.error(request, "You're not a member of any wargame factions.")
        return redirect('/')
    try:
        faction = Line.objects.filter(lineorder__character=user).exclude(faction=None)[0].faction
    except IndexError:
        raise Http404
    #    units = Unit.live_units().filter(faction=faction)
    territories = Territory.objects.all()
    owned_terrs = faction.territory_set.all()
    builds = BuildOrder.objects.filter(faction=faction, turn=GameBoard.get_turn())
    context = {
        'faction': faction,
        'gameboard': GameBoard,
        'w_turn': GameBoard.get_turn(),
        'last_w_turn': GameBoard.get_turn()-1, #ugh
        'orders': json.dumps(get_orders(faction.code)),
        'builds': builds,
        'somalia': somalia,
        'territories': territories,
        'owned_terrs': owned_terrs
    }
    return render(request, template, context)
Exemple #3
0
def security(request, template='security/security.html'):
    char = gtc(request)
    if request.method == 'POST':
        if request.POST.get('type') == 'entry':
            try:
                try:
                    time = make_aware(parse(request.POST.get('time')),
                                      timezone.get_default_timezone())
                except ValueError:
                    raise ValidationError("Invalid time; window not created.")
                except NonExistentTimeError:
                    raise ValidationError(
                        "Go google 'Daylight Saving Time' and try again.")
                if time < now():
                    raise ValidationError("Start time must be in the future.")
                try:
                    location = SecureLocation.objects.get(
                        room=request.POST.get('room').strip())
                except SecureLocation.DoesNotExist:
                    raise ValidationError("No secure location in room %s." %
                                          request.POST.get('room').strip())
                new = EntryWindow.objects.create(
                    location=location,
                    start_time=time,
                    creator=char,
                    person=request.POST.get('person'))
                messages.success(request, "Window created!")
                check_inspiration(request)
            except ValidationError, e:
                messages.error(request, e.messages[0])
        else:
            try:
                try:
                    time = make_aware(parse(request.POST.get('time')),
                                      timezone.get_default_timezone())
                except NonExistentTimeError:
                    raise ValidationError(
                        "Go google 'Daylight Saving Time' and try again.")
                except ValueError:
                    raise ValidationError("Invalid time; window not created.")
                if time < now():
                    raise ValidationError("Start time must be in the future.")
                try:
                    location = SecureLocation.objects.get(
                        room=request.POST.get('room').strip())
                except SecureLocation.DoesNotExist:
                    raise ValidationError("No secure location in room %s." %
                                          request.POST.get('room').strip())
                new = SecurityWindow.objects.create(location=location,
                                                    start_time=time,
                                                    creator=char)
                messages.success(request, "Window created!")
                check_inspiration(request)
            except ValidationError, e:
                messages.error(request, e.messages[0])
Exemple #4
0
def char_profile(request, char_id, template="consortium/char_profile.html"):
    char = gtc(request)
    p_char = get_object_or_404(Character, id=char_id)
    fields = GameTeXFieldValue.objects.filter(object=p_char.gto)
    context = {
        'request_char': char,
        'char': p_char,
        'fields': fields
    }

    return render(request, template, context)
Exemple #5
0
def mail_home(request, template="messaging/mail_home.html"):
    char = gtc(request)
    context = {
        # 'special_mailboxes': Mailbox.objects.filter(public=True, type=0).order_by('name'),
        'char_mailboxes':
        Mailbox.objects.filter(public=True, type=1).order_by('name'),
        'group_mailboxes':
        Mailbox.objects.filter(public=True, type=2).order_by('name'),
        'send_mailboxes':
        Mailbox.objects.filter(
            Q(character=char)
            | Q(line__lineorder__order=1, line__lineorder__character=char)).
        order_by('type'),
        'read_mailboxes':
        Mailbox.objects.filter(
            Q(character=char) | Q(line__lineorder__character=char))
    }
    if request.method == 'POST':
        try:
            context['mail_text'] = request.POST.get('text')
            new_mail = Message()
            new_mail.sender = Mailbox.objects.get(
                code=request.POST.get('from_code'))
            try:
                new_mail.to = Mailbox.objects.get(
                    code=request.POST.get('to_code'))
            except Mailbox.DoesNotExist:
                try:
                    new_mail.to = Mailbox.objects.get(
                        name=request.POST.get('to_name'))
                except Mailbox.DoesNotExist:
                    raise ValidationError("That mailbox doesn't exist.")
            new_mail.text = request.POST.get('text')
            new_mail.subject = request.POST.get('subject')
            new_mail.anon = request.POST.get('anon') == 'on'
            new_mail.save()
            if new_mail.anon:
                check_inspiration(request)
            try:
                subprocess.Popen([
                    'zwrite', '-d', '-c', 'consortium-sekrit-auto', '-m',
                    "Mail from %s to %s\nSubject: %s\n%s" %
                    (new_mail.sender.name, new_mail.to.name, new_mail.subject,
                     new_mail.text.replace('"', "'"))
                ])
            except:
                pass
            messages.success(request, "Sent mail to %s" % new_mail.to.name)
            context['mail_text'] = ''
        except ValidationError, e:
            messages.error(request, e.messages[0])
Exemple #6
0
def security(request, template='security/security.html'):
    char = gtc(request)
    if request.method == 'POST':
        if request.POST.get('type') == 'entry':
            try:
                try:
                    time = make_aware(parse(request.POST.get('time')), timezone.get_default_timezone())
                except ValueError:
                    raise ValidationError("Invalid time; window not created.")
                except NonExistentTimeError:
                    raise ValidationError("Go google 'Daylight Saving Time' and try again.")
                if time < now():
                    raise ValidationError("Start time must be in the future.")
                try:
                    location = SecureLocation.objects.get(room=request.POST.get('room').strip())
                except SecureLocation.DoesNotExist:
                    raise ValidationError("No secure location in room %s." % request.POST.get('room').strip())
                new = EntryWindow.objects.create(location=location, start_time=time, creator=char, person=request.POST.get('person'))
                messages.success(request, "Window created!")
                check_inspiration(request)
            except ValidationError, e:
                messages.error(request, e.messages[0])
        else:
            try:
                try:
                    time = make_aware(parse(request.POST.get('time')), timezone.get_default_timezone())
                except NonExistentTimeError:
                    raise ValidationError("Go google 'Daylight Saving Time' and try again.")
                except ValueError:
                    raise ValidationError("Invalid time; window not created.")
                if time < now():
                    raise ValidationError("Start time must be in the future.")
                try:
                    location = SecureLocation.objects.get(room=request.POST.get('room').strip())
                except SecureLocation.DoesNotExist:
                    raise ValidationError("No secure location in room %s." % request.POST.get('room').strip())
                new = SecurityWindow.objects.create(location=location, start_time=time, creator=char)
                messages.success(request, "Window created!")
                check_inspiration(request)
            except ValidationError, e:
                messages.error(request, e.messages[0])
Exemple #7
0
def mail_home(request, template="messaging/mail_home.html"):
    char = gtc(request)
    context = {
        # 'special_mailboxes': Mailbox.objects.filter(public=True, type=0).order_by('name'),
        'char_mailboxes': Mailbox.objects.filter(public=True, type=1).order_by('name'),
        'group_mailboxes': Mailbox.objects.filter(public=True, type=2).order_by('name'),
        'send_mailboxes': Mailbox.objects.filter(Q(character=char) | Q(line__lineorder__order=1, line__lineorder__character=char)).order_by('type'),
        'read_mailboxes': Mailbox.objects.filter(Q(character=char) | Q(line__lineorder__character=char))

    }
    if request.method == 'POST':
        try:
            context['mail_text'] = request.POST.get('text')
            new_mail = Message()
            new_mail.sender = Mailbox.objects.get(code=request.POST.get('from_code'))
            try:
                new_mail.to = Mailbox.objects.get(code=request.POST.get('to_code'))
            except Mailbox.DoesNotExist:
                try:
                    new_mail.to = Mailbox.objects.get(name=request.POST.get('to_name'))
                except Mailbox.DoesNotExist:
                    raise ValidationError("That mailbox doesn't exist.")
            new_mail.text = request.POST.get('text')
            new_mail.subject = request.POST.get('subject')
            new_mail.anon = request.POST.get('anon') == 'on'
            new_mail.save()
            if new_mail.anon:
                check_inspiration(request)
            try:
                subprocess.Popen(['zwrite', '-d', '-c', 'consortium-sekrit-auto', '-m', "Mail from %s to %s\nSubject: %s\n%s" % (new_mail.sender.name,
                new_mail.to.name, new_mail.subject, new_mail.text.replace('"', "'"))])
            except:
                pass
            messages.success(request, "Sent mail to %s" % new_mail.to.name)
            context['mail_text'] = ''
        except ValidationError, e:
            messages.error(request, e.messages[0])