Beispiel #1
0
    def process(self):
        from voluptuous import Schema
        from appname.vendor import Vendor
        from appname.vendor import vendor_schema

        vendor = json.loads(self.request.body)
        schema = Schema(vendor_schema, extra=True)
        try:
            schema(vendor)
        except:
            logging.exception('validation failed')
            logging.info(vendor)

        vendor_entity = Vendor.from_dict(vendor)
        vendor_entity.put()

        user_id = users.get_current_user().user_id()
        person = Person.get_by_id(user_id)
        if vendor_entity.is_new:
            what = "Vendor Created."
        else:
            what = "Vendor Updated."
        what = "%s %s with tags: %s" % (what, vendor_entity.name,
                                        vendor_entity.tags)
        loc = ""
        if person is not None and person.location_info is not None:
            loc = person.location_info.get('latlong')
        message = {'location': loc, 'what': what}
        event.send("ACTIVITY", message)
        logging.info("Sending message: %s" % message)

        out = vendor_entity.to_dict()
        self.response.out.write(json.dumps(out))
Beispiel #2
0
    def process(self):
        from voluptuous import Schema
        from appname.transaction import Transaction
        from appname.transaction import transaction_schema

        transaction = json.loads(self.request.body)
        schema = Schema(transaction_schema, extra=True)
        try:
            schema(transaction)
        except:
            logging.exception('validation failed')
            logging.info(transaction)

        transaction_entity = Transaction.from_dict(transaction)
        transaction_entity.put()

        user_id = users.get_current_user().user_id()
        person = Person.get_by_id(user_id)
        if transaction_entity.is_new:
            what = "Transaction Created."
        else:
            what = "Transaction Updated."
        what = "%s $%s at %s" % (what, transaction_entity.amount,
                                 transaction_entity.vendor_name)
        loc = ""
        if person is not None and person.location_info is not None:
            loc = person.location_info.get('latlong')
        message = {'location': loc, 'what': what}
        event.send("ACTIVITY", message)
        logging.info("Sending message: %s" % message)

        out = transaction_entity.to_dict()
        self.response.out.write(json.dumps(out))
Beispiel #3
0
    def process(self):
        from voluptuous import Schema
        from appname.transaction import Transaction
        from appname.transaction import transaction_schema

        transaction = json.loads(self.request.body)
        schema = Schema(transaction_schema, extra=True)
        try:
            schema(transaction)
        except:
            logging.exception('validation failed')
            logging.info(transaction)

        transaction_entity = Transaction.from_dict(transaction)
        transaction_entity.put()

        user_id = users.get_current_user().user_id()
        person = Person.get_by_id(user_id)
        if transaction_entity.is_new:
            what = "Transaction Created."
        else:
            what = "Transaction Updated."
        what = "%s $%s at %s" % (what, transaction_entity.amount, transaction_entity.vendor_name)
        loc = ""
        if person is not None and person.location_info is not None:
            loc = person.location_info.get('latlong')
        message = {'location': loc,
                    'what': what}
        event.send("ACTIVITY", message)
        logging.info("Sending message: %s" % message)

        out = transaction_entity.to_dict()
        self.response.out.write(json.dumps(out))
Beispiel #4
0
    def process(self):
        from voluptuous import Schema
        from appname.vendor import Vendor
        from appname.vendor import vendor_schema

        vendor = json.loads(self.request.body)
        schema = Schema(vendor_schema, extra=True)
        try:
            schema(vendor)
        except:
            logging.exception('validation failed')
            logging.info(vendor)

        vendor_entity = Vendor.from_dict(vendor)
        vendor_entity.put()

        user_id = users.get_current_user().user_id()
        person = Person.get_by_id(user_id)
        if vendor_entity.is_new:
            what = "Vendor Created."
        else:
            what = "Vendor Updated."
        what = "%s %s with tags: %s" % (what, vendor_entity.name, vendor_entity.tags)
        loc = ""
        if person is not None and person.location_info is not None:
            loc = person.location_info.get('latlong')
        message = {'location': loc,
                    'what': what}
        event.send("ACTIVITY", message)
        logging.info("Sending message: %s" % message)


        out = vendor_entity.to_dict()
        self.response.out.write(json.dumps(out))
Beispiel #5
0
    def post(self):
        """Bundle up work and apply it to our TagStats entity."""
        queue = taskqueue.Queue('work-groups')
        work = queue.lease_tasks_by_tag(30, 500)
        if not work:
            return

        # Go look for more stuff to do.
        taskqueue.add(
            queue_name='default',
            url='/_ah/task/batcher'
        )

        # Process the work we've got.
        namespace, stat_models = apply_work(work)
        queue.delete_tasks(work)

        models = [model.to_dict() for model in stat_models]

        limit_per_message = 5
        while models:
            to_send = models[:limit_per_message]
            models = models[limit_per_message:]

            payload = {'what': 'Summaries updated.', 'summaries': to_send}
            event.send("SUMMARY-%s" % namespace, payload)
Beispiel #6
0
def send_change_password_message():
    try:
        if do_or_not_do():
            user = database.get_user('admin')
            if user['password'] == 'e10adc3949ba59abbe56e057f20f883e':
                event.send('user', 21, 'admin', False, user, True)
            else:
                pass
    except Exception as error:
        handler.log(handler.error(error), 2)
        handler.log('Run send change password message task failed!')
Beispiel #7
0
def run_snapshot_schedule():
    try:
        if do_or_not_do():
            current_time = handler.current_time()
            schedule_is_running = database.get_is_running_snapshot_schedule()
            if schedule_is_running is not None:
                name = schedule_is_running['name']
                start_time = schedule_is_running['startTime']
                auto_disable_time = schedule_is_running['autoDisableTime']
                interval = schedule_is_running['interval']
                delete_round = schedule_is_running['deleteRound']
                time_gap_in_second = handler.iso2stamp(
                    current_time) - handler.iso2stamp(start_time)
                if time_gap_in_second >= interval and not (time_gap_in_second % interval) and (not auto_disable_time or time_gap_in_second <= auto_disable_time):
                    snapshot_setting = database.get_setting('SNAPSHOT-SETTING')
                    limit = snapshot_setting['auto']
                    count = database.count_snapshot(True)
                    name_to_create = name + '-' + \
                        process.run('date "+%Y%m%d%H%M%S"')
                    if count < limit:
                        database.create_snapshot(
                            name_to_create, '', True, current_time)
                        event.send('snapshot', 11, name_to_create, True)
                        create_status = backend.create_snapshot(
                            name_to_create, True)
                        if not create_status['errorId']:
                            database.update_snapshot_status(name_to_create)
                            event.send('snapshot', 12, name_to_create, True)
                        else:
                            database.delete_snapshot(name_to_create)
                            event.send('snapshot', 12, name_to_create, False)
                    elif delete_round:
                        auto_snapshots = database.get_auto_snapshot()
                        name_to_delete = auto_snapshots[0]['name']
                        database.update_snapshot_status(
                            name_to_delete, False, True, False)
                        delete_status = backend.delete_snapshot(name_to_delete)
                        if not delete_status['errorId']:
                            database.delete_snapshot(name_to_delete)
                            database.create_snapshot(
                                name_to_create, '', True, current_time)
                            event.send('snapshot', 11, name_to_create, True)
                            create_status = backend.create_snapshot(
                                name_to_create, True)
                            if not create_status['errorId']:
                                database.update_snapshot_status(name_to_create)
                                event.send('snapshot', 12,
                                           name_to_create, True)
                            else:
                                database.delete_snapshot(name_to_create)
                                event.send('snapshot', 12,
                                           name_to_create, False)
                        else:
                            database.update_snapshot_status(name_to_delete)
                elif auto_disable_time and time_gap_in_second > auto_disable_time:
                    database.disable_snapshot_schedule(name)
    except Exception as error:
        handler.log(handler.error(error), 2)
        handler.log('Run snapshot schedule task failed!')