Permalink
Browse files

Refactor requirements read to model.

  • Loading branch information...
Dusty Phillips
Dusty Phillips committed Sep 6, 2010
1 parent 82f127a commit 55e030437006fe0c752ed4a71fcc83df58c8ab23
Showing with 11 additions and 4 deletions.
  1. +3 −4 greatbigcrane/project/forms.py
  2. +8 −0 greatbigcrane/project/models.py
@@ -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):
@@ -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.