def clean(self): cleaned_data = super(UserForm, self).clean() if 'person_1' not in cleaned_data or 'person_2' not in cleaned_data: return cleaned_data # error in one of that filed, no need to continue cleaning person_1 = persons_storage.persons[int(cleaned_data['person_1'])] person_2 = persons_storage.persons[int(cleaned_data['person_2'])] if (not politic_power_logic.get_inner_circle(person_id=person_1.id).in_circle(self.owner_id) and not politic_power_logic.get_inner_circle(person_id=person_2.id).in_circle(self.owner_id)): raise ValidationError('Вы не состоите в ближнем круге ни одного из Мастеров') return cleaned_data
def show(context): inner_circle = politic_power_logic.get_inner_circle( place_id=context.place.id) accounts_short_infos = game_short_info.get_accounts_accounts_info( inner_circle.heroes_ids()) job_power = politic_power_logic.get_job_power(place_id=context.place.id) persons_inner_circles = { person.id: politic_power_logic.get_inner_circle(person_id=person.id) for person in context.place.persons } return dext_views.Page( 'places/show.html', content={ 'place': context.place, 'place_bills': info.place_info_bills(context.place), 'place_chronicle': chronicle_prototypes.RecordPrototype.get_last_actor_records( context.place, conf.settings.CHRONICLE_RECORDS_NUMBER), 'accounts_short_infos': accounts_short_infos, 'inner_circle': inner_circle, 'persons_inner_circles': persons_inner_circles, 'HABIT_TYPE': game_relations.HABIT_TYPE, 'place_meta_object': meta_relations.Place.create_from_object(context.place), 'hero': heroes_logic.load_hero( account_id=context.account.id) if context.account else None, 'places_power_storage': politic_power_storage.places, 'persons_power_storage': politic_power_storage.persons, 'job_power': job_power, 'resource': context.resource })
def clean_person_1(self): person_id = person_id = int(self.cleaned_data['person_1']) if not politic_power_logic.get_inner_circle( person_id=person_id).in_circle(self.owner_id): raise ValidationError( 'Ваш герой должен быть в ближнем круге первого Мастера') return person_id
def person_info(person): building = places_storage.buildings.get_by_person_id(person.id) inner_circle = politic_power_logic.get_inner_circle(person_id=person.id) data = { 'id': person.id, 'name': person.name, 'updated_at': time.mktime(person.updated_at.timetuple()), 'profession': person.type.value, 'race': person.race.value, 'gender': person.gender.value, 'place': { 'id': person.place.id, 'name': person.place.name, 'size': person.place.attrs.size, 'specialization': person.place.modifier.value, 'position': { 'x': person.place.x, 'y': person.place.y } }, 'building': places_info.building_info(building) if building else None, 'politic_power': { 'heroes': inner_circle.ui_info(), 'power': politic_power_storage.persons.ui_info(person.id) }, 'attributes': attributes.attributes_info(effects=person.all_effects(), attrs=person.attrs, relation=relations.ATTRIBUTE), 'chronicle': chronicle_prototypes.chronicle_info( person, conf.settings.CHRONICLE_RECORDS_NUMBER), 'job': person.job.ui_info(), 'accounts': None, 'clans': None } accounts_ids = set() accounts_ids.update(data['politic_power']['heroes']['positive']) accounts_ids.update(data['politic_power']['heroes']['negative']) data['accounts'] = game_logic.accounts_info(accounts_ids) data['clans'] = game_logic.clans_info(data['accounts']) return data
def clean_person(self): person_id = super().clean_person() if not politic_power_logic.get_inner_circle( person_id=person_id).in_circle(self.owner_id): raise ValidationError( 'Ваш герой должен быть в ближнем круге Мастера') return person_id
def place_info(place, full_building_info): inner_circle = politic_power_logic.get_inner_circle(place_id=place.id) data = { 'id': place.id, 'name': place.name, 'frontier': place.is_frontier, 'new_for': time.mktime(place.new_for.timetuple()), 'description': place.description_html, 'updated_at': time.mktime(place.updated_at.timetuple()), 'position': { 'x': place.x, 'y': place.y }, 'politic_power': { 'heroes': inner_circle.ui_info(), 'power': politic_power_storage.places.ui_info(place.id) }, 'persons': place_info_persons_data(place, full_building_info=full_building_info), 'attributes': attributes.attributes_info(effects=place.all_effects(), attrs=place.attrs, relation=relations.ATTRIBUTE), 'demographics': place_info_demographics(place), 'bills': place_info_bills(place), 'habits': place_info_habits(place), 'job': place.job.ui_info(), 'chronicle': chronicle_prototypes.chronicle_info( place, conf.settings.CHRONICLE_RECORDS_NUMBER), 'accounts': None, 'clans': None } accounts_ids = set() accounts_ids.update(data['politic_power']['heroes']['positive']) accounts_ids.update(data['politic_power']['heroes']['negative']) data['accounts'] = game_logic.accounts_info(accounts_ids) data['clans'] = game_logic.clans_info(data['accounts']) return data
def show(context): inner_circle = politic_power_logic.get_inner_circle( person_id=context.person.id) accounts_short_infos = game_short_info.get_accounts_accounts_info( inner_circle.heroes_ids()) job_power = politic_power_logic.get_job_power(person_id=context.person.id) return dext_views.Page( 'persons/show.html', content={ 'person': context.person, 'person_meta_object': meta_relations.Person.create_from_object(context.person), 'accounts_short_infos': accounts_short_infos, 'hero': heroes_logic.load_hero( account_id=context.account.id) if context.account else None, 'social_connections': storage.social_connections.get_connected_persons(context.person), 'master_chronicle': chronicle_prototypes.RecordPrototype.get_last_actor_records( context.person, conf.settings.CHRONICLE_RECORDS_NUMBER), 'inner_circle': inner_circle, 'persons_power_storage': politic_power_storage.persons, 'job_power': job_power, 'resource': context.resource })
def load_inner_circle(self, actor_id): return politic_power_logic.get_inner_circle(place_id=actor_id)
def cell_info(context): x, y = context.x, context.y if x < 0 or y < 0 or x >= map_settings.WIDTH or y >= map_settings.HEIGHT: raise dext_views.ViewError( code='outside_map', message='Запрашиваемая зона не принадлежит карте') map_info = map_info_storage.item terrain = map_info.terrain[y][x] cell = map_info.cells.get_cell(x, y) nearest_place_name = None nearest_place = map_info.get_dominant_place(x, y) if nearest_place: nearest_place_name = nearest_place.utg_name.form( utg_words.Properties(utg_relations.CASE.GENITIVE)) place = places_storage.places.get_by_coordinates(x, y) exchanges = [] terrain_points = [] building = places_storage.buildings.get_by_coordinates(x, y) place_inner_circle = None persons_inner_circles = None if place: place_inner_circle = politic_power_logic.get_inner_circle( place_id=place.id) persons_inner_circles = { person.id: politic_power_logic.get_inner_circle(person_id=person.id) for person in place.persons } return dext_views.Page( 'map/cell_info.html', content={ 'place': place, 'building': building, 'places_power_storage': politic_power_storage.places, 'persons_power_storage': politic_power_storage.persons, 'persons_inner_circles': persons_inner_circles, 'place_inner_circle': place_inner_circle, 'place_bills': places_info.place_info_bills(place) if place else None, 'place_chronicle': chronicle_prototypes.RecordPrototype.get_last_actor_records( place, conf.map_settings.CHRONICLE_RECORDS_NUMBER) if place else None, 'exchanges': exchanges, 'cell': cell, 'terrain': terrain, 'nearest_place_name': nearest_place_name, 'x': x, 'y': y, 'terrain_points': terrain_points, 'hero': heroes_logic.load_hero(account_id=context.account.id) if context.account.is_authenticated else None, 'resource': context.resource, 'ABILITY_TYPE': ABILITY_TYPE })