def update(): """ Fetch a /corp/ContactList.xml.aspx api response, parse it and store it to the database. """ LOG.info("fetching /corp/ContactList.xml.aspx...") api_conn = api.connect() corpApi = api_conn.corp.ContactList(characterID=api.get_charID()) api.check_version(corpApi._meta.version) currentTime = timezone.make_aware(datetime.utcfromtimestamp( \ corpApi._meta.currentTime), timezone.utc) my_corp = Corporation.objects.mine() # clean existing standings first Standing.objects.filter(corp=my_corp).delete() for contact in corpApi.corporateContactList: Standing.objects.create(corp=my_corp, contactID=contact.contactID, is_corp_contact=True, contactName=contact.contactName, value=contact.standing, ) for contact in corpApi.allianceContactList: Standing.objects.create(corp=my_corp, contactID=contact.contactID, is_corp_contact=False, contactName=contact.contactName, value=contact.standing, ) UpdateDate.mark_updated(model=Standing, date=currentTime) LOG.info("corp standings updated")
def update(): """ Fetch a /corp/ContactList.xml.aspx api response, parse it and store it to the database. """ LOG.info("fetching /corp/ContactList.xml.aspx...") api_conn = api.connect() corpApi = api_conn.corp.ContactList(characterID=api.get_charID()) api.check_version(corpApi._meta.version) currentTime = timezone.make_aware(corpApi._meta.currentTime, timezone.utc) my_corp = Corporation.objects.mine() # clean existing standings first Standing.objects.filter(corp=my_corp).delete() for contact in corpApi.corporateContactList: Standing.objects.create(corp=my_corp, contactID=contact.contactID, is_corp_contact=True, contactName=contact.contactName, value=contact.standing, ) for contact in corpApi.allianceContactList: Standing.objects.create(corp=my_corp, contactID=contact.contactID, is_corp_contact=False, contactName=contact.contactName, value=contact.standing, ) UpdateDate.mark_updated(model=Standing, date=currentTime) LOG.info("corp standings updated")
def write_results(new_items, old_items, assets_to_locate, currentTime): if len(old_items) > 0: Asset.objects.all().delete() for asset in new_items.values(): asset.save() update_assets_locations(assets_to_locate) update_assets_names() # we store the update time of the table UpdateDate.mark_updated(model=Asset, date=currentTime)
def update(): """ Updates all wallets with the missing accounting entries since last scan. """ for wallet in Wallet.objects.all(): update_journal_wallet(wallet) for wallet in Wallet.objects.all(): update_transaction_wallet(wallet) UpdateDate.mark_updated(model=JournalEntry, date=timezone.now()) UpdateDate.mark_updated(model=TransactionEntry, date=timezone.now()) LOG.debug("wallets journal updated")
def update(): """ Updates all wallets with the missing accounting entries since last scan. """ # Temporary fix for this new Wallet division (This is the "Mercenary Wallet") for wallet in Wallet.objects.exclude(walletID=10000): update_journal_wallet(wallet) # for wallet in Wallet.objects.all(): update_transaction_wallet(wallet) UpdateDate.mark_updated(model=JournalEntry, date=timezone.now()) UpdateDate.mark_updated(model=TransactionEntry, date=timezone.now()) LOG.debug("wallets journal updated")
def update(): """ Update all orders """ LOG.info("fetching /corp/MarketOrders.xml.aspx...") # Connect to EVE API api_conn = api.connect() ordersApi = api_conn.corp.MarketOrders() # checkApiVersion(ordersApi._meta.version) LOG.debug("parsing api response...") processOrders(ordersApi.orders, api_conn) UpdateDate.mark_updated(model=MarketOrder, date=timezone.now())
def member_contrib(request): """ View function URL : '/accounting/contributions/' """ from_date = JournalEntry.objects.all().aggregate(date=Min("date"))["date"] if from_date is None: from_date = datetime.utcfromtimestamp(0) to_date = JournalEntry.objects.all().aggregate(date=Max("date"))["date"] if to_date is None: to_date = timezone.now() query = JournalEntry.objects.filter(type__in=OPERATION_TYPES, date__gte=from_date, date__lte=to_date) total_contribs = query.aggregate(sum=Sum('amount'))['sum'] data = { 'scan_date': UpdateDate.get_latest(JournalEntry), 'from_date': datetime.strftime(from_date, DATE_PATTERN), 'to_date': datetime.strftime(to_date, DATE_PATTERN), 'total_contribs': total_contribs, 'datatables_defaults': DATATABLES_DEFAULTS, 'member_contrib_columns': MEMBER_CONTRIB_COLUMNS, 'system_contrib_columns': SYSTEM_CONTRIB_COLUMNS, 'player_contrib_columns': PLAYER_CONTRIB_COLUMNS, 'member_ajax_url': '/accounting/contributions/members/data/', 'system_ajax_url': '/accounting/contributions/systems/data/', 'player_ajax_url': '/accounting/contributions/players/data/', 'sorting': [[1, 'desc']], } return render_to_response("ecm/accounting/contrib.html", data, Ctx(request))
def root(request): scan_date = UpdateDate.get_latest(Asset) if scan_date == '<no data>': return render_to_response('ecm/assets/assets_no_data.html', Ctx(request)) my_corp = Corporation.objects.mine() all_hangars = Hangar.objects.all().order_by('hangarID') for hangar in all_hangars: hangar.name = hangar.get_name(my_corp) try: divisions_str = request.GET['divisions'] divisions = [int(div) for div in divisions_str.split(',')] for h in all_hangars: h.checked = h.hangar_id in divisions except: divisions, divisions_str = None, None for h in all_hangars: h.checked = True show_in_space = json.loads(request.GET.get('space', 'true')) show_in_stations = json.loads(request.GET.get('stations', 'true')) data = { 'show_in_space': show_in_space, 'show_in_stations': show_in_stations, 'divisions_str': divisions_str, 'hangars': all_hangars, 'scan_date': scan_date } return render_to_response('ecm/assets/assets.html', data, Ctx(request))
def update_hangar_divisions(corpApi, currentTime): LOG.debug("HANGAR DIVISIONS:") my_corp = Corporation.objects.mine() hangars = CorpHangar.objects.filter(corp=my_corp) for hangarDiv in corpApi.divisions: h_id = hangarDiv.accountKey h_name = hangarDiv.description try: h = hangars.get(hangar_id=h_id) h.name = h_name except CorpHangar.DoesNotExist: h = CorpHangar(corp=my_corp, hangar_id=h_id, name=h_name) LOG.debug(" %s [%s]", h.name, h.hangar_id) h.save() # we store the update time of the table UpdateDate.mark_updated(model=Hangar, date=currentTime)
def root(request): scan_date = UpdateDate.get_latest(Asset) if scan_date == '<no data>': return render_to_response('ecm/assets/assets_no_data.html', Ctx(request)) my_corp = Corporation.objects.mine() all_hangars = Hangar.objects.all().order_by('hangarID') for hangar in all_hangars: hangar.name = hangar.get_name(my_corp) try: divisions_str = request.GET['divisions'] divisions = [ int(div) for div in divisions_str.split(',') ] for h in all_hangars: h.checked = h.hangar_id in divisions except: divisions, divisions_str = None, None for h in all_hangars: h.checked = True show_in_space = json.loads(request.GET.get('space', 'true')) show_in_stations = json.loads(request.GET.get('stations', 'true')) data = { 'show_in_space' : show_in_space, 'show_in_stations' : show_in_stations, 'divisions_str' : divisions_str, 'hangars' : all_hangars, 'scan_date' : scan_date } return render_to_response('ecm/assets/assets.html', data, Ctx(request))
def update_wallet_divisions(corpApi, currentTime): LOG.debug("WALLET DIVISIONS:") my_corp = Corporation.objects.mine() wallets = CorpWallet.objects.filter(corp=my_corp) for walletDiv in corpApi.walletDivisions: w_id = walletDiv.accountKey w_name = walletDiv.description try: w = wallets.get(wallet_id=w_id) w.name = w_name except CorpWallet.DoesNotExist: w = CorpWallet(corp=my_corp, wallet_id=w_id, name=w_name) LOG.debug(" %s [%s]", w.name, w.wallet_id) w.save() # we store the update time of the table UpdateDate.mark_updated(model=Wallet, date=currentTime)
def member_contrib(request): """ View function URL : '/accounting/contributions/' """ from_date = JournalEntry.objects.all().aggregate(date=Min("date"))["date"] if from_date is None: from_date = datetime.utcfromtimestamp(0) to_date = JournalEntry.objects.all().aggregate(date=Max("date"))["date"] if to_date is None: to_date = timezone.now() query = JournalEntry.objects.filter(type__in=OPERATION_TYPES, date__gte=from_date, date__lte=to_date) total_contribs = query.aggregate(sum=Sum('amount'))['sum'] data = { 'scan_date' : UpdateDate.get_latest(JournalEntry), 'from_date' : datetime.strftime(from_date, DATE_PATTERN), 'to_date' : datetime.strftime(to_date, DATE_PATTERN), 'total_contribs' : total_contribs, 'datatables_defaults': DATATABLES_DEFAULTS, 'member_contrib_columns': MEMBER_CONTRIB_COLUMNS, 'system_contrib_columns': SYSTEM_CONTRIB_COLUMNS, 'player_contrib_columns': PLAYER_CONTRIB_COLUMNS, 'member_ajax_url': '/accounting/contributions/members/data/', 'system_ajax_url': '/accounting/contributions/systems/data/', 'player_ajax_url': '/accounting/contributions/players/data/', 'sorting': [[1,'desc']], } return render_to_response("ecm/accounting/contrib.html", data, Ctx(request))
def root(request, date_str): my_corp = Corporation.objects.mine() all_hangars = Hangar.objects.all().order_by('hangarID') for hangar in all_hangars: hangar.name = hangar.get_name(my_corp) try: divisions_str = request.GET['divisions'] divisions = [ int(div) for div in divisions_str.split(',') ] for h in all_hangars: h.checked = h.hangar_id in divisions except: divisions, divisions_str = None, None for h in all_hangars: h.checked = True show_in_space = json.loads(request.GET.get('space', 'true')) show_in_stations = json.loads(request.GET.get('stations', 'true')) since_weeks = int(request.GET.get('since_weeks', '8')) to_weeks = int(request.GET.get('to_weeks', '0')) oldest_date = timezone.now() - timedelta(weeks=since_weeks) newest_date = timezone.now() - timedelta(weeks=to_weeks) query = AssetDiff.objects.values_list('date', flat=True).distinct().order_by('-date') query = query.filter(date__gte=oldest_date) query = query.filter(date__lte=newest_date) dates = [] for date in query: dates.append({ 'value' : datetime.strftime(date, DATE_PATTERN), 'show' : date }) data = { 'show_in_space' : show_in_space, 'show_in_stations' : show_in_stations, 'divisions_str' : divisions_str, 'hangars' : all_hangars, 'scan_date' : UpdateDate.get_latest(Asset), 'since_weeks' : since_weeks, 'to_weeks' : to_weeks, 'date_str' : date_str, 'dates' : dates } try: date_asked = datetime.strptime(date_str, DATE_PATTERN) date_asked = timezone.make_aware(date_asked, timezone.utc) next_date = date_asked + timedelta(seconds=1) except ValueError: return redirect('/assets/changes/') if AssetDiff.objects.filter(date__range=(date_asked, next_date)).exists(): data['date'] = date_asked return render_to_response('ecm/assets/assets_diff.html', data, Ctx(request)) else: return render_to_response('ecm/assets/assets_no_data.html', {}, Ctx(request))
def changes(request): data = { 'scan_date' : UpdateDate.get_latest(TitleComposition), 'columns': DIFFS_COLUMNS, 'datatables_defaults': DATATABLES_DEFAULTS, "colorThresholds" : ColorThreshold.as_json(), } return render_to_response("ecm/hr/titles/changes.html", data, Ctx(request))
def changes(request): data = { 'scan_date': UpdateDate.get_latest(TitleComposition), 'columns': DIFFS_COLUMNS, 'datatables_defaults': DATATABLES_DEFAULTS, "colorThresholds": ColorThreshold.as_json(), } return render_to_response("ecm/hr/titles/changes.html", data, Ctx(request))
def update(): """ Update all contracts """ LOG.info("fetching /corp/Contracts.xml.aspx...") # Connect to EVE API api_conn = api.connect() LOG.debug("Fetching Contracts...") contractsApi = api_conn.corp.Contracts() current_time = timezone.make_aware(contractsApi._meta.currentTime, timezone.utc) cached_until = timezone.make_aware(contractsApi._meta.cachedUntil, timezone.utc) LOG.debug("current time : %s", str(current_time)) LOG.debug("cached util : %s", str(cached_until)) LOG.debug("parsing api response...") process_contracts(contractsApi.contractList, api_conn) UpdateDate.mark_updated(model=Contract, date=timezone.now())
def unassociated(request): data = { 'scan_date' : UpdateDate.get_latest(Member), 'colorThresholds' : ColorThreshold.as_json(), 'directorAccessLvl' : Member.DIRECTOR_ACCESS_LVL, 'datatables_defaults': DATATABLES_DEFAULTS, 'columns': MEMBERS_COLUMNS, 'ajax_url': '/hr/members/unassociated/data/', } return render_to_response("ecm/hr/members/unassociated.html", data, Ctx(request))
def transactions(request): walletID = int(request.GET.get('walletID', 0)) entryTypeID = int(request.GET.get('entryTypeID', -1)) entryForID = int(request.GET.get('entryForID', -1)) amount = request.GET.get('amount', None) comparator = request.GET.get('comparator', '>') from_date = TransactionEntry.objects.all().aggregate( date=Min("date"))["date"] if from_date is None: from_date = datetime.utcfromtimestamp(0) to_date = TransactionEntry.objects.all().aggregate( date=Max("date"))["date"] if to_date is None: to_date = timezone.now() wallets = [{'walletID': 0, 'name': 'All', 'selected': walletID == 0}] for w in Corporation.objects.mine().wallets.all().order_by('wallet'): wallets.append({ 'walletID': w.wallet_id, 'name': w.name, 'selected': w.wallet_id == walletID }) entryTypes = [{ 'refTypeID': -1, 'refTypeName': 'Both', 'selected': entryTypeID == -1 }] for tet in TransactionEntry.TYPES: entryTypes.append({ 'refTypeID': tet, 'refTypeName': TransactionEntry.TYPES[tet], 'selected': tet == entryTypeID }) entryFor = [{ 'refTypeID': -1, 'refTypeName': 'Both', 'selected': entryForID == -1 }] for ter in TransactionEntry.FOR: entryFor.append({ 'refTypeID': ter, 'refTypeName': TransactionEntry.FOR[ter], 'selected': ter == entryForID }) data = { 'wallets': wallets, 'entryTypes': entryTypes, 'entryFor': entryFor, 'amount': amount, 'comparator': comparator, 'scan_date': UpdateDate.get_latest(TransactionEntry), 'from_date': datetime.strftime(from_date, DATE_PATTERN), 'to_date': datetime.strftime(to_date, DATE_PATTERN), } return render_to_response("ecm/accounting/wallet_transactions.html", data, Ctx(request))
def history(request): defaults = DATATABLES_DEFAULTS.copy() defaults['aaSorting'] = [[3, "desc"]] data = { 'scan_date' : UpdateDate.get_latest(Member), 'ajax_url': '/hr/members/history/data/', 'datatables_defaults': defaults, 'columns': COLUMNS, } return render_to_response("ecm/hr/members/history.html", data, Ctx(request))
def unassociated(request): data = { 'scan_date': UpdateDate.get_latest(Member), 'colorThresholds': ColorThreshold.as_json(), 'directorAccessLvl': Member.DIRECTOR_ACCESS_LVL, 'datatables_defaults': DATATABLES_DEFAULTS, 'columns': MEMBERS_COLUMNS, 'ajax_url': '/hr/members/unassociated/data/', } return render_to_response("ecm/hr/members/unassociated.html", data, Ctx(request))
def access_changes(request): data = { 'scan_date' : UpdateDate.get_latest(TitleMembership), 'colorThresholds' : ColorThreshold.as_json(), 'directorAccessLvl': Member.DIRECTOR_ACCESS_LVL, 'datatable_defaults': DATATABLES_DEFAULTS, 'columns' : ACCESS_CHANGES_COLUMNS, 'sorting': [[3, 'desc']], 'ajax_url': '/hr/members/accesschanges/data/', } return render_to_response("ecm/hr/members/access_changes.html", data, Ctx(request))
def titles(request): colorThresholds = [] for c in ColorThreshold.objects.all().order_by("threshold"): colorThresholds.append({"threshold": c.threshold, "color": c.color}) data = { 'scan_date': UpdateDate.get_latest(TitleComposition), 'colorThresholds': json.dumps(colorThresholds), 'columns': TITLES_COLUMNS, 'datatables_defaults': DATATABLES_DEFAULTS } return render_to_response("ecm/hr/titles/titles.html", data, Ctx(request))
def titles(request): colorThresholds = [] for c in ColorThreshold.objects.all().order_by("threshold"): colorThresholds.append({"threshold": c.threshold, "color": c.color}) data = { "scan_date": UpdateDate.get_latest(TitleComposition), "colorThresholds": json.dumps(colorThresholds), "columns": TITLES_COLUMNS, "datatables_defaults": DATATABLES_DEFAULTS, } return render_to_response("ecm/hr/titles/titles.html", data, Ctx(request))
def storeTitles(oldTitles, newTitles, date): if len(oldTitles) != 0: titleDiffs = getTitleMemberDiffs(oldTitles, newTitles, date) if titleDiffs: for d in titleDiffs: try: d.save() except Database.Warning: # When DEBUG=true, MySQLdb warnings get counted as exceptions, and there's often a "Warning: Field 'id' doesn't have a default value" # thrown here. Ignore it. https://github.com/evecm/ecm/issues/14 pass # we store the update time of the table UpdateDate.mark_updated(model=TitleMemberDiff, date=date) TitleMembership.objects.all().delete() for tm in newTitles.values(): tm.save() # we store the update time of the table UpdateDate.mark_updated(model=TitleMembership, date=date) # if no diff, we do nothing return len(titleDiffs) else: # 1st import, no diff to write for tm in newTitles.values(): tm.save() # we store the update time of the table UpdateDate.mark_updated(model=TitleMembership, date=date) return 0
def cyno_list(request): corps = Corporation.objects.others().order_by("corporationName") corps = corps.annotate(member_count=Count("members")) data = { "scan_date": UpdateDate.get_latest(Member), "trusted_corps": corps.filter(member_count__gt=0, is_trusted=True), "other_corps": corps.filter(member_count__gt=0, is_trusted=False), "datatables_defaults": DATATABLES_DEFAULTS, "columns": MEMBERS_COLUMNS, "ajax_url": "/hr/cyno_alts/data/", } return render_to_response("ecm/hr/members/cyno_alts.html", data, Ctx(request))
def contracts(request): _type = request.GET.get('type', 0) # default to All _status = request.GET.get('status', 0) # default to All # Get contract types data = { 'types': [ (ID, name, ID == _type) for ID, name in TYPES ], 'statuses': [ (ID, name, ID == _status) for ID, name in STATUSES ], 'scan_date': UpdateDate.get_latest(Contract), 'columns': COLUMNS, } return render_to_response('ecm/accounting/contracts.html', data, Ctx(request))
def access_changes(request): data = { 'scan_date': UpdateDate.get_latest(TitleMembership), 'colorThresholds': ColorThreshold.as_json(), 'directorAccessLvl': Member.DIRECTOR_ACCESS_LVL, 'datatable_defaults': DATATABLES_DEFAULTS, 'columns': ACCESS_CHANGES_COLUMNS, 'sorting': [[3, 'desc']], 'ajax_url': '/hr/members/accesschanges/data/', } return render_to_response("ecm/hr/members/access_changes.html", data, Ctx(request))
def journal(request): walletID = int(request.GET.get('walletID', 0)) entryTypeID = int(request.GET.get('entryTypeID', 0)) amount = request.GET.get('amount', None) comparator = request.GET.get('comparator', '>') from_date = JournalEntry.objects.all().aggregate(date=Min("date"))["date"] if from_date is None: from_date = datetime.utcfromtimestamp(0) to_date = JournalEntry.objects.all().aggregate(date=Max("date"))["date"] if to_date is None: to_date = timezone.now() my_corp = Corporation.objects.mine() wallets = [{'walletID': 0, 'name': 'All', 'selected': walletID == 0}] for w in my_corp.wallets.all().order_by('wallet'): wallets.append({ 'walletID': w.wallet_id, 'name': w.name, 'selected': w.wallet_id == walletID }) entryTypes = [{ 'refTypeID': 0, 'refTypeName': 'All', 'selected': entryTypeID == 0 }] for et in EntryType.objects.exclude(refTypeID=0).exclude( refTypeName='').order_by('refTypeName'): entryTypes.append({ 'refTypeID': et.refTypeID, 'refTypeName': et.refTypeName, 'selected': et.refTypeID == entryTypeID }) data = { 'wallets': wallets, 'entryTypes': entryTypes, 'amount': amount, 'comparator': comparator, 'scan_date': UpdateDate.get_latest(JournalEntry), 'from_date': datetime.strftime(from_date, DATE_PATTERN), 'to_date': datetime.strftime(to_date, DATE_PATTERN), 'datatable_defaults': DATATABLES_DEFAULTS, 'columns': WALLET_JOURNAL_COLUMNS, 'colorThresholds': ColorThreshold.as_json(), 'ajax_url': '/accounting/journal/data/', } return render_to_response("ecm/accounting/wallet_journal.html", data, Ctx(request))
def contracts(request): _type = request.GET.get('type', 0) # default to All _status = request.GET.get('status', 0) # default to All # Get contract types data = { 'types': [(ID, name, ID == _type) for ID, name in TYPES], 'statuses': [(ID, name, ID == _status) for ID, name in STATUSES], 'scan_date': UpdateDate.get_latest(Contract), 'columns': COLUMNS, } return render_to_response('ecm/accounting/contracts.html', data, Ctx(request))
def cyno_list(request): corps = Corporation.objects.others().order_by('corporationName') corps = corps.annotate(member_count=Count('members')) data = { 'scan_date': UpdateDate.get_latest(Member), 'trusted_corps': corps.filter(member_count__gt=0, is_trusted=True), 'other_corps': corps.filter(member_count__gt=0, is_trusted=False), 'datatables_defaults': DATATABLES_DEFAULTS, 'columns': MEMBERS_COLUMNS, 'ajax_url': '/hr/cyno_alts/data/', } return render_to_response("ecm/hr/members/cyno_alts.html", data, Ctx(request))
def update(): """ Retrieve all corp titles, their names and their role composition. If there are changes in the composition of the titles, the changes are also stored in the database. If there's an error, nothing is written in the database """ logger.info("fetching /corp/Titles.xml.aspx...") # connect to eve API api_conn = api.connect() # retrieve /corp/Titles.xml.aspx titlesApi = api_conn.corp.Titles(characterID=api.get_charID()) api.check_version(titlesApi._meta.version) currentTime = timezone.make_aware(titlesApi._meta.currentTime, timezone.utc) cachedUntil = timezone.make_aware(titlesApi._meta.cachedUntil, timezone.utc) logger.debug("current time : %s", str(currentTime)) logger.debug("cached util : %s", str(cachedUntil)) logger.debug("parsing api response...") my_corp = Corporation.objects.mine() newList = [] # we get all the old TitleComposition from the database oldList = list(TitleComposition.objects.all()) for title in titlesApi.titles: newList.extend(parse_one_title(title, my_corp)) diffs = [] if len(oldList) != 0 : diffs = getDiffs(newList, oldList, currentTime) if diffs : for d in diffs: d.save() # we store the update time of the table UpdateDate.mark_updated(model=TitleCompoDiff, date=currentTime) TitleComposition.objects.all().delete() for c in newList: c.save() # we store the update time of the table UpdateDate.mark_updated(model=TitleComposition, date=currentTime) # if no diff, we do nothing else: # 1st import for c in newList: c.save() # we store the update time of the table UpdateDate.mark_updated(model=TitleComposition, date=currentTime) # update titles access levels for t in Title.objects.all(): t.accessLvl = t.get_access_lvl() t.save() logger.info("%d roles in titles parsed, %d changes since last scan", len(newList), len(diffs))
def members(request): corps = Corporation.objects.others().order_by('corporationName') corps = corps.annotate(member_count=Count('members')) data = { 'scan_date' : UpdateDate.get_latest(Member), 'trusted_corps': corps.filter(member_count__gt=0, is_trusted=True), 'other_corps': corps.filter(member_count__gt=0, is_trusted=False), 'colorThresholds' : ColorThreshold.as_json(), 'directorAccessLvl' : Member.DIRECTOR_ACCESS_LVL, 'datatables_defaults': DATATABLES_DEFAULTS, 'columns': MEMBERS_COLUMNS, 'ajax_url': '/hr/members/data/', } return render_to_response("ecm/hr/members/list.html", data, Ctx(request))
def members(request): corps = Corporation.objects.others().order_by('corporationName') corps = corps.annotate(member_count=Count('members')) data = { 'scan_date': UpdateDate.get_latest(Member), 'trusted_corps': corps.filter(member_count__gt=0, is_trusted=True), 'other_corps': corps.filter(member_count__gt=0, is_trusted=False), 'colorThresholds': ColorThreshold.as_json(), 'directorAccessLvl': Member.DIRECTOR_ACCESS_LVL, 'datatables_defaults': DATATABLES_DEFAULTS, 'columns': MEMBERS_COLUMNS, 'ajax_url': '/hr/members/data/', } return render_to_response("ecm/hr/members/list.html", data, Ctx(request))
def journal(request): walletID = int(request.GET.get('walletID', 0)) entryTypeID = int(request.GET.get('entryTypeID', 0)) amount = request.GET.get('amount',None) comparator = request.GET.get('comparator','>') from_date = JournalEntry.objects.all().aggregate(date=Min("date"))["date"] if from_date is None: from_date = datetime.utcfromtimestamp(0) to_date = JournalEntry.objects.all().aggregate(date=Max("date"))["date"] if to_date is None: to_date = timezone.now() my_corp = Corporation.objects.mine() wallets = [{ 'walletID' : 0, 'name' : 'All', 'selected' : walletID == 0 }] for w in my_corp.wallets.all().order_by('wallet'): wallets.append({ 'walletID' : w.wallet_id, 'name' : w.name, 'selected' : w.wallet_id == walletID }) entryTypes = [{ 'refTypeID' : 0, 'refTypeName' : 'All', 'selected' : entryTypeID == 0 }] for et in EntryType.objects.exclude(refTypeID=0).exclude(refTypeName='').order_by('refTypeName'): entryTypes.append({ 'refTypeID' : et.refTypeID, 'refTypeName' : et.refTypeName, 'selected' : et.refTypeID == entryTypeID }) data = { 'wallets' : wallets, 'entryTypes' : entryTypes, 'amount' : amount, 'comparator' : comparator, 'scan_date' : UpdateDate.get_latest(JournalEntry), 'from_date' : datetime.strftime(from_date, DATE_PATTERN), 'to_date' : datetime.strftime(to_date, DATE_PATTERN), 'datatable_defaults': DATATABLES_DEFAULTS, 'columns': WALLET_JOURNAL_COLUMNS, 'colorThresholds': ColorThreshold.as_json(), 'ajax_url':'/accounting/journal/data/', } return render_to_response("ecm/accounting/wallet_journal.html", data, Ctx(request))
def journal(request): walletID = int(request.GET.get("walletID", 0)) entryTypeID = int(request.GET.get("entryTypeID", 0)) amount = request.GET.get("amount", None) comparator = request.GET.get("comparator", ">") from_date = JournalEntry.objects.all().aggregate(date=Min("date"))["date"] if from_date is None: from_date = datetime.utcfromtimestamp(0) to_date = JournalEntry.objects.all().aggregate(date=Max("date"))["date"] if to_date is None: to_date = timezone.now() my_corp = Corporation.objects.mine() wallets = [{"walletID": 0, "name": "All", "selected": walletID == 0}] for w in my_corp.wallets.all().order_by("wallet"): wallets.append({"walletID": w.wallet_id, "name": w.name, "selected": w.wallet_id == walletID}) entryTypes = [{"refTypeID": 0, "refTypeName": "All", "selected": entryTypeID == 0}] for et in EntryType.objects.exclude(refTypeID=0).exclude(refTypeName="").order_by("refTypeName"): entryTypes.append( {"refTypeID": et.refTypeID, "refTypeName": et.refTypeName, "selected": et.refTypeID == entryTypeID} ) data = { "wallets": wallets, "entryTypes": entryTypes, "amount": amount, "comparator": comparator, "scan_date": UpdateDate.get_latest(JournalEntry), "from_date": datetime.strftime(from_date, DATE_PATTERN), "to_date": datetime.strftime(to_date, DATE_PATTERN), "datatable_defaults": DATATABLES_DEFAULTS, "columns": WALLET_JOURNAL_COLUMNS, "colorThresholds": ColorThreshold.as_json(), "ajax_url": "/accounting/journal/data/", } return render_to_response("ecm/accounting/wallet_journal.html", data, Ctx(request))
def marketorders(request): stateID = int(request.GET.get('stateID', -1)) typeID = request.GET.get('typeID', 0) states = [{ 'stateID': -1, 'name': 'All', 'selected' : stateID == -1 , }] for sid, name in MarketOrder.STATE.items(): states.append({ 'stateID': sid, 'name': name, 'selected': name == stateID, }) types = [{ 'typeID': 0, 'name': 'All', 'selected': typeID == 0, }, { 'typeID': 1, 'name': 'Buy Order', 'selected': typeID == 1, }, { 'typeID': 2, 'name': 'Sell Order', 'selected': typeID == 2 }] data = { 'states': states, 'types': types, 'columns': COLUMNS, 'scan_date': UpdateDate.get_latest(MarketOrder), } return render_to_response('ecm/accounting/marketorders.html', data, Ctx(request))
def transactions(request): walletID = int(request.GET.get("walletID", 0)) entryTypeID = int(request.GET.get("entryTypeID", -1)) entryForID = int(request.GET.get("entryForID", -1)) amount = request.GET.get("amount", None) comparator = request.GET.get("comparator", ">") from_date = TransactionEntry.objects.all().aggregate(date=Min("date"))["date"] if from_date is None: from_date = datetime.utcfromtimestamp(0) to_date = TransactionEntry.objects.all().aggregate(date=Max("date"))["date"] if to_date is None: to_date = timezone.now() wallets = [{"walletID": 0, "name": "All", "selected": walletID == 0}] for w in Corporation.objects.mine().wallets.all().order_by("wallet"): wallets.append({"walletID": w.wallet_id, "name": w.name, "selected": w.wallet_id == walletID}) entryTypes = [{"refTypeID": -1, "refTypeName": "Both", "selected": entryTypeID == -1}] for tet in TransactionEntry.TYPES: entryTypes.append( {"refTypeID": tet, "refTypeName": TransactionEntry.TYPES[tet], "selected": tet == entryTypeID} ) entryFor = [{"refTypeID": -1, "refTypeName": "Both", "selected": entryForID == -1}] for ter in TransactionEntry.FOR: entryFor.append({"refTypeID": ter, "refTypeName": TransactionEntry.FOR[ter], "selected": ter == entryForID}) data = { "wallets": wallets, "entryTypes": entryTypes, "entryFor": entryFor, "amount": amount, "comparator": comparator, "scan_date": UpdateDate.get_latest(TransactionEntry), "from_date": datetime.strftime(from_date, DATE_PATTERN), "to_date": datetime.strftime(to_date, DATE_PATTERN), } return render_to_response("ecm/accounting/wallet_transactions.html", data, Ctx(request))
def storeRoles(oldRoles, newRoles, date): if len(oldRoles) != 0: roleDiffs = getRoleMemberDiffs(oldRoles, newRoles, date) if roleDiffs: for d in roleDiffs: d.save() # we store the update time of the table UpdateDate.mark_updated(model=RoleMemberDiff, date=date) RoleMembership.objects.all().delete() for rm in newRoles.values(): rm.save() # we store the update time of the table UpdateDate.mark_updated(model=RoleMembership, date=date) # if no diff, we do nothing return len(roleDiffs) else: # 1st import, no diff to write for rm in newRoles.values(): rm.save() # we store the update time of the table UpdateDate.mark_updated(model=RoleMembership, date=date) return 0
def storeTitles(oldTitles, newTitles, date): if len(oldTitles) != 0: titleDiffs = getTitleMemberDiffs(oldTitles, newTitles, date) if titleDiffs: for d in titleDiffs: d.save() # we store the update time of the table UpdateDate.mark_updated(model=TitleMemberDiff, date=date) TitleMembership.objects.all().delete() for tm in newTitles.values(): tm.save() # we store the update time of the table UpdateDate.mark_updated(model=TitleMembership, date=date) # if no diff, we do nothing return len(titleDiffs) else: # 1st import, no diff to write for tm in newTitles.values(): tm.save() # we store the update time of the table UpdateDate.mark_updated(model=TitleMembership, date=date) return 0
def root(request, date_str): my_corp = Corporation.objects.mine() all_hangars = Hangar.objects.all().order_by('hangarID') for hangar in all_hangars: hangar.name = hangar.get_name(my_corp) try: divisions_str = request.GET['divisions'] divisions = [int(div) for div in divisions_str.split(',')] for h in all_hangars: h.checked = h.hangar_id in divisions except: divisions, divisions_str = None, None for h in all_hangars: h.checked = True show_in_space = json.loads(request.GET.get('space', 'true')) show_in_stations = json.loads(request.GET.get('stations', 'true')) since_weeks = int(request.GET.get('since_weeks', '8')) to_weeks = int(request.GET.get('to_weeks', '0')) oldest_date = timezone.now() - timedelta(weeks=since_weeks) newest_date = timezone.now() - timedelta(weeks=to_weeks) query = AssetDiff.objects.values_list( 'date', flat=True).distinct().order_by('-date') query = query.filter(date__gte=oldest_date) query = query.filter(date__lte=newest_date) dates = [] for date in query: dates.append({ 'value': datetime.strftime(date, DATE_PATTERN), 'show': date }) data = { 'show_in_space': show_in_space, 'show_in_stations': show_in_stations, 'divisions_str': divisions_str, 'hangars': all_hangars, 'scan_date': UpdateDate.get_latest(Asset), 'since_weeks': since_weeks, 'to_weeks': to_weeks, 'date_str': date_str, 'dates': dates } try: date_asked = datetime.strptime(date_str, DATE_PATTERN) date_asked = timezone.make_aware(date_asked, timezone.utc) next_date = date_asked + timedelta(seconds=1) except ValueError: return redirect('/assets/changes/') if AssetDiff.objects.filter(date__range=(date_asked, next_date)).exists(): data['date'] = date_asked return render_to_response('ecm/assets/assets_diff.html', data, Ctx(request)) else: return render_to_response('ecm/assets/assets_no_data.html', {}, Ctx(request))
def write_diff_results(diffs, currentTime): for assetDiff in diffs: assetDiff.save() # we store the update time of the table UpdateDate.mark_updated(model=AssetDiff, date=currentTime) LOG.info("%d changes since last scan", len(diffs))
def wallets(request): data = { 'scan_date' : UpdateDate.get_latest(JournalEntry) } return render_to_response("ecm/accounting/wallets.html", data, Ctx(request))
def update(): """ Retrieve all corp members, with all basic information about them. If some members have left or have arrived we also store the diff in the database. If there's an error, nothing is written in the database """ LOG.info("fetching /corp/MemberTracking.xml.aspx...") # connect to eve API api_conn = api.connect() # retrieve /corp/MemberTracking.xml.aspx membersApi = api_conn.corp.MemberTracking(characterID=api.get_charID(), extended=1) api.check_version(membersApi._meta.version) currentTime = timezone.make_aware(membersApi._meta.currentTime, timezone.utc) cachedUntil = timezone.make_aware(membersApi._meta.cachedUntil, timezone.utc) LOG.debug("current time : %s", str(currentTime)) LOG.debug("cached util : %s", str(cachedUntil)) LOG.debug("parsing api response...") newMembers = {} oldMembers = {} notCorped = {} oldAccessLvls = {} oldOwners = {} my_corp = Corporation.objects.mine() # we get the old member list from the database for m in Member.objects.all(): if m.corp == my_corp: oldMembers[m] = m else: notCorped[m] = m oldAccessLvls[m.characterID] = m.accessLvl oldOwners[m.characterID] = m.owner for member in membersApi.members: m = parseOneMember(member, my_corp) session = MemberSession(character_id=m.characterID, session_begin=m.lastLogin, session_end=m.lastLogoff, session_seconds=(member.logoffDateTime - member.logonDateTime).seconds) dbsession = MemberSession.objects.filter(character_id=m.characterID, session_begin=m.lastLogin) if len(dbsession) == 0: session.save() newMembers[m] = m diffs, leaved = getDiffs(oldMembers, newMembers, currentTime) # "leaved" is the list of members that leaved (not a list of MemberDiff but real Character objects) # If we delete the old members each time, then all the diffs in roles/titles will not match # as the foreign keys will be gone from the members table... for L in leaved: L.corp = None newMembers[L] = L LOG.info("%d members parsed, %d changes since last scan", len(newMembers), len(diffs)) for m in notCorped.values(): try: # if the previously "not corped" members can now be found in the "new members" # we do nothing newMembers[m] except KeyError: # if the previously "not corped" members still cannot be found in the "new members" # we add them again to the members list newMembers[m] = m for m in newMembers.values(): try: # we restore the old access levels from the database m.accessLvl = oldAccessLvls[m.characterID] m.owner = oldOwners[m.characterID] except KeyError: # 'm' is a brand new member, his/her access level didn't exist before # we leave it to the default value '0' continue for m in newMembers.values(): # to be sure to store the nicknames change, etc. # even if there are no diff, we always overwrite the members m.save() if len(oldMembers) > 0 and len(diffs) > 0: for d in diffs: d.save() # we store the update time of the table UpdateDate.mark_updated(model=MemberDiff, date=currentTime) # we store the update time of the table UpdateDate.mark_updated(model=Member, date=currentTime)
def details(request, characterID): avg_session = { 'sessionlength': 0, '30days': 0, '7days': 0, } now = timezone.now() try: member = Member.objects.get(characterID=int(characterID)) try: member.base = CelestialObject.objects.get(itemID=member.baseID).itemName except CelestialObject.DoesNotExist: member.base = str(member.baseID) member.color = ColorThreshold.get_access_color(member.accessLvl) member.roles_no_director = member.roles.exclude(roleID=1) # exclude 'director' query = MemberSession.objects.filter(character_id=member.characterID).order_by('session_begin') query_30 = query.filter(session_begin__gt=now - timedelta(30)) query_7 = query.filter(session_begin__gt=now - timedelta(7)) session_len = query.aggregate(len=Avg('session_seconds'))['len'] or 0 session_len_30 = query_30.aggregate(len=Avg('session_seconds'))['len'] or 0 session_len_7 = query_7.aggregate(len=Avg('session_seconds'))['len'] or 0 # Totals total = query.aggregate(len=Sum('session_seconds'))['len'] or 0 lastWeek = query_7.aggregate(len=Sum('session_seconds'))['len'] or 0 lastMonth = query_30.aggregate(len=Sum('session_seconds'))['len'] or 0 loginhistory = query.order_by('-session_begin')[:10] avg_session['sessionlength'] = timedelta(seconds=session_len) avg_session['30days'] = timedelta(seconds=session_len_30) avg_session['7days'] = timedelta(seconds=session_len_7) if member.corp_id == Corporation.objects.mine().corporationID: member.date = UpdateDate.get_latest(Member) else: try: d = MemberDiff.objects.filter(member=member, new=False).order_by("-id")[0] member.date = d.date except IndexError: member.date = 0 skills, skill_count, skillpoint_count = get_skills(member) except Member.DoesNotExist: member = Member(characterID=int(characterID), name="???") try: killboardUrl = Setting.get('corp_killboard_url') except Setting.DoesNotExist: killboardUrl = None data = { 'member' : member, 'killboardUrl' : killboardUrl, 'sessiondata' : avg_session, 'lastWeek' : lastWeek, 'lastMonth' : lastMonth, 'total' : total, 'logins' : loginhistory, 'skills_tree' : json.dumps(skills), 'skill_count' : skill_count, 'skillpoint_count' : print_integer(skillpoint_count), 'datatables_defaults': DATATABLES_DEFAULTS, 'access_columns' : ACCESS_CHANGES_COLUMNS, 'sorting' : [[2, 'desc']], } return render_to_response("ecm/hr/members/details.html", data, Ctx(request))
def update_corp_info(corpApi, currentTime): try: try: try: alliance = Alliance.objects.get(allianceID = corpApi.allianceID) except Alliance.DoesNotExist: LOG.info("Adding new Alliance: "+ corpApi.allianceName) alliance = Alliance() alliance.allianceID = corpApi.allianceID alliance.name = corpApi.allianceName alliancesApi = api.connect().eve.AllianceList() for a in alliancesApi.alliances: if a.allianceID == corpApi.allianceID: alliance.shortName = a.shortName alliance.save() break except api.Error: LOG.exception("Failed to fetch AllianceList.xml.aspx from EVE API server") corp = Corporation.objects.mine() alliance = None except: alliance = None description = fix_description(corpApi.description) # reset all other corps Corporation.objects.exclude(corporationID=corpApi.corporationID).update(is_my_corp=False) try: # try to retrieve the db stored corp info corp = Corporation.objects.get(corporationID=corpApi.corporationID) corp.is_my_corp = True corp.corporationID = corpApi.corporationID corp.corporationName = corpApi.corporationName corp.ticker = corpApi.ticker corp.ceoID = corpApi.ceoID corp.ceoName = corpApi.ceoName corp.stationID = corpApi.stationID corp.stationName = corpApi.stationName corp.alliance = alliance corp.description = description corp.taxRate = corpApi.taxRate corp.memberLimit = corpApi.memberLimit except Corporation.DoesNotExist: LOG.debug('First scan, creating corp...') # no corp parsed yet corp = Corporation(is_my_corp = True, corporationID = corpApi.corporationID, corporationName = corpApi.corporationName, ticker = corpApi.ticker, ceoID = corpApi.ceoID, ceoName = corpApi.ceoName, stationID = corpApi.stationID, stationName = corpApi.stationName, description = description, alliance = alliance, taxRate = corpApi.taxRate, memberLimit = corpApi.memberLimit ) if settings.USE_HTTPS: corp.ecm_url = 'https://' + settings.EXTERNAL_HOST_NAME else: corp.ecm_url = 'http://' + settings.EXTERNAL_HOST_NAME if not (corp.private_key and corp.public_key and corp.key_fingerprint): # as this is the first time, we must generate the RSA keypair of our own corp LOG.debug('Generating RSA key pair...') corp.private_key = crypto.generate_rsa_keypair() corp.public_key = crypto.extract_public_key(corp.private_key) corp.key_fingerprint = crypto.key_fingerprint(corp.public_key) LOG.info('Generated RSA key pair for corporation ID %d.' % corpApi.corporationID) corp.save() # we store the update time of the table UpdateDate.mark_updated(model=Corporation, date=currentTime) return corp
def wallets(request): data = {'scan_date': UpdateDate.get_latest(JournalEntry)} return render_to_response("ecm/accounting/wallets.html", data, Ctx(request))