diff options
author | Sverre Johansen <sverrej@opera.com> | 2009-11-11 15:05:53 +0100 |
---|---|---|
committer | Sverre Johansen <sverrej@opera.com> | 2009-11-11 15:22:23 +0100 |
commit | ef5dab30fd4451d3ee9db6504537fe4746882faa (patch) | |
tree | 50eba0ac52d6eac90a4c441909e4ffd4e18f6424 | |
parent | 403fae9f8ad14cd1596920ac37fa454b065e5905 (diff) | |
download | chishop-ef5dab30fd4451d3ee9db6504537fe4746882faa.tar.bz2 chishop-ef5dab30fd4451d3ee9db6504537fe4746882faa.tar.xz chishop-ef5dab30fd4451d3ee9db6504537fe4746882faa.zip |
Added distutils register support
-rw-r--r-- | djangopypi/views.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/djangopypi/views.py b/djangopypi/views.py index 784651b..e004a19 100644 --- a/djangopypi/views.py +++ b/djangopypi/views.py | |||
@@ -42,15 +42,17 @@ from django.conf import settings | |||
42 | from django.http import Http404, HttpResponse, HttpResponseBadRequest | 42 | from django.http import Http404, HttpResponse, HttpResponseBadRequest |
43 | from django.http import QueryDict, HttpResponseForbidden | 43 | from django.http import QueryDict, HttpResponseForbidden |
44 | from django.shortcuts import render_to_response | 44 | from django.shortcuts import render_to_response |
45 | from djangopypi.models import Project, Classifier, Release, UPLOAD_TO | ||
46 | from djangopypi.forms import ProjectForm, ReleaseForm | ||
47 | from django.template import RequestContext | 45 | from django.template import RequestContext |
48 | from django.utils.datastructures import MultiValueDict | 46 | from django.utils.datastructures import MultiValueDict |
49 | from django.utils.translation import ugettext_lazy as _ | 47 | from django.utils.translation import ugettext_lazy as _ |
50 | from django.core.files.uploadedfile import SimpleUploadedFile | 48 | from django.core.files.uploadedfile import SimpleUploadedFile |
51 | from django.contrib.auth import authenticate, login | 49 | from django.contrib.auth import authenticate, login |
52 | from djangopypi.http import HttpResponseNotImplemented | 50 | from registration.backends import get_backend |
53 | from djangopypi.http import HttpResponseUnauthorized | 51 | from registration.forms import RegistrationForm |
52 | |||
53 | from djangopypi.models import Project, Classifier, Release, UPLOAD_TO | ||
54 | from djangopypi.forms import ProjectForm, ReleaseForm | ||
55 | from djangopypi.http import HttpResponseNotImplemented, HttpResponseUnauthorized | ||
54 | from djangopypi.utils import decode_fs | 56 | from djangopypi.utils import decode_fs |
55 | 57 | ||
56 | 58 | ||
@@ -140,12 +142,33 @@ def register_or_upload(request, post_data, files): | |||
140 | 142 | ||
141 | return submit_project_or_release(user, post_data, files) | 143 | return submit_project_or_release(user, post_data, files) |
142 | 144 | ||
145 | def create_user(request, post_data, files): | ||
146 | """Create new user from a distutil client request""" | ||
147 | form = RegistrationForm({"username": post_data["name"], | ||
148 | "email": post_data["email"], | ||
149 | "password1": post_data["password"], | ||
150 | "password2": post_data["password"]}) | ||
151 | if not form.is_valid(): | ||
152 | # Dist Utils requires error msg in HTTP status: "HTTP/1.1 400 msg" | ||
153 | # Which is HTTP/WSGI incompatible, so we're just returning a empty 400. | ||
154 | return HttpResponseBadRequest() | ||
155 | |||
156 | backend = get_backend("registration.backends.default.DefaultBackend") | ||
157 | if not backend.registration_allowed(request): | ||
158 | return HttpResponseBadRequest() | ||
159 | new_user = backend.register(request, **form.cleaned_data) | ||
160 | return HttpResponse("OK\n", status=200, mimetype='text/plain') | ||
161 | |||
162 | |||
143 | ACTIONS = { | 163 | ACTIONS = { |
144 | # file_upload is the action used with distutils ``sdist`` command. | 164 | # file_upload is the action used with distutils ``sdist`` command. |
145 | "file_upload": register_or_upload, | 165 | "file_upload": register_or_upload, |
146 | 166 | ||
147 | # submit is the :action used with distutils ``register`` command. | 167 | # submit is the :action used with distutils ``register`` command. |
148 | "submit": register_or_upload, | 168 | "submit": register_or_upload, |
169 | |||
170 | # user is the action used when registering a new user | ||
171 | "user": create_user, | ||
149 | } | 172 | } |
150 | 173 | ||
151 | 174 | ||