Example #1
0
from django_micro import route, run, configure
from django.http import HttpResponse, HttpRequest, FileResponse
import dominate.tags as dom
from dominate.document import document
from PIL import Image

DEBUG = True
configure(locals())


def page():
    doc = document()
    with doc as root:
        with doc.body:  ## form input button;input三个属性:type,name,value
            with dom.form(action="/file",
                          method="post",
                          enctype="multipart/form-data"):
                dom.input(type="file", name="image")
                dom.button("submit", type="submit")
    return root.render()


@route("")
def index(request: HttpRequest):
    return HttpResponse(page())


@route('file')
def filehandler(request: HttpRequest):
    #创建一个 PIL 的image 的对象,顺便给它压缩 保存
    user_image = request.FILES.get("image")
Example #2
0
from django_micro import configure, route, run
from django.http import HttpResponse
import csv

setting = {
    "DEBUG": True,
    "LANGUAGE_CODE": 'en-us'
}
configure(setting)

f = open('e:/dev/happycoding/l02/download_2_1_v2/source.csv','r')
table = csv.reader(f)
data  = ''


for row in table:
    data += f'''
    <tr style="border-top:1pt solid #555555">
        <td><h3> { row[2] } </h3></td>
        <td><h3> { row[3] } </h3></td>
        <td><h3> { row[0] } </h3></td>
    </tr>'''

print(table)

@route('', name='home')
def homepage(request):
    html = f'''
    <div style="background-color:#0A0A0E;height:100%">
        <image src="https://file-rctyjgetlr.now.sh" style="height:70%;margin:auto;display:block">
        <table style="width:60%;color:white;border-collapse:collapse" align="center">
Example #3
0
IMG_CARD = "flex flex-col bg-white shadow-xl p-3 rounded-lg w-120 h-120 p-2"
LABEL_CARD = "flex flex-col bg-green-400 w-120 h-24 p-2 mb-2 rounded-lg shadow-xl"
LABEL_INPUT = "h-10 rounded border-none p-4 text-center text-xl text-gray-600 placeholder-gray-400 outline-none focus:shadow-outline"
IMG_FORM = "flex flex-col items-center justify-center border-dashed border-4 border-gray-200 h-full"
FORM_ATTR = {
    "ic-post-to": "/file",
    "ic-target": "#here",
    "ic-replace-target": "true",
    "enctype": "multipart/form-data"
}
UPLOAD_ICON = "fas fa-file-upload text-gray-300 font-medium text-6xl"
BUTTON = "flex flex-row items-center justify-center bg-green-400 px-3 py-2 mt-4 text-white rounded shadow"
RESULT_CONTAINER = "flex flex-col"
RESULT_ITEM = "flex flex-col items-center justify-between bg-white p-4 border-t border-gray-200 w-96"

configure({'DEBUG': True})


def link_(lk):
    return dom.link(rel="stylesheet", type="text/css", href=lk)


def script_(s):
    return dom.script(src=s)


def page():
    doc = document()
    with doc.head:
        link_("https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css")
        link_("https://extra-uru1z3cxu.now.sh/css/extra.css")
Example #4
0
import pathlib

import django_micro
from django.http import HttpResponse
from django.db import models
from django.core.files.base import ContentFile, File

django_micro.configure({
    'DEBUG': True,
    'DATABASES': {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': ':memory:'
        },
    },
})


@django_micro.route('', name='homepage')
def homepage(request):
    name = request.GET.get('name', 'World')
    return HttpResponse('Hello, {}!'.format(name))


class Post(models.Model):
    title = models.CharField(max_length=255)
    parent = models.ForeignKey('self', null=True, on_delete=models.CASCADE)
    file = models.FileField()

    class Meta:
        app_label = django_micro.get_app_label()
Example #5
0
import os
from importlib import import_module
settings = import_module(os.environ.get('DJANGO_SETTINGS_MODULE', 'settings.dev'))
from django import forms
from django.conf.urls.static import static
from django.db import models
from django.shortcuts import redirect, render
from django_micro import configure, get_app_label, route, run, urlpatterns

configure(settings.__dict__)

from django.conf import settings


#
# models
#

class Post(models.Model):
    image = models.ImageField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        app_label = get_app_label()
        ordering = ['-id']


#
# forms
#
Example #6
0
GRAPHENE = {
    "SCHEMA": "schema.schema",
    "SCHEMA_INDENT": 2,
    "MIDDLEWARE": (
        "graphene_django.debug.DjangoDebugMiddleware",
    ),
}

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": os.path.join(BASE_DIR, "db.sqlite3"),
    }
}

configure(locals(), django_admin=True)

# ************************************************************************
# ********************* graphene-elastic routes **************************
# ************************************************************************
from graphene_django.views import GraphQLView  # NOQA
from graphene_elastic.settings import graphene_settings  # NOQA
route(
    'graphql',
    GraphQLView.as_view(
        graphiql=True,
        middleware=graphene_settings.MIDDLEWARE
    ),
)

# ************************************************************************
Example #7
0
CENTER_FRAME = "flex flex-col items-center justify-center bg-gray-800 h-screen"
CARD = "flex flex-col bg-white shadow-xl p-3 rounded-lg w-120 h-120 p-2"
UPLOAD_FORM_ATTRS = {
    "class":
    "flex flex-col items-center justify-center border-dashed border-4 border-gray-200 h-full",
    "ic-post-to": "/file",
    "ic-target": "#here",  #新增
    "ic-replace-target": "true",
    "enctype": "multipart/form-data"
}
UPLOAD_ICON = "fas fa-file-upload text-gray-300 font-medium text-6xl"
BUTTON = "flex flex-row items-center justify-center bg-green-400 px-3 py-2 mt-4 text-white rounded shadow"
RESULT_CONTAINER = "flex flex-col"
RESULT_ITEM = "flex flex-row items-center justify-between bg-gray-700 p-4 border-t border-gray-600 w-96"

configure({"DEBUG": True})


def link_(lk):
    return dom.link(rel="stylesheet", type="text/css", href=lk)


def script_(s):
    return dom.script(src=s)


def Page():
    doc = document()
    with doc.head:
        link_("https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css")
        link_("https://extra-uru1z3cxu.now.sh/css/extra.css")
Example #8
0
"""
The test runner
"""

import os

from django_micro import configure, run

from ontulily.settings import *  # noqa

# Configuration
# this must be run at the top before anything else is imported/used
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
DEBUG = True
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(TEST_DIR, 'db.sqlite3'),
    },
}

configure(locals(), django_admin=False)

from ontulily.tests.test_flood import *  # noqa

# Expose application
application = run()