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@web2-0.0.1.tar.gz (63.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tesla_web2-0.0.1-py3-none-any.whl (79.2 kB view details)

Uploaded Python 3

File details

Details for the file tesla@web2-0.0.1.tar.gz.

File metadata

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

File hashes

Hashes for tesla@web2-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2970c911fee0371f105cc2e187ac03a89572a4062ca9e0be9e76c4d84439490f
MD5 0d3878a49f658ac1b5d4bc800b5ae57e
BLAKE2b-256 465e8c26f374650ef13b10e5d06e4a83e4b66f3011d47fea5035b57cfd4e9354

See more details on using hashes here.

File details

Details for the file tesla_web2-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: tesla_web2-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 79.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.2

File hashes

Hashes for tesla_web2-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c950afe3506b200fb17f7ec1e3aba13f3b55ee9dc0eeb2edfa9cec59f967309f
MD5 e6b0ddfe4925e0243032a9cc66fbc3a2
BLAKE2b-256 7af394f78bf508a86affd5c352f0fd50d6c338664c5e3b3cb45951907bb11166

See more details on using hashes here.

Supported by

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