Commits

Robert Myers committed 0f8f3a0

fixing project creation.

  • Participants
  • Parent commits 45f9bec
  • Branches worker

Comments (0)

Files changed (4)

File cannula/api/base/projects.py

 from cannula.api import PermissionError
 from cannula.api import ApiError
 from cannula.api import BaseAPI
-from cannula.conf import api, PACKAGE_CHOICES, VCS_CHOICES
+from cannula.conf import api, WORKER_CHOICES, VCS_CHOICES
 from cannula import tasks
 from cannula.utils import format_exception, validate_python_package_name, add_blank_choice
 
         " that you would 'clone' or 'checkout'")
     vcs = forms.ChoiceField(choices=VCS_CHOICES,
         help_text="Repository type.")
-    user = forms.CharField(max_length=100, required=False,
-        help_text="(Optional) Repository username.")
-    password = forms.CharField(max_length=100, required=False,
-        help_text="(Optional) Repository password.")
-    package = forms.ChoiceField(choices=PACKAGE_CHOICES, required=False,
-        help_text="(Optional) Select the type of project you wish to create.")
+    requirements = forms.CharField(widget=forms.Textarea, required=False,
+        help_text="Requirements for this project, overrides project or repository defaults")
+    settings = forms.CharField(widget=forms.Textarea, required=False,
+        help_text="Settings for this project, overrides project or repository defaults. "
+        "Depending on the project type this will be written out differently.")
     desc = forms.CharField(max_length=1024, required=False,
         widget=forms.Textarea(attrs={'rows': 3}),
         help_text="(Optional) Description of this project.")
 
+
     def __init__(self, *args, **kwargs):
         """
         Dynamically populate the env and stage choices.
     revision = forms.CharField(max_length=25, required=False,
         help_text="Enter the revision number to deploy, or leave blank to"
                   " deploy the latest revision.")
-    package = forms.ChoiceField()
+    requirements = forms.CharField(widget=forms.Textarea, required=False,
+        help_text="Requirements for this project, overrides project or repository defaults")
+    settings = forms.CharField(widget=forms.Textarea, required=False,
+        help_text="Settings for this project, overrides project or repository defaults. "
+        "Depending on the project type this will be written out differently.")
 
+    
     def __init__(self, *args, **kwargs):
         """
         Dynamically populate the env and stage choices.
         self.username = kwargs.pop('username')
         super(DeployProject, self).__init__(*args, **kwargs)
 
-        packages = api.packages.list(self.username)
-        choices = [(env.pk, env) for env in packages]
-        choices = add_blank_choice(choices)
-        self.fields['package'].choices = choices
-
         clusters = api.clusters.list(self.username)
         choices = [(stage.abbr, stage) for stage in clusters]
         self.fields['cluster'].choices = choices
         return self._list(user, group)
     
     
-    def _create(self, group, abbr, name, pkg):
+    def _create(self, group, abbr, name, requirements, settings):
         "Subclasses must define this"
         raise NotImplementedError()
     
     
-    def create(self, user, group, abbr, pkg, name=None, 
-               desc='', perm='create', **kwargs):
+    def create(self, user, group, abbr, requirements='', settings='',
+               name=None, desc='', perm='create', **kwargs):
         """
         Create a project and return its project object.
 
          * user: (String) User attempting the create function.
          * group: (String) Name of project group to put project under.
          * abbr: (String) Name of project to create.
-         * pkg: The name of the package to use.
 
         Optional Arguments:
 
             name=name,
             abbr=abbr,
             desc=desc,
+            settings=settings,
+            requirements=requirements,
         )
 
         log.info("Project %s created in %s" % (project, group))
         if request.method == "POST":
             form = self.create_form(data=request.POST, username=request.user)
             if form.is_valid():
-                group = form.cleaned_data['group']
-                abbr = form.cleaned_data['abbr']
-                package = form.cleaned_data['package']
-                name = form.cleaned_data['name'] or None
-                desc = form.cleaned_data['desc'] or None
                 try:
-                    self.create(request.user, group, abbr, package, name, desc)
+                    self.create(request.user, **form.cleaned_data)
                     request.session['message'] = "Project successfully created."
                     transaction.commit()
                     return http.HttpResponseRedirect(reverse('cannula-index'))

File cannula/api/djangodb/models.py

     group = models.ForeignKey(Group)
     name = models.CharField(max_length=50)
     abbr = models.CharField(max_length=50, db_index=True)
-    desc = models.TextField(blank=True, null=True)
+    desc = models.TextField(blank=True)
+    requirements = models.TextField(blank=True)
+    settings = models.TextField(blank=True)
     url = models.CharField(max_length=255, blank=True,
                            help_text="Default URL to use when deploying.")
     repo = models.CharField(max_length=512)
 
 class Server(models.Model, ApiModels.BaseServer):
     name = models.CharField(max_length=255)
+    cluster = models.ForeignKey("Cluster", related_name='servers')
     ipaddr = models.CharField(max_length=255)
     port = models.IntegerField(default=22)
     platform_class = models.CharField(max_length=255,
     parent = models.ForeignKey('self', blank=True, null=True)
     name = models.CharField(max_length=255)
     abbr = models.CharField(max_length=30, unique=True)
-    servers = models.ManyToManyField(Server)
     order = models.IntegerField(default=1,
         help_text="Sorting order of this cluster.")
     deployable = models.NullBooleanField(default=True)

File cannula/api/djangodb/projects.py

         return Project.objects.all()
     
     
-    def _create(self, group, abbr, name, desc):
+    def _create(self, group, abbr, name, desc, requirements, settings):
         "Subclasses must define this"
         project = Project.objects.create(group=group,
-            name=name, abbr=abbr, desc=desc)
+            name=name, abbr=abbr, desc=desc, requirements=requirements, settings=settings)
         return project

File cannula/templates/cannula/project.html

-{%  extends "admin/base_site.html" %}
+{%  extends "cannula/base.html" %}
 
 {% block content %}