diff options
author | Ask Solem <askh@modwheel.net> | 2009-03-20 14:33:10 +0100 |
---|---|---|
committer | Ask Solem Hoel <askh@opera.com> | 2009-03-20 14:33:10 +0100 |
commit | f5211dc0f3371c52bf0805ac59d4b505a14e4537 (patch) | |
tree | 4f2cf24943bf69116f8257a459dfa59d94c302f9 | |
parent | 627f889580f9ea3e613d174aa47255b42e159c29 (diff) | |
download | chishop-f5211dc0f3371c52bf0805ac59d4b505a14e4537.tar.bz2 chishop-f5211dc0f3371c52bf0805ac59d4b505a14e4537.tar.xz chishop-f5211dc0f3371c52bf0805ac59d4b505a14e4537.zip |
Remove previous file if it already exists.
-rw-r--r-- | djangopypi/forms.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/djangopypi/forms.py b/djangopypi/forms.py index 1cf9a9d..54707e0 100644 --- a/djangopypi/forms.py +++ b/djangopypi/forms.py | |||
@@ -30,6 +30,7 @@ POSSIBILITY OF SUCH DAMAGE. | |||
30 | 30 | ||
31 | """ | 31 | """ |
32 | 32 | ||
33 | import os | ||
33 | from django import forms | 34 | from django import forms |
34 | from djangopypi.models import Project, Classifier, Release | 35 | from djangopypi.models import Project, Classifier, Release |
35 | 36 | ||
@@ -56,8 +57,23 @@ class ProjectRegisterForm(forms.Form): | |||
56 | for classifier in classifiers: | 57 | for classifier in classifiers: |
57 | project.classifiers.add( | 58 | project.classifiers.add( |
58 | Classifier.objects.get_or_create(name=classifier)[0]) | 59 | Classifier.objects.get_or_create(name=classifier)[0]) |
59 | release, c = Release.objects.get_or_create(version=version, | 60 | |
60 | platform=platform, project=project) | 61 | # If the old file already exists, django will append a _ after the |
62 | # filename, however with .tar.gz files django does the "wrong" thing | ||
63 | # and saves it as project-0.1.2.tar_.gz. So remove it before | ||
64 | # django sees anything. | ||
65 | try: | ||
66 | previous_entry = Release.objects.get(version=version, | ||
67 | platform=platform, project=project) | ||
68 | except Release.DoesNotExist: | ||
69 | pass | ||
70 | |||
71 | release, created = Release.objects.get_or_create(version=version, | ||
72 | platform=platform, | ||
73 | project=project) | ||
61 | if file: | 74 | if file: |
75 | if not created: | ||
76 | if os.path.exists(release.distribution.path): | ||
77 | os.remove(release.distribution.path) | ||
62 | release.distribution.save(file.name, file, save=True) | 78 | release.distribution.save(file.name, file, save=True) |
63 | release.save() | 79 | release.save() |