Example #1
0
def aidpage(request, nation_id):
    nation = utils.get_player(nation_id)
    order = request.COOKIES.get('order_by', '-timestamp')
    try:
        if '-' in order:
            Aid._meta.get_field(order[1:])
        else:
            Aid._meta.get_field(order)
    except:
        order = "-timestamp"
    aid = Aid.objects.filter(Q(sender=nation)
                             | Q(reciever=nation)).order_by(order)
    pager, logs = utils.paginate_me(aid, 25, request.GET.get('page', 1))

    direction = "up"
    if '-' in order:
        direction = "down"
        order = order[1:]

    context = {
        'target': nation,
        'pages': utils.pagination(pager, logs),
        'aids': logs,
        'ordering': order,
        'direction': 'arrow-' + direction,
    }
    """
    disabled because not implemented for sqlite
    incoming = calculaid(nation.incoming_aid, 'sender')
    if incoming:
        context.update({'incoming': {'player': incoming[0], 'count': incoming[1]}})
    outgoing = calculaid(nation.outgoing_aid, 'reciever')
    if outgoing:
        context.update({'outgoing': {'player': outgoing[0], 'count': outgoing[1]}})
        """

    #This section is for the totals regarding aid
    #like how much money has been sent or recieved
    #in a specfic order so dicts don't derp it
    #this data should be cached at some point to avoid the excess database hits
    ordering = [
        'budget', 'rm', 'mg', 'oil', 'food', 'troops', 'weapons', 'research',
        'uranium', 'nuke'
    ]
    totals = []
    for resource in ordering:
        total_in = nation.incoming_aid.filter(resource=resource).aggregate(
            total=Sum('amount'))['total']
        total_in = (total_in if total_in != None else 0)
        total_out = nation.outgoing_aid.filter(resource=resource).aggregate(
            total=Sum('amount'))['total']
        total_out = (total_out if total_out != None else 0)
        totals.append({
            'resource': v.aidnames[resource],
            'incoming': total_in,
            'outgoing': total_out
        })
    context.update({'totals': totals})
    return render(request, 'mod/aidpage.html', context)
Example #2
0
def main(request):
    context = {}
    nation = request.user.nation
    result = False

    if request.method == 'POST':
        if 'newid' in request.POST:
            form = newidform(request.POST)
            if form.is_valid():
                player = utils.get_player(form.cleaned_data['old'])
                if player:
                    assign_id(player, form.cleaned_data['new'])
                    result = "%s has been assigned ID %s" % (
                        player.name, form.cleaned_data['new'])
                else:
                    result = "No nation found for '%s'" % form.cleaned_data[
                        'old']

        elif 'viewplayer' in request.POST:
            form = viewplayerform(request.POST)
            if form.is_valid():
                player = utils.get_active_player(form.cleaned_data['player'])
                if player:
                    return redirect('mod:nation', nation_id=player.index)

        elif 'comm' in request.POST:
            form = globalcommform(request.POST)
            if form.is_valid():
                for n in Nation.objects.filter(deleted=False).iterator():
                    n.comms.create(message=form.cleaned_data['content'],
                                   globalcomm=True)
                result = "Global communique has been issued!"
            else:
                result = "Bad input"

        elif 'quick' in request.POST:
            form = quickactionform(request.POST)
            if form.is_valid():
                player = utils.get_active_player(form.cleaned_data['player'])
                if player:
                    result = actions.__dict__[form.cleaned_data['action']](
                        nation, player, form.cleaned_data['reason'])

                else:
                    result = "That nation doesn't exist!"
            else:
                result = "Invalid POST data (did you forget the enter a reason?)"

    context.update({
        'result': result,
        'reportcount': Report.objects.filter(closed=False).count(),
        'globalcommform': globalcommform(),
        'quickactionform': quickactionform(),
        'viewplayerform': viewplayerform(),
        'newidform': newidform(),
    })
    return render(request, 'mod/main.html', context)
