当前位置: 首页>>代码示例>>Python>>正文


Python ajax.ajax_answer_lazy函数代码示例

本文整理汇总了Python中nnmware.core.ajax.ajax_answer_lazy函数的典型用法代码示例。如果您正苦于以下问题:Python ajax_answer_lazy函数的具体用法?Python ajax_answer_lazy怎么用?Python ajax_answer_lazy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ajax_answer_lazy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: client_review

def client_review(request, pk):
    try:
        hotel = Hotel.objects.get(id=pk)
        #        guests = Booking.objects.filter(hotel=hotel,to_date__gte=now()).values_list('user', flat=True)
        if request.user.is_superuser:
            message = _('You are superuser and may add review.')
        elif request.user.pk in hotel.complete_booking_users_id:
            message = _('Thanks for you review!')
        else:
            raise UserNotAllowed
        if Review.objects.filter(hotel=hotel, user=request.user).count():
            raise UserNotAllowed
        food = request.POST['point_food']
        service = request.POST['point_service']
        purity = request.POST['point_purity']
        transport = request.POST['point_transport']
        prices = request.POST['point_prices']
        review = request.POST['review']
        r = Review()
        r.user = request.user
        r.username = request.user.first_name
        r.hotel = hotel
        r.food = food
        r.service = service
        r.purity = purity
        r.transport = transport
        r.prices = prices
        r.review = review
        r.save()
        payload = {'success': True, 'message': message}
    except UserNotAllowed:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
开发者ID:cdrone-hotels,项目名称:nnmware,代码行数:33,代码来源:ajax.py

示例2: booking_sysadm

def booking_sysadm(request, pk, action):
    if not request.is_ajax():
        raise Http404
    try:
        if not request.user.is_superuser:
            raise UserNotAllowed
        booking = Booking.objects.select_related().get(id=pk)
        if action == 'delete':
            from_date = booking.from_date
            to_date = booking.to_date
            settlement = booking.settlement
            while from_date < to_date:
                avail = Availability.objects.get(room=settlement.room, date=from_date)
                avail.placecount += 1
                avail.save()
                from_date += timedelta(days=1)
            booking_delete_client_mail(booking)
            booking.delete()
            url = reverse_lazy('bookings_list')
        elif action == 'enable':
            booking.enabled = True
            booking.save()
            booking_new_hotel_mail(booking)
            url = reverse_lazy('booking_admin_detail', args=[booking.uuid, ])
        else:
            raise UserNotAllowed
        payload = {'success': True, 'location': url}
    except UserNotAllowed:
        payload = {'success': False, 'error_msg': _('You are not allowed for this action.')}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
开发者ID:biomassives,项目名称:nnmware,代码行数:32,代码来源:ajax.py

示例3: hotels_in_country

def hotels_in_country(request):
    try:
        searched = Hotel.objects.all()
        return filter_hotels_on_map(request, searched)
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
开发者ID:cdrone-hotels,项目名称:nnmware,代码行数:7,代码来源:ajax.py

示例4: booking_status_change

def booking_status_change(request, uuid):
    try:
        booking = Booking.objects.get(uuid=uuid)
        if request.user not in booking.hotel.admins.all() and not request.user.is_superuser:
            raise UserNotAllowed
        status = request.POST["status"]
        if booking.status != int(status):
            booking.status = status
            booking.save()
            subject = _("Changed status of booking")
            message = _("Hotel: ") + booking.hotel.get_name + "\n"
            message += _("Booking: ") + str(booking.system_id) + "\n"
            message += _("Booking link: ") + booking.get_absolute_url() + "\n"
            message += _("New status: ") + booking.get_status_display() + "\n"
            message += (
                "\n"
                + "IP: %s USER-AGENT: %s"
                % (request.META.get("REMOTE_ADDR", ""), request.META.get("HTTP_USER_AGENT", "")[:255])
                + "\n"
            )
            mail_managers(subject, message)
            payload = {"success": True}
    except UserNotAllowed as naerr:
        payload = {"success": False, "error": _("You are not allowed change booking status.")}
    except:
        payload = {"success": False}
    return ajax_answer_lazy(payload)
开发者ID:nnmware,项目名称:nnmware,代码行数:27,代码来源:ajax.py

示例5: client_booking_cancel

def client_booking_cancel(request, uuid):
    try:
        booking = Booking.objects.get(uuid=uuid)
        if not request.user.is_authenticated():
            raise UserNotAllowed
        if request.user != booking.user and not request.user.is_superuser:
            raise UserNotAllowed
        if booking.status == STATUS_ACCEPTED or booking.status == STATUS_CONFIRMED:
            booking.status = STATUS_CANCELED_CLIENT
            booking.cancel_time = now()
            booking.save()
            subject = _("Changed status of booking")
            message = _("Hotel: ") + booking.hotel.get_name + "\n"
            message += _("Booking: ") + str(booking.system_id) + "\n"
            message += _("Booking link: ") + booking.get_absolute_url() + "\n"
            message += _("New status: ") + booking.get_status_display() + "\n"
            message += '\n' + "IP: %s USER-AGENT: %s" % (request.META.get('REMOTE_ADDR', ''),
                                                         request.META.get('HTTP_USER_AGENT', '')[:255]) + '\n'
            mail_managers(subject, message)
            payload = {'success': True}
    except UserNotAllowed:
        payload = {'success': False, 'error': _('You are not allowed change booking status.')}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
开发者ID:cdrone-hotels,项目名称:nnmware,代码行数:25,代码来源:ajax.py

示例6: room_rates

def room_rates(request):
    try:
        json_data = json.loads(request.body)
        currency = Currency.objects.get(code=setting('DEFAULT_CURRENCY', 'RUB'))
        room = Room.objects.get(id=int(json_data['room_id']))
        if request.user not in room.hotel.admins.all() and not request.user.is_superuser:
            raise UserNotAllowed
            # find settlements keys in data
        all_settlements, all_discounts = [], []
        for k in json_data.keys():
            if k[0] == 's':
                all_settlements.append(k)
            elif k[0] == 'd':
                all_discounts.append(k)
        for i, v in enumerate(json_data['dates']):
            on_date = datetime.fromtimestamp(time.mktime(time.strptime(v, "%d%m%Y")))
            if 'placecount' in json_data.keys():
                try:
                    placecount = int(json_data['placecount'][i])
                    try:
                        min_days = int(json_data['min_days'][i])
                    except:
                        min_days = None
                        # store availability
                    availability, created = Availability.objects.get_or_create(date=on_date, room=room)
                    availability.placecount = placecount
                    if min_days is not None:
                        availability.min_days = min_days
                    availability.save()
                except ValueError:
                    pass
            for k in all_discounts:
                try:
                    discount_id = int(k[1:])
                    discount = Discount.objects.get(id=discount_id)
                    value = int(json_data[k][i])
                    room_discount, created = RoomDiscount.objects.get_or_create(date=on_date, discount=discount,
                                                                                room=room)
                    room_discount.value = value
                    room_discount.save()
                except ValueError:
                    pass
            for k in all_settlements:
                try:
                    settlement_id = int(k[1:])
                    settlement = SettlementVariant.objects.get(id=settlement_id)
                    price = int(json_data[k][i])
                    placeprice, created = PlacePrice.objects.get_or_create(date=on_date, settlement=settlement)
                    placeprice.amount = price
                    placeprice.currency = currency
                    placeprice.save()
                except ValueError:
                    pass
        payload = {'success': True}
    except UserNotAllowed:
        payload = {'success': False}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
开发者ID:biomassives,项目名称:nnmware,代码行数:59,代码来源:ajax.py

示例7: form_invalid

 def form_invalid(self, form, *args, **kwargs):
     self.data = as_json(form.errors)
     self.success = False
     payload = {'success': self.success, 'data': self.data}
     if self.request.is_ajax():
         return ajax_answer_lazy(payload)
     else:
         return super(AjaxFormMixin, self).form_invalid(form, *args, **kwargs)
开发者ID:nnmware,项目名称:nnmware,代码行数:8,代码来源:views.py

示例8: payment_method

def payment_method(request):
    try:
        p_m = request.POST['p_m']
        paymnt_method = PaymentMethod.objects.get(pk=p_m)
        payload = {'success': True, 'id': paymnt_method.pk, 'description': paymnt_method.description,
                   'card': paymnt_method.use_card}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
开发者ID:cdrone-hotels,项目名称:nnmware,代码行数:9,代码来源:ajax.py

示例9: edit_discount

def edit_discount(request):
    try:
        d = Discount.objects.get(pk=int(request.POST["discount"]))
        if request.user not in d.hotel.admins.all() and not request.user.is_superuser:
            raise AccessError
        html = render_to_string("cabinet/edit_discount.html", {"discount": d})
        payload = {"success": True, "html": html}
    except:
        payload = {"success": False}
    return ajax_answer_lazy(payload)
开发者ID:nnmware,项目名称:nnmware,代码行数:10,代码来源:ajax.py

示例10: base_autocomplete

def base_autocomplete(obj, request):
    search_qs = obj.objects.filter(
        Q(name__icontains=request.POST['q']) |
        Q(name_en__icontains=request.POST['q'])).order_by('name')
    results = []
    for r in search_qs:
        userstring = {'name': r.get_name, 'slug': r.slug}
        results.append(userstring)
    payload = {'answer': results}
    return ajax_answer_lazy(payload)
开发者ID:biomassives,项目名称:nnmware,代码行数:10,代码来源:ajax.py

示例11: post

 def post(self, request, *args, **kwargs):
     success = True
     location = None
     try:
         logout(self.request)
         location = '/'
     except:
         success = False
     payload = {'success': success, 'location': location}
     return ajax_answer_lazy(payload)
开发者ID:biomassives,项目名称:nnmware,代码行数:10,代码来源:views.py

示例12: base_autocomplete

def base_autocomplete(obj, request):
    search_qs = obj.objects.filter(
        Q(name__icontains=request.POST["q"]) | Q(name_en__icontains=request.POST["q"])
    ).order_by("name")
    results = []
    for r in search_qs:
        userstring = {"name": r.get_name, "slug": r.slug}
        results.append(userstring)
    payload = {"answer": results}
    return ajax_answer_lazy(payload)
开发者ID:nnmware,项目名称:nnmware,代码行数:10,代码来源:ajax.py

示例13: delete_discount

def delete_discount(request):
    try:
        d = Discount.objects.get(pk=int(request.POST['discount']))
        if request.user not in d.hotel.admins.all() and not request.user.is_superuser:
            raise AccessError
        d.delete()
        payload = {'success': True}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
开发者ID:cdrone-hotels,项目名称:nnmware,代码行数:10,代码来源:ajax.py

示例14: room_rates

def room_rates(request):
    try:
        json_data = json.loads(request.body)
        currency = Currency.objects.get(code=setting('DEFAULT_CURRENCY', 'RUB'))
        hotel = Hotel.objects.get(id=int(json_data['hotel']))
        if request.user not in hotel.admins.all() and not request.user.is_superuser:
            raise UserNotAllowed
            # find settlements keys in data
        all_rooms, all_avail, all_limits = [], [], []
        for k in json_data.keys():
            if k[0] == 'r':
                all_rooms.append(k)
            elif k[0] == 'a':
                all_avail.append(k)
            elif k[0] == 'l':
                all_limits.append(k)
        for i, v in enumerate(json_data['dates']):
            on_date = datetime.fromtimestamp(time.mktime(time.strptime(v, "%d%m%Y")))
            for k in all_rooms:
                try:
                    settlement_id = int(k[1:])
                    settlement = SettlementVariant.objects.get(id=settlement_id)
                    price = int(json_data[k][i])
                    placeprice, created = PlacePrice.objects.get_or_create(date=on_date, settlement=settlement)
                    placeprice.amount = price
                    placeprice.currency = currency
                    placeprice.save()
                except ValueError:
                    pass
            for k in all_avail:
                try:
                    room_id = int(k[1:])
                    room = Room.objects.get(pk=room_id)
                    p = json_data[k][i]
                    if len(p.strip()) == 0:
                        placecount = 0
                    else:
                        placecount = int(p)
                    availability, created = Availability.objects.get_or_create(date=on_date, room=room)
                    availability.placecount = placecount
                    try:
                        min_days = int(json_data['l' + k[1:]][i])
                    except:
                        min_days = None
                    if min_days is not None:
                        availability.min_days = min_days
                    availability.save()
                except ValueError:
                    pass
        payload = {'success': True}
    except UserNotAllowed:
        payload = {'success': False}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
开发者ID:cdrone-hotels,项目名称:nnmware,代码行数:55,代码来源:ajax.py

示例15: form_valid

 def form_valid(self, form):
     if self.request.is_ajax():
         self.success = True
         payload = dict(success=self.success, location=self.success_url or self.get_success_url())
         try:
             payload['status_msg'] = self.status_msg
         except:
             pass
         return ajax_answer_lazy(payload)
     else:
         return HttpResponseRedirect(self.success_url)
开发者ID:biomassives,项目名称:nnmware,代码行数:11,代码来源:views.py


注:本文中的nnmware.core.ajax.ajax_answer_lazy函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。