aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSverre Johansen <sverrej@opera.com>2009-11-11 15:05:53 +0100
committerSverre Johansen <sverrej@opera.com>2009-11-11 15:22:23 +0100
commitef5dab30fd4451d3ee9db6504537fe4746882faa (patch)
tree50eba0ac52d6eac90a4c441909e4ffd4e18f6424
parent403fae9f8ad14cd1596920ac37fa454b065e5905 (diff)
downloadchishop-ef5dab30fd4451d3ee9db6504537fe4746882faa.tar.bz2
chishop-ef5dab30fd4451d3ee9db6504537fe4746882faa.tar.xz
chishop-ef5dab30fd4451d3ee9db6504537fe4746882faa.zip
Added distutils register support
-rw-r--r--djangopypi/views.py31
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
42from django.http import Http404, HttpResponse, HttpResponseBadRequest 42from django.http import Http404, HttpResponse, HttpResponseBadRequest
43from django.http import QueryDict, HttpResponseForbidden 43from django.http import QueryDict, HttpResponseForbidden
44from django.shortcuts import render_to_response 44from django.shortcuts import render_to_response
45from djangopypi.models import Project, Classifier, Release, UPLOAD_TO
46from djangopypi.forms import ProjectForm, ReleaseForm
47from django.template import RequestContext 45from django.template import RequestContext
48from django.utils.datastructures import MultiValueDict 46from django.utils.datastructures import MultiValueDict
49from django.utils.translation import ugettext_lazy as _ 47from django.utils.translation import ugettext_lazy as _
50from django.core.files.uploadedfile import SimpleUploadedFile 48from django.core.files.uploadedfile import SimpleUploadedFile
51from django.contrib.auth import authenticate, login 49from django.contrib.auth import authenticate, login
52from djangopypi.http import HttpResponseNotImplemented 50from registration.backends import get_backend
53from djangopypi.http import HttpResponseUnauthorized 51from registration.forms import RegistrationForm
52
53from djangopypi.models import Project, Classifier, Release, UPLOAD_TO
54from djangopypi.forms import ProjectForm, ReleaseForm
55from djangopypi.http import HttpResponseNotImplemented, HttpResponseUnauthorized
54from djangopypi.utils import decode_fs 56from 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
145def 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
143ACTIONS = { 163ACTIONS = {
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