Skip to content

Commit

Permalink
Refactor requirements read to model.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dusty Phillips committed Sep 6, 2010
1 parent 82f127a commit 55e0304
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 3 additions & 4 deletions greatbigcrane/project/forms.py
Expand Up @@ -57,10 +57,9 @@ def clean_virtualenv_path(self):

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()
initial = kwargs.setdefault('initial', {})
initial['requirements'] = instance.requirements

super(PipProjectForm, self).__init__(*args, **kwargs)

def save(self, *args, **kwargs):
Expand Down
8 changes: 8 additions & 0 deletions greatbigcrane/project/models.py
Expand Up @@ -115,3 +115,11 @@ class PipProject(models.Model):
blank=True,
help_text="Command to run tests. Eg: py.test, nose, ./run_tests.py")

@property
def requirements(self):
if os.path.exists(self.project.requirements_filename()):
with open(self.project.requirements_filename()) as req_file:
return req_file.read()
return ""


0 comments on commit 55e0304

Please sign in to comment.