Beispiel #1
0
 def __init__(self,
              path,
              session,
              search_placeholder=None,
              signer=None,
              db=None,
              auth=None):
     """
     Displays a grid.
     :param path: Path where the grid is loaded via AJAX.
     :param session: used by the signer.
     :param signer: singer for URLs.
     :param db: specify a db if you need it added as widget.
     :param auth: specify auth if you need it added as widget.
     """
     self.path = path
     self.search_placeholder = search_placeholder
     self.signer = signer or URLSigner(session)
     # Creates an action (an entry point for URL calls),
     # mapped to the api method, that can be used to request pages
     # for the table.
     self.__prerequisites__ = [session]
     args = list(filter(None, [session, db, auth, self.signer.verify()]))
     f = action.uses(*args)(self.api)
     action(self.path, method=["GET"])(f)
Beispiel #2
0
    def __init__(self, url, session, signer=None, db=None, auth=None):
        self.get_url = url + '/get'
        self.add_url = url + '/add'
        self.edit_url = url + '/edit'
        self.delete_url = url + '/delete'
        self.signer = signer or URLSigner(session)
        self.db = db
        self.auth = auth

        # creates actions (entry points of the calls)
        # same as decorators but registered on object creation
        # very similar to Luca's old component creation
        self.__prerequisites__ = [session]
        args = list(filter(None, [session, db, auth, self.signer.verify()]))

        # function definition
        f = action.uses(*args)(self.get_comments)
        action(self.get_url + "/<id>", method=["GET"])(f)

        f = action.uses(*args)(self.add_comment)
        action(self.add_url, method=["POST"])(f)

        f = action.uses(*args)(self.edit_comment)
        action(self.edit_url, method=["POST"])(f)

        f = action.uses(*args)(self.delete_comment)
        action(self.delete_url, method=["POST"])(f)
Beispiel #3
0
 def __init__(self, path, session, fields_or_table,
              redirect_url=None, readonly=False, signer=None,
              db=None, auth=None, url_params=None,
              validate=None):
     """fields_or_table is a list of Fields from DAL, or a table.
     If a table is passed, the fields that are marked writable
     (or readable, if readonly=True) are included.
     session is used to sign the URLs.
     The other parameters are optional, and are used only
     if they will be needed to process the get and post metods.
     @param path: path used for form GET/POST
     @param session: session, used to validate access and sign.
     @param fields_or_table: list of Field for a database table, or table itself.
     @param redirect_url: redirect URL after success.
     @param readonly: If true, the form is readonly.
     @param signer: signer for URLs, or else, a new signer is created.
     @param db: database.  Used by implementation.
     @param auth: auth.  Used by implementation.
     @param url_params: parameters for AJAX URLs.
     @param validate: A function that takes as arguments the dictionary of
         fields, and performs any desired extra validation.  If an error is
         set, then the form is not acted upon, and the error is shown to the user.
     """
     self.path_form = path + '/form'
     self.path_check = path + '/check'
     self.redirect_url = redirect_url
     self.db = db
     self.__prerequisites__ = [session]
     self.signer = signer or URLSigner(session)
     self.validate = validate
     # Creates entry points for giving the blank form, and processing form submissions.
     # There are three entry points:
     # - Form setup GET: This gets how the form is set up, including the types of the fields.
     # - Form GET: This gets the values of the fields.
     # - Form PUT: This gives the values of the fields, and performs whatever
     #   action needs to be peformed.
     # This division is done so that the GET and PUT action, but not the setup_GET,
     # need to be over-ridden when the class is subclassed.
     url_params = url_params or []
     # NOTE: we need a list below, as the iterator otherwise can be used only once.
     # Iterators by default are a very lame idea indeed.
     args = list(filter(None, [session, db, auth, self.signer.verify()]))
     f = action.uses(*args)(self.get)
     action('/'.join([self.path_form] + url_params), method=["GET"])(f)
     f = action.uses(*args)(self.post)
     action('/'.join([self.path_form] + url_params), method=["POST"])(f)
     f = action.uses(*args)(self.validate_field)
     action('/'.join([self.path_check] + url_params), method=["POST"])(f)
     # Stores the parameters that are necessary for creating the form.
     # Generates the list of field descriptions.
     self.readonly = readonly
     self.fields = collections.OrderedDict()
     for field in fields_or_table:
         self.fields[field.name] = dict(
             field=field, # Field in the form specification.
             error=None,  # Any error found.
             value=None,
             validated_value=None,
         )
Beispiel #4
0
 def __init__(self, url, session, signer=None, db=None, auth=None, dumpDir="dump"):
     self.dumpDir = dumpDir
     self.url = url
     self.signer = signer or URLSigner(session)
     self.__prerequisites__ = [session]
     args = list(filter(None, [session, db, auth, self.signer.verify()]))
     f = action.uses(*args)(self.api)
     action(self.url + "/<id>", method=["POST"])(f)
Beispiel #5
0
 def __init__(self, path, session, signer=None, db=None, auth=None):
     self.path = path
     self.signer = signer or URLSigner(session)
     # Creates an action (an entry point for URL calls),
     # mapped to the api method, that can be used to request pages
     # for the table.
     self.__prerequisites__ = [session]
     args = list(filter(None, [session, db, auth, self.signer.verify()]))
     f = action.uses(*args)(self.api)
     action(self.path + "/<id>", method=["POST"])(f)
    def __init__(self, url, session, signer=None, db=None, auth=None):
        self.url = url + '/get'
        self.callback_url = url + '/set'
        self.signer = signer or URLSigner(session)

        self.__prerequisites__ = [session]
        args = list(filter(None, [session, db, auth, self.signer.verify()]))
        func = action.uses(*args)(self.get_rating)
        action(self.url + '/<id>', method=['GET'])(func)
        func = action.uses(*args)(self.set_rating)
        action(self.callback_url + '/<id>', method=["GET"])(func)
Beispiel #7
0
 def __init__(self, url, session, signer=None, db=None, auth=None):
     self.url = url + '/get'
     self.callback_url = url + '/set'
     self.signer = signer or URLSigner(session)
     # Creates an action (an entry point for URL calls),
     # mapped to the api method, that can be used to request pages
     # for the table.
     self.__prerequisites__ = [session]
     args = list(filter(None, [session, db, auth, self.signer.verify()]))
     f = action.uses(*args)(self.get_rating)
     action(self.url + "/<id>", method=["GET"])(f)
     f = action.uses(*args)(self.set_rating)
     action(self.callback_url + "/<id>", method=["GET"])(f)
    def __init__(self, url, session, signer=None, db=None, auth=None):
        self.base_url = url
        self.db = db
        self.__prerequisites__ = [session]
        self.signer = signer or URLSigner(session)
        self.args = list(
            filter(None,
                   [session, db, auth, self.signer.verify()]))

        self.define_urls()

        self.create_route(self.get_posts_url, self.get_posts, "GET")
        self.create_route(self.get_about_url, self.get_about, "GET")
        self.create_route(self.delete_all_posts_url, self.delete_all_posts,
                          "GET")
        self.create_route(self.create_post_url, self.create_post, "POST")
Beispiel #9
0
 def __init__(self, path, session, signer=None, db=None, auth=None):
     """
     :param path: path at which the star rating does the AJAX calls
     :param session: session, used to validate access and sign.
     :param signer: A URL signer, or else one is created.
     :param db: Used in case db should be one of the widgets.
     :param auth: Used in case auth should be one of the widgets.
     """
     self.path = path
     self.signer = signer or URLSigner(session)
     # Creates an action (an entry point for URL calls),
     # mapped to the api method, that can be used to request pages
     # for the table.
     self.__prerequisites__ = [session]
     args = list(filter(None, [session, db, auth, self.signer.verify()]))
     f = action.uses(*args)(self.get_stars)
     action(self.path + "/<id>", method=["GET"])(f)
     f = action.uses(*args)(self.set_stars)
     action(self.path + "/<id>", method=["POST"])(f)
