return True
@gilbert_method
- def passwd(self, request, current_password, new_password, new_password_confirm):
- user = request.user
- if user.check_password(current_password) and (new_password == new_password_confirm):
- user.set_password(new_password)
- user.save()
- return True
- return False
+ def get_passwd_form(self, request):
+ from django.contrib.auth.forms import PasswordChangeForm
+ return PasswordChangeForm(request.user).as_ext()
+
+ @gilbert_method(form_handler=True)
+ def submit_passwd_form(self, request):
+ from django.contrib.auth.forms import PasswordChangeForm
+ form = PasswordChangeForm(request.user, data=request.POST)
+ if form.is_valid():
+ form.save()
+ return {'success': True}
+ else:
+ return {'success': False, 'errors': form.errors}
@gilbert_method
def whoami(self, request):
model_methods.append({
'name': method.name,
'len': method.argc,
+ 'formHandler': method.form_handler,
})
if model_methods:
model_actions[model_name] = model_methods
plugin_methods.append({
'name': method.name,
'len': method.argc,
+ 'formHandler': method.form_handler,
})
if plugin_methods:
plugin_actions[plugin_name] = plugin_methods
submitted_form = True
if submitted_form:
- post_dict = dict(request.POST)
ext_request = {
- 'action': post_dict.pop('extAction'),
- 'method': post_dict.pop('extMethod'),
- 'type': post_dict.pop('extType'),
- 'tid': post_dict.pop('extTID'),
- 'upload': post_dict.pop('extUpload', False),
+ 'action': request.POST.get('extAction'),
+ 'method': request.POST.get('extMethod'),
+ 'type': request.POST.get('extType'),
+ 'tid': request.POST.get('extTID'),
+ 'upload': request.POST.get('extUpload', False),
'data': None,
- 'kwdata': post_dict
}
+ response = self.handle_ext_request(request, ext_request, app_label)
else:
- ext_request = json.loads(request.raw_post_data)
- ext_request['upload'] = False
- ext_request['kwdata'] = None
+ ext_requests = json.loads(request.raw_post_data)
+ if type(ext_requests) is dict:
+ ext_requests['upload'] = False
+ response = self.handle_ext_request(request, ext_requests, app_label)
+ else:
+ responses = []
+ for ext_request in ext_requests:
+ ext_request['upload'] = False
+ responses.append(self.handle_ext_request(request, ext_request, app_label))
+ response = responses
+ if submitted_form:
+ if ext_request['upload'] is True:
+ return HttpResponse(('<html><body><textarea>%s</textarea></body></html>' % json.dumps(response)))
+ return HttpResponse(json.dumps(response), content_type=('application/json; charset=%s' % settings.DEFAULT_CHARSET))
+
+ def handle_ext_request(self, request, ext_request, app_label=None):
try:
plugin = None
if method is None or (method.restricted and not self.has_permission(request)):
raise NotImplementedError('The method named \'%s\' is not available' % method.name)
- response = {'type': 'rpc', 'tid': ext_request['tid'], 'action': ext_request['action'], 'method': ext_request['method'], 'result': method(request, *(ext_request['data'] or []), **(ext_request['kwdata'] or {}))}
+ return {'type': 'rpc', 'tid': ext_request['tid'], 'action': ext_request['action'], 'method': ext_request['method'], 'result': method(request, *(ext_request['data'] or []))}
except:
exc_type, exc_value, exc_traceback = sys.exc_info()
- response = {'type': 'exception', 'tid': ext_request['tid'], 'message': ('%s: %s' % (exc_type, exc_value)), 'where': format_tb(exc_traceback)[0]}
-
- if submitted_form:
- return HttpResponse(('<html><body><textarea>%s</textarea></body></html>' % json.dumps(response)))
- return HttpResponse(json.dumps(response), content_type=('application/json; charset=%s' % settings.DEFAULT_CHARSET))
+ return {'type': 'exception', 'tid': ext_request['tid'], 'message': ('%s: %s' % (exc_type, exc_value)), 'where': format_tb(exc_traceback)[0]}
site = GilbertSite()
\ No newline at end of file