Ejemplo n.º 1
0
	def wrap(f, self, request, *a, **kwa):
		form = v_form(getattr(request, operation))
		if form.is_valid():
			setattr(request, 'form', form)
			return f(self, request, *a, **kwa)
		else:
			raise FormValidationError(form)
Ejemplo n.º 2
0
    def read(self, request):
        pagination_form = request.form
        geo_form = GeoForm(request.GET)
        search_form = APISearchForm(request.GET)

        queryset = LightMap.objects.all()

        if geo_form.is_valid():
            queryset = queryset.filter(venue__coordinates__distance_lte=(point(
                geo_form.cleaned_data['longitude'],
                geo_form.cleaned_data['latitude'],
            ), D(mi=geo_form.get_radius(max_radius=100))))
        elif not search_form.is_valid():
            raise FormValidationError(geo_form)

        if search_form.is_valid():
            search_query = ' '.join(search_form.cleaned_data['query'])
            queryset = queryset.filter(
                Q(name__icontains=search_query)
                | Q(lineup_denorm__icontains=search_query)
                | Q(venue__name__icontains=search_query))

        page = self.paginate(queryset,
                             page=pagination_form.cleaned_data['page'],
                             objects_per_page=pagination_form.get_limit(25))

        tags = list(page.object_list)

        return self.get_paginated_response_dict(page, [
            self.tag_to_dict(tags,) \
                for tag in tags
        ])
Ejemplo n.º 3
0
 def create(self, request, *args, **kwargs):
     f = OrderForm(request.POST, request=request)
     if f.is_valid():
         inst = f.save(commit=False)
         inst.master = request.user
         inst.status = ORDER_STATUS.UNACCEPT
         inst.save()
         return inst.valueDict
     else:
         raise FormValidationError(f)
Ejemplo n.º 4
0
    def wrap(f, self, request, *a, **kwa):
        form = v_form(request.data)

        if form.is_valid():
            setattr(request, 'form', form)
            return f(self, request, *a, **kwa)
        else:
            #setattr(request, 'form', form)
            #return f(self, request, *a, **kwa)
            raise FormValidationError(form)
Ejemplo n.º 5
0
 def create(self,request,*args,**kwargs):
     f = IAPIAuthenticationForm(data=request.POST)
     if f.is_valid():
         auth_login(request, f.get_user())
         log.debug('f.is_valid true')
     else:
         log.debug('f.is_valid false,%s' % f)
         raise FormValidationError(f)
     log.debug('request.user:%s' % request.user)
     request.META['slogin']=True
     return request.user
Ejemplo n.º 6
0
    def update(self, request, msisdn):
        try:
            customer = Customer.objects.get(msisdn=msisdn)
        except Customer.DoesNotExist:
            return rc.NOT_FOUND

        form = CustomerForm(data=request.data, instance=customer)
        if not form.is_valid():
            raise FormValidationError(form)

        return form.save()
Ejemplo n.º 7
0
	def wrap(wrapped_function, self, request, *a, **kwa):
		if hasattr(request, 'FILES'):
			form = v_form(request.POST, request.FILES)
		else:
			raise AttributeError("Validator expects multipart data.")

		if form.is_valid():
			setattr(request, 'form', form)
			return wrapped_function(self, request, *a, **kwa)
		else:
			raise FormValidationError(form)
Ejemplo n.º 8
0
 def wrap(f, self, request, *a, **kwa):
     if hasattr(v_form, 'get_form_instance'):
         form = v_form.get_form_instance(request, getattr(request, operation))
     else:
         form = v_form(getattr(request, operation))
 
     if form.is_valid():
         setattr(request, 'form', form)
         return f(self, request, *a, **kwa)
     else:
         raise FormValidationError(form)
Ejemplo n.º 9
0
 def create(self, request, *args, **kwargs):
     f = RegisterForm(request.POST)
     if f.is_valid():
         username = f.cleaned_data['username']
         password = f.cleaned_data['password']
         inst = User.objects.create_user(username, '', password)
         account = Account(balance=0, master=inst)
         account.save()
         return inst
     else:
         raise FormValidationError(f)
