diff --git a/tailbone/templates/generate_project.mako b/tailbone/templates/generate_project.mako index 9ae13d59..93da4df6 100644 --- a/tailbone/templates/generate_project.mako +++ b/tailbone/templates/generate_project.mako @@ -1,9 +1,162 @@ ## -*- coding: utf-8; -*- -<%inherit file="/form.mako" /> +<%inherit file="/page.mako" /> <%def name="title()">Generate Project <%def name="content_title()"> +<%def name="page_content()"> + + + + + + + +
+
+

New 'rattail' Project

+
+
+
+ ${h.form(request.current_route_url(), ref='rattailForm')} + ${h.csrf_token(request)} + ${h.hidden('project_type', value='rattail')} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${h.end_form()} +
+
+
+ +
+
+

New 'byjove' Project

+
+
+
+ ${h.form(request.current_route_url(), ref='byjoveForm')} + ${h.csrf_token(request)} + ${h.hidden('project_type', value='byjove')} + + + + + + + + + + ${h.end_form()} +
+
+
+ +
+
+ + Generate Project + +
+ + + +<%def name="modify_this_page_vars()"> + ${parent.modify_this_page_vars()} + + + ${parent.body()} diff --git a/tailbone/views/projects.py b/tailbone/views/projects.py index 8bf9e7e8..df6d072c 100644 --- a/tailbone/views/projects.py +++ b/tailbone/views/projects.py @@ -81,6 +81,15 @@ class GenerateProject(colander.MappingSchema): uses_fabric = colander.SchemaNode(colander.Boolean()) +class GenerateByjoveProject(colander.MappingSchema): + """ + Schema for generating a new 'byjove' project + """ + name = colander.SchemaNode(colander.String()) + + slug = colander.SchemaNode(colander.String()) + + class GenerateProjectView(View): """ View for generating new project source code @@ -102,13 +111,20 @@ class GenerateProjectView(View): # 'type': 'bool'}), # ]) - form = forms.Form(schema=GenerateProject(), - request=self.request, use_buefy=use_buefy) + project_type = 'rattail' + if self.request.method == 'POST': + project_type = self.request.POST.get('project_type', 'rattail') + if project_type not in ('rattail', 'byjove'): + raise ValueError("Unknown project type: {}".format(project_type)) + + schema = GenerateByjoveProject if project_type == 'byjove' else GenerateProject + form = forms.Form(schema=schema(), request=self.request, + use_buefy=use_buefy) form.submit_label = "Generate Project" form.auto_disable = False form.auto_disable_save = False if form.validate(newstyle=True): - zipped = self.generate_project(form) + zipped = self.generate_project(project_type, form) return self.file_response(zipped) # self.request.session.flash("New project was generated: {}".format(form.validated['name'])) # return self.redirect(self.request.current_route_url()) @@ -146,10 +162,10 @@ class GenerateProjectView(View): 'use_buefy': use_buefy, } - def generate_project(self, form): + def generate_project(self, project_type, form): options = form.validated slug = options['slug'] - path = self.handler.generate_project(slug, options) + path = self.handler.generate_project(project_type, slug, options) zipped = '{}.zip'.format(path) with zipfile.ZipFile(zipped, 'w', zipfile.ZIP_DEFLATED) as z: