Skip to main content

A flexiable web framework

Project description

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

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

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

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

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

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

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

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

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

  • build-in Admin panel

  • build-in API provider ( for registered models )

  • build-in Authentication mechanism

  • Documentation website

  • community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tesla@web-0.0.3.8.tar.gz (61.3 kB view details)

Uploaded Source

Built Distribution

tesla_web-0.0.3.8-py3-none-any.whl (2.0 MB view details)

Uploaded Python 3

File details

Details for the file tesla@web-0.0.3.8.tar.gz.

File metadata

  • Download URL: tesla@web-0.0.3.8.tar.gz
  • Upload date:
  • Size: 61.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.2

File hashes

Hashes for tesla@web-0.0.3.8.tar.gz
Algorithm Hash digest
SHA256 fe97f2734085ca99e40def8c7b48c07db6b42c3002bb355171641ed2d00d1029
MD5 ea6efe4b581e2354ea437b934ad2d398
BLAKE2b-256 509f11893a3b505606818c883fffe3e2c67953bfa4b36c83899e8ac8d0027c9d

See more details on using hashes here.

File details

Details for the file tesla_web-0.0.3.8-py3-none-any.whl.

File metadata

  • Download URL: tesla_web-0.0.3.8-py3-none-any.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.2

File hashes

Hashes for tesla_web-0.0.3.8-py3-none-any.whl
Algorithm Hash digest
SHA256 da4cea2c848f9f7d4d8b8154f07fb8ece963ebf91860224b5475f580145e04f7
MD5 0b20892fb07ca7494ff8ed02f4ff728a
BLAKE2b-256 fb84d8c8e63affdcf3bb559df9a97fcb896d0348a8e386dfb77d48237078179c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page