def validate(self): """ Validate a corp API key. Return False if invalid, True if valid. :returns: bool -- True if valid, False if invalid """ auth = self.get_authenticated_api() self.lastvalidated = datetime.now(pytz.utc) try: result = auth.account.APIKeyInfo() except eveapi.AuthenticationError: self.valid = False self.validation_error("Access Denied: Key not valid.") self.save() return False if result.key.type == u'Corporation': self.valid = True self.character_name = result.key.characters[0].characterName self.access_mask = result.key.accessMask self.corp = update_corporation( result.key.characters[0].corporationID, sync=True) self.validation_error = True self.save() return True else: self.valid = False self.validation_error = "API Key is not a corporation key." return False
def edit_pos(request, msID, posID): """ GET gets the edit POS dialog, POST processes it. """ if not request.is_ajax(): raise PermissionDenied mapsystem = get_object_or_404(MapSystem, pk=msID) system = get_object_or_404(System, pk=mapsystem.system.pk) pos = get_object_or_404(POS, pk=posID) if request.method == 'POST': tower = get_object_or_404(Type, name=request.POST['tower']) try: corp = Corporation.objects.get(name=request.POST['corp']) except Corporation.DoesNotExist: api = eveapi.EVEAPIConnection(cacheHandler=handler) corp_id = api.eve.CharacterID( names=request.POST['corp']).characters[0].characterID if corp_id == 0: return HttpResponse('Corp does not exist!', status=404) corp = core_tasks.update_corporation(corp_id) pos.corporation = corp pos.towertype = tower pos.posname = request.POST['name'] pos.planet = int(request.POST['planet']) pos.moon = int(request.POST['moon']) pos.status = int(request.POST['status']) pos.fitting = request.POST['fitting'] # Have the async worker update the corp just so that it is up to date core_tasks.update_corporation.delay(corp.id) if pos.status == 3: if request.POST['rfdays'] == '': rf_days = 0 else: rf_days = int(request.POST['rfdays']) if request.POST['rfhours'] == '': rf_hours = 0 else: rf_hours = int(request.POST['rfhours']) if request.POST['rfminutes'] == '': rf_minutes = 0 else: rf_minutes = int(request.POST['rfminutes']) delta = timedelta(days=rf_days, hours=rf_hours, minutes=rf_minutes) pos.rftime = datetime.now(pytz.utc) + delta pos.save() if request.POST.get('dscan', None) == "1": pos.fit_from_dscan(request.POST['fitting'].encode('utf-8')) return HttpResponse() else: fitting = pos.fitting if fitting is not None: fitting = fitting.replace("<br />", "\n") return TemplateResponse( request, 'edit_pos.html', { 'system': system, 'mapsystem': mapsystem, 'pos': pos, 'fitting': fitting })
def edit_pos(request, msID, posID): """ GET gets the edit POS dialog, POST processes it. """ if not request.is_ajax(): raise PermissionDenied mapsystem = get_object_or_404(MapSystem, pk=msID) system = get_object_or_404(System, pk=mapsystem.system.pk) pos = get_object_or_404(POS, pk=posID) if request.method == 'POST': tower = get_object_or_404(Type, name=request.POST['tower']) try: corp = Corporation.objects.get(name=request.POST['corp']) except Corporation.DoesNotExist: api = eveapi.EVEAPIConnection(cacheHandler=handler) corp_id = api.eve.CharacterID( names=request.POST['corp']).characters[0].characterID if corp_id == 0: return HttpResponse('Corp does not exist!', status=404) corp = core_tasks.update_corporation(corp_id) pos.corporation = corp pos.towertype = tower pos.posname = request.POST['name'] pos.planet = int(request.POST['planet']) pos.moon = int(request.POST['moon']) pos.status = int(request.POST['status']) pos.fitting = request.POST['fitting'] # Have the async worker update the corp just so that it is up to date core_tasks.update_corporation.delay(corp.id) if pos.status == 3: if request.POST['rfdays'] == '': rf_days = 0 else: rf_days = int(request.POST['rfdays']) if request.POST['rfhours'] == '': rf_hours = 0 else: rf_hours = int(request.POST['rfhours']) if request.POST['rfminutes'] == '': rf_minutes = 0 else: rf_minutes = int(request.POST['rfminutes']) delta = timedelta(days=rf_days, hours=rf_hours, minutes=rf_minutes) pos.rftime = datetime.now(pytz.utc) + delta pos.save() if request.POST.get('dscan', None) == "1": pos.fit_from_dscan(request.POST['fitting'].encode('utf-8')) return HttpResponse() else: fitting = pos.fitting if fitting is not None: fitting = fitting.replace("<br />", "\n") return TemplateResponse(request, 'edit_pos.html', {'system': system, 'mapsystem': mapsystem, 'pos': pos, 'fitting': fitting})
def add_pos(request, sysID): """ GET gets the add POS dialog, POST processes it. """ if not request.is_ajax(): raise PermissionDenied system = get_object_or_404(System, pk=sysID) if request.method == 'POST': tower = get_object_or_404(Type, name=request.POST['tower']) try: corp = Corporation.objects.get(name=request.POST['corp']) except: # Corp isn't in our DB, get its ID and add it try: api = eveapi.EVEAPIConnection(cacheHandler=handler) corpID = api.eve.CharacterID(names=request.POST['corp']).characters[0].characterID corp = core_tasks.update_corporation(corpID) except: # The corp doesn't exist raise Http404 pos=POS(system=system, planet=int(request.POST['planet']), moon=int(request.POST['moon']), towertype=tower, posname=request.POST['name'], fitting=request.POST['fitting'], status=int(request.POST['status']), corporation=corp) # Have the async worker update the corp just so that it is up to date core_tasks.update_corporation.delay(corp.id) if pos.status == 3: if request.POST['rfdays'] == '': rf_days = 0 else: rf_days = int(request.POST['rfdays']) if request.POST['rfhours'] == '': rf_hours = 0 else: rf_hours = int(request.POST['rfhours']) if request.POST['rfminutes'] == '': rf_minutes = 0 else: rf_minutes = int(request.POST['rfminutes']) delta = timedelta(days=rf_days, hours=rf_hours, minutes=rf_minutes) pos.rftime = datetime.now(pytz.utc) + delta pos.save() if request.POST.get('dscan', None) == "1": pos.fit_from_dscan(request.POST['fitting'].encode('utf-8')) return HttpResponse('[]') else: return TemplateResponse(request, 'add_pos.html', {'system': system})
def add_pos(request, sysID): """ GET gets the add POS dialog, POST processes it. """ if not request.is_ajax(): raise PermissionDenied system = get_object_or_404(System, pk=sysID) if request.method == 'POST': tower = get_object_or_404(Type, name=request.POST['tower']) try: corp = Corporation.objects.get(name=request.POST['corp']) except: # Corp isn't in our DB, get its ID and add it try: api = eveapi.EVEAPIConnection(cacheHandler=handler) corpID = api.eve.CharacterID(names=request.POST['corp']).characters[0].characterID corp = core_tasks.update_corporation(corpID, True) except: # The corp doesn't exist raise Http404 pos=POS(system=system, planet=int(request.POST['planet']), moon=int(request.POST['moon']), towertype=tower, posname=request.POST['name'], fitting=request.POST['fitting'], status=int(request.POST['status']), corporation=corp) # Have the async worker update the corp just so that it is up to date core_tasks.update_corporation.delay(corp.id) if pos.status == 3: if request.POST['rfdays'] == '': rf_days = 0 else: rf_days = int(request.POST['rfdays']) if request.POST['rfhours'] == '': rf_hours = 0 else: rf_hours = int(request.POST['rfhours']) if request.POST['rfminutes'] == '': rf_minutes = 0 else: rf_minutes = int(request.POST['rfminutes']) delta = timedelta(days=rf_days, hours=rf_hours, minutes=rf_minutes) pos.rftime = datetime.now(pytz.utc) + delta pos.save() if request.POST.get('dscan', None) == "1": pos.fit_from_dscan(request.POST['fitting'].encode('utf-8')) return HttpResponse('[]') else: return TemplateResponse(request, 'add_pos.html', {'system': system})
def update_from_import_list(cls, system, import_list): """ Imports starbases from YAML importer. """ for pos in import_list: planet = pos['planet'] moon = pos['moon'] warpin = pos['warpin'] status = pos['status'] rftime = pos['rftime'] name = pos['name'] tower = Type.objects.get(name=pos['tower']) try: owner = Corporation.objects.get(name=pos['owner']) except Corporation.DoesNotExist: from core import tasks api = eveapi.EVEAPIConnection(cacheHandler=handler) corp_id = api.eve.CharacterID( names=pos['owner']).characters[0].characterID owner = tasks.update_corporation(corp_id, True) if POS.objects.filter(system=system, planet=planet, moon=moon, corporation=owner).exists(): # Update first existing record starbase = POS.objects.filter(system=system, planet=planet, moon=moon, corporation=owner).all()[0] starbase.status = status starbase.name = name starbase.towertype = tower if status == 3: starbase.rftime = rftime starbase.warpin_notice = warpin else: new_pos = POS(system=system, planet=planet, moon=moon, corporation=owner, towertype=tower, warpin_notice=warpin, status=status) if status == 3: new_pos.rftime = rftime new_pos.save()
def add_pos(request, sysID): """ GET gets the add POS dialog, POST processes it. """ if not request.is_ajax(): raise PermissionDenied system = get_object_or_404(System, pk=sysID) if request.method == 'POST': try: corp_name = request.POST.get('corp', None) if not corp_name: return HttpResponse('Corp cannot be blank!', status=400) corp = Corporation.objects.get(name=corp_name) except Corporation.DoesNotExist: # Corp isn't in our DB, get its ID and add it api = eveapi.EVEAPIConnection(cacheHandler=handler) corpID = api.eve.CharacterID( names=corp_name).characters[0].characterID try: corp = core_tasks.update_corporation(corpID, True) except AttributeError: # The corp doesn't exist return HttpResponse('Corp does not exist!', status=404) else: # Have the async worker update the corp just so that it is up to date core_tasks.update_corporation.delay(corp.id) if request.POST['auto'] == '1': fittings = [] moon_distance = 150000000 for i in request.POST['fitting'].splitlines(): cols = i.split('\t') #ignore offgrid stuff if cols[2] != '-': fittings.append(cols) if cols[1] == 'Moon' and cols[2].endswith('km'): #found a moon close by distance = int(cols[2][:-3].replace(',','').replace('.','').replace(u'\xa0','')) if distance < moon_distance: #closest moon so far moon_distance = distance moon_name = cols[0] if moon_distance == 150000000: #No moon found return HttpResponse('No moon found in d-scan!', status=404) #parse POS location regex = '^%s ([IVX]+) - Moon ([0-9]+)$' % (system.name) re_result = re.match(regex, moon_name) if not re_result: return HttpResponse( 'Invalid D-Scan! Do you have the right system?', status=400) else: result = re_result.groups() NUMERALS = {'X': 10, 'V': 5, 'I': 1} planet = 0 for i in range(len(result[0])): value = NUMERALS[result[0][i]] try: next_value = NUMERALS[result[0][i+1]] except IndexError: next_value = 0 if value < next_value: planet -= value else: planet += value moon = int(result[1]) pos=POS(system=system, planet=planet, moon=moon, status=int(request.POST['status']), corporation=corp) try: pos.fit_from_iterable(fittings) except AttributeError as e: return HttpResponse(e, status=404) else: tower = get_object_or_404(Type, name=request.POST['tower']) pos=POS(system=system, planet=int(request.POST['planet']), moon=int(request.POST['moon']), towertype=tower, posname=request.POST['name'], fitting=request.POST['fitting'], status=int(request.POST['status']), corporation=corp) if request.POST.get('dscan', None) == "1": pos.fit_from_dscan(request.POST['fitting'].encode('utf-8')) if pos.status == 3: if request.POST['rfdays'] == '': rf_days = 0 else: rf_days = int(request.POST['rfdays']) if request.POST['rfhours'] == '': rf_hours = 0 else: rf_hours = int(request.POST['rfhours']) if request.POST['rfminutes'] == '': rf_minutes = 0 else: rf_minutes = int(request.POST['rfminutes']) delta = timedelta(days=rf_days, hours=rf_hours, minutes=rf_minutes) pos.rftime = datetime.now(pytz.utc) + delta pos.save() return HttpResponse() else: return TemplateResponse(request, 'add_pos.html', {'system': system})
def add_pos(request, msID): """ GET gets the add POS dialog, POST processes it. """ if not request.is_ajax(): raise PermissionDenied mapsystem = get_object_or_404(MapSystem, pk=msID) system = get_object_or_404(System, pk=mapsystem.system.pk) if request.method == 'POST': corp_name = request.POST.get('corp', None) if not corp_name: return HttpResponse('Corp cannot be blank!', status=400) try: corp = Corporation.objects.get(name=corp_name) except Corporation.DoesNotExist: # Corp isn't in our DB, get its ID and add it try: api = eveapi.EVEAPIConnection(cacheHandler=handler) corp_id = (api.eve.CharacterID( names=corp_name).characters[0].characterID) if corp_id == 0: return HttpResponse('Corp does not exist!', status=404) corp = core_tasks.update_corporation(corp_id, True) except: # Error while talking to the EVE API return HttpResponse( 'Could not verify Corp name. Please try again later.', status=404) else: # Have the async worker update the corp so that it is up to date core_tasks.update_corporation.delay(corp.id) if request.POST['auto'] == '1': fittings = [] moon_distance = 150000000 for i in request.POST['fitting'].splitlines(): cols = i.split('\t') # ignore offgrid stuff if cols[2] != '-': fittings.append(cols) if cols[1] == 'Moon' and cols[2].endswith('km'): # found a moon close by distance = int(cols[2][:-3].replace(',', '').replace( '.', '').replace(u'\xa0', '')) if distance < moon_distance: # closest moon so far moon_distance = distance moon_name = cols[0] if moon_distance == 150000000: # No moon found return HttpResponse('No moon found in d-scan!', status=404) # parse POS location regex = '^%s ([IVX]+) - Moon ([0-9]+)$' % (system.name, ) re_result = re.match(regex, moon_name) if not re_result: return HttpResponse( 'Invalid D-Scan! Do you have the right system?', status=400) else: result = re_result.groups() NUMERALS = {'X': 10, 'V': 5, 'I': 1} planet = 0 for i in range(len(result[0])): value = NUMERALS[result[0][i]] try: next_value = NUMERALS[result[0][i + 1]] except IndexError: next_value = 0 if value < next_value: planet -= value else: planet += value moon = int(result[1]) pos = POS(system=system, planet=planet, moon=moon, status=int(request.POST['status']), corporation=corp) try: pos.fit_from_iterable(fittings) except AttributeError as e: return HttpResponse(e, status=404) else: tower = get_object_or_404(Type, name=request.POST['tower']) pos = POS(system=system, planet=int(request.POST['planet']), moon=int(request.POST['moon']), towertype=tower, posname=request.POST['name'], fitting=request.POST['fitting'], status=int(request.POST['status']), corporation=corp) if request.POST.get('dscan', None) == "1": pos.fit_from_dscan(request.POST['fitting'].encode('utf-8')) if pos.status == 3: if request.POST['rfdays'] == '': rf_days = 0 else: rf_days = int(request.POST['rfdays']) if request.POST['rfhours'] == '': rf_hours = 0 else: rf_hours = int(request.POST['rfhours']) if request.POST['rfminutes'] == '': rf_minutes = 0 else: rf_minutes = int(request.POST['rfminutes']) delta = timedelta(days=rf_days, hours=rf_hours, minutes=rf_minutes) pos.rftime = datetime.now(pytz.utc) + delta pos.log(request.user, "Added", mapsystem) pos.save() return HttpResponse() else: return TemplateResponse(request, 'add_pos.html', { 'system': system, 'mapsystem': mapsystem })
def _process_app_type_form(request, app_type=None): if not app_type: app_type = AppType() name = request.POST.get("name", None) instructions = request.POST.get("instructions", "") frontpage_instructions = request.POST.get("frontpage_instructions", "") disable_user = request.POST.get("disable_user", "False") == "on" purge_api = request.POST.get("purge_api", "False") == "on" require_user = request.POST.get("require_user", "False") == "on" standings_text = request.POST.get("standings", None) required_votes = request.POST.get("required_votes", "1") if standings_text: try: corp = Corporation.objects.get(name=standings_text) except Corporation.DoesNotExist: # Corp isn't in our DB, get its ID and add it api = eveapi.EVEAPIConnection(cacheHandler=handler) corpID = api.eve.CharacterID(names=standings_text).characters[0].characterID try: corp = core_tasks.update_corporation(corpID, True) except AttributeError: # The corp doesn't exist return HttpResponse("Corp does not exist!", status=404) else: # Have the async worker update the corp just so that it is up to date core_tasks.update_corporation.delay(corp.id) standings_corp = get_object_or_404(Corporation, name=standings_text) else: standings_corp = None accept_text = request.POST.get("accept_group", None) if accept_text: accept_group = get_object_or_404(Group, name=accept_text) else: accept_group = None accept_subject = request.POST.get("accept_sbj", None) accept_body = request.POST.get("accept_mail", None) defer_subject = request.POST.get("defer_sbj", None) defer_body = request.POST.get("defer_mail", None) reject_subject = request.POST.get("reject_sbj", None) reject_body = request.POST.get("reject_mail", None) if name: if name != app_type.name and AppType.objects.filter(name=name).exists(): raise AttributeError("The name must be unique!") app_type.name = name else: raise AttributeError("Name cannot be blank.") app_type.instructions = instructions app_type.frontpage_instructions = frontpage_instructions app_type.use_standings = standings_corp app_type.accept_group = accept_group app_type.required_votes = required_votes app_type.require_account = require_user app_type.disable_user_on_failure = disable_user app_type.purge_api_on_failure = purge_api app_type.accept_subject = accept_subject app_type.accept_mail = accept_body app_type.defer_subject = defer_subject app_type.defer_mail = defer_body app_type.reject_subject = reject_subject app_type.reject_mail = reject_body app_type.save() return app_type