Browse Source

Implement most of members module logic.

master
Ben Kurtovic 4 years ago
parent
commit
da788d83fb
5 changed files with 68 additions and 5 deletions
  1. +17
    -0
      calefaction/auth.py
  2. +36
    -2
      calefaction/modules/members.py
  3. +3
    -3
      templates/campaigns/campaign.mako
  4. +11
    -0
      templates/members/members.mako
  5. +1
    -0
      templates/members/navitem.mako

+ 17
- 0
calefaction/auth.py View File

@@ -282,6 +282,22 @@ class AuthManager:
self._update_prop_cache(module, prop, value)
return True

def get_token(self):
"""Return a valid token for the current character, or None.

Assuming this is called in a restricted route (following a True result
from is_authenticated), this function makes no API calls and should
always succeed. If it is called in other circumstances, it may fail and
return None.
"""
cid = self.get_character_id()
if not cid:
return None

if not hasattr(g, "_cached_token"):
g._cached_token = self._get_token(cid)
return g._cached_token

def is_authenticated(self):
"""Return whether the user has permission to access this site.

@@ -308,6 +324,7 @@ class AuthManager:
self._debug("Access granted for char id=%d session id=%d", cid,
session["id"])
g.db.touch_session(session["id"])
g._cached_token = token
return True

def make_login_link(self):


+ 36
- 2
calefaction/modules/members.py View File

@@ -1,8 +1,42 @@
# -*- coding: utf-8 -*-

# ...
from collections import namedtuple

from flask import g
from flask_mako import render_template

from ._provided import blueprint

SCOPES = {"esi-corporations.read_corporation_membership.v1"}

_Member = namedtuple("_Member", ["id", "name"])

def get_members():
"""Return a list of the members of the user's corporation.

Members are returned as 2-namedtuples of (id, name). An empty list is
returned if there was some error with tokens.
"""
token = g.auth.get_token()
if not token:
return []

corp_id = g.config.get("corp.id")
resp = g.eve.esi(token).v2.corporations(corp_id).members.get()
cids = ",".join(str(item["character_id"]) for item in resp)
resp = g.eve.esi(token).v1.characters.names.get(character_ids=cids)
return [_Member(item["character_id"], item["character_name"])
for item in resp]

def home():
"""Render and return the main members page."""
return render_template("members/members.mako", members=get_members())

def navitem():
return "Members"
"""Render and return the navigation item for this module."""
return render_template("members/navitem.mako").decode("utf8")

@blueprint.rroute("/members")
def members():
"""Render and return the main members page."""
return home()

+ 3
- 3
templates/campaigns/campaign.mako View File

@@ -1,7 +1,7 @@
<%inherit file="../_default.mako"/>
%if current:
% if current:
<h2><span class="understate">Campaign:</span> ${current} <!-- select ... --></h2>
<p>Hello! ...</p>
%else:
% else:
<p>No campaigns currently.</p>
%endif
% endif

+ 11
- 0
templates/members/members.mako View File

@@ -0,0 +1,11 @@
<%inherit file="../_default.mako"/>
<h2>Members</h2>
<!-- ... handle case where members is empty - means something went wrong -->
<ul>
% for member in members:
<li>
<img title="${member.name}" alt="${member.name}'s Portrait" src="${g.eve.image.character(member.id, 256)}"/>
${member.name}
</li>
% endfor
</ul>

+ 1
- 0
templates/members/navitem.mako View File

@@ -0,0 +1 @@
<a href="${url_for('members.members')}">Members</a>

Loading…
Cancel
Save