diff --git a/src/assets/js/edit-page.js b/src/assets/js/edit-page.js index 55ddfe2..7ec646d 100644 --- a/src/assets/js/edit-page.js +++ b/src/assets/js/edit-page.js @@ -21,12 +21,15 @@ export const init = () => { const blocktypes = JSON.parse(elem.dataset['blocktypes']); const valid_blocktypes = blocktypes.map(({type}) => type); const UnfilteredContent = JSON.parse(elem.dataset['content']); + + const getBlock = (blocks, id) => blocks.filter((b) => b.id == id)[0]; + const content = { blocks: UnfilteredContent.blocks.filter( (block) => valid_blocktypes.indexOf(block.type) > -1 ), blockLists: UnfilteredContent.blockLists.map((l) => - l.filter((blockId) => valid_blocktypes.indexOf(UnfilteredContent.blocks[blockId].type) > -1) + l.filter((blockId) => valid_blocktypes.indexOf(getBlock(UnfilteredContent.blocks, blockId).type) > -1) ), }; diff --git a/src/pages/models.py b/src/pages/models.py index 0b681c7..5dc0d5a 100644 --- a/src/pages/models.py +++ b/src/pages/models.py @@ -24,7 +24,8 @@ def get_plugin_id(block): return utils.block_types[block["type"]].__class__.__module__[:-12] def filter_block_list_item(id): - return plugin_enabled(get_plugin_id(self.content["blocks"][id])) + block = [b for b in self.content["blocks"] if b["id"] == id][0] + return plugin_enabled(get_plugin_id(block)) def map_block_lists(block_list): return filter(filter_block_list_item, block_list) diff --git a/src/pages/page_blocks.py b/src/pages/page_blocks.py index c044ef6..99809be 100644 --- a/src/pages/page_blocks.py +++ b/src/pages/page_blocks.py @@ -68,7 +68,7 @@ class PastEventsBlockType(BlockType): def get_past_events(self): """Get past events.""" - return [e for e in Event.objects.order_by('start') if not e.is_future] + return [e for e in Event.objects.order_by('-start') if not e.is_future] def render(self, request, data): """Return each event in its own block.""" diff --git a/src/pages/views.py b/src/pages/views.py index e388e6a..dc10577 100644 --- a/src/pages/views.py +++ b/src/pages/views.py @@ -8,9 +8,12 @@ def view(request, pk): """Show page.""" page = get_object_or_404(Page, url=pk) + def get_block(i): + return [b for b in page.content["blocks"] if b["id"] == i][0] + # We can use .content directly as we're using a dictionary lookup # So the unused blocks won't be included - blockLists = [[render_block(page.content["blocks"][i], request) + blockLists = [[render_block(get_block(i), request) for i in l] for l in page.filtered_block_lists] return render(request, "pages/view.html",