tesla-web


Nametesla-web JSON
Version 0.0.3.8 PyPI version JSON
download
home_page
SummaryA flexiable web framework
upload_time2023-01-06 01:10:57
maintainer
docs_urlNone
authorJafar idris
requires_python
license
keywords python web auth
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# tesla-web



Under construction! Not ready for use yet! Currently experimenting and planning!



Developed by Jafar Idris.



### Examples of How To Use (Buggy Alpha Version)



## Creating a project



```cmd

tesla startproject

```



it will prompt you to enter your project name, a folder will be created with that name navigate to the project folder.



## project structure 

```

[project_name]

     - core

         - settings.py

         - urls.py

     - manage.py

    

```

- ### settings.py

```python

from tesla.static import staticfiles

from tesla import TeslaApp



from tesla.admin.models import User

from tesla.admin import abs_path, register_collections

import os

from pathlib import Path as Pa



# Build paths inside the project like this: BASE_DIR / 'subdir'.

BASE_DIR = Pa(__file__).resolve().parent.parent 



TeslaApp.middlewares.set_middlewares([])



TeslaApp.auth_model = User



TeslaApp.templates_folders = [

    os.path.join(abs_path, 'templates'),    os.path.join(BASE_DIR, 'templates')

]



# Register models to Admin panel

register_collections(User)



staticfiles.paths = [ os.path.join(BASE_DIR, 'static'), os.path.join(abs_path, 'statics')]

        



```



- ### urls.py

```python



from tesla.router.url import Mount



from tesla.admin.urls import patterns as admin_urls



# map admin urls with the project 

Mount('/admin/', admin_urls, app_name='admin')



```





- Start server



to start Tesla web server, open your command prompt and run Belo code

```cmd

tesla serve [port]

```

port = 8000 by default



open your browser and navigate to the address display on your command line, you will see a 404 page because no route is specified



## Creating an Application



```cmd

tesla startapp

```



it will prompt you to enter your Application name, a folder will be created with that name navigate to the Application folder.



## Application structure

```

[app_name]

    - models.py

    - urls.py

    - views.py



```



- ### models.py

```python

from tesla.auth.modal import UserBaseModal

from tesla.modal import Model, CharField, ListField, TextField, EmailField, PasswordField,DateField



from dataclasses import dataclass



class User(UserBaseModal):

    

    username = CharField(min=4, max=10)

    email = EmailField(required=True)

    password = PasswordField(min=8, max=16, required=True)

    

    dob = DateField()

    bio = TextField()

    

    

    @classmethod

    def __meta__(self):

        

        return ('id', 'username', 'email')

```



- ### urls.py

```python

from tesla.router import Path

from . import views



# your urls path should be here

patterns = [

    Path('', views.index, name='index'),

    Path('login', views.login, name='login'),

    Path('logout', views.logout, name='logout'),

    Path('register', views.register, name='register'),

    Path('reset-password', views.reset_password, name='reset-password'),

    Path('collections', views.collections, name='collections'),

    Path('collections/{collection}/', views.collection, name='collection'),

    Path('collections/{collection}/new/', views.collection_new, name='collection_new'),

    Path('collections/{collection}/delete/', views.collection_del_all, name='collection_del_all'),

    Path('collections/{collection}/json/', views.collection_download, name='collection_download'),

    Path('collections/{collection}/{lookup}/', views.collection_obj, name='collection_obj'),

    Path('collections/{collection}/{lookup}/delete/', views.collection_del, name='collection_del')

]



```

---



- ### views.py

a view is a function that return instance of Response

example

```python

def login(request):

    

    if request.method == 'POST':

        u = request.post.get('username')

        p = request.post.get('password')

        user = User.get(username=u, password=p)

        if isinstance(user, User):

            user_login(request , user)

            return Redirect(request, 'admin:index')

    return Render(request, 'admin/login.html')



```

## What Tesla Web will consist



- [x] build-in Admin panel

- [x] build-in API provider ( for registered models )

- [ ] build-in Authentication mechanism 

- [ ] Documentation website 

- [ ] community 


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "tesla-web",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,web,auth",
    "author": "Jafar idris",
    "author_email": "<jafaridris82@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/50/9f/11893a3b505606818c883fffe3e2c67953bfa4b36c83899e8ac8d0027c9d/tesla@web-0.0.3.8.tar.gz",
    "platform": null,
    "description": "\r\n# tesla-web\r\n\r\n\r\n\r\nUnder construction! Not ready for use yet! Currently experimenting and planning!\r\n\r\n\r\n\r\nDeveloped by Jafar Idris.\r\n\r\n\r\n\r\n### Examples of How To Use (Buggy Alpha Version)\r\n\r\n\r\n\r\n## Creating a project\r\n\r\n\r\n\r\n```cmd\r\n\r\ntesla startproject\r\n\r\n```\r\n\r\n\r\n\r\nit will prompt you to enter your project name, a folder will be created with that name navigate to the project folder.\r\n\r\n\r\n\r\n## project structure \r\n\r\n```\r\n\r\n[project_name]\r\n\r\n     - core\r\n\r\n         - settings.py\r\n\r\n         - urls.py\r\n\r\n     - manage.py\r\n\r\n    \r\n\r\n```\r\n\r\n- ### settings.py\r\n\r\n```python\r\n\r\nfrom tesla.static import staticfiles\r\n\r\nfrom tesla import TeslaApp\r\n\r\n\r\n\r\nfrom tesla.admin.models import User\r\n\r\nfrom tesla.admin import abs_path, register_collections\r\n\r\nimport os\r\n\r\nfrom pathlib import Path as Pa\r\n\r\n\r\n\r\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\r\n\r\nBASE_DIR = Pa(__file__).resolve().parent.parent \r\n\r\n\r\n\r\nTeslaApp.middlewares.set_middlewares([])\r\n\r\n\r\n\r\nTeslaApp.auth_model = User\r\n\r\n\r\n\r\nTeslaApp.templates_folders = [\r\n\r\n    os.path.join(abs_path, 'templates'),    os.path.join(BASE_DIR, 'templates')\r\n\r\n]\r\n\r\n\r\n\r\n# Register models to Admin panel\r\n\r\nregister_collections(User)\r\n\r\n\r\n\r\nstaticfiles.paths = [ os.path.join(BASE_DIR, 'static'), os.path.join(abs_path, 'statics')]\r\n\r\n        \r\n\r\n\r\n\r\n```\r\n\r\n\r\n\r\n- ### urls.py\r\n\r\n```python\r\n\r\n\r\n\r\nfrom tesla.router.url import Mount\r\n\r\n\r\n\r\nfrom tesla.admin.urls import patterns as admin_urls\r\n\r\n\r\n\r\n# map admin urls with the project \r\n\r\nMount('/admin/', admin_urls, app_name='admin')\r\n\r\n\r\n\r\n```\r\n\r\n\r\n\r\n\r\n\r\n- Start server\r\n\r\n\r\n\r\nto start Tesla web server, open your command prompt and run Belo code\r\n\r\n```cmd\r\n\r\ntesla serve [port]\r\n\r\n```\r\n\r\nport = 8000 by default\r\n\r\n\r\n\r\nopen your browser and navigate to the address display on your command line, you will see a 404 page because no route is specified\r\n\r\n\r\n\r\n## Creating an Application\r\n\r\n\r\n\r\n```cmd\r\n\r\ntesla startapp\r\n\r\n```\r\n\r\n\r\n\r\nit will prompt you to enter your Application name, a folder will be created with that name navigate to the Application folder.\r\n\r\n\r\n\r\n## Application structure\r\n\r\n```\r\n\r\n[app_name]\r\n\r\n    - models.py\r\n\r\n    - urls.py\r\n\r\n    - views.py\r\n\r\n\r\n\r\n```\r\n\r\n\r\n\r\n- ### models.py\r\n\r\n```python\r\n\r\nfrom tesla.auth.modal import UserBaseModal\r\n\r\nfrom tesla.modal import Model, CharField, ListField, TextField, EmailField, PasswordField,DateField\r\n\r\n\r\n\r\nfrom dataclasses import dataclass\r\n\r\n\r\n\r\nclass User(UserBaseModal):\r\n\r\n    \r\n\r\n    username = CharField(min=4, max=10)\r\n\r\n    email = EmailField(required=True)\r\n\r\n    password = PasswordField(min=8, max=16, required=True)\r\n\r\n    \r\n\r\n    dob = DateField()\r\n\r\n    bio = TextField()\r\n\r\n    \r\n\r\n    \r\n\r\n    @classmethod\r\n\r\n    def __meta__(self):\r\n\r\n        \r\n\r\n        return ('id', 'username', 'email')\r\n\r\n```\r\n\r\n\r\n\r\n- ### urls.py\r\n\r\n```python\r\n\r\nfrom tesla.router import Path\r\n\r\nfrom . import views\r\n\r\n\r\n\r\n# your urls path should be here\r\n\r\npatterns = [\r\n\r\n    Path('', views.index, name='index'),\r\n\r\n    Path('login', views.login, name='login'),\r\n\r\n    Path('logout', views.logout, name='logout'),\r\n\r\n    Path('register', views.register, name='register'),\r\n\r\n    Path('reset-password', views.reset_password, name='reset-password'),\r\n\r\n    Path('collections', views.collections, name='collections'),\r\n\r\n    Path('collections/{collection}/', views.collection, name='collection'),\r\n\r\n    Path('collections/{collection}/new/', views.collection_new, name='collection_new'),\r\n\r\n    Path('collections/{collection}/delete/', views.collection_del_all, name='collection_del_all'),\r\n\r\n    Path('collections/{collection}/json/', views.collection_download, name='collection_download'),\r\n\r\n    Path('collections/{collection}/{lookup}/', views.collection_obj, name='collection_obj'),\r\n\r\n    Path('collections/{collection}/{lookup}/delete/', views.collection_del, name='collection_del')\r\n\r\n]\r\n\r\n\r\n\r\n```\r\n\r\n---\r\n\r\n\r\n\r\n- ### views.py\r\n\r\na view is a function that return instance of Response\r\n\r\nexample\r\n\r\n```python\r\n\r\ndef login(request):\r\n\r\n    \r\n\r\n    if request.method == 'POST':\r\n\r\n        u = request.post.get('username')\r\n\r\n        p = request.post.get('password')\r\n\r\n        user = User.get(username=u, password=p)\r\n\r\n        if isinstance(user, User):\r\n\r\n            user_login(request , user)\r\n\r\n            return Redirect(request, 'admin:index')\r\n\r\n    return Render(request, 'admin/login.html')\r\n\r\n\r\n\r\n```\r\n\r\n## What Tesla Web will consist\r\n\r\n\r\n\r\n- [x] build-in Admin panel\r\n\r\n- [x] build-in API provider ( for registered models )\r\n\r\n- [ ] build-in Authentication mechanism \r\n\r\n- [ ] Documentation website \r\n\r\n- [ ] community \r\n\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A flexiable web framework",
    "version": "0.0.3.8",
    "split_keywords": [
        "python",
        "web",
        "auth"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fb84d8c8e63affdcf3bb559df9a97fcb896d0348a8e386dfb77d48237078179c",
                "md5": "0b20892fb07ca7494ff8ed02f4ff728a",
                "sha256": "da4cea2c848f9f7d4d8b8154f07fb8ece963ebf91860224b5475f580145e04f7"
            },
            "downloads": -1,
            "filename": "tesla_web-0.0.3.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0b20892fb07ca7494ff8ed02f4ff728a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 1968617,
            "upload_time": "2023-01-06T01:10:44",
            "upload_time_iso_8601": "2023-01-06T01:10:44.863516Z",
            "url": "https://files.pythonhosted.org/packages/fb/84/d8c8e63affdcf3bb559df9a97fcb896d0348a8e386dfb77d48237078179c/tesla_web-0.0.3.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "509f11893a3b505606818c883fffe3e2c67953bfa4b36c83899e8ac8d0027c9d",
                "md5": "ea6efe4b581e2354ea437b934ad2d398",
                "sha256": "fe97f2734085ca99e40def8c7b48c07db6b42c3002bb355171641ed2d00d1029"
            },
            "downloads": -1,
            "filename": "tesla@web-0.0.3.8.tar.gz",
            "has_sig": false,
            "md5_digest": "ea6efe4b581e2354ea437b934ad2d398",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 61306,
            "upload_time": "2023-01-06T01:10:57",
            "upload_time_iso_8601": "2023-01-06T01:10:57.550447Z",
            "url": "https://files.pythonhosted.org/packages/50/9f/11893a3b505606818c883fffe3e2c67953bfa4b36c83899e8ac8d0027c9d/tesla@web-0.0.3.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-06 01:10:57",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "tesla-web"
}
        
Elapsed time: 0.02699s