コード例 #1
0
    def respond(self,
                payload={},
                context=None,
                payment_id=None,
                check_payment=False,
                **kwargs):
        if not check_payment:
            return super().respond(payload=payload, context=context, **kwargs)

        payload = merge(
            payload,
            {
                with_payment_constants.PAYMENT_COMPLETE: payment_id is None,
            },
        )

        if payment_id is not None:
            payload = merge(
                payload,
                {
                    with_payment_constants.OPEN_PAYMENT_ID: payment_id,
                },
            )

        return super().respond(payload=payload, context=context, **kwargs)
コード例 #2
0
    def respond(self,
                payload=None,
                context=None,
                challenge_id=None,
                check_challenge=False,
                **kwargs):
        if not check_challenge:
            return super().respond(payload=payload, context=context, **kwargs)

        payload = merge(
            payload,
            {
                with_challenge_constants.CHALLENGE_COMPLETE:
                challenge_id is None,
            },
        )

        if challenge_id is not None:
            payload = merge(
                payload,
                {
                    with_challenge_constants.OPEN_CHALLENGE_ID: challenge_id,
                },
            )

        return super().respond(payload=payload, context=context, **kwargs)
コード例 #3
0
ファイル: test_merge.py プロジェクト: sgricci/digsby
    def test_merge(self):
        d = {1: 2}
        merge_values(d, 3, 4); assert d == {1: 2, 3: 4}

        d = {1: 2}
        merge_values(d, 1, 3); assert d == {1: 3}

        d, d2 = {1: {2: 3}}, {1: {2: 4}}
        res = merge(d, d2)
        assert res == {1: {2: 4}}, repr(res)

        d, d2 = {1: {2: 3}}, [(1, {2: 4})]
        res = merge(d, d2)
        assert res == {1: {2: 4}}, repr(res)
コード例 #4
0
 def __init__(self, **kwargs):
   super().__init__(
     **kwargs,
     description=(
       'Welcome to the Transactino interface'
       ' Please refer to the README and the glossary'
       ' for more information.'
     ),
     children={
       api_constants.SCHEMA: StructureSchema(
         description='The schema accepts data in plaintext JSON and interacts with the API',
         children=merge(
           CommonSchema(mode=mode_constants.ANONYMOUS).children,
           {
             api_constants.MODELS: StructureSchema(
               description='Models available to the user',
               children={
                 Model.__name__: Model.objects.schema(mode=mode_constants.ANONYMOUS)
                 for Model
                 in [
                   Account,
                   System,
                 ]
               },
             ),
           },
         ),
       ),
     },
   )
コード例 #5
0
 def __init__(self,
              response=WithChallengeClientResponse,
              children=None,
              **kwargs):
     super().__init__(
         **kwargs,
         description=('The result of a challenge-blocked method.'
                      ' Contains information relevant to the open challenge'
                      ' needed to complete the method execution.'),
         response=response,
         children=merge(
             {
                 with_challenge_constants.CHALLENGE_COMPLETE:
                 Schema(
                     description=
                     'A flag indicating whether the challenge is complete',
                     types=types.BOOLEAN(),
                 ),
                 with_challenge_constants.OPEN_CHALLENGE_ID:
                 Schema(
                     description='The ID of the open challenge',
                     types=types.UUID(),
                 ),
             },
             children,
         ),
     )
コード例 #6
0
 def __init__(self, **kwargs):
     super().__init__(
         **kwargs,
         children=merge(
             {
                 api_constants.SCHEMA:
                 StructureSchema(children={
                     api_constants.MODELS:
                     ModelsSchemaWithExternal(children={
                         Model.__name__: Model.objects.schema(
                             mode=mode_constants.SUPERADMIN)
                         for Model in [
                             Account,
                             Address,
                             Challenge,
                             Discount,
                             IP,
                             Payment,
                             Subscription,
                             FeeReport,
                         ]
                     }, ),
                 }, ),
             }, ),
     )
コード例 #7
0
 def __init__(self,
              response=WithPaymentClientResponse,
              children=None,
              **kwargs):
     super().__init__(
         **kwargs,
         response=response,
         children=merge(
             {
                 with_payment_constants.PAYMENT_COMPLETE:
                 Schema(types=types.BOOLEAN()),
                 with_payment_constants.OPEN_PAYMENT_ID:
                 Schema(types=types.UUID()),
             },
             children,
         ),
     )
コード例 #8
0
    def __init__(self, context=None, **kwargs):

        models = [
            Account,
            Address,
            Announcement,
            Challenge,
            System,
        ]

        account = context.get_account()
        if account.is_verified:
            models.extend([
                Subscription,
                Payment,
            ])

        super().__init__(
            **kwargs,
            description=('The account does not have an active subscription.'
                         ' Refer to the Subscription model to create one.'),
            children={
                api_constants.SCHEMA:
                TransactinoControlSchema(
                    description=
                    'The schema accepts data in plaintext JSON and interacts with the API',
                    children=merge(
                        CommonSchema().children,
                        {
                            api_constants.MODELS:
                            ModelsSchemaWithExternal(
                                description='Models available to the user',
                                children={
                                    Model.__name__: Model.objects.schema(
                                        mode=mode_constants.UNSUBSCRIBED)
                                    for Model in models
                                },
                            ),
                        },
                    ),
                ),
            },
        )