Example #3
0
def basedetails(request, nation_id, manager, pcheck, var):
    nation = request.user.nation
    target = utils.get_player(nation_id)
    if target == False:
        return render(request, 'mod/not_found.html')
    context = {'target': target}
    utils.pagecheck(nation, target, pcheck)
    query = getattr(target, manager).all().order_by('-pk')
    paginator, actionlist = utils.paginate_me(query, 50, page)
    context.update({
        'pages': utils.pagination(paginator, actionlist),
        var: actionlist,
    })
    return context
Example #4
0
def nation_logins(request, nation_id):
    nation = request.user.nation
    target = utils.get_player(nation_id)
    if target == False:
        return render(request, 'mod/not_found.html')
    context = {'target': target}
    page = (request.GET['page'] if 'page' in request.GET else 1)
    utils.pagecheck(nation, target, "all wars")
    query = target.login_times.all().order_by('-pk')
    paginator, actionlist = utils.paginate_me(query, 50, page)
    context.update({
        'pages': utils.pagination(paginator, actionlist),
        'logins': actionlist,
    })
    return details(request, nation_id, page, 'logins')
Example #5
0
def nation_allaid(request, nation_id):
    nation = request.user.nation
    target = utils.get_player(nation_id)
    if target == False:
        return render(request, 'mod/not_found.html')
    context = {'target': target}
    page = (request.GET['page'] if 'page' in request.GET else 1)
    utils.pagecheck(nation, target, "all aid")
    query = Aidlog.objects.filter(Q(sender=target)
                                  | Q(reciever=target)).order_by('-pk')
    paginator, actionlist = utils.paginate_me(query, 50, page)
    context.update({
        'pages': utils.pagination(paginator, actionlist),
        'aidlist': actionlist,
    })
    return render(request, 'mod/allaid.html', context)
Example #6
0
def nation_wars(request, nation_id):
    nation = request.user.nation
    target = utils.get_player(nation_id)
    if target == False:
        return render(request, 'mod/not_found.html')
    context = {'target': target}
    page = (request.GET['page'] if 'page' in request.GET else 1)
    utils.pagecheck(nation, target, "all wars")
    query = War.objects.filter(Q(attacker=target)
                               | Q(defender=target)).order_by('-pk')
    paginator, actionlist = utils.paginate_me(query, 50,
                                              request.GET.get('page', 1))
    context.update({
        'pages': utils.pagination(paginator, actionlist),
        'reports': actionlist,
    })
    return render(request, 'mod/wars.html', context)
Example #7
0
def nation_outgoing(request, nation_id):
    nation = request.user.nation
    target = utils.get_player(nation_id)
    if target == False:
        return render(request, 'mod/not_found.html')
    page = (request.GET['page'] if 'page' in request.GET else 1)
    context = {
        'target': target,
        'title': 'All outgoing aid',
        'direction': 'out'
    }
    utils.pagecheck(nation, target, "outgoing aid")
    query = target.outgoing_aid.all().order_by('-pk')
    paginator, actionlist = utils.paginate_me(query, 50, page)
    context.update({
        'pages': utils.pagination(paginator, actionlist),
        'aidlist': actionlist,
    })
    return render(request, 'mod/aid.html', context)
Example #8
0
def iplogs(request, nation_id):
    nation = request.user.nation
    target = utils.get_player(nation_id)
    if target == False:
        return render(request, 'mod/not_found.html')
    context = {'target': target}
    #POST data handling
    #what little of it there are
    if request.method == "POST":
        if 'correlate' in request.POST:
            context.update({'result': 'not yet implemented'})

        elif 'checkip' in request.POST:
            try:
                ip = target.IPs.get(pk=request.POST['checkip'])
            except:
                context.update({'result': 'Invalid entry'})
            else:
                context.update({
                    'associates':
                    IP.objects.select_related('nation').filter(IP=ip.IP),
                    'checked':
                    True,
                    'selected_ip':
                    ip.IP,
                })

    query = target.IPs.all().order_by('-pk')
    iplist = []
    for ip in query:
        ip.nationcount = IP.objects.filter(IP=ip.IP).count()
        iplist.append(ip)
    context.update({
        'IPs': query,
    })
    return render(request, 'mod/ips.html', context)
