Exemplo n.º 1
0
def mission(request,
            instance_id,
            mission_id=None,
            template="admin/trans_mission_edit_new.html"):
    is_new = False
    ok = verify(request)
    if ok != None:
        return ok

    try:
        instance = Instance.objects.untranslated().get(pk=int(instance_id))
    except Instance.DoesNotExist:
        raise Http404("Instance with id %s does not exist" % instance_id)

    if (request.POST.has_key("submit_btn")
            and request.POST["submit_btn"] == "Cancel"):
        return HttpResponseRedirect(
            reverse("admin:manage-missions", args=[instance_id]))

    if mission_id is not None and mission_id != 'None':
        try:
            mission = Mission.objects.untranslated().get(pk=int(mission_id))
        except Mission.DoesNotExist:
            raise Http404("Mission with id %s does not exist" % mission_id)
    else:
        mission = Mission(instance=instance)
        is_new = True

    errors = {}
    form = MissionForm(instance=mission,
                       languages=instance.languages.all(),
                       data=request.POST or None)

    if request.method == "POST":
        if form.is_valid():
            try:
                mission = form.save(commit=True)
                return HttpResponseRedirect(
                    reverse("admin:manage-missions", args=[instance_id]))
            except Exception, err:
                #transaction.rollback()
                print "error while saving mission: %s" % str(err)
                log.error("error while saving mission: %s" % str(err))
                errors.update({
                    "Updating mission":
                    "Server error took place. Please contact the admin."
                })
        else:
            for f in form.inner_trans_forms:
                if f.errors:
                    errors.update(f.errors)
            if form.errors:
                errors.update(form.errors)
Exemplo n.º 2
0
def mission_edit(request, mission_id=0, template="admin/mission/mission/edit.tpl"):
    mission = Mission.get_by_id(mission_id)
    if request.method == "GET":
        scenario_list = Scenario.get_all()
        return render_response(template, scenario_list=scenario_list, mission=mission)
    elif request.method == "POST":
        form = MissionForm(request.POST)
        if form.is_valid():
#             name = form.cleaned_data['name']
            ep = form.cleaned_data['ep']
#             vm = form.cleaned_data['vm']
#             xp = form.cleaned_data['xp']
            description = form.cleaned_data['description']
#             sum_count = form.cleaned_data['sum_count']
            is_unlock = form.cleaned_data['is_unlock']
            scenario_id = form.cleaned_data['scenario_id']
            mission_group_id = form.cleaned_data['mission_group_id']
            order = form.cleaned_data['order']
            level = form.cleaned_data['level']
            is_group_last = form.cleaned_data['is_group_last']
            vm = 35
            sum_count = 10
            if is_group_last:
                ep = 25
                vm = 180
                sum_count = 1
            if scenario_id < 3:
                ep = form.cleaned_data['ep']
            xp = ep * 5
            try:
#                 mission.name = name
                mission.ep = ep
                mission.vm = vm
                mission.xp = xp
                mission.description = description
                mission.sum_count = sum_count
                mission.is_unlock = is_unlock
                mission.scenario_id = scenario_id
                mission.mission_group_id = mission_group_id
                mission.order = order
                mission.level = level
                mission.is_group_last = is_group_last
                mission.save()
            except Exception, e:
                if config.debug:
                    print e
            else:
                return HttpResponse("<script type='text/javascript'>window.top.right.location.reload();window.top.art.dialog({id:'mission_edit'}).close();</script>")
Exemplo n.º 3
0
def mission_add(request, template="admin/mission/mission/add.tpl"):
    if request.method == "GET":
        scenario_list = Scenario.get_all()
        return render_response(template, scenario_list=scenario_list)
    elif request.method == "POST":
        form = MissionForm(request.POST)
        if form.is_valid():
#             name = form.cleaned_data['name']
            ep = form.cleaned_data['ep']
#             vm = form.cleaned_data['vm']
#             xp = form.cleaned_data['xp']
            description = form.cleaned_data['description']
#             sum_count = form.cleaned_data['sum_count']
            is_unlock = form.cleaned_data['is_unlock']
            scenario_id = form.cleaned_data['scenario_id']
            mission_group_id = form.cleaned_data['mission_group_id']
            order = form.cleaned_data['order']
            level = form.cleaned_data['level']
            is_group_last = form.cleaned_data['is_group_last']
            vm = 35
            sum_count = 10
            if is_group_last:
                ep = 25
                vm = 180
                sum_count = 1
            xp = ep * 5
            try:
                mission = Mission.objects.create(ep=ep, vm=vm, xp=xp, sum_count=sum_count,
                                               is_unlock=is_unlock, scenario_id=scenario_id,
                                               description=description, order=order, level=level,
                                               mission_group_id=mission_group_id, is_group_last=is_group_last)
                mission.save()
            except Exception, e:
                if config.debug:
                    print e
            else:
                return HttpResponse("<script type='text/javascript'>window.top.right.location.reload();window.top.art.dialog({id:'mission_add'}).close();</script>")