Ejemplo n.º 1
0
 def clean(self, data):
     data = super(StationField, self).clean(data)
     data = data.strip()
     stationid = get_itemid(data)
     if stationid is None:
         raise forms.ValidationError('Station not found')
     return get_itemname(stationid)
Ejemplo n.º 2
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}
    )
Ejemplo 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})
Ejemplo n.º 4
0
def view_auto(request):
    isigb = 'EVE-IGB' in request.META.get('HTTP_USER_AGENT', '')
    regionname = request.META.get('HTTP_EVE_REGIONNAME', None)
    regionid = dbutils.get_itemid(regionname)
    return direct_to_template(
        request, 'uploader/auto.html',
        extra_context={'isigb': isigb,
                       'regionid': regionid,
                       'regionname': regionname,
                       })
Ejemplo n.º 5
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})
Ejemplo n.º 6
0
def json_suggest_markethistory(request):
    regionname = request.META.get('HTTP_EVE_REGIONNAME', None)
    if regionname is None:
        return HttpResponse(json.dumps([]), content_type="text/json")
    regionid = dbutils.get_itemid(regionname)
    result = []
    c = connection.cursor()
    c.execute("""
SELECT t.typeid,
       (SELECT MAX(h.cachetimestamp AT TIME ZONE 'UTC')
        FROM uploader_markethistorylastupload h
        WHERE regionid = %s
          AND h.typeid = t.typeid) AS timestamp
FROM index_index t
WHERE NOT t.refineable
ORDER BY timestamp ASC, t.typeid ASC
""", (regionid,))
    midnight = datetime.datetime.utcnow().replace(hour=0, minute=0, second=0,
                                                  microsecond=0)
    result = [typeid for (typeid, timestamp) in c.fetchall()
              if timestamp is None or timestamp < midnight]
    return HttpResponse(json.dumps(result), content_type="text/json")
Ejemplo n.º 7
0
def json_suggest_marketorders(request):
    regionname = request.META.get('HTTP_EVE_REGIONNAME', None)
    if regionname is None:
        return HttpResponse(json.dumps([]), content_type="text/json")
    regionid = dbutils.get_itemid(regionname)
    c = connection.cursor()
    c.execute("""
SELECT typeid,
       (SELECT MIN(DATE_PART('days', (NOW() at time zone 'UTC')
                                      - h.cachetimestamp)) AS age
        FROM uploader_marketorderlastupload h
        WHERE regionid = %s
          AND h.typeid = mo.typeid) AS age
FROM industry_marketorder mo
     INNER JOIN ccp.stastations st
       ON mo.stationid = st.stationid
     INNER JOIN ccp.mapsolarsystems sys
       ON st.solarsystemid = sys.solarsystemid
WHERE sys.regionid = %s
ORDER BY age DESC, typeid ASC
""",
              (regionid, regionid))
    have = set(typeid for (typeid, age) in c.fetchall()
               if age is None or age > 0)
    c.execute("""
SELECT typeid,
       (SELECT MIN(DATE_PART('days', (NOW() at time zone 'UTC')
                                      - h.cachetimestamp)) AS age
        FROM uploader_marketorderlastupload h
        WHERE regionid = %s
          AND h.typeid = mo.typeid) AS age
FROM industry_wantedmarketorder mo
     INNER JOIN ccp.stastations st
       ON mo.stationid = st.stationid
     INNER JOIN ccp.mapsolarsystems sys
       ON st.solarsystemid = sys.solarsystemid
WHERE sys.regionid = %s
ORDER BY age DESC, typeid ASC
""",
              (regionid, regionid))
    want = set(typeid for (typeid, age) in c.fetchall()
               if age is None or age > 0)
    c.execute("""
(
SELECT typeid,
       (SELECT MIN(DATE_PART('days', (NOW() at time zone 'UTC')
                                      - h.cachetimestamp)) AS age
        FROM uploader_marketorderlastupload h
        WHERE regionid = %s
          AND h.typeid = t.typeid) AS age
FROM industry_pricelist t
UNION
SELECT typeid,
       (SELECT MIN(DATE_PART('days', (NOW() at time zone 'UTC')
                                      - h.cachetimestamp)) AS age
        FROM uploader_marketorderlastupload h
        WHERE regionid = %s
          AND h.typeid = t.typeid) AS age
FROM index_index t
WHERE NOT t.refineable
)
ORDER BY age DESC, typeid ASC
""", (regionid, regionid))
    rest = set(typeid for (typeid, age) in c.fetchall()
               if age is None or age > 0)
    result = (list(have) +
              list(want - have) +
              list(rest - want - have))
    return HttpResponse(json.dumps(result), content_type="text/json")