Example #9
0
def nation_page(request, nation_id):
    nation = request.user.nation
    context = {}
    pagename = "overview"
    result = False
    target = utils.get_player(nation_id)
    if target == False:
        return render(request, 'mod/not_found.html')
    utils.pagecheck(nation, target, pagename)
    if request.method == "POST":
        form = reasonform(request.POST)
        if form.is_valid():
            if 'delete' in request.POST:
                delete_nation(target)
                nation.mod_actions.create(
                    action="Deleted %s" % target.name,
                    reason=form.cleaned_data['reason'],
                    reversible=True,
                    reverse="not yet implemented",
                )
                result = "%s has been deleted" % target.name

            elif 'reportban' in request.POST:
                delall = (True if 'killreports' in request.POST else False)
                report_ban(target, delall)
                nation.mod_actions.create(
                    action="Report banned %s" % target.name,
                    reason=form.cleaned_data['reason'],
                    reversible=True,
                    reverse="not yet implemented",
                )
                result = "%s has banned from reporting" % target.name

            elif 'ban' in request.POST:
                act = "Deleted and banned %s" % target.name
                delete_nation(target)
                ips = []
                if 'banall' in request.POST:
                    act += " and banned all associated IPs"
                    for ip in target.IPs.all():
                        if not Ban.objects.filter(IP=ip.IP).exists():
                            Ban.objects.create(IP=ip.IP)
                            ips.append(ip.IP)
                else:
                    latest = target.IPs.all().latest('pk')
                    if not Ban.objects.filter(IP=latest.IP).exists():
                        Ban.objects.create(IP=latest.IP)
                        ips.append(latest.IP)

                nation.mod_actions.create(
                    action=act,
                    reason=form.cleaned_data['reason'],
                    reversible=True,
                    reverse="not yet implemented",
                )
                result = act

            elif 'deletewar' in request.POST:
                result, otherguy = delete_war(request, target)
                nation.mod_actions.create(
                    action="Deleted war between %s and %s" %
                    (target.name, otherguy),
                    reason=form.cleaned_data['reason'],
                    reversible=True,
                    reverse="not yet implemented",
                )
                result = "War between %s and %s has been deleted" % (
                    target.name, otherguy)

            elif 'force' in request.POST:
                target.vacation = True
                target.save(update_fields=["vacation"])
                nation.mod_actions.create(
                    action="Placed %s into vacation mode" % target.name,
                    reason=form.cleaned_data['reason'],
                    reversible=True,
                    reverse="not yet implemented",
                )
                result = "%s has been placed into vacation mode" % target.name

            elif 'remove' in request.POST:
                target.vacation = False
                target.save(update_fields=["vacation"])
                nation.mod_actions.create(
                    action="Removed %s from vacation mode" % target.name,
                    reason=form.cleaned_data['reason'],
                    reversible=True,
                    reverse="not yet implemented",
                )
                result = "%s has been removed from vacation mode" % target.name

        else:
            result = 'invalid reason (did you forget it?)'

    #set a variable that determines whether mod can see sensitive data
    #like logs of pretty much everything
    can_see = True
    #nation.investigated.all().filter(reported=target).exists()

    if can_see:
        context.update({
            'warlogs':
            War.objects.filter(Q(attacker=target) | Q(defender=target))[0:10],
            'aids':
            Aidlog.objects.filter(Q(sender=target) | Q(reciever=target))[0:10],
            'actionlogs':
            target.actionlogs.all()[0:10],
            'login_times':
            target.login_times.all()[0:10],
            'associated_IPs':
            target.IPs.all(),
        })
    context.update({
        'result':
        result,
        'can_see':
        can_see,
        'reasonform':
        reasonform(),
        'target':
        target,
        'reports_made':
        Report.objects.filter(reporter=target),
        'reports_made_count':
        Report.objects.filter(reporter=target).count(),
        'reports_dismissed_count':
        Report.objects.filter(reporter=target, guilty=False).count(),
    })

    return render(request, 'mod/nation.html', context)