Пример #1
0
  def post(self, request, *args, **kwargs):
    action = self.request.POST.get('action', None)
    name = self.request.POST.get('name', None)
    value = self.request.POST.get('value', None)
    user = self.request.user

    if action == 'delete':
      if name is None:
        return HttpResponse('Invalid request', status=400)
      r = list(paged_query('get', 'userattribute', params={'user': user.username, 'attribute': name}))
      if len(r) > 1:
        LOG.error('User has duplicate attributes', extra={'data': {'user': user.username, 'attribute': name}})
        return HttpResponse('Multiple attributes error', status=500)
      elif len(r) == 0:
        return HttpResponse(status=404)
      attribute_id = r[0]['id']
      roledb_client('delete', 'userattribute/{id}'.format(id=attribute_id))
      return HttpResponse('OK')
    if action == 'add':
      # get attribute
      # if not existing, create new attribute
      # add attribute with value
      # TODO: auth-data sets UserAttributes always for request.user
      pass
    else:
      return HttpResponse('Invalid action', status=400)
 def form_valid(self, form):
   users = []
   params = form.cleaned_data
   params['page_size'] = 1000
   for d in paged_query('get', 'user', params=params):
     users.append((d['username'], d))
   self.request.session['inviteform_users_choices'] = users
   # TODO: Or we could just send the user to InviteView here
   invite_form = InviteForm(users_choices=users)
   context = {
     'form': form,
     'invite_form': invite_form,
     'data': json.dumps(users),  # for debug
   }
   return self.render_to_response(self.get_context_data(**context))