コード例 #9
0
    def has_matching_rammetid(self, umbrella_org_id, start_date, end_date, week_day, start_time, end_time):
        times = []

        query = current_app.db_session.query(RammetidSlot)
        slots = query.filter(
            RammetidSlot.start_date <= cast(start_date, Date),
            RammetidSlot.end_date >= cast(end_date, Date),
            week_day == RammetidSlot.week_day,
            umbrella_org_id == Rammetid.umbrella_organisation_id,
        ).order_by(RammetidSlot.start_time, RammetidSlot.end_time).all()

        # create list of time-periods for all slots
        for slot in slots:
            times.append((slot.start_time, slot.end_time))

        # return if any merged slot covers whole time-period
        if any(i[0] <= start_time and i[1] >= end_time for i in merge(times)):
            return True

        return False
コード例 #10
0
 def __init__(self, **kwargs):
     super().__init__(
         **kwargs,
         description=(
             'This account has an active subscription.'
             ' Please refer to the README and review the available models.'
         ),
         children={
             api_constants.SCHEMA:
             TransactinoControlSchema(
                 description=
                 'The schema accepts data in plaintext JSON and interacts with the API',
                 children=merge(
                     CommonSchema().children,
                     {
                         api_constants.MODELS:
                         ModelsSchemaWithExternal(
                             description='Models available to the user',
                             children={
                                 Model.__name__: Model.objects.schema(
                                     mode=mode_constants.SUBSCRIBED)
                                 for Model in [
                                     Account,
                                     Address,
                                     Announcement,
                                     System,
                                     Challenge,
                                     IP,
                                     Payment,
                                     Subscription,
                                     FeeReport,
                                     TransactionReport,
                                     TransactionMatch,
                                 ]
                             },
                         ),
                     },
                 ),
             ),
         },
     )
コード例 #11
0
def set_active(skin, variant = None, update_gui = False, callback = None):
    'Changes the active skin.'
    log.info('set_active(%r, %r)', skin, variant)
    app  = GetApp()
    global activeTree

    # Search all resource_paths for skin
    skinname = skin
    for rp in resource_paths:
        skin = path(rp) / 'skins' / skinname
        skinpath = skin / SKIN_FILENAME
        if skinpath.isfile():
            break
    import hooks
    hooks.notify('skin.set.pre', skin, variant)

    # Find the variant file, if specified.
    if variant is not None:
        variant = skin / VARIANT_DIR / variant + '.yaml'

    default_path = resource_paths[0] / 'skins' / 'default' / SKIN_FILENAME

    paths = [default_path]
    insert_position = 1

    if os.path.basename(skin) == 'native':
        paths.append(resource_paths[0] / path('skins') / 'silverblue' / SKIN_FILENAME)

    if not skinpath.isfile():
        log.critical('cannot find %r (%r.isfile() == False, defaulting to silverblue', skin, skinpath)
        skin = resource_paths[0] / path('skins') / 'silverblue'
        skinpath = skin / SKIN_FILENAME
        variant = None

    if default_path.abspath() != skinpath.abspath():
        paths.append(skinpath)
    if variant is not None:
        if variant.isfile():
            paths.append(variant)
        else:
            log.warning('cannot find variant %r for skin %r', variant, skin)

    if not update_gui and hasattr(app, 'skin') and \
        app.skin.paths == paths:
        log.info('skin did not change, returning')

    with traceguard:
        load_skinfonts(paths)

    # load YAML from disk
    log.info('loading YAML from %d path(s):\n  %r', len(paths), '\n  '.join(paths))

    trees = get_skintrees(skin, paths, insert_position)

    # Ignore AppDefaults in all skins except default
    for tree in trees[1:]:
        tree.pop('appdefaults', None)

    # copy the default tree in case there is an exception later
    default_tree = deepcopy(trees[0])

    # merge keys from different trees into one (case insensitive)
    combined_tree = merge(*trees, **dict(keytransform = lambda k: getattr(k, 'lower', lambda k: k)()))

    # create a skin storage object (transformation below depends on this being
    # in the app)
    if not hasattr(app, 'skin'):
        app.skin = S()

    app.skin.update(path  = skinpath.parent, paths = get_image_load_paths(paths))

    for pretransform in pretransforms:
        pretransform(combined_tree)

    # do skin transformation, creating images, brushes, etc.
    try:
        finaltree = transform(combined_tree)
    except Exception, e:
        MessageBox('There was an error processing skin "%s":\n\n%s' % (skin, str(e)),
                   'Skin Error')

        # on an exception try loading the default tree
        print_exc()
        finaltree = transform(default_tree)