Ejemplo n.º 10
0
 def create(self, request, *args, **kwargs):
     log.debug(request)
     f = AuthenticationForm(data=request.POST)
     if f.is_valid():
         log.debug("f.is_valid()")
         auth_login(request, f.get_user())
     else:
         log.debug("FormValidationError")
         raise FormValidationError(f)
     request.META['slogin'] = True
     return request.user
Ejemplo n.º 11
0
    def wrap(f, self, request, *a, **kwa):

        # Assume that the JSON response is in request.data
        # Probably want to do a getattr(request, data, None)
        #   and raise an exception if data is not found
        form = v_form(request.data)

        if form.is_valid():
            setattr(request, 'form', form)
            return f(self, request, *a, **kwa)
        else:
            raise FormValidationError(form)
Ejemplo n.º 12
0
 def create(self, request, *args, **kwargs):
     if kwargs.get('login', False):
         f = LoginForm(request.POST)
         if f.is_valid():
             user = authenticate(username=f.cleaned_data['username'],
                                 password=f.cleaned_data['password'])
             if user:
                 auth_login(request, user)
                 return user
             else:
                 return HttpResponse(
                     {
                         'error_code': 1,
                         'error_msg': u'登录失败,请使用正确的用户名和密码'
                     },
                     status=400)
         raise FormValidationError(f)
     if kwargs.get('logout', False):
         auth_logout(request)
         return 'logout ok!'
     uf = RegisterForm(request.POST)
     if uf.is_valid():
         if uf.cleaned_data['password1'] != uf.cleaned_data['password2']:
             return HttpResponse(
                 {
                     'error_code': 1,
                     'error_msg': u'两次输入的密码不一致!'
                 }, status=400)
         if len(User.objects.filter(username=uf.cleaned_data['username'])):
             return HttpResponse(
                 {
                     'error_code': 2,
                     'error_msg': u'该用户名已经被注册!'
                 }, status=400)
         user = User.objects.create_user(
             username=uf.cleaned_data['username'],
             password=uf.cleaned_data['password1'])
         user.save()
         return user
     raise FormValidationError(uf)
Ejemplo n.º 13
0
	def wrap(wrapped_function, self, request, *a, **kwa):
		if not hasattr(request, 'data'):
			raise AttributeError("Validator expects serialized data.")
		if hasattr(request, 'FILES'):
			form = v_form(request.data, request.FILES)
		else:
			form = v_form(request.data)

		if form.is_valid():
			setattr(request, 'form', form)
			return wrapped_function(self, request, *a, **kwa)
		else:
			raise FormValidationError(form)
Ejemplo n.º 14
0
    def create(self, request, *args, **kwargs):
        '''
        新用户注册
            URL:user/register/
            描述:新用户注册
            参数:
            username:用户名
            password1:密码
            password2:密码确认
            agreement:用户协议
        '''
        f = MyUserCreationForm(request.POST)     
        if f.is_valid():
            instance = f.save()
#             p = instance.get_profile()
            p = UserProfile(user = instance)
            p.save()
        else:
            raise FormValidationError(f)
        return instance
Ejemplo n.º 15
0
    def update(self, request):
        """
        Updates subtitles for video.
        
        Send in request:
        <b>language_id:</b> id of language, you can get this from AnonymousSubtitleLanguagese
        <b>format</b>: format of subtitles(srt, ass, ssa, ttml, sbv)
        <b>subtitles</b>: subtitles(max size 256kB. Can be less, not tested with big content)
        
        <em>curl -i -X PUT "http://mirosubs.example.com:8000/api/1.0/subtitles/languages/update/?username=xxx&password=xxx" -d "language_id=24980" -d 'format=srt' -d 'subtitles=1%0A00:00:01,46 --> 00:00:03,05%0Atestme -some'</em>

        """
        ds = request.REQUEST
        sl = get_object_or_404(SubtitleLanguage, pk=ds['language_id'])

        form = UpdateSubtitlesForm(user=request.user.customuser, data=ds)
        if form.is_valid():
            form.save(sl)
            return rc.CREATED
        raise FormValidationError(form)