Exemple #1
0
def view_order_detail(environ, orderid):
    """
    View a specific order.
    """
    user = environ["emapps.user"]
    order = sql_get_order(orderid)
    if order is None:
        return kgi.template_response('404.html', status='404 Not Found')
    elif not (user.username in [order.customer, order.producer]
              or user.has_permission('producer')):
        return kgi.template_response('403.html', status='403 Forbidden',
                                     reason='This is none of your orders.')
    elif environ["REQUEST_METHOD"] == "POST":
        form = cgi.FieldStorage()
        text = form.getfirst("comment", None)
        if text is not None:
            sql_add_comment(orderid, user.username, text)
        return kgi.redirect_response('http://www.electusmatari.com/market/order/%s/'
                                     % orderid)
    else:
        comments = sql_get_comments(orderid)
        return kgi.template_response('market/order_detail.html',
                                     user=user,
                                     current_time=eve_time(),
                                     order=order,
                                     comments=comments)
Exemple #2
0
def view_recentcomments(environ):
    user = environ['emapps.user']
    return kgi.template_response('gallery/comments.html',
                                 user=user,
                                 current_time=eve_time(),
                                 breadcrumbs=[],
                                 comments=get_recent_comments()
                                 )
def view_rc(environ):
    update_rc(environ)
    page = kgi.paginate('standings_rc',
                        dbname='dbforcer',
                        extra='ORDER BY date DESC, entity ASC')
    return kgi.template_response('standings/rc.html',
                                 user=environ['emapps.user'],
                                 current_time=eve_time(),
                                 page=page)
def standings_check(environ):
    user = environ['emapps.user']
    if not user.has_permission(environ["org"]):
        return kgi.html_response(
            unauthorized(user, 'You are not authorized.')
            )
    tids = {}
    bogus = []
    to_set = []
    to_diplo = []
    to_act = {}
    now = datetime.datetime.utcnow()
    for (tid, subject, edittime, prefix, editor) in get_threads(standings_forums[environ["org"]]):
        try:
            edittime = datetime.datetime.utcfromtimestamp(edittime)
        except:
            edittime = now
        p = parse_subject(subject)
        if p is None:
            bogus.append((subject, tid))
        else:
            (entity, ticker, standing, comments, internal) = p
            tids.setdefault(entity, [])
            tids[entity].append((subject, tid))
            if prefix in PREFIX_TOSET:
                age = (now - edittime).days
                to_set.append((subject, tid, age))
            elif prefix in PREFIX_DIPLO:
                age = (now - edittime).days
                to_diplo.append((subject, tid, age))
            elif prefix in PREFIX_ACT:
                age = (now - edittime).days
                if editor is None:
                    editor = "None?"
                to_act.setdefault(editor, [])
                to_act[editor].append((subject, tid, age))
    dups = []
    for (entity, threads) in tids.items():
        if len(threads) > 1:
            dups.append((entity, threads))
    bogus.sort()
    dups.sort()
    to_act = to_act.items()
    to_act.sort(lambda a, b: cmp((a[0].lower(), a[1]), (b[0].lower(), b[1])))
    return kgi.template_response('standings/check.html',
                                 user=environ["emapps.user"],
                                 current_time=eve_time(),
                                 to_diplo=to_diplo,
                                 to_set=to_set,
                                 to_act=to_act,
                                 bogus=bogus,
                                 dups=dups)
Exemple #5
0
def view_orders(environ, own=False):
    """
    View orders - your own, or those assigned to you.
    """
    user = environ['emapps.user']
    form = cgi.FieldStorage()
    if environ["REQUEST_METHOD"] == 'POST':
        orderid = form.getfirst("orderid", None)
        action = form.getfirst("action", None)
        if None in (orderid, action):
            return kgi.redirect_response('http://www.electusmatari.com/market/order/')
        order = sql_get_order(orderid)
        if action == 'cancel':
            if order.customer == user.username:
                sql_drop_order(orderid)
            return kgi.redirect_response('http://www.electusmatari.com/market/order/')
        elif action == 'claim':
            if oder.state == 'unclaimed':
                sql_update_order(orderid, state='claimed',
                                 producer=user.username)
            return kgi.redirect_response('http://www.electusmatari.com/market/order/unclaimed/')
        elif action == 'markdelivered':
            if user.username == order.producer:
                sql_update_order(orderid, state='delivered')
            return kgi.redirect_response('http://www.electusmatari.com/market/order/')
        elif action == 'markdone':
            if user.username == order.producer:
                sql_update_order(orderid, state='done')
            return kgi.redirect_response('http://www.electusmatari.com/market/order/')
        return kgi.redirect_response('http://www.electusmatari.com/market/order/')
    if own:
        title = 'Your Buy Orders'
        orders = sql_get_own_orderlist(user.username)
    else:
        title = 'Buy Requests'
        producer = user.username
        allowed_sources = sql_get_sources(user)
        requested_sources = form.getlist('source')
        sources = [source for source in allowed_sources
                   if len(requested_sources) == 0
                   or source in requested_sources]
        states = form.getlist('state')
        orders = sql_get_orderlist(producer=producer,
                                   sources=sources,
                                   states=states)
    return kgi.template_response('market/order_list.html',
                                 user=user,
                                 current_time=eve_time(),
                                 orders=orders,
                                 title=title,
                                 states=STATES)
