Skip to content

Instantly share code, notes, and snippets.

@mekhami
Created August 26, 2015 20:36
Show Gist options
  • Select an option

  • Save mekhami/4f816f109ac162c15fb9 to your computer and use it in GitHub Desktop.

Select an option

Save mekhami/4f816f109ac162c15fb9 to your computer and use it in GitHub Desktop.
class ServiceType(object):
def __init__(self, name=None, form=None, template=None, context=None)
self.name = name
self.slug = slugify(self.name) if self.name else None
self.form = form
self.service_template = template
self.context = context
if not self.name and self.form and self.template:
raise CustomError("You must define {}".format(missing_field)
def __str__(self):
return self.name
def render_service_template(self):
# logic with self.context
pass
def deploy(self):
# shouldn't this be on the service model itself?
pass
# Any other functions that are required to be implemented in the child classes
# can raise NotImplementedError to force them to be defined
class PostgresForm(forms.Form):
username = forms.CharField(max_length=56, required=True)
password = forms.PasswordField(max_length=30)
# etc etc, get built in validation from django form
class PostgresServiceType(ServiceType):
# overwrite any functionality as necessary from Service Type
# then in the view or whatever:
form = PostgresForm
postgres_type = PostgresServiceType(name="Postgres Database",
form=form,
template='templatefile',
context=[],)
service = Service.objects.create(service_type=postgres_type, otherfields=othervalues)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment