Пример #1
0
    def send(self, sender, **named):
        """
        Send this signal asynchronously to the registered receivers

        @param sender: sender 
        @param named: named arguments
        @return:
        """
        if not self.receivers:
            logging.warning("no receivers found. sender: %s, signal type: %s" %
                            (sender, self.signal_type))
            return None

        logging.info("sending signal: %s" % self.signal_type)

        for receiver in self._live_receivers(_make_id(sender)):
            args = {
                "receiver": receiver,
                "sender": sender,
                "signal_type": self.signal_type
            }
            args.update(named)

            signal_data = AsyncSignal.dump_signal_data(args)

            deferred.defer(send_async,
                           signal_data=signal_data,
                           _queue="signals",
                           _name="send-signal-%s-%s-%s" %
                           (sender, self.signal_type, get_uuid()))

        return None  # discard the responses
Пример #2
0
    def get(self):
        """ GET path to do health checking on different APIs. """
        remote_api_key = self.request.get(constants.ApiTags.API_KEY)
        if remote_api_key != settings.API_KEY:
            logging.error("Request with bad API key")
            self.response.set_status(constants.HTTP_DENIED)
            self.response.write("Bad API Key")
            return
        results = {}
        uuid_tag = util.get_uuid()
        for suite_tag in constants.AllTestSuites.all_suites():
            suite_runner_constructor = get_runner_constructor(suite_tag)
            suite_runner = suite_runner_constructor(uuid_tag)
            results[suite_tag] = suite_runner.run()
            suite_runner.cleanup()
        json_result = json.dumps({
            constants.ApiTags.DATA: {
                uuid_tag: results
            },
            constants.ApiTags.APP_ID: settings.APP_ID,
            constants.ApiTags.USER_ID: settings.USER_ID,
            constants.ApiTags.API_KEY: settings.API_KEY
        })

        self.response.write(json_result)
Пример #3
0
def kpi(request):
    na = "N/A"
    init_start_date = default_tz_now_min() - timedelta(days=1)
    init_end_date = default_tz_now_max()
    channel_id = get_uuid()
    token = channel.create_channel(channel_id)

    from analytics.kpi import calc_kpi_data
    return base_datepicker_page(request, calc_kpi_data, 'kpi.html', locals(), init_start_date, init_end_date, async=True)
Пример #4
0
def get_discounted_offers(request, order_settings, start_ride_algo_data):
    user = request.user if request.user.is_authenticated() else None

    discounted_offers = []

    earliest_offer_dt = ceil_datetime(max(trim_seconds(default_tz_now()) + datetime.timedelta(minutes=asap_interval()), order_settings.pickup_dt - OFFERS_TIMEDELTA), minutes=booking_interval())
    discounts_data = compute_discounts_data(order_settings,
        earliest_offer_dt,
        order_settings.pickup_dt + OFFERS_TIMEDELTA,
        datetime.timedelta(minutes=booking_interval()),
        user = user
    )

    for discount_data in discounts_data:
        discount_rule = discount_data.discount_rule
        discount_dt = discount_data.pickup_dt

        tariff_for_discount_offer = RuleSet.get_active_set(discount_dt)
        base_price_for_discount_offer = start_ride_algo_data.order_price(NEW_ORDER_ID, tariff_for_discount_offer)
        if base_price_for_discount_offer:
            discount = discount_rule.get_discount(base_price_for_discount_offer)
            if discount == 0:
                logging.info(u"skipping %s: grants zero discount" % discount_rule.name)
                continue

            offer_key = "%s_%s" % (DISCOUNTED_OFFER_PREFIX, get_uuid())
            memcache.set(offer_key, DiscountData.dump(discount_data), namespace=DISCOUNTED_OFFERS_NS)

            offer_text = _(u"The price includes a discount of %g NIS") % discount
            if discount_rule.offer_text:
                offer_text = discount_rule.offer_text
                if offer_text.find("%g") > -1:  # render discount amount
                    offer_text %= discount

            discount_offer_data = {
                "ride_id": offer_key,
                "pickup_time": to_js_date(discount_dt),
                "discount_picture_url": discount_rule.picture_url,
                "discount_name": discount_rule.display_name,
                "passengers": [],
                "seats_left": MAX_SEATS,
                "price": base_price_for_discount_offer - discount,
                "new_ride": True,
                "comment": offer_text
            }


            user_agent = request.META.get("HTTP_USER_AGENT", "")
            if RE_2_1_AGENT.match(user_agent) is None:  # only for client < 1.2.1
                discount_offer_data.update({
                    "seats_left": MAX_SEATS - 1,
                    "passengers": [{'name': discount_rule.display_name, 'picture_url': discount_rule.picture_url}]
                })

            discounted_offers.append(discount_offer_data)

    return discounted_offers
Пример #5
0
def kpi(request):
    na = "N/A"
    init_start_date = default_tz_now_min() - timedelta(days=1)
    init_end_date = default_tz_now_max()
    channel_id = get_uuid()
    token = channel.create_channel(channel_id)

    from analytics.kpi import calc_kpi_data
    return base_datepicker_page(request,
                                calc_kpi_data,
                                'kpi.html',
                                locals(),
                                init_start_date,
                                init_end_date,
                                async=True)
Пример #6
0
def create_ride(ride):
    logging.info("[create_ride] ride = '%s'" % ride)
    try:
        station = ride.station
        assert station, "ride [%s] is not assigned to a station" % ride.id
        assert station.fleet_station_id, "station %s has no fleet_station_id" % ride.station.name
        assert ride.dn_fleet_manager_id, "ride [%s] is not associated with a fleet manager" % ride.id

        # refresh uuid so that we can re-insert this ride into fleet_manager db without conflict
        ride.update(uuid=get_uuid())

        ride_fm = FleetManager.by_id(ride.dn_fleet_manager_id)
        result = ride_fm.create_ride(ride, ride.station, taxi_number=ride.taxi_number)
        return bool(result)
    except Exception, e:
        logging.error(traceback.format_exc())
        return False
Пример #7
0
def create_ride(ride):
    logging.info("[create_ride] ride = '%s'" % ride)
    try:
        station = ride.station
        assert station, "ride [%s] is not assigned to a station" % ride.id
        assert station.fleet_station_id, "station %s has no fleet_station_id" % ride.station.name
        assert ride.dn_fleet_manager_id, "ride [%s] is not associated with a fleet manager" % ride.id

        # refresh uuid so that we can re-insert this ride into fleet_manager db without conflict
        ride.update(uuid=get_uuid())

        ride_fm = FleetManager.by_id(ride.dn_fleet_manager_id)
        result = ride_fm.create_ride(ride,
                                     ride.station,
                                     taxi_number=ride.taxi_number)
        return bool(result)
    except Exception, e:
        logging.error(traceback.format_exc())
        return False
Пример #8
0
 def get(self):
   """ GET path to do health checking on different APIs. """
   remote_api_key = self.request.get(constants.ApiTags.API_KEY)
   if remote_api_key != settings.API_KEY:
     logging.error("Request with bad API key")
     self.response.set_status(constants.HTTP_DENIED)
     self.response.write("Bad API Key")
     return
   results = {}
   uuid_tag = util.get_uuid()
   for suite_tag in constants.AllTestSuites.all_suites():
     suite_runner_constructor = get_runner_constructor(suite_tag)
     suite_runner = suite_runner_constructor(uuid_tag)
     results[suite_tag] = suite_runner.run()
     suite_runner.cleanup()
   json_result = json.dumps( 
     {constants.ApiTags.DATA: {uuid_tag:results},
      constants.ApiTags.APP_ID: settings.APP_ID,
      constants.ApiTags.USER_ID: settings.USER_ID,
      constants.ApiTags.API_KEY: settings.API_KEY})
     
   self.response.write(json_result)
Пример #9
0
 def __init__(self, orders):
     self.orders = FakeOrdersManager(orders)
     self.status = 0
     self.uuid = get_uuid()
Пример #10
0
 def __init__(self, orders):
     self.orders = FakeOrdersManager(orders)
     self.status = 0
     self.uuid = get_uuid()
Пример #11
0
from google.appengine.api.urlfetch import POST
from common.fax.backends.default import AbstractFaxBackend, FaxStatus
from common.pdf_service import convert_to_pdf
from common.util import get_uuid, safe_fetch
from django.utils import simplejson
import base64
import logging
import time
import urllib

CRLF = '\r\n'
BOUNDARY = get_uuid()

#USERNAME = "******"
#PASSWORD = "******"

# The following are used for authentication functions.
REFRESH_TOKEN = '***REMOVED***'
CLIENT_SECRET = '***REMOVED***'
CLIENT_ID = '***REMOVED***'

# The following are used for general backend access.
CLOUDPRINT_URL = 'http://www.google.com/cloudprint'
# CLIENT_NAME should be some string identifier for the client you are writing.
CLIENT_NAME = 'WAYbetter Client'

def GetUrl(url, access_token, data=None):
    """Get URL, with GET or POST depending data, adds Authorization header.

    Args:
      url: Url to access.
Пример #12
0
    def send(self, sender, **named):
        """
        Send this signal asynchronously to the registered receivers

        @param sender: sender 
        @param named: named arguments
        @return:
        """
        if not self.receivers:
            logging.warning("no receivers found. sender: %s, signal type: %s" % (sender, self.signal_type))
            return None

        logging.info("sending signal: %s" % self.signal_type)

        for receiver in self._live_receivers(_make_id(sender)):
            args = {"receiver": receiver, "sender": sender, "signal_type": self.signal_type}
            args.update(named)

            signal_data = AsyncSignal.dump_signal_data(args)

            deferred.defer(send_async, signal_data=signal_data, _queue="signals", _name="send-signal-%s-%s-%s" % (sender, self.signal_type, get_uuid()))

        return None # discard the responses
Пример #13
0
from google.appengine.api.urlfetch import POST
from common.fax.backends.default import AbstractFaxBackend, FaxStatus
from common.pdf_service import convert_to_pdf
from common.util import get_uuid, safe_fetch
from django.utils import simplejson
import base64
import logging
import time
import urllib

CRLF = '\r\n'
BOUNDARY = get_uuid()

#USERNAME = "******"
#PASSWORD = "******"

# The following are used for authentication functions.
REFRESH_TOKEN = '***REMOVED***'
CLIENT_SECRET = '***REMOVED***'
CLIENT_ID = '***REMOVED***'

# The following are used for general backend access.
CLOUDPRINT_URL = 'http://www.google.com/cloudprint'
# CLIENT_NAME should be some string identifier for the client you are writing.
CLIENT_NAME = 'WAYbetter Client'


def GetUrl(url, access_token, data=None):
    """Get URL, with GET or POST depending data, adds Authorization header.

    Args: