Skip to content

1.2.0.1a

Pre-release
Pre-release
Compare
Choose a tag to compare
@gaetan1903 gaetan1903 released this 16 Mar 04:13
· 11 commits to main since this release
0ef4841

Alpha version of Ampalibe 1.2.X

What's Changed

Migrate ampalibe to use asyncio instead of threading by @gaetan1903 in #91

You can now use an async/await for your function decorated by ampalibe if needed,

import ampalibe 
import asyncio

@amaplibe.command('/')
async def main(**ext):
  await asyncio.sleep(3)
  ...

Fix ampalibe batch command exiting on cmd by @rootkit7628 in #93

Add Admin Interface for ampalibe CRUD by @gaetan1903 in #92

You can enable admin interface for Ampalibe by adding ADMIN_ENABLE = 1 in your conf file.

You can create a database model using SQLModel

# -- file: model.py 
from datetime import datetime
from sqlmodel import Field, SQLModel


class AmpalibeUser(SQLModel, table=True):
    __tablename__: str = "amp_user"
    id: Optional[int] = Field(default=None, primary_key=True)
    user_id: str = Field(max_length=50, unique=True, nullable=False)
    action: Optional[str] = None
    last_use: datetime = Field(default=datetime.now(), nullable=False, index=True)
    lang: Optional[str] = Field(min_length=2, max_length=3)

And to make it accessible in the ADMIN interface, create a resource for it

# -- file: resource.Py
from sqladmin import ModelView
from models import AmpalibeUser
from ampalibe import __version__, __author__
from sqladmin import BaseView, expose

#  Declare here all class ofModelView or BaseView to put in Admin dahsboard

'''
Example CRUD for a table
'''

class UserAmpalibe(ModelView, model=AmpalibeUser):
    name = "Ampalibe User"
    icon = "fa-solid fa-user"
    column_list = [
        AmpalibeUser.user_id,
        AmpalibeUser.action,
        AmpalibeUser.last_use,
        AmpalibeUser.lang,
    ]
    can_create = True
    can_edit = True
    can_delete = False
    can_view_details = True

You can too create a custom page ADMIN panel by adding a resource like this model

class OtherView(BaseView):
    name = "Other Page"
    icon = "fa-solid fa-list-alt"

    @expose("/other", methods=["GET"])
    def other_page(self, request):
        return self.templates.TemplateResponse(
            "other.html",
            context={"request": request, "version": __version__, "author": __author__},
        )

where the html content is like this :

< !-- file: templates/other.html -->
{% extends "layout.html" %}
{% block content %}
    <div>
        <h1 style="text-align: center ;">
            Custom Admin Page for Ampalibe {{ version }} authored by {{ author }}
        </h1>
    </div>
{% endblock %}

- Introduce with async_download_file && async_simulate to avoid requests blocking

if you use download_file or simulate function it may issue a deadlock, use async_simulate/async_download_file instead

import ampalibe
from ampalibe import async_simulate as simulate
from ampalibe import async_download_file as download_file

@ampalibe.command('/)
async main(cmd, **ext):
   if cmd.webhook == 'attachment'
       await download_file(cmd)
       await simulate('/test')
   ...

Full Changelog: 1.1.8.LTS...1.2.0.1a