def read(req): if req.method != 'POST': return Controller.goto('/collect/index') path = req.POST.get('path') data = {'status':'processing', 'name': os.path.basename(path), 'create_by': req.user.username } mkdir, created = Directory.objects.get_or_create(full_path=path, defaults=data,) sect = req.POST.get('section-select') loc = req.POST.get('location-select') sect_obj = Section.objects.filter(id=1).values('id', 'name')[0] loc_obj = Location.objects.filter().values('id', 'name')[0] ctx = {"path": path, "section_id":sect, "sect_obj":sect_obj, 'loc_id':loc, 'loc_obj':loc_obj, "mkdir": mkdir} return Controller.render(req, ctx, 'collect/read.html')
def login(req): errors = [] if req.user.is_authenticated: return Controller.goto('/collect/index') if req.method == "POST": username = req.POST.get('username') password = req.POST.get('password') user = authenticate(req, username=username, password=password) if user is not None: login(req, user) return Controller.goto('/collect/index') errors.append("Hmm I cant find that user/password combo") ctx = {"errors": errors} return Controller.render(req, ctx, 'login/login.html')
def index(req): """ List the all companies """ companies = Company.objects.all().values() return Controller.render_json({ 'companies': list(companies), "total_companies": len(companies) })
def search_sequance(req): f = {'date':req.GET.get('date', datetime.datetime.now()), 'section_id': req.GET.get('section_id'), 'company_id': req.GET.get('company_id'), 'import_status': 'sequence'} sequences = Manifest.objects.filter(**f).distinct('sequence').values('sequence'); return Controller.render_json({'results':list(sequences), "total": len(sequences)})
def index(req): """ List the all UIs by type """ type = req.GET.get('type') uis = UI.objects.filter(**{'type': type}).order_by('name').values() return Controller.render_json({ 'results': list(uis), "total": len(uis) })
def upload(req): if req.method == 'POST': fname = "{}{}".format(settings.UPLOAD_DIR, req.POST.get('name')) with zipfile.ZipFile(req.FILES['images'],"r") as zip_ref: zip_ref.extractall(fname) return Collect.sort(req, name=fname) else: return Controller.render(req, {}, 'collect/upload.html')
def search(req): """ List search results """ f = {'name__icontains': req.GET.get('keyword', '')} companies = Company.objects.filter(**f).order_by('name').values( 'id', 'name')[:100] return Controller.render_json({ 'companies': list(companies), "total_companies": len(companies) })
def index(req): company = Company.objects.all().exclude(name="Not Set").values( 'id', 'name') section = Section.objects.all().values('id', 'name') ctx = { "date": datetime.date.today().strftime("%Y-%m-%d"), "company": company, 'section': section } return Controller.render(req, ctx, 'index/index.html')
def create(req): post = req.POST; dir = post.get('dir') img_dir = "{}{}/*.jpg".format(settings.UPLOAD_DIR, dir) out_dir = "{}{}/thumbs/".format(settings.UPLOAD_DIR, dir) meta_data = thumb_nail(glob.glob(img_dir), out_dir, (700, 700)) for key, val in meta_data.items(): img = Manifest._format(post, val, 'init') obj, created = Manifest.objects.get_or_create(directory_id=img['directory_id'], name=img['name'], defaults=img) count = Manifest.objects.filter(directory_id=img['directory_id']).count() return Controller.render_json({'success':True, 'count':count, 'directory_id':img['directory_id']})
def rotate(req): _dir = req.GET.get('dir') _file = req.GET.get('file_name') _path = "{}{}/{}".format(settings.UPLOAD_DIR, _dir, _file) _thumb = "{}{}/thumbs/".format(settings.UPLOAD_DIR, _dir) img = Image.open(_path) img = img.rotate(90) img.save(_path) thumb_nail([_path], _thumb, (500, 500)) return Controller.render_json({ 'dir': _dir, 'file_name': _file, 'path': _path })
def create(req): id = False if req.method == 'POST': nw = UI.objects.create( **{ 'name': req.POST.get('name'), 'type': req.POST.get('type'), 'markup': req.POST.get('markup'), 'group': req.POST.get('group'), }) id = nw.id nw.markup = nw.markup.format(nw.id) nw.save() return Controller.render_json({ 'success': True, 'id': id, })
def index(req): """ List the dir. to process """ current_dir = req.POST.get('current_dir', settings.UPLOAD_DIR) dirs = Collect.get_dir_list(current_dir) root = Collect.get_dir_list(settings.UPLOAD_ROOT, True) dir_list = [] for d in dirs: path = "{}{}".format(current_dir, d) is_dir_in_db = Directory.objects.filter(**{'full_path':path}).values('id', 'name', 'status') if len(is_dir_in_db) > 0 and is_dir_in_db[0]['status'] == 'done': continue status = is_dir_in_db[0]['status'] if len(is_dir_in_db) > 0 else "Not Processed" dir_list.append( {'name':d, 'status':status, 'path': path } ) res = {'dir_list':dir_list, "total_dirs": len(dir_list), "root_path":settings.UPLOAD_ROOT, "root_dir":root, "current_dir":current_dir} return Controller.render(req, res, 'collect/index.html')
def update(req): """ Update an a indexed image from the sort route. """ if req.method == "POST": p = req.POST m = Manifest.objects.get(id=p.get('id')) m.subject = p.get('subject') m.company_id = p.get('company_id') m.location_id = p.get('location_id') m.section_id = p.get('section_id') m.date = p.get('date') m.lat = p.get('lat') m.lng = p.get('lng') m.sequence = p.get('sequence') m.import_status = 'sequence' m.save() return Controller.render_json({'success': True, 'params':req.POST})
def index(req): return Controller.goto('index/index.html')
def router(req, **kwargs): return Controller.route(CompanyController, CompanyController.actions, req, kwargs)
def router(req, **kwargs): return Controller.route(SectionController, SectionController.actions, req, kwargs)
def delete_all(req): UI.objects.filter(**{}).delete() return Controller.render_json({'action': 'delete_all'})
def index(req): """ List the all locations """ v = ('id', 'name', 'section_id', 'section__name', 'lat', 'lng') locs = Location.objects.filter(**{}).values(*v) return Controller.render_json({'locations':list(locs), "total": len(locs)})
def index(req): """ List the all Sections """ secs = Section.objects.all().values() return Controller.render_json({'sections':list(secs), "total": len(secs)})
def logout(req): logout(req) return Controller.goto('index')
def index(req): return Controller.render(req, {}, 'collect/index.html')
def router(req, **kwargs): return Controller.route(ImgEditor, ImgEditor.actions, req, kwargs)
def get_sequence(req): f = {'sequence': req.GET.get('sequence')} sequence = Manifest.objects.filter(**f).values(*Manifest.default_fields()); return Controller.render_json({'results':list(sequence), "total": len(sequence)})
def router(req, **kwargs): return Controller.route(ImageController, ImageController.actions, req, kwargs)
def manifest(req): imgs = Manifest.objects.filter(directory_id=req.GET.get('directory_id')).values(*Manifest.default_fields()) return Controller.render_json({'results':list(imgs)})
def router(req, **kwargs): return Controller.route(Collect, Collect.actions, req, kwargs)