diff options
author | Ask Solem <askh@modwheel.net> | 2009-03-17 15:45:47 +0100 |
---|---|---|
committer | Ask Solem Hoel <askh@opera.com> | 2009-03-17 15:45:47 +0100 |
commit | 836f683018aec80a4842109deb78800f28e3c8cd (patch) | |
tree | 9af69b4cfcd30222ea049f350ec1188ca32c4000 | |
parent | 86fa508407289814f81ce7a2c4c46055c55c2374 (diff) | |
download | chishop-836f683018aec80a4842109deb78800f28e3c8cd.tar.bz2 chishop-836f683018aec80a4842109deb78800f28e3c8cd.tar.xz chishop-836f683018aec80a4842109deb78800f28e3c8cd.zip |
Projects now has owners, and you must be logged in to register/upload
-rw-r--r-- | djangopypi/forms.py | 3 | ||||
-rw-r--r-- | djangopypi/models.py | 5 | ||||
-rw-r--r-- | djangopypi/views.py | 14 |
3 files changed, 16 insertions, 6 deletions
diff --git a/djangopypi/forms.py b/djangopypi/forms.py index 1cf9a9d..7865723 100644 --- a/djangopypi/forms.py +++ b/djangopypi/forms.py | |||
@@ -47,11 +47,12 @@ class ProjectRegisterForm(forms.Form): | |||
47 | version = forms.CharField() | 47 | version = forms.CharField() |
48 | platform = forms.CharField(required=False) | 48 | platform = forms.CharField(required=False) |
49 | 49 | ||
50 | def save(self, classifiers, file=None): | 50 | def save(self, classifiers, user, file=None): |
51 | values = dict(self.cleaned_data) | 51 | values = dict(self.cleaned_data) |
52 | name = values.pop("name") | 52 | name = values.pop("name") |
53 | version = values.pop("version") | 53 | version = values.pop("version") |
54 | platform = values.pop("platform") | 54 | platform = values.pop("platform") |
55 | values["owner"] = user | ||
55 | project, c = Project.objects.get_or_create(name=name, defaults=values) | 56 | project, c = Project.objects.get_or_create(name=name, defaults=values) |
56 | for classifier in classifiers: | 57 | for classifier in classifiers: |
57 | project.classifiers.add( | 58 | project.classifiers.add( |
diff --git a/djangopypi/models.py b/djangopypi/models.py index d66f5c8..d7c5fc7 100644 --- a/djangopypi/models.py +++ b/djangopypi/models.py | |||
@@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. | |||
32 | 32 | ||
33 | import os | 33 | import os |
34 | from django.db import models | 34 | from django.db import models |
35 | from django.contrib.auth.models import User | ||
35 | from django.utils.translation import ugettext_lazy as _ | 36 | from django.utils.translation import ugettext_lazy as _ |
36 | 37 | ||
37 | OS_NAMES = ( | 38 | OS_NAMES = ( |
@@ -85,6 +86,7 @@ class Project(models.Model): | |||
85 | description = models.TextField(blank=True) | 86 | description = models.TextField(blank=True) |
86 | author_email = models.CharField(max_length=255, blank=True) | 87 | author_email = models.CharField(max_length=255, blank=True) |
87 | classifiers = models.ManyToManyField(Classifier) | 88 | classifiers = models.ManyToManyField(Classifier) |
89 | owner = models.ForeignKey(User, related_name="projects") | ||
88 | 90 | ||
89 | class Meta: | 91 | class Meta: |
90 | verbose_name = _(u"project") | 92 | verbose_name = _(u"project") |
@@ -108,7 +110,8 @@ class Release(models.Model): | |||
108 | verbose_name_plural = _(u"releases") | 110 | verbose_name_plural = _(u"releases") |
109 | 111 | ||
110 | def __unicode__(self): | 112 | def __unicode__(self): |
111 | return self.version | 113 | return u"%s %s (%s)" % ( |
114 | self.project.name, self.version, self.distribution.name) | ||
112 | 115 | ||
113 | @property | 116 | @property |
114 | def filename(self): | 117 | def filename(self): |
diff --git a/djangopypi/views.py b/djangopypi/views.py index b1323fb..560b461 100644 --- a/djangopypi/views.py +++ b/djangopypi/views.py | |||
@@ -31,8 +31,9 @@ POSSIBILITY OF SUCH DAMAGE. | |||
31 | """ | 31 | """ |
32 | 32 | ||
33 | from django.http import Http404, HttpResponse, HttpResponseBadRequest | 33 | from django.http import Http404, HttpResponse, HttpResponseBadRequest |
34 | from django.http import QueryDict | 34 | from django.http import QueryDict, HttpResponseForbidden |
35 | from django.shortcuts import render_to_response | 35 | from django.shortcuts import render_to_response |
36 | from django.contrib.auth import authenticate, login | ||
36 | from djangopypi.models import Project | 37 | from djangopypi.models import Project |
37 | from djangopypi.forms import ProjectRegisterForm | 38 | from djangopypi.forms import ProjectRegisterForm |
38 | from django.template import RequestContext | 39 | from django.template import RequestContext |
@@ -73,14 +74,19 @@ def parse_weird_post_data(data): | |||
73 | 74 | ||
74 | def simple(request, template_name="djangopypi/simple.html"): | 75 | def simple(request, template_name="djangopypi/simple.html"): |
75 | if request.method == "POST": | 76 | if request.method == "POST": |
77 | if not request.user.is_authenticated(): | ||
78 | return HttpResponseForbidden( | ||
79 | "Not logged in, or invalid user/password") | ||
76 | post_data, files = parse_weird_post_data(request.raw_post_data) | 80 | post_data, files = parse_weird_post_data(request.raw_post_data) |
77 | action = post_data.get(":action") | 81 | action = post_data.get(":action") |
78 | classifiers = post_data.getlist("classifiers") | 82 | classifiers = post_data.getlist("classifiers") |
79 | register_form = ProjectRegisterForm(post_data.copy()) | 83 | register_form = ProjectRegisterForm(post_data.copy()) |
80 | if register_form.is_valid(): | 84 | if register_form.is_valid(): |
81 | return HttpResponse(register_form.save(classifiers, | 85 | registered = register_form.save(classifiers, request.user, |
82 | file=files.get("content"))) | 86 | file=files.get("content")) |
83 | return HttpResponse("Successfully registered.") | 87 | if registered: |
88 | return HttpResponse("Successfully registered.") | ||
89 | return HttpResponseForbidden("That's not your project!") | ||
84 | return HttpResponse("ERRORS: %s" % register_form.errors) | 90 | return HttpResponse("ERRORS: %s" % register_form.errors) |
85 | 91 | ||
86 | dists = Project.objects.all() | 92 | dists = Project.objects.all() |