Skip to content

Commit

Permalink
#240 Create page context. Move base contexts to page module side
Browse files Browse the repository at this point in the history
  • Loading branch information
duker33 committed Feb 11, 2019
1 parent e2fba39 commit 9cb261f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
20 changes: 2 additions & 18 deletions catalog/newcontext/context.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import abc
import collections

import typing

from django.db.models import QuerySet


class Context(abc.ABC):

@abc.abstractmethod
def context(self) -> typing.Dict[str, typing.Any]:
...
from pages.newcontext import Context


class ModelContext(abc.ABC):
Expand All @@ -28,17 +23,6 @@ def context(self) -> typing.Dict[str, typing.Any]:
Context.register(ModelContext)


class Contexts(Context):

def __init__(self, *contexts: typing.List[Context]):
self.contexts = contexts

def context(self):
return dict(collections.ChainMap(
*[ctx.context() for ctx in self.contexts]
))


class Tags(ModelContext):

def context(self):
Expand Down
3 changes: 3 additions & 0 deletions pages/newcontext/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import base, pages
from .base import Context, Contexts
from .pages import Page
21 changes: 21 additions & 0 deletions pages/newcontext/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import abc
import collections
import typing


class Context(abc.ABC):

@abc.abstractmethod
def context(self) -> typing.Dict[str, typing.Any]:
...


class Contexts(Context):

def __init__(self, *contexts: typing.List[Context]):
self.contexts = contexts

def context(self):
return dict(collections.ChainMap(
*[ctx.context() for ctx in self.contexts]
))
12 changes: 12 additions & 0 deletions pages/newcontext/pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .base import Context


class Page(Context):

def __init__(self, page):
self.page = page

def context(self):
return {
'page': self.page,
}

0 comments on commit 9cb261f

Please sign in to comment.