예제 #1
0
    def test_can_fetch_models_properly(self):
        maps = [
            CategorieMap(),
            FormMap(),
            GenderMap(),
            MaterialFondMap(),
            MaterialFrontMap(),
            MaterialLensMap(),
            MarqueMap(),
            StructureMap(),
            TailleTempleMap(),
            TailleLunettesMap()
        ]
        with concurrent.futures.ThreadPoolExecutor() as executor:
            fs = [
                executor.submit(m.mapModels, self.url + 'boutique')
                for m in maps
            ]
            for _ in concurrent.futures.as_completed(fs):
                continue

        models = []
        for m in maps:
            assert len(m.models) > 0
            models.extend(m.models)

        session = db()
        session.add_all(models)
        session.commit()
예제 #2
0
def action(request):
    #sid=Session.objects.get()
      
    if request.method == 'POST':
        username=request.POST.get("username",None)   
        if not username:
          return render_to_response('login.html')
         #get_id= request.session.get("username",None):
        usersid = request.session.get("username",None)
        if usersid:
             return render_to_response('login.html', {'username': username})
        else:
             #passwd=request.POST['password']
             passwd = request.POST.get("password",None) 
             if not passwd:
                 return HttpResponse("shurumima")
             try:
                 rel=models.db(username, passwd)
             #if rel['username'] and rel['passwd']:
                 request.session["username"] = username
                 return render_to_response('login.html', {'username': username})
             except:
                 return HttpResponse("用户名和密码错误")
    else:
         return render_to_response("login.html")
예제 #3
0
def submit_jobs():
    db.job.approver.readable= False
    db.job.approver.writable= False
    child_query = ((db.auth_group.role == 'child') &
        (db.auth_membership.group_id == db.auth_group.id) & 
        (db.auth_user.id == db.auth_membership.user_id))
    child_set = db(child_query)
    db.job.child.requires = IS_IN_DB( child_set,'auth_user.id','auth_user.username')
    grid=SQLFORM.grid(db.job,fields=[db.job.chore,db.job.child,db.job.job_date])
    return dict(form=grid)
예제 #4
0
def approve_jobs():
    if len(request.post_vars) > 0:
        for key, value in request.post_vars.iteritems():
            (field_name,sep,row_id) = key.partition('_row_') #name looks like home_state_row_99
            if row_id:
                db(db.job.id == row_id).update(**{field_name:value})


    db.job.approver.represent = lambda value,row: option_widget(db.job.approver,value,
                                                                **{'_name':'approver_row_%s' % row.id})
    parent_query = ((db.auth_group.role == 'parent') &
        (db.auth_membership.group_id == db.auth_group.id) & 
        (db.auth_user.id == db.auth_membership.user_id))
    parent_set = db(parent_query)
    db.job.approver.requires = IS_IN_DB( parent_set,'auth_user.id','auth_user.username')
    grid=SQLFORM.grid(db.job,
                      selectable=lambda ids: redirect(URL('default','approve_jobs',vars=request._get_vars)))
    grid.elements(_type='checkbox',replace=None)
    return dict(form=grid)
def mysearch(request):
    l=[]
    if request.method == "GET":
        data=db()
        c=dersler()
        return render_to_response("base.html",{"bolumler":data})

    elif request.method == "POST":
        v=derslerbolum()
        searchbolum = request.POST.get("bolum")
        for i in v:
            if searchbolum==i[0]:
                #l.append(i[2:4])
                l.append(i[0:4])
        return render_to_response("yeni.html",{"bb":l}, context_instance=RequestContext(request))
예제 #6
0
def mysearch(request):
    l = []
    if request.method == "GET":
        data = db()
        c = dersler()
        return render_to_response("base.html", {"bolumler": data})

    elif request.method == "POST":
        v = derslerbolum()
        searchbolum = request.POST.get("bolum")
        for i in v:
            if searchbolum == i[0]:
                #l.append(i[2:4])
                l.append(i[0:4])
        return render_to_response("yeni.html", {"bb": l},
                                  context_instance=RequestContext(request))