Beispiel #10
0
 def __init__(
     self,
     path,
     session,
     use_id=False,
     search_placeholder=None,
     signer=None,
     db=None,
     sort_fields=None,
     default_sort=None,
     auth=None,
     page_size=20,
 ):
     """
     Displays a grid.
     :param path: Path where the grid is loaded via AJAX.
     :param session: used by the signer.
     :param signer: singer for URLs.
     :param use_id: does the AJAX call come with an id?
     :param db: specify a db if you need it added as widget.
     :param sort_fields: list of fields that are sortable.  If a
         field is not sortable, use None.  E.g.:
         [db.user.name, None, db.user.email]
     :param default_sort: array that indicates the default sorting order.
     :param auth: specify auth if you need it added as widget.
     """
     assert session is not None, "You must provide a session."
     self.path = path
     self.search_placeholder = search_placeholder
     self.signer = signer or URLSigner(session)
     # Creates an action (an entry point for URL calls),
     # mapped to the api method, that can be used to request pages
     # for the table.
     self.use_id = use_id
     self.__prerequisites__ = [self.signer]
     args = list(filter(None, [session, db, auth, self.signer.verify()]))
     f = action.uses(*args)(self.api)
     p = "/".join([self.path, "<id>"]) if use_id else self.path
     action(p, method=["GET"])(f)
     # Some defaults.  Over-ride them in subclasses.
     self.sort_fields = sort_fields
     self.default_sort = default_sort
     self.page_size = page_size
    def __init__(self, url, session, signer=None, db=None, auth=None):
        self.url = url
        self.signer = signer or URLSigner(session)
        self.db = db
        self.auth = auth

        self.get_notes_url = url
        self.add_notes_url = url + "/new"
        self.save_notes_url = url + "/edit"
        self.delete_notes_url = url + "/delete"

        self.__prerequisites__ = [session]
        args = list(filter(
            None, [session, db, auth, self.signer.verify()]))

        self.define_routes(args, ["GET"], self.get_notes_url, self.get_notes)
        self.define_routes(args, ["GET"], self.add_notes_url, self.add_notes)
        self.define_routes(args, ["POST"], self.save_notes_url,
                           self.save_notes)
        self.define_routes(args, ["POST"], self.delete_notes_url,
                           self.delete_notes)
    def __init__(self, url, session, signer=None, db=None, auth=None):

        # Creating generic get/set URLS
        self.url = url + '/get'

        self.callback_url = url + '/set'

        # Setting URL Signer
        self.signer = signer or URLSigner(session)

        #
        self.__prerequisites__ = [session]

        # Set each element to None in args
        args = list(filter(None, [session, db, auth, self.signer.verify()]))

        # *var in a function call unpacks a list or tuple into positional arguments
        # Gets the rating from database based on id

        # Equivalent of:
        # @action('url/<id>', method=["GET"])
        # @action.uses(session, db, auth, signer.verify())
        # def get_thumb():

        f = action.uses(*args)(self.get_rating)
        action(self.url + "/<id>", method=["GET"])(f)

        # Sets/Updates the rating in database based on id

        # Equivalent of:
        # @action('callback_url</id>', method=["GET"])
        # @action.uses(session, db, auth, signer.verify())
        # def set_thumb():

        f = action.uses(*args)(self.set_rating)
        action(self.callback_url + "/<id>", method=["GET"])(f)
Beispiel #13
0
session, db, T, auth, and tempates are examples of Fixtures.
Warning: Fixtures MUST be declared with @action.uses({fixtures}) else your app will result in undefined behavior
"""

import uuid

from py4web import action, request, abort, redirect, URL, Field
from py4web.utils.form import Form, FormStyleBulma
from py4web.utils.url_signer import URLSigner

from yatl.helpers import A

from .common import db, session, T, cache, auth, signed_url
from pydal.validators import *

url_signer = URLSigner(session)


# The auth.user below forces login.
@action('index', method='GET')
@action.uses(db, session, auth.user, 'index.html')
def index():
    user = auth.get_user()
    rows = db(db.person.user_email == auth.current_user.get(
        'email')).select().as_list()
    for row in rows:
        # get phone numbers associated with contact person
        sub_rows = db(db.phone.person_id == row.get('id')).select().as_list()
        s = ""
        count = 0
        # construct string & assign to row
import datetime
import uuid

from py4web import action, request, abort, redirect, URL, Field
from py4web.utils.form import Form, FormStyleBulma
from py4web.utils.url_signer import URLSigner
from pydal.validators import *

from yatl.helpers import A
from .common import db, session, T, cache, auth
from .components.grid import Grid
from .components.vueform import VueForm, InsertForm, TableForm
from .components.fileupload import FileUpload
from .components.starrater import StarRater

signed_url = URLSigner(session)

# -----------------------------
# Sample grid.

vue_grid = Grid("grid_api", session)


@action("vuegrid", method=["GET"])
@action.uses(vue_grid, "vuegrid.html")
def vuegrid():
    """This page generates a sample grid."""
    # We need to instantiate our grid component.
    return dict(grid=vue_grid())

Beispiel #15
0
"""
import time

import uuid
import random

from yatl.helpers import A
from .models import get_user_email, get_user

from pydal.validators import *
from py4web.utils.url_signer import URLSigner
from py4web.utils.form import Form, FormStyleBulma
from py4web import action, request, abort, redirect, URL
from .common import db, session, T, cache, auth, logger, authenticated, unauthenticated, flash, Field

url_signer = URLSigner(session)


@action('search_recipes')
@action.uses(db)
def search_recipes():
    """
    Returns a list of all the shared recipes which have a title containing
    the search query and which are tagged with all of the tag filters bring used
    in the search.
    """

    query = request.params.get("q")
    tag = request.params.get("t")

    tag = [] if tag is None or tag == '' else tag.split(',')
Beispiel #16
0
        "id": 4,
        "content": "I love tomatoes",
        "author": "Olga Kabarova",
        "email": "*****@*****.**",
        "is_reply": None,  # Main post.  Followed by its replies if any.
    },
    {
        "id": 5,
        "content": "I prefer nuts",
        "author": "Hao Wang",
        "email": "*****@*****.**",
        "is_reply": 4,
    },
]

url_signer = URLSigner(session)


def get_name_from_email(e):
    """Given the email of a user, returns the name."""
    u = db(db.auth_user.email == e).select().first()
    return "" if u is None else u.first_name + " " + u.last_name


# The auth.user below forces login.
@action('index')
@action.uses(auth.user, url_signer, session, db, 'index.html')
def index():
    return dict(
        # This is an example of a signed URL for the callback.
        # See the index.html template for how this is passed to the javascript.
Beispiel #17
0
@action.uses(db)              indicates that the action uses the db
@action.uses(T)               indicates that the action uses the i18n & pluralization
@action.uses(auth.user)       indicates that the action requires a logged in user
@action.uses(auth)            indicates that the action requires the auth object

session, db, T, auth, and tempates are examples of Fixtures.
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.utils.url_signer import URLSigner
from .models import get_user_email

url_signer = URLSigner(session)


############################# HOME AND PROFILE FUNCTIONS ###########################
@action('index')
@action.uses(auth.user, url_signer, db, 'index.html')
def index():
    print("looking good so far")
    user_info = db(db.auth_user.email == get_user_email()).select().first()
    profile_info = db(db.profiles.user == user_info.id).select().first()
    return dict(
        # COMPLETE: return here any signed URLs you need.
        my_callback_url=URL('my_callback', signer=url_signer),
        profile_info=profile_info,
    )
session, db, T, auth, and tempates are examples of Fixtures.
Warning: Fixtures MUST be declared with @action.uses({fixtures}) else your app will result in undefined behavior
"""

import uuid

from py4web import action, request, abort, redirect, URL, Field
from py4web.utils.form import Form, FormStyleBulma
from py4web.utils.url_signer import URLSigner

from yatl.helpers import A
from . common import db, session, T, cache, auth, signed_url


url_signer = URLSigner(session)

# The auth.user below forces login.
@action('index')
@action.uses('index.html', auth.user, db, session)
def index():
    user = auth.current_user.get('email')
    
    rows = db(db.person.user_email == user).select().as_list()
    # rows = db().select().as_list()
    #onc as list, must use brackets
    for index, row in enumerate(rows):
        person_id = row["id"]
        phone_numbers = db(db.phone.person_id == person_id).select().as_list()
        formatted_nums = ""
        for index2, phone_number in enumerate(phone_numbers):
Beispiel #19
0
@action.uses(auth)            indicates that the action requires the auth object

session, db, T, auth, and tempates are examples of Fixtures.
Warning: Fixtures MUST be declared with @action.uses({fixtures}) else your app will result in undefined behavior
"""

import uuid

from py4web import action, request, abort, redirect, URL, Field
from py4web.utils.form import Form, FormStyleBulma
from py4web.utils.url_signer import URLSigner

from yatl.helpers import A
from .common import db, session, T, cache, auth, signed_url

url_signer = URLSigner(session)


@action('index')
@action.uses('index.html', auth.user, db, session, url_signer)
def view_contacts():
    rows = db(db.contact.user_email == auth.current_user.get('email')).select()
    for row in rows:
        phones = db(db.phone_number.contact_id == row.id).select()
        nicestring = ''
        for phone in phones:
            nicestring = nicestring + phone.phone_number + " (" + phone.type + "), "
        row['phone_number'] = nicestring[:-2]
    return dict(rows=rows, url_signer=url_signer)

Beispiel #20
0
import datetime
import json
import os
import traceback
import uuid
import math
from nqgcs import NQGCS

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.utils.url_signer import URLSigner
from .settings import APP_FOLDER
from .gcs_url import gcs_url

url_signer = URLSigner(session)

BUCKET = '/witr-uploads'
# GCS keys.  You have to create them for this to work.  See README.md
GCS_KEY_PATH = os.path.join(APP_FOLDER, 'private/witr_keys.json')
with open(GCS_KEY_PATH) as gcs_key_f:
    GCS_KEYS = json.load(gcs_key_f)

# I create a handle to gcs, to perform the various operations.
gcs = NQGCS(json_key_path=GCS_KEY_PATH)


@action('index')
@action.uses(db, auth, url_signer, 'index.html')
def index():
    user = auth.get_user() or redirect(URL('auth/login'))
Beispiel #21
0
import datetime
import uuid

from py4web import action, request, abort, redirect, URL, Field
from py4web.utils.form import Form, FormStyleBulma
from py4web.utils.url_signer import URLSigner
from pydal.validators import *

from yatl.helpers import A
from .common import db, session, T, cache, auth
from .components.grid import Grid
from .components.vueform import VueForm, InsertForm, TableForm
from .components.fileupload import FileUpload
from .components.starrater import StarRater

signed_url = URLSigner(session, lifespan=3600)

# -----------------------------
# Sample grid.

vue_grid = Grid("grid_api", session)


@action("vuegrid", method=["GET"])
@action.uses(vue_grid, "vuegrid.html")
def vuegrid():
    """This page generates a sample grid."""
    # We need to instantiate our grid component.
    return dict(grid=vue_grid())

Beispiel #22
0
@action.uses(auth.user)       indicates that the action requires a logged in user
@action.uses(auth)            indicates that the action requires the auth object

session, db, T, auth, and tempates are examples of Fixtures.
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.utils.url_signer import URLSigner
from .models import get_user_email
from py4web.utils.form import Form, FormStyleBulma
from .common import Field

url_signer = URLSigner(session)

# /add_contact work, along with /edit_contact and /delete_contact.

@action('index')
@action.uses(db, auth.user, 'index.html')
def index():
    print("User:"******"354242 (Home), 34343423 (Vacation)" for the contact.  
        s = ""
        phone_row = db(db.phone.contact_id == row["id"]).select()
Beispiel #23
0
@action.uses(auth)            indicates that the action requires the auth object

session, db, T, auth, and tempates are examples of Fixtures.
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, Field
from py4web.utils.url_signer import URLSigner
from .models import get_user_email, get_user_username, get_user_id, get_time
from py4web.utils.form import Form, FormStyleBulma
from pydal.validators import *
import bisect

url_signer = URLSigner(session)


@action('index')
@action.uses(db, auth.user, 'index.html')
def index():
    user = auth.get_user()
    db.profile.update_or_insert(
        user_id=user["id"])  #creates empty profile on first login
    songs = db(db.song.name).select(orderby=~db.song.time_added)
    #need to somehow pull the band name here as well
    user = auth.get_user()
    message = T("Hello {first_name}".format(**user) if user else "Hello")
    return dict(message=message, songs=songs, band=band)