def test_game_add_newsfeed_from_template_read_directory(self): """ Should read all directory until failure, then loop on '_.md' """ for i in range(1, 10): self.g.add_newsfeed_from_template( category=Newsfeed.MATRIX_BUZZ, path='datasteal/shiawase/success') newsfeed = self.g.newsfeed_set.last() try: expected_content = read_file_from_path( '%s/datas/newsfeeds/4-matrix-buzz/datasteal/shiawase/success/%s.md' % (settings.BASE_DIR, i)) self.assertEqual(newsfeed.content, expected_content) except IOError: expected_content = read_file_from_path( '%s/datas/newsfeeds/4-matrix-buzz/datasteal/shiawase/success/_.md' % settings.BASE_DIR) self.assertEqual(newsfeed.content, expected_content) break else: raise Exception("Never looped :(")
def add_newsfeed_from_template(self, category, path, **kwargs): """ Construct the content of a newsfeed, avoiding messages already displayed within the same game. """ message_number = Newsfeed.objects.filter(category=category, game=self, path=path).count() + 1 try: content = read_file_from_path("%s/datas/newsfeeds/%s/%s/%s.md" % (settings.BASE_DIR, category, path, message_number)) except IOError: content = read_file_from_path("%s/datas/newsfeeds/%s/%s/_.md" % (settings.BASE_DIR, category, path)) kwargs['content'] = content kwargs['category'] = category kwargs['path'] = path self.add_newsfeed(**kwargs)
def test_game_add_newsfeed_from_template(self): """ Should store used path """ self.g.add_newsfeed_from_template(category=Newsfeed.MATRIX_BUZZ, path='datasteal/shiawase/success') newsfeed = self.g.newsfeed_set.get() self.assertEqual(newsfeed.content, read_file_from_path('%s/datas/newsfeeds/4-matrix-buzz/datasteal/shiawase/success/1.md' % settings.BASE_DIR))
def test_game_add_newsfeed_from_template_read_directory(self): """ Should read all directory until failure, then loop on '_.md' """ for i in range(1, 10): self.g.add_newsfeed_from_template(category=Newsfeed.MATRIX_BUZZ, path='datasteal/shiawase/success') newsfeed = self.g.newsfeed_set.last() try: expected_content = read_file_from_path('%s/datas/newsfeeds/4-matrix-buzz/datasteal/shiawase/success/%s.md' % (settings.BASE_DIR, i)) self.assertEqual(newsfeed.content, expected_content) except IOError: expected_content = read_file_from_path('%s/datas/newsfeeds/4-matrix-buzz/datasteal/shiawase/success/_.md' % settings.BASE_DIR) self.assertEqual(newsfeed.content, expected_content) break else: raise Exception("Never looped :(")
def test_game_add_newsfeed_from_template(self): """ Should store used path """ self.g.add_newsfeed_from_template(category=Newsfeed.MATRIX_BUZZ, path='datasteal/shiawase/success') newsfeed = self.g.newsfeed_set.get() self.assertEqual( newsfeed.content, read_file_from_path( '%s/datas/newsfeeds/4-matrix-buzz/datasteal/shiawase/success/1.md' % settings.BASE_DIR))
def get_display(self, display_context, is_personal=False): """ Return a formatted string with the Log values, according to is_personal (are we displaying this for the player who triggered the action ?) and display_context (is the reader already aware of the corporation? The corporationmarket?) """ if is_personal: path_personal = 'personal' else: path_personal = 'not_personal' # Read file data file_name = self.event_type path = '%s/logs/templates/logs/%s/%s/%s.md' % (settings.BASE_DIR, path_personal, display_context, file_name.lower()) raw_template = read_file_from_path(path) # Parse template context = Context(json.loads(self.data)) template = Template(raw_template) text = template.render(context) html, _ = parse_markdown(text) return html
def index(request, page): # On récupère le game id si on l'a en session pour accéder aux onglets de la session en cours gameid = None try: gameid = request.session['gameid'] except: pass if page == '': page = 'index' page = '%s/data/docs/%s.md' % (settings.BASE_DIR, page.replace('.', '')) raw = "" try: raw = read_file_from_path(page) except IOError: raise Http404("No documentation on this subject.") # Replace custom {{ corporations }} markup with a list of corporations: def list_corporation_as_markdown(): strings = ["* [%s](corporations/%s.md)" % (c.name, c.slug) for c in BaseCorporation.retrieve_all()] return "\n".join(strings) raw = raw.replace('{{ corporations }}', list_corporation_as_markdown()) content, metas = parse_markdown(raw) try: title = metas['title'][0] except: title = "Corporate Game" title = mark_safe(title) content = mark_safe(content) data = get_base_data() data.update({"content": content, "title": title, "gameid": gameid, "request": request}) return render(request, 'docs/index.html', data)