예제 #7
0
def calculate_payment():
    """ called after sqlform.grid submit via selectable
    """
    children_payout = {}
    ids = request.vars.id
    if ids:
        sum_value = db.chore.chore_value.sum()
        children_totals = db((db.job.id.belongs(ids)) &
                      (db.auth_user.id == db.job.child) &
                      (db.chore.id == db.job.chore)
        ).select(db.auth_user.username,sum_value,groupby=db.auth_user.username)
        for row in children_totals:
            children_payout[row.auth_user.username] = row._extra[sum_value]

    
    return dict(ids=ids,children_payout=children_payout)
예제 #8
0
def action1(request):     
     username=request.POST.get("username",None)                  
     passwd = request.POST.get("password",None)             # if not passwd:               #  return render_to_response("login.html")
     userid=request.session.get("username",None)
     if not userid:          # return render_to_response('login.html', {'username': username}) 
          try:
             rel=models.db(username, passwd)
             #if rel['username'] and rel['passwd']:
             request.session['username']=username
             sid=request.session.get("username",None)
             request.session.save()
             
             return render_to_response('login.html', {'username': username})
          except:
             return render_to_response("login.html")       
     else:
         return render_to_response('login.html',{'username': userid})
예제 #9
0
    def buildModel(self, elements):

        # Values from html
        marque_content, categorie_content, gender_content,\
            form_content, structure_content, materialFront_content,\
            materialFond_content,  taille_content, tailleTemple_content,\
            year\
            =elements
        
        
        # Correspondant Ids
        session = db()
        def queryBuilder(columnName, name):
            if name is None:
                self.logger.warning(f'Found a None value for {columnName}')
            return session.query(columnName).filter_by(name = name)\
                .one().id \
                if name is not None \
                else None
        try:
            m = Lunettes(
                id=None, 
                categorie_id = queryBuilder(Categorie.id, categorie_content),
                form_id = queryBuilder(Form.id, form_content),
                gender_id = queryBuilder(Gender.id, gender_content),
                marque_id = queryBuilder(Marque.id, marque_content),
                material_fond_id = queryBuilder(Material_Fond.id, materialFond_content),
                material_front_id = queryBuilder(Material_Front.id, materialFront_content),
                structure_id = queryBuilder(Structure.id, structure_content),
                taille_lunettes_id = queryBuilder(Taille_Lunettes.id, taille_content),
                taille_temple_id = queryBuilder(Taille_Temple.id, tailleTemple_content),
                year = year
            )
            session = scoped_session(db)
            session.add(m)
            session.commit()
            session.remove()
            return m
        except Exception as err:
            self.logger.error(f"buildModel => {err.args}")
            return None
예제 #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-  
import sys
import models
import time

db = models.db()

def usage():
    print "usage:"
    print "./admin.py  actor    [name]"
    print "./admin.py  deposit  [name]  [money]"
    print "./admin.py  expense  [money] [details]"
    print "./admin.py  list"

'''
    actor
'''
def show_actor():
    print "NAME\tNAME_ID"
    if None == db.show_table("actor"):
        print "Show table error!"
        
def add_actor(name):
    if name != "_default_":
        nameid = 2 ** (len(db.get_table("actor"))-1)
        if None == db.add_row("actor", ["\"" + name + "\"", str(nameid)]):
            print "Add actor error!"
        else:
            show_actor()
    else:
예제 #11
0
def complete_payment():
    ids = request.vars.ids
    db(db.job.id.belongs(ids)).update(paid=True)

    session.flash="Payments have been recorded"
    redirect(URL('default','index'))
예제 #12
0
 def orm(self):
     return db()
예제 #13
0
import concurrent.futures
url = "http://contrastlens.com/"

maps = [
    CategorieMap(),
    FormMap(),
    GenderMap(),
    MaterialFondMap(),
    MaterialFrontMap(),
    MaterialLensMap(),
    MarqueMap(),
    StructureMap(),
    TailleTempleMap(),
    TailleLunettesMap()
]
with concurrent.futures.ThreadPoolExecutor() as executor:
    fs = [executor.submit(m.mapModels, url + 'boutique') for m in maps]
    for _ in concurrent.futures.as_completed(fs):
        continue

models = []
for m in maps:
    assert len(m.models) > 0
    models.extend(m.models)

session = db()
session.add_all(models)
session.commit()

map = LunetteMap()
map.mapModels(url + 'boutique')
예제 #14
0
def init_app(app, debug=False):
    app.debug = debug
    from .api import Api
    app.register_blueprint(Api(app.logger))
    app.db_engine = models.db(os.environ['DATABASE_URL'])
