Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Last active May 17, 2017 15:07
Show Gist options
  • Save kezabelle/cb4feb2b63af8ef1f5e4eb781d76e738 to your computer and use it in GitHub Desktop.
Save kezabelle/cb4feb2b63af8ef1f5e4eb781d76e738 to your computer and use it in GitHub Desktop.
an idea for pattern atlas?
class BaseComponent(object):
def get_name(self):
try:
return force_text(name)
except AttributeError:
return self.__class__.__name__
def get_dependencies(self):
try:
return list(self.dependencies)
except AttributeError:
return []
def get_template(self):
try:
return self.template
except AttributeError:
raise ImproperlyConfigured("missing template = 'path/to/file'")
class ClientComponent(BaseComponent):
def server_data(self):
raise NotImplementedError("Client components don't have server data")
class ServerComponent(BaseComponent):
def client_data(self):
raise NotImplementedError("Server components don't have client data")
class Component(ClientComponent, ServerComponent):
pass
class MyComponent(Component):
name = "lol wut"
template = "a/b/c.html" # load from DTL templates
dependencies = (
'x/y/z.js', # load from staticfiles
)
def server_data(self):
return list(range(1, 10))
def client_data(self):
return list(range(2, 20))
class MyClientComponent(ClientComponent):
name = "my nice JS component"
template = "a/b/c.js" # load from staticfiles
dependencies = (
'x/y/z.js', # load from staticfiles
)
def client_data(self):
return list(range(2, 20))
class MyServerComponent(ServerComponent):
name = "goose!"
template = "a/b/c.html" # load from DTL templates
dependencies = (
'x/y/z.js', # load from staticfiles
)
def server_data(self):
return list(range(1, 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment