Exemplo n.º 1
0
    def __init__(self, request: Request, user: User):
        super(UserWallet, self).__init__(request)
        self.user = user

        uaf = UserAddressFolder(request, user)
        uof = UserOperationFolder(request, self)
        self.address_folder = Resource.make_lineage(self, uaf, "accounts")
        self.op_folder = Resource.make_lineage(self, uof, "transactions")
Exemplo n.º 2
0
    def __init__(self, request: Request, user: User):
        super(UserWallet, self).__init__(request)
        self.user = user

        uaf = UserAddressFolder(request, user)
        uof = UserOperationFolder(request, self)
        self.address_folder = Resource.make_lineage(self, uaf, "accounts")
        self.op_folder = Resource.make_lineage(self, uof, "transactions")
Exemplo n.º 3
0
    def __getitem__(self, item):
        """Traverse to model admins. """
        registry = self.request.registry
        model_admin_resource = registry.queryAdapter(self.request, IModelAdmin, name=item)
        if not model_admin_resource:
            raise RuntimeError("Did not find model admin with id: {}".format(item))

        Resource.make_lineage(self, model_admin_resource, item)
        return model_admin_resource
Exemplo n.º 4
0
    def __getitem__(self, item):
        """Traverse to model admins. """
        registry = self.request.registry
        model_admin_resource = registry.queryAdapter(self.request, IModelAdmin, name=item)
        if not model_admin_resource:
            raise RuntimeError("Did not find model admin with id: {}".format(item))

        Resource.make_lineage(self, model_admin_resource, item)
        return model_admin_resource
Exemplo n.º 5
0
def contribute_model_admin(event):
    """Add model menus to the admin user interface."""

    admin = event.admin
    request = event.admin.request

    model_admin_root = ModelAdminRoot(request)
    Resource.make_lineage(admin, model_admin_root, "models")
    admin.children["models"] = model_admin_root

    # Create a model entries to menu
    data_menu = admin.get_admin_menu().get_entry("admin-menu-data").submenu
    for id, model_admin in model_admin_root.items():
        entry = menu.TraverseEntry("admin-menu-data-{}".format(id), label=model_admin.title, resource=model_admin, name="listing")
        data_menu.add_entry(entry)
Exemplo n.º 6
0
    def get_description(self, asset: Asset):

        factory = self.request.registry.queryUtility(IAssetDescriptionFactory, default=AssetDescription)
        asset_desc = factory(self.request, asset)

        assert asset.network == self.get_network()
        return Resource.make_lineage(self, asset_desc, AssetDescription.asset_to_slug(asset))
Exemplo n.º 7
0
def get_human_readable_resource_name(resource: Resource) -> str:
    """Extract human-readable name of the resource for breadcrumbs."""
    # TODO: Add adapter implementation here
    if hasattr(resource, "get_title"):
        return resource.get_title()
    if hasattr(resource, "title"):
        return resource.title
    return resource.__name__
Exemplo n.º 8
0
    def get_operations(self, state: Iterable):

        ops = self.wallet.user.owned_crypto_operations.join(
            CryptoOperation).filter(CryptoOperation.state.in_(state)).order_by(
                CryptoOperation.created_at.desc())
        for op in ops:
            uo = UserOperation(self.request, op)
            yield Resource.make_lineage(self, uo, uuid_to_slug(op.id))
Exemplo n.º 9
0
    def get_description(self, asset: Asset):

        factory = self.request.registry.queryUtility(IAssetDescriptionFactory,
                                                     default=AssetDescription)
        asset_desc = factory(self.request, asset)

        assert asset.network == self.get_network()
        return Resource.make_lineage(self, asset_desc,
                                     AssetDescription.asset_to_slug(asset))
Exemplo n.º 10
0
def contribute_model_admin(event):
    """Add model menus to the admin user interface."""

    admin = event.admin
    request = event.admin.request

    model_admin_root = ModelAdminRoot(request)
    Resource.make_lineage(admin, model_admin_root, "models")
    admin.children["models"] = model_admin_root

    # Create a model entries to menu
    data_menu = admin.get_admin_menu().get_entry("admin-menu-data").submenu
    for id, model_admin in model_admin_root.items():
        entry = menu.TraverseEntry("admin-menu-data-{}".format(id),
                                   label=model_admin.title,
                                   resource=model_admin,
                                   name="listing")
        data_menu.add_entry(entry)
Exemplo n.º 11
0
    def __init__(self,
                 request: Request,
                 network: AssetNetwork,
                 asset_count=None):
        super(NetworkDescription, self).__init__(request)
        self.network = network

        self.asset_folder = Resource.make_lineage(self, AssetFolder(request),
                                                  "assets")
        self.asset_count = asset_count
Exemplo n.º 12
0
    def get_operations(self, state: Iterable):

        ops = (
            self.wallet.user.owned_crypto_operations.join(CryptoOperation)
            .filter(CryptoOperation.state.in_(state))
            .order_by(CryptoOperation.created_at.desc())
        )
        for op in ops:
            uo = UserOperation(self.request, op)
            yield Resource.make_lineage(self, uo, uuid_to_slug(op.id))
Exemplo n.º 13
0
    def __getitem__(self, item):
        uuid = slug_to_uuid(item)
        uop = self.request.dbsession.query(UserCryptoOperation).get(uuid)

        if not uop:
            raise KeyError()

        if uop.user != self.wallet.user:
            raise httpexceptions.HTTPForbidden()

        return Resource.make_lineage(self, UserOperation(self.request, uop), uuid_to_slug(uop.id))
Exemplo n.º 14
0
def get_human_readable_resource_name(resource:Resource) -> str:
    """Extract human-readable name of the resource for breadcrumps."""

    # TODO: Add adapter implementation here

    if hasattr(resource, "get_title"):
        return resource.get_title()

    if hasattr(resource, "title"):
        return resource.title

    return resource.__name__
Exemplo n.º 15
0
    def __getitem__(self, item):
        uuid = slug_to_uuid(item)
        uop = self.request.dbsession.query(UserCryptoOperation).get(uuid)

        if not uop:
            raise KeyError()

        if uop.user != self.wallet.user:
            raise httpexceptions.HTTPForbidden()

        return Resource.make_lineage(self, UserOperation(self.request, uop),
                                     uuid_to_slug(uop.id))
Exemplo n.º 16
0
    def recurse_traversable(self, router: Router, route: Route, context: Resource):
        """Walk through traversable hierarchy.

        For each context iterate available views and add to sitemap.
        """

        if not self.has_public_view_acl(context):
            # This resource limits view permission to subgroup and is not public. E.g. /admin/*
            return

        # Add all views for this leaf
        for view_data in self.enumerate_available_views(route, context):
            if self.is_public_get_view(view_data) and self.is_included(view_data, context, self.request):
                self.add_traverse_item(context, view_data["name"])

        # Recurse to children
        if IContainer.providedBy(context):
            for name, child in context.items():
                self.recurse_traversable(router, route, child)
Exemplo n.º 17
0
    def recurse_traversable(self, router: Router, route: Route,
                            context: Resource):
        """Walk through traversable hierarchy.

        For each context iterate available views and add to sitemap.
        """

        if not self.has_public_view_acl(context):
            # This resource limits view permission to subgroup and is not public. E.g. /admin/*
            return

        # Add all views for this leaf
        for view_data in self.enumerate_available_views(route, context):
            if self.is_public_get_view(view_data):
                self.add_traverse_item(context, view_data["name"])

        # Recurse to children
        if IContainer.providedBy(context):
            for name, child in context.items():
                self.recurse_traversable(router, route, child)
Exemplo n.º 18
0
def container_factory(request):
    """Set up __parent__ and __name__ pointers required for traversal for container root."""
    container = SampleContainer(request, "Container folder")
    root = Root.root_factory(request)
    return Resource.make_lineage(root, container, "container")
Exemplo n.º 19
0
 def construct_child(child_id, resource: Resource):
     # Set __parent__ pointer
     resource = Resource.make_lineage(self, resource, child_id)
     return child_id, resource
Exemplo n.º 20
0
 def wrap_post(self, post: Post) -> "PostResource":
     """Convert raw SQLAlchemy Post instance to traverse and permission aware PostResource with its public URL."""
     res = PostResource(self.request, post)
     return Resource.make_lineage(self, res, post.slug)
Exemplo n.º 21
0
 def construct_child(child_id, resource: Resource):
     # Set __parent__ pointer
     resource = Resource.make_lineage(self, resource, child_id)
     return child_id, resource
Exemplo n.º 22
0
def container_factory(request):
    """Set up __parent__ and __name__ pointers required for traversal for container root."""
    container = SampleContainer(request, "Container folder")
    root = Root.root_factory(request)
    return Resource.make_lineage(root, container, "container")
Exemplo n.º 23
0
def route_factory(request):
    """Set up __parent__ and __name__ pointers required for traversal."""
    folder = NetworkFolder(request)
    root = Root.root_factory(request)
    return Resource.make_lineage(root, folder, "blockchain")
Exemplo n.º 24
0
 def get_addresses(self):
     addresses = self.user.owned_crypto_addresses
     for addr in addresses:
         ua = UserAddress(self.request, addr)
         yield Resource.make_lineage(self, ua, uuid_to_slug(addr.id))
Exemplo n.º 25
0
 def get_user_wallet(self, user):
     wallet = UserWallet(self.request, user)
     return Resource.make_lineage(self, wallet, uuid_to_slug(user.uuid))
Exemplo n.º 26
0
 def get_user_wallet(self, user):
     wallet = UserWallet(self.request, user)
     return Resource.make_lineage(self, wallet, uuid_to_slug(user.uuid))
Exemplo n.º 27
0
def route_factory(request):
    """Set up __parent__ and __name__ pointers required for traversal."""
    wallet_root = WalletFolder(request)
    root = Root.root_factory(request)
    return Resource.make_lineage(root, wallet_root, "wallet")
Exemplo n.º 28
0
 def get_user_address_asset(self, crypto_account: CryptoAddressAccount):
     uaa = UserAddressAsset(self.request, crypto_account)
     return Resource.make_lineage(self, uaa, uuid_to_slug(crypto_account.id))
Exemplo n.º 29
0
 def get_user_address_asset(self, crypto_account: CryptoAddressAccount):
     uaa = UserAddressAsset(self.request, crypto_account)
     return Resource.make_lineage(self, uaa,
                                  uuid_to_slug(crypto_account.id))
Exemplo n.º 30
0
 def get_addresses(self):
     addresses = self.user.owned_crypto_addresses
     for addr in addresses:
         ua = UserAddress(self.request, addr)
         yield Resource.make_lineage(self, ua, uuid_to_slug(addr.id))
Exemplo n.º 31
0
def blog_container_factory(request) -> BlogContainer:
    """Set up __parent__ and __name__ pointers for BlogContainer required for traversal."""
    folder = BlogContainer(request)
    root = Root.root_factory(request)
    return Resource.make_lineage(root, folder, "blog")
Exemplo n.º 32
0
 def get_description(self, network: AssetNetwork, asset_count=None):
     desc = NetworkDescription(self.request, network, asset_count)
     return Resource.make_lineage(self, desc, network.name)
Exemplo n.º 33
0
    def __init__(self, request: Request, network: AssetNetwork, asset_count=None):
        super(NetworkDescription, self).__init__(request)
        self.network = network

        self.asset_folder = Resource.make_lineage(self, AssetFolder(request), "assets")
        self.asset_count = asset_count
Exemplo n.º 34
0
def route_factory(request):
    """Set up __parent__ and __name__ pointers required for traversal."""
    folder = NetworkFolder(request)
    root = Root.root_factory(request)
    return Resource.make_lineage(root, folder, "blockchain")
Exemplo n.º 35
0
def route_factory(request):
    """Set up __parent__ and __name__ pointers required for traversal."""
    wallet_root = WalletFolder(request)
    root = Root.root_factory(request)
    return Resource.make_lineage(root, wallet_root, "wallet")
Exemplo n.º 36
0
 def get_description(self, network: AssetNetwork, asset_count=None):
     desc = NetworkDescription(self.request, network, asset_count)
     return Resource.make_lineage(self, desc, network.name)