Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add the pip editing form.

  • Loading branch information...
commit 0503311c1f36f4e4463036250b04e253969f7151 1 parent e087378
@buchuki buchuki authored
View
23 greatbigcrane/project/forms.py
@@ -17,7 +17,8 @@
import os.path
from django import forms
-from project.models import Project
+from project.models import Project, PipProject
+from project.widgets import LineEditorWidget
class AddProjectForm(forms.ModelForm):
class Meta:
@@ -40,3 +41,23 @@ class EditProjectForm(AddProjectForm):
class Meta:
model = Project
exclude =("project_type",)
+
+class PipProjectForm(forms.ModelForm):
+ requirements = forms.CharField(widget=LineEditorWidget)
+
+ class Meta:
+ model = PipProject
+ exclude = ("project",)
+
+ def __init__(self, *args, **kwargs):
+ instance = kwargs.get('instance')
+ if os.path.exists(instance.project.requirements_filename()):
+ initial = kwargs.setdefault('initial', {})
+ with open(instance.project.requirements_filename()) as req_file:
+ initial['requirements'] = req_file.read()
+ super(PipProjectForm, self).__init__(*args, **kwargs)
+
+ def save(self, *args, **kwargs):
+ instance = super(PipProjectForm, self).save(*args, **kwargs)
+ with open(instance.project.requirements_filename(), "w") as req_file:
+ req_file.write(self.cleaned_data['requirements'])
View
4 greatbigcrane/project/models.py
@@ -51,6 +51,10 @@ def buildout_filename(self):
'''Get the filename that holds the buildout configuration.'''
return os.path.join(self.base_directory, 'buildout.cfg')
+ def requirements_filename(self):
+ '''Get the filename that holds the pip requirements.'''
+ return os.path.join(self.base_directory, 'requirements.txt')
+
def buildout(self):
sections = buildout_parse(self.buildout_filename())
return sections
View
14 greatbigcrane/project/views.py
@@ -30,7 +30,7 @@
from job_queue.jobs import queue_job
from project.models import Project, PipProject
-from project.forms import AddProjectForm, EditProjectForm
+from project.forms import AddProjectForm, EditProjectForm, PipProjectForm
from preferences.models import Preference
from notifications.models import Notification
@@ -116,8 +116,16 @@ def favourite_project(request, project_id):
# I'm wondering if pip doesn't deserve its own app
def edit_pip(request, project_id):
- from django.http import HttpResponse
- return HttpResponse("Boilerplate")
+ project = get_object_or_404(Project, id=project_id,
+ pipproject__isnull=False)
+ pip = project.pipproject
+ form = PipProjectForm(request.POST or None, instance=pip)
+ if form.is_valid():
+ instance = form.save()
+ return redirect(project)
+
+ return render_to_response("project/pip_edit_form.html",
+ RequestContext(request, {'form': form}))
def project_notifications(request, project_id):
project = Project.objects.get(pk=project_id)
View
9 greatbigcrane/templates/project/pip_edit_form.html
@@ -0,0 +1,9 @@
+{% extends 'nosidebar.html' %}
+
+{% block main %}
+<form method="POST">
+ {{form.media}}
+ {{form.as_p}}
+ <input type="submit" value="Submit" />
+</form>
+{% endblock %}
Please sign in to comment.
Something went wrong with that request. Please try again.