Exemple #6
0
def view_oplist(environ):
    import simplejson as json
    db = kgi.connect('dbforcer')
    c = db.cursor()
    c.execute("SELECT id, created, title FROM opwarn_list "
              "WHERE created > NOW() - INTERVAL 1 HOUR "
              "ORDER BY created DESC LIMIT 1")
    if c.rowcount == 0:
        return kgi.html_response(json.dumps({}),
                                 header=[('Content-Type', 'application/json')]
                                 )
    (id, created, title) = c.fetchone()
    delta = datetime.datetime.utcnow() - created
    return kgi.html_response(json.dumps({'id': id,
                                         'created': eve_time(created),
                                         'seconds': delta.seconds,
                                         'title': title}),
        header=[('Content-Type', 'application/json')]
        )
Exemple #7
0
def view_listing(environ):
    form = cgi.FieldStorage()
    needle = form.getfirst("search", "")
    extra = ""
    extra_args = []
    if needle != "":
        extra += ("WHERE target LIKE %s "
                  "   OR system LIKE %s "
                  "   OR station LIKE %s "
                  "   OR agent LIKE %s "
                  "   OR submitter LIKE %s ")
        extra_args.extend(["%%%s%%" % needle] * 5)
    extra += "ORDER BY ts DESC, id DESC"
    page = kgi.paginate('locator_trace', dbname='dbforcer',
                        extra=extra, extra_args=extra_args)
    return kgi.template_response('intel/listing.html',
                                 user=environ['emapps.user'],
                                 current_time=eve_time(),
                                 traces=page,
                                 search=needle)
def view_standings(environ):
    update_rc(environ)
    positive = []
    negative = []
    for (tid, subject, edittime, prefix, editor) in get_threads(standings_forums[environ["org"]]):
        p = parse_subject(subject)
        if p is None:
            continue
        (entity, ticker, standing, comments, internal) = p
        standing = normalize_standing(standing)
        if standing == 0:
            continue
        b = tempita.bunch(entity=entity,
                          ticker=ticker,
                          standing=standing,
                          comments=comments,
                          tid=tid)
        if standing > 0:
            positive.append(b)
        else:
            negative.append(b)
    positive.sort(lambda a, b: cmp(a.entity.lower(), b.entity.lower()))
    negative.sort(lambda a, b: cmp(a.entity.lower(), b.entity.lower()))
    form = cgi.FieldStorage()
    format = form.getfirst("format", "html")
    if (format == 'igb'
        or (format == 'html'
            and environ["HTTP_USER_AGENT"].startswith("EVE-minibrowser"))):
        return kgi.template_response('standings/list_igb.html',
                              positive=positive,
                              negative=negative)
    elif format == 'xml':
        return kgi.template_response('standings/list_xml.html',
                                     header=[('Content-Type', 'text/xml')],
                                     standings=positive + negative)
    else:
        return kgi.template_response('standings/list.html',
                                     user=environ['emapps.user'],
                                     current_time=eve_time(),
                                     positive=positive,
                                     negative=negative)
Exemple #9
0
def view_gallery(environ, path):
    user = environ['emapps.user']
    gallerydir = os.path.normpath(os.path.join(BASEDIR, path))
    breadcrumbs = make_breadcrumbs(path)
    if not gallerydir.startswith(BASEDIR):
        return kgi.html_response(
            unauthorized(user, 'File or directory does not exist.')
            )
    if os.path.isdir(gallerydir):
        if path != "" and not path.endswith("/"):
            return kgi.redirect_response('http://www.electusmatari.com/gallery/' + path + '/')
        (series, images, thumbs) = get_album(gallerydir)
        return kgi.template_response('gallery/index.html',
                                     user=user,
                                     current_time=eve_time(),
                                     breadcrumbs=breadcrumbs,
                                     series=series,
                                     images=images,
                                     thumbs=thumbs
                                     )
    elif os.path.isfile(gallerydir):
        if gallerydir.endswith(".png"):
            ct = "image/png"
        elif gallerydir.endswith(".jpg"):
            ct = "image/jpeg"
        else:
            ct = "application/binary"
        return kgi.html_response(file(gallerydir).read(),
                                 header=[('Content-Type', ct),
                                         ('Cache-Control', 'max-age=604800')])
    else:
        imagefile = None
        for ext in [".png", ".jpg"]:
            if os.path.isfile(gallerydir + ext):
                (seriesdir, imagename) = os.path.split(gallerydir)
                imagefile = imagename + ext
                if os.path.isfile(gallerydir + "_preview" + ext):
                    imagepreviewfile = imagename + "_preview" + ext
                else:
                    imagepreviewfile = imagefile
                break
        if imagefile is None:
            return kgi.template_response('404.html', status='404 Not Found')
        if environ["REQUEST_METHOD"] == 'POST':
            form = cgi.FieldStorage()
            comment = form.getfirst("comment")
            add_comment(path, user.username, comment)
            return kgi.redirect_response('http://www.electusmatari.com/gallery/' + path)
        (series, images, thumbs) = get_album(seriesdir)
        thisindex = images.index(imagename)
        if thisindex > 0:
            prev = images[thisindex - 1]
        else:
            prev = None
        if thisindex + 1 < len(images):
            next = images[thisindex + 1]
        else:
            next = None
        return kgi.template_response('gallery/image.html',
                                     user=user,
                                     current_time=eve_time(),
                                     breadcrumbs=breadcrumbs,
                                     imagename=imagename,
                                     imagefile=imagefile,
                                     imagepreviewfile=imagepreviewfile,
                                     prev=prev,
                                     next=next,
                                     comments=get_comments(path),
                                     )