Exemplo n.º 1
0
def marketorders_edit(request, orderid=None):
    if orderid is None:
        instance = None
        forcorp = False
    else:
        instance = get_object_or_404(WantedMarketOrder, pk=orderid)
        forcorp = instance.forcorp
    if request.method == "POST":
        form = WantedMarketOrderForm(request.POST, instance=instance)
        if form.is_valid():
            wmo = form.save(commit=False)
            wmo.characterid = request.user.profile.characterid
            wmo.charactername = request.user.profile.name
            wmo.stationid = get_itemid(wmo.stationname)
            wmo.typeid = get_typeid(wmo.typename)
            wmo.save()
            messages.add_message(request, messages.SUCCESS, "Order requests updated")
            if wmo.forcorp or forcorp:
                Change.objects.create(
                    app="industry",
                    category="order",
                    text=(
                        "%s edited the order for "
                        "%s at %s" % (request.user.profile.name, wmo.typename, wmo.stationname)
                    ),
                )
            return HttpResponseRedirect("/industry/marketorders/config/")
    else:
        form = WantedMarketOrderForm(instance=instance)
    return direct_to_template(
        request, "industry/marketconfig_edit.html", extra_context={"form": form, "instance": instance}
    )
Exemplo n.º 2
0
 def clean(self, data):
     data = super(BlueprintTypeField, self).clean(data)
     data = data.strip()
     typeid = get_typeid(data)
     if typeid is None:
         raise forms.ValidationError('Blueprint name not found')
     return get_typename(typeid)
Exemplo n.º 3
0
def marketorders_edit(request, orderid=None):
    if orderid is None:
        instance = None
        forcorp = False
    else:
        instance = get_object_or_404(WantedMarketOrder, pk=orderid)
        forcorp = instance.forcorp
    if request.method == 'POST':
        form = WantedMarketOrderForm(request.POST, instance=instance)
        if form.is_valid():
            wmo = form.save(commit=False)
            wmo.characterid = request.user.profile.characterid
            wmo.charactername = request.user.profile.name
            wmo.stationid = get_itemid(wmo.stationname)
            wmo.typeid = get_typeid(wmo.typename)
            wmo.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Order requests updated')
            if wmo.forcorp or forcorp:
                Change.objects.create(app='industry',
                                      category='order',
                                      text=('%s edited the order for '
                                            '%s at %s' %
                                            (request.user.profile.name,
                                             wmo.typename,
                                             wmo.stationname)))
            return HttpResponseRedirect('/industry/marketorders/config/')
    else:
        form = WantedMarketOrderForm(instance=instance)
    return direct_to_template(request, 'industry/marketconfig_edit.html',
                              extra_context={'form': form,
                                             'instance': instance})
Exemplo n.º 4
0
def stocks_edit(request, stockid=None):
    if stockid is None:
        instance = None
        oldhigh = None
    else:
        instance = get_object_or_404(StockLevel, pk=stockid)
        oldhigh = instance.high
    if request.method == 'POST':
        form = StockLevelForm(request.POST, instance=instance)
        if form.is_valid():
            sl = form.save(commit=False)
            sl.stationid = get_itemid(sl.stationname)
            sl.typeid = get_typeid(sl.typename)
            try:
                sl.save()
            except IntegrityError:
                transaction.rollback()
                messages.add_message(request, messages.ERROR,
                                     'Stock level already exists')
                return HttpResponseRedirect('/industry/stocks/')
            try:
                st = Stock.objects.get(typeid=sl.typeid,
                                       stationid=sl.stationid)
            except Stock.DoesNotExist:
                pass
            else:
                st.level = sl
                st.save()
            Change.objects.create(app='industry',
                                  category='stocks',
                                  text=('%s updated the stock level for %s '
                                        'at %s from %s to %s' %
                                        (request.user.profile.name,
                                         sl.typename,
                                         sl.stationname,
                                         oldhigh,
                                         sl.high)))
            messages.add_message(request, messages.SUCCESS,
                                 'Stock level updated')
            return HttpResponseRedirect('/industry/stocks/')
    else:
        form = StockLevelForm(instance=instance)
    return direct_to_template(request, 'industry/stocks_edit.html',
                              extra_context={'form': form,
                                             'instance': instance})
Exemplo n.º 5
0
def bpos_edit(request, bpoid=None):
    if bpoid is None:
        instance = None
    else:
        instance = get_object_or_404(BlueprintOriginal, pk=bpoid)
    if request.method == "POST":
        form = BlueprintOriginalForm(request.POST, instance=instance)
        if form.is_valid():
            bpo = form.save(commit=False)
            bpo.typeid = get_typeid(bpo.typename)
            bpo.save()
            Change.objects.create(
                app="industry", category="bpos", text=("%s edited the %s" % (request.user.profile.name, bpo.typename))
            )
            messages.add_message(request, messages.SUCCESS, "BPO saved")
            return HttpResponseRedirect("/industry/bpos/")
    else:
        form = BlueprintOriginalForm(instance=instance)
    return direct_to_template(request, "industry/bpos_edit.html", extra_context={"form": form, "instance": instance})
Exemplo n.º 6
0
def bpos_edit(request, bpoid=None):
    if bpoid is None:
        instance = None
    else:
        instance = get_object_or_404(BlueprintOriginal, pk=bpoid)
    if request.method == 'POST':
        form = BlueprintOriginalForm(request.POST, instance=instance)
        if form.is_valid():
            bpo = form.save(commit=False)
            bpo.typeid = get_typeid(bpo.typename)
            bpo.save()
            Change.objects.create(app='industry',
                                  category='bpos',
                                  text=('%s edited the %s' %
                                        (request.user.profile.name,
                                         bpo.typename)))
            messages.add_message(request, messages.SUCCESS,
                                 'BPO saved')
            return HttpResponseRedirect('/industry/bpos/')
    else:
        form = BlueprintOriginalForm(instance=instance)
    return direct_to_template(request, 'industry/bpos_edit.html',
                              extra_context={'form': form,
                                             'instance': instance})
Exemplo n.º 7
0
 def from_typename(cls, typename):
     typeid = get_typeid(typename)
     if typeid is None:
         raise RuntimeError("typename %r does not exist" % typename)
     typename = get_typename(typeid)
     return cls(typeid=typeid, typename=typename)