Skip to content

Instantly share code, notes, and snippets.

View thomaxxl's full-sized avatar

Thomas Pollet thomaxxl

View GitHub Profile
"""
System support for login / authentication.
Applications POST to login to obtain an access token,
which they provide in the header of subsequent requests.
e.g.
def login():
post_uri = 'http://localhost:5656/api/authentication-User/login'
post_data = {"username": "_user_","password": "_password_"}
#!/usr/bin/env python
# run:
# $ FLASK_APP=mini_app flask run
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from safrs import SAFRSBase, SAFRSAPI
db = SQLAlchemy()
#!/usr/bin/env python
# run:
# $ FLASK_APP=mini_app flask run
from flask import Flask, request
from flask_sqlalchemy import SQLAlchemy
from safrs import SAFRSBase, SAFRSAPI
db = SQLAlchemy()
def post_hook(func):
{
"api_root": "//thomaxxl.pythonanywhere.com/api",
"resources": {
"People": {
"type": "Person",
"search_cols": [
"name"
],
"user_key": "name",
"columns": [
"""
SAFRS example calling a postgres TVF.
Suppose the database has this function defined:
---
CREATE FUNCTION public.f_2(v1 integer, OUT v2 integer, OUT v3 integer) RETURNS record
LANGUAGE plpgsql
AS $$
@thomaxxl
thomaxxl / ja.py
Last active March 16, 2021 11:36
#!/usr/bin/env python
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from safrs import SAFRSBase, SAFRSAPI, jsonapi_attr
db = SQLAlchemy()
class User(SAFRSBase, db.Model):
#!/usr/bin/env python
# run:
# $ FLASK_APP=mini_app flask run
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from safrs import SAFRSBase, SAFRSAPI, jsonapi_rpc
import datetime
db = SQLAlchemy()
@thomaxxl
thomaxxl / geo1.py
Last active January 20, 2021 09:46
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import func
from geoalchemy2 import Geometry
from flask_sqlalchemy import SQLAlchemy
from safrs import SAFRSBase, SAFRSAPI
from flask.json import JSONEncoder
from flask import jsonify
import shapely_geojson
from safrs.json_encoder import SAFRSJSONEncoder
import React from 'react'
class JAObject {
constructor(id, attributes, relationships){
this.id = id // todo: check if the object with this id already exists in the redux store or the backend API
this._attributes = attributes // this contains both attributes and relationships
// TODO: add to redux store and save to jsonapi-backend
for(let attr_name of Object.keys(attributes || {})){
import sys
from flask import Flask, redirect
from flask_sqlalchemy import SQLAlchemy
from flask_swagger_ui import get_swaggerui_blueprint
from flask_cors import CORS
from sqlalchemy import Column, String, ForeignKey
from flask_admin import Admin
from flask_admin import BaseView
from flask_admin.contrib import sqla