本文整理汇总了Python中services.managers.eve_api_manager.EveApiManager.get_corp_membertracking方法的典型用法代码示例。如果您正苦于以下问题:Python EveApiManager.get_corp_membertracking方法的具体用法?Python EveApiManager.get_corp_membertracking怎么用?Python EveApiManager.get_corp_membertracking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类services.managers.eve_api_manager.EveApiManager
的用法示例。
在下文中一共展示了EveApiManager.get_corp_membertracking方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: corputils_search
# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_corp_membertracking [as 别名]
def corputils_search(request, corpid=settings.CORP_ID):
logger.debug("corputils_search called by user %s" % request.user)
corp = EveCorporationInfo.objects.get(corporation_id=corpid)
if request.method == 'POST':
form = CorputilsSearchForm(request.POST)
logger.debug("Request type POST contains form valid: %s" % form.is_valid())
if form.is_valid():
# Really dumb search and only checks character name
# This can be improved but it does the job for now
searchstring = form.cleaned_data['search_string']
logger.debug("Searching for player with character name %s for user %s" % (searchstring, request.user))
if settings.IS_CORP:
try:
member_list = EveApiManager.get_corp_membertracking(settings.CORP_API_ID, settings.CORP_API_VCODE)
except APIError:
logger.debug("Corp API does not have membertracking scope, using EveWho data instead.")
member_list = EveWhoManager.get_corporation_members(corpid)
else:
member_list = EveWhoManager.get_corporation_members(corpid)
Member = namedtuple('Member', ['name', 'main', 'api_registered'])
members = []
for memberid, member_data in member_list.items():
if searchstring.lower() in member_data["name"].lower():
try:
char = EveCharacter.objects.get(character_name=member_data["name"])
user = char.user
mainid = int(AuthServicesInfoManager.get_auth_service_info(user=user).main_char_id)
mainname = EveCharacter.objects.get(character_id=mainid).character_name
api_registered = True
except EveCharacter.DoesNotExist:
api_registered = False
mainname = ""
members.append(Member(name=member_data["name"], main=mainname, api_registered=api_registered))
logger.info("Found %s members for user %s matching search string %s" % (len(members), request.user, searchstring))
context = {'corp': corp, 'members': members, 'search_form': CorputilsSearchForm()}
return render_to_response('registered/corputilssearchview.html',
context, context_instance=RequestContext(request))
else:
logger.debug("Form invalid - returning for user %s to retry." % request.user)
context = {'corp': corp, 'members': None, 'search_form': CorputilsSearchForm()}
return render_to_response('registered/corputilssearchview.html',
context, context_instance=RequestContext(request))
else:
logger.debug("Returning empty search form for user %s" % request.user)
return HttpResponseRedirect("/corputils/")
示例2: corp_member_view
# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_corp_membertracking [as 别名]
def corp_member_view(request, corpid = None, year=datetime.date.today().year, month=datetime.date.today().month):
year = int(year)
month = int(month)
start_of_month = datetime.datetime(year, month, 1)
start_of_next_month = first_day_of_next_month(year, month)
start_of_previous_month = first_day_of_previous_month(year, month)
logger.debug("corp_member_view called by user %s" % request.user)
try:
user_main = EveCharacter.objects.get(character_id=AuthServicesInfoManager.get_auth_service_info(user=request.user).main_char_id)
user_corp_id = int(user_main.corporation_id)
except (ValueError, EveCharacter.DoesNotExist):
user_corp_id = settings.CORP_ID
if not settings.IS_CORP:
alliance = EveAllianceInfo.objects.get(alliance_id=settings.ALLIANCE_ID)
alliancecorps = EveCorporationInfo.objects.filter(alliance=alliance)
membercorplist = [(int(membercorp.corporation_id), str(membercorp.corporation_name)) for membercorp in alliancecorps]
membercorplist.sort(key=lambda tup: tup[1])
membercorp_id_list = [int(membercorp.corporation_id) for membercorp in alliancecorps]
bluecorps = EveCorporationInfo.objects.filter(is_blue=True)
bluecorplist = [(int(bluecorp.corporation_id), str(bluecorp.corporation_name)) for bluecorp in bluecorps]
bluecorplist.sort(key=lambda tup: tup[1])
bluecorp_id_list = [int(bluecorp.corporation_id) for bluecorp in bluecorps]
if not (user_corp_id in membercorp_id_list or user_corp_id not in bluecorp_id_list):
user_corp_id = None
if not corpid:
if(settings.IS_CORP):
corpid = settings.CORP_ID
elif user_corp_id:
corpid = user_corp_id
else:
corpid = membercorplist[0][0]
corp = EveCorporationInfo.objects.get(corporation_id=corpid)
if check_if_user_has_permission(request.user, 'alliance_apis') or (check_if_user_has_permission(request.user, 'corp_apis') and (user_corp_id == corpid)):
logger.debug("Retreiving and sending API-information")
if settings.IS_CORP:
try:
member_list = EveApiManager.get_corp_membertracking(settings.CORP_API_ID, settings.CORP_API_VCODE)
except APIError:
logger.debug("Corp API does not have membertracking scope, using EveWho data instead.")
member_list = EveWhoManager.get_corporation_members(corpid)
else:
member_list = EveWhoManager.get_corporation_members(corpid)
characters_with_api = {}
characters_without_api = {}
num_registered_characters = 0
for char_id, member_data in member_list.items():
try:
char = EveCharacter.objects.get(character_id=char_id)
char_owner = char.user
try:
mainid = int(AuthServicesInfoManager.get_auth_service_info(user=char_owner).main_char_id)
mainchar = EveCharacter.objects.get(character_id=mainid)
mainname = mainchar.character_name
maincorp = mainchar.corporation_name
maincorpid = mainchar.corporation_id
api_pair = EveApiKeyPair.objects.get(api_id=char.api_id)
except (ValueError, EveCharacter.DoesNotExist, EveApiKeyPair.DoesNotExist):
logger.info("No main character seem to be set for character %s" % char.character_name)
mainname = "User: " + char_owner.username
mainchar = char
maincorp = "Not set."
maincorpid = None
api_pair = None
num_registered_characters = num_registered_characters + 1
characters_with_api.setdefault(mainname, Player(main=mainchar,
user=char_owner,
maincorp=maincorp,
maincorpid=maincorpid,
altlist=[],
apilist=[],
n_fats=0)
).altlist.append(char)
if api_pair:
characters_with_api[mainname].apilist.append(api_pair)
except (EveCharacter.DoesNotExist):
characters_without_api.update({member_data["name"]: member_data["id"]})
for char in EveCharacter.objects.filter(corporation_id=corpid):
if not int(char.character_id) in member_list:
logger.info("Character '%s' does not exist in EveWho dump." % char.character_name)
char_owner = char.user
try:
mainid = int(AuthServicesInfoManager.get_auth_service_info(user=char_owner).main_char_id)
mainchar = EveCharacter.objects.get(character_id=mainid)
mainname = mainchar.character_name
maincorp = mainchar.corporation_name
maincorpid = mainchar.corporation_id
api_pair = EveApiKeyPair.objects.get(api_id=char.api_id)
#.........这里部分代码省略.........
示例3: corp_member_view
# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_corp_membertracking [as 别名]
def corp_member_view(request, corpid = None):
logger.debug("corp_member_view called by user %s" % request.user)
if not settings.IS_CORP:
alliance = EveAllianceInfo.objects.get(alliance_id=settings.ALLIANCE_ID)
alliancecorps = EveCorporationInfo.objects.filter(alliance=alliance)
membercorp_list = [(int(membercorp.corporation_id), str(membercorp.corporation_name)) for membercorp in alliancecorps]
membercorp_list.sort(key=lambda tup: tup[1])
if not corpid:
if(settings.CORP_ID):
corpid = settings.CORP_ID
else:
corpid = membercorp_list[0][0]
corp = EveCorporationInfo.objects.get(corporation_id=corpid)
Player = namedtuple("Player", ["main", "maincorp", "maincorpid", "altlist"])
if settings.IS_CORP:
try:
member_list = EveApiManager.get_corp_membertracking(settings.CORP_API_ID, settings.CORP_API_VCODE)
except APIError:
logger.debug("Corp API does not have membertracking scope, using EveWho data instead.")
member_list = EveWhoManager.get_corporation_members(corpid)
else:
member_list = EveWhoManager.get_corporation_members(corpid)
characters_with_api = {}
characters_without_api = {}
for char_id, member_data in member_list.items():
try:
char = EveCharacter.objects.get(character_id=char_id)
user = char.user
try:
mainid = int(AuthServicesInfoManager.get_auth_service_info(user=user).main_char_id)
mainchar = EveCharacter.objects.get(character_id=mainid)
mainname = mainchar.character_name
maincorp = mainchar.corporation_name
maincorpid = mainchar.corporation_id
except (ValueError, EveCharacter.DoesNotExist):
mainname = "User: " + user.username
mainchar = char
maincorp = "Not set."
maincorpid = None
characters_with_api.setdefault(mainname, Player(main=mainchar,
maincorp=maincorp,
maincorpid=maincorpid,
altlist=[])
).altlist.append(char)
except EveCharacter.DoesNotExist:
characters_without_api.update({member_data["name"]: member_data["id"]})
if not settings.IS_CORP:
context = {"membercorp_list": membercorp_list,
"corp": corp,
"characters_with_api": sorted(characters_with_api.items()),
"characters_without_api": sorted(characters_without_api.items()),
"search_form": CorputilsSearchForm()}
else:
logger.debug("corp_member_view running in corportation mode")
context = {"corp": corp,
"characters_with_api": sorted(characters_with_api.items()),
"characters_without_api": sorted(characters_without_api.items()),
"search_form": CorputilsSearchForm()}
return render_to_response('registered/corputils.html',context, context_instance=RequestContext(request) )
示例4: corputils_search
# 需要导入模块: from services.managers.eve_api_manager import EveApiManager [as 别名]
# 或者: from services.managers.eve_api_manager.EveApiManager import get_corp_membertracking [as 别名]
def corputils_search(request, corpid=settings.CORP_ID):
logger.debug("corputils_search called by user %s" % request.user)
corp = EveCorporationInfo.objects.get(corporation_id=corpid)
authorized = False
try:
user_main = EveCharacter.objects.get(
character_id=AuthServicesInfo.objects.get_or_create(user=request.user)[0].main_char_id)
if request.user.has_perm('auth.alliance_apis') or (
request.user.has_perm('auth.corp_apis') and (user_main.corporation_id == corpid)):
logger.debug("Retreiving and sending API-information")
authorized = True
except (ValueError, EveCharacter.DoesNotExist):
if request.user.has_perm('auth.alliance_apis'):
logger.debug("Retrieving and sending API-information")
authorized = True
if authorized:
if request.method == 'POST':
form = CorputilsSearchForm(request.POST)
logger.debug("Request type POST contains form valid: %s" % form.is_valid())
if form.is_valid():
# Really dumb search and only checks character name
# This can be improved but it does the job for now
searchstring = form.cleaned_data['search_string']
logger.debug("Searching for player with character name %s for user %s" % (searchstring, request.user))
member_list = {}
if settings.IS_CORP:
member_list = EveApiManager.get_corp_membertracking(settings.CORP_API_ID, settings.CORP_API_VCODE)
if not member_list:
logger.debug('Unable to fetch members from API. Pulling from EveWho')
member_list = EveWhoManager.get_corporation_members(corpid)
SearchResult = namedtuple('SearchResult',
['name', 'id', 'main', 'api_registered', 'character', 'apiinfo'])
searchresults = []
for memberid, member_data in member_list.items():
if searchstring.lower() in member_data["name"].lower():
try:
char = EveCharacter.objects.get(character_name=member_data["name"])
user = char.user
mainid = int(AuthServicesInfo.objects.get_or_create(user=user)[0].main_char_id)
main = EveCharacter.objects.get(character_id=mainid)
if can_see_api(request.user, char):
api_registered = True
apiinfo = EveApiKeyPair.objects.get(api_id=char.api_id)
else:
api_registered = False
apiinfo = None
except EveCharacter.DoesNotExist:
api_registered = False
char = None
main = ""
apiinfo = None
searchresults.append(SearchResult(name=member_data["name"], id=memberid, main=main,
api_registered=api_registered,
character=char, apiinfo=apiinfo))
logger.info("Found %s members for user %s matching search string %s" % (
len(searchresults), request.user, searchstring))
context = {'corp': corp, 'results': searchresults, 'search_form': CorputilsSearchForm(),
"year": datetime.datetime.now().year, "month": datetime.datetime.now().month}
return render(request, 'registered/corputilssearchview.html',
context=context)
else:
logger.debug("Form invalid - returning for user %s to retry." % request.user)
context = {'corp': corp, 'members': None, 'search_form': CorputilsSearchForm()}
return render(request, 'registered/corputilssearchview.html', context=context)
else:
logger.debug("Returning empty search form for user %s" % request.user)
return redirect("auth_corputils")
else:
logger.warn('User %s not authorized to view corp stats for corp ID %s' % (request.user, corpid))
return redirect("auth_dashboard")