예제 #15
0
 def orm(self):
     return db()
예제 #16
0
from flask import Flask, render_template, request, redirect, url_for, jsonify, json
from flask_wtf import FlaskForm
from wtforms import SelectField
from models import db

app = Flask(__name__)
app.secret_key = 'secret_key'
graph = db()


class Form(FlaskForm):
    topic = SelectField('topic', choices=[])
    application = SelectField('application', choices=[("", "---")])


@app.route('/', methods=['GET', 'POST'])
def home():
    form = Form()
    form.topic.choices = [
        topic['name'] for topic in graph.nodes.match("Topic")
    ]
    # form.application.choices = [(app['name']) for app in graph.nodes.match("Application")]

    if request.method == 'POST':
        topic = request.form['topic']
        app = request.form['application']

        # get datasets used by app
        data = get_datasets(app)
        datasets = [d[0] for d in data]
예제 #17
0
import hashlib
from os import listdir
from os.path import isfile, join
import subprocess
import time
import shutil
import models
import encodings

db = models.db('pre_ocr')
source = 'raw/'
destination = 'processed/'
raw_files = [f for f in listdir(source) if isfile(join(source, f))]

print("%d files in raw" % (len(raw_files)))
for f in raw_files:
    ''' Renames scrapped images and and moves to processed folder '''
    fname = f
    fname = ''.join([i if ord(i) < 128 else ' ' for i in fname])
    pfile = hashlib.sha256((str(time.time()) + f).encode('utf-8')).hexdigest()
    ext = f.split('.')[-1]
    location = "{}{}.{}".format(destination, pfile, ext)
    shutil.move("{}{}".format(source, f), location)
    files_data = {'location': location, 'attributes': fname.split('.')[0]}
    db.insert_one(files_data)
예제 #18
0
파일: views.py 프로젝트: puchchi/ProjectX
    def create(self, request, rawData):
        data = {}
        if (type(rawData) == QueryDict):
            rawDataDict = rawData.dict()

            newPlaceID = rawDataDict["place_id"]
            newPlaceLatitude = float(rawDataDict["latitude"])
            newPlaceLongitude = float(rawDataDict["longitude"])

            placeFound = False
            # Checking if given place is already not in database
            oldPlaceSerializer = PlaceSerializer(db.objects.search_text(
                rawDataDict["place_name"]),
                                                 many=True)
            for place in oldPlaceSerializer.data[:]:
                placeDict = dict(place)
                if (newPlaceID == placeDict["place_id"]
                        and newPlaceLatitude == placeDict["latitude"]
                        and newPlaceLongitude == placeDict["longitude"]):
                    placeFound = True

            if placeFound:
                msg = rawDataDict["place_name"] + " already exists."
                return dataAdminViews.addPlace(request, msg, False)

            data["name"] = rawDataDict["place_name"]
            data["state"] = rawDataDict["state"]
            data["country"] = rawDataDict["country"]
            data["address"] = rawDataDict["address"]
            data["latitude"] = newPlaceLatitude
            data["longitude"] = newPlaceLongitude
            data["place_id"] = newPlaceID
            data["map_url"] = rawDataDict["map_url"]
            data["description"] = rawDataDict["description"]
            data["place_type"] = map(
                str.strip, rawDataDict["place_type"].encode().split(','))
            if (data["description"] == ''):
                data["description"] = data["name"]
            photo_urls = []
            for key in rawDataDict.keys():
                if (key.find("place_photo_url") != -1):
                    photo_urls.append(getOriginalURL(rawDataDict[key]))
            data["photo_urls"] = photo_urls
        else:
            data = rawData
        #print data
        serializer = PlaceSerializer(data=data)
        print serializer.is_valid()
        if serializer.is_valid():
            place = db(**data)
            place.save()
            if (type(rawData) == QueryDict):
                msg = data["name"] + " added successfully."
                return dataAdminViews.addPlace(request, msg, True)
            else:
                response = serializer.data
                return Response(response, status=status.HTTP_200_OK)
        else:
            if (type(rawData) == QueryDict):
                msg = "Couldn't add " + data["name"] + ". Errors: " + str(
                    serializer.errors)
                return dataAdminViews.addPlace(request, msg, False)
            else:
                return Response(serializer.errors,
                                status=status.HTTP_400_BAD_REQUEST)