Skip to content

Commit

Permalink
fixed expiration of session when auth is required, fixed utcnow for p…
Browse files Browse the repository at this point in the history
…y 3.13, formatting
  • Loading branch information
mdipierro committed Nov 12, 2024
1 parent 02bada9 commit 7b2e49e
Show file tree
Hide file tree
Showing 39 changed files with 272 additions and 241 deletions.
1 change: 0 additions & 1 deletion apps/_dashboard/diff2kryten.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys


# Note, when changing the Highlight.js css,
# the background color of .file .diff should match the
# background in the .hljs class in gitlog.min.css
Expand Down
9 changes: 4 additions & 5 deletions apps/_dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
---------------
"""

import glob
import gzip
import logging
import os
import re
import tarfile
import glob
import shutil
import logging
import gzip

import tarfile

__all__ = (
"safe_join",
Expand Down
4 changes: 3 additions & 1 deletion apps/_default/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
from py4web import action, Cache

from py4web import Cache, action

cache = Cache(size=1000)

@action("index")
Expand Down
2 changes: 1 addition & 1 deletion apps/_documentation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from py4web import action, redirect, URL
from py4web import URL, action, redirect


@action("index")
Expand Down
6 changes: 2 additions & 4 deletions apps/_scaffold/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

assert py4web.check_compatible("0.1.20190709.1")

# by importing controllers you expose the actions defined in it
from . import controllers
# by importing db you expose it to the _dashboard/dbadmin
from .models import db

# import the scheduler
from .tasks import scheduler

# by importing controllers you expose the actions defined in it
from . import controllers

# optional parameters
__version__ = "0.0.0"
__author__ = "you <[email protected]>"
Expand Down
23 changes: 14 additions & 9 deletions apps/_scaffold/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"""
import os
import sys
from py4web import Session, Cache, Translator, Flash, DAL, Field, action

from pydal.tools.scheduler import Scheduler
from pydal.tools.tags import Tags

from py4web import DAL, Cache, Field, Flash, Session, Translator, action
from py4web.server_adapters.logging_utils import make_logger
from py4web.utils.mailer import Mailer
from py4web.utils.auth import Auth
from py4web.utils.downloader import downloader
from pydal.tools.tags import Tags
from pydal.tools.scheduler import Scheduler
from py4web.utils.factories import ActionFactory
from py4web.utils.mailer import Mailer

from . import settings

# #######################################################
Expand Down Expand Up @@ -56,7 +59,9 @@
session = Session(secret=settings.SESSION_SECRET_KEY, storage=conn)

elif settings.SESSION_TYPE == "memcache":
import memcache, time
import time

import memcache

conn = memcache.Client(settings.MEMCACHE_CLIENTS, debug=0)
session = Session(secret=settings.SESSION_SECRET_KEY, storage=conn)
Expand Down Expand Up @@ -127,9 +132,8 @@
)

if settings.OAUTH2GOOGLE_SCOPED_CREDENTIALS_FILE:
from py4web.utils.auth_plugins.oauth2google_scoped import (
OAuth2GoogleScoped,
) # TESTED
from py4web.utils.auth_plugins.oauth2google_scoped import \
OAuth2GoogleScoped # TESTED

auth.register_plugin(
OAuth2GoogleScoped(
Expand All @@ -151,7 +155,8 @@
)

if settings.OAUTH2FACEBOOK_CLIENT_ID:
from py4web.utils.auth_plugins.oauth2facebook import OAuth2Facebook # UNTESTED
from py4web.utils.auth_plugins.oauth2facebook import \
OAuth2Facebook # UNTESTED

auth.register_plugin(
OAuth2Facebook(
Expand Down
17 changes: 5 additions & 12 deletions apps/_scaffold/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@
Warning: Fixtures MUST be declared with @action.uses({fixtures}) else your app will result in undefined behavior
"""

from py4web import action, request, abort, redirect, URL
from yatl.helpers import A
from .common import (
db,
session,
T,
cache,
auth,
logger,
authenticated,
unauthenticated,
flash,
)

from py4web import URL, abort, action, redirect, request

from .common import (T, auth, authenticated, cache, db, flash, logger, session,
unauthenticated)


@action("index")
Expand Down
3 changes: 2 additions & 1 deletion apps/_scaffold/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
This file defines the database models
"""

from .common import db, Field
from pydal.validators import *

from .common import Field, db

### Define your table below
#
# db.define_table('thing', Field('name'))
Expand Down
1 change: 1 addition & 0 deletions apps/_scaffold/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
This file is provided as an example:
"""
import os

from py4web.core import required_folder

# mode (default or development)
Expand Down
2 changes: 1 addition & 1 deletion apps/_scaffold/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .common import settings, scheduler
from .common import scheduler, settings
from .models import db

# #######################################################
Expand Down
5 changes: 2 additions & 3 deletions apps/fadebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

assert py4web.check_compatible("0.1.20190709.1")

# by importing db you expose it to the _dashboard/dbadmin
from .models import db

# by importing controllers you expose the actions defined in it
from . import controllers
# by importing db you expose it to the _dashboard/dbadmin
from .models import db

# optional parameters
__version__ = "0.0.0"
Expand Down
23 changes: 14 additions & 9 deletions apps/fadebook/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"""
import os
import sys
from py4web import Session, Cache, Translator, Flash, DAL, Field, action

from pydal.tools.scheduler import Scheduler
from pydal.tools.tags import Tags

from py4web import DAL, Cache, Field, Flash, Session, Translator, action
from py4web.server_adapters.logging_utils import make_logger
from py4web.utils.mailer import Mailer
from py4web.utils.auth import Auth
from py4web.utils.downloader import downloader
from pydal.tools.tags import Tags
from pydal.tools.scheduler import Scheduler
from py4web.utils.factories import ActionFactory
from py4web.utils.mailer import Mailer

from . import settings

# #######################################################
Expand Down Expand Up @@ -56,7 +59,9 @@
session = Session(secret=settings.SESSION_SECRET_KEY, storage=conn)

elif settings.SESSION_TYPE == "memcache":
import memcache, time
import time

import memcache

conn = memcache.Client(settings.MEMCACHE_CLIENTS, debug=0)
session = Session(secret=settings.SESSION_SECRET_KEY, storage=conn)
Expand Down Expand Up @@ -127,9 +132,8 @@
)

if settings.OAUTH2GOOGLE_SCOPED_CREDENTIALS_FILE:
from py4web.utils.auth_plugins.oauth2google_scoped import (
OAuth2GoogleScoped,
) # TESTED
from py4web.utils.auth_plugins.oauth2google_scoped import \
OAuth2GoogleScoped # TESTED

auth.register_plugin(
OAuth2GoogleScoped(
Expand All @@ -151,7 +155,8 @@
)

if settings.OAUTH2FACEBOOK_CLIENT_ID:
from py4web.utils.auth_plugins.oauth2facebook import OAuth2Facebook # UNTESTED
from py4web.utils.auth_plugins.oauth2facebook import \
OAuth2Facebook # UNTESTED

auth.register_plugin(
OAuth2Facebook(
Expand Down
5 changes: 3 additions & 2 deletions apps/fadebook/controllers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from py4web import action, redirect, URL, Field, HTTP
from py4web import HTTP, URL, Field, action, redirect
from py4web.utils.form import Form
from .common import flash, session, db, auth

from .common import auth, db, flash, session
from .make_up_data import make

#
Expand Down
3 changes: 2 additions & 1 deletion apps/fadebook/make_up_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

def make():
# prevent circular imports
from .common import db, action
from py4web.utils.populate import populate

from .common import action, db

if db(db.auth_user).count() == 1:
populate(db.auth_user, 10, contents={"is_active": True})
populate(db.feed_item, 100, contents={"is_active": True})
Expand Down
3 changes: 2 additions & 1 deletion apps/fadebook/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .common import *
from pydal.validators import IS_NOT_EMPTY

from .common import *

db.define_table(
"feed_item", Field("body", "text", requires=IS_NOT_EMPTY()), auth.signature
)
Expand Down
1 change: 1 addition & 0 deletions apps/fadebook/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
This file is provided as an example:
"""
import os

from py4web.core import required_folder

# mode (default or development)
Expand Down
12 changes: 6 additions & 6 deletions apps/showcase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
from .examples.page_with_redirect import page_with_redirect, target
from .examples.page_with_template import page_with_template
from .examples.page_without_template import page_without_template
from .examples.rest import rest
from .examples.rpc import rpc
from .examples.session_clear import session_clear
from .examples.session_counter import session_counter
from .examples.tagsinput_form import tagsinput_form
from .examples.rest import rest
from .examples.rpc import rpc
from .vue_components_examples.vue_file_uploader import vue_file_uploader
from .vue_components_examples.vue_grid import vue_grid
from .vue_components_examples.vue_star_rater import vue_star_rater
Expand All @@ -33,7 +33,6 @@
from .examples.auth_form import auth_form
from .examples.auth_forms import auth_forms
from .examples.create_form import create_form
from .examples.update_form import update_form
from .examples.custom_form import custom_form
from .examples.example_ajax_grid import example_ajax_grid
from .examples.example_html_grid import example_html_grid
Expand All @@ -43,11 +42,12 @@
from .examples.show_a_button import show_a_button
from .examples.socketio import index as socketio
from .examples.test_expose import test_expose1, test_expose2, test_expose3
from .vue_components_examples.vue_view_form import vue_view_form
from .vue_components_examples.vue_insert_form import vue_insert_form
from .examples.update_form import update_form
from .examples.ws import index as ws
from .vue_components_examples.vue_edit_form import vue_edit_form
from .vue_components_examples.vue_grid_and_forms import vue_grid_and_forms
from .examples.ws import index as ws
from .vue_components_examples.vue_insert_form import vue_insert_form
from .vue_components_examples.vue_view_form import vue_view_form


@action("index")
Expand Down
2 changes: 1 addition & 1 deletion apps/showcase/examples/example_html_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from yatl.helpers import A, I

from py4web import action, URL, redirect
from py4web import URL, action, redirect
from py4web.utils.form import FormStyleDefault
from py4web.utils.grid import Column, Grid, GridClassStyle

Expand Down
7 changes: 4 additions & 3 deletions apps/showcase/examples/rest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import uuid
import json
from py4web.core import action, request, response, Fixture
from .models import db, Field
import uuid

from py4web.core import Fixture, action, request, response

from .models import Field, db

# for demo purposes we create a table of tokens
# in practice you want to link them to users
Expand Down
3 changes: 2 additions & 1 deletion apps/showcase/examples/rpc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import requests

from py4web import action, request
from py4web.utils.jsonrpc import JsonRpc

import requests

# define a function you want to expose
def add(x, y):
Expand Down
5 changes: 2 additions & 3 deletions apps/tagged_posts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

assert py4web.check_compatible("0.1.20190709.1")

# by importing db you expose it to the _dashboard/dbadmin
from .models import db

# by importing controllers you expose the actions defined in it
from . import controllers
# by importing db you expose it to the _dashboard/dbadmin
from .models import db

# optional parameters
__version__ = "0.0.0"
Expand Down
Loading

0 comments on commit 7b2e49e

Please sign in to comment.