class UserHandler(tornado.web.RequestHandler): def initialize(self, mysql_handler, redis_handler, LOG): self.mysql_handler = mysql_handler self.redis_handler = redis_handler self.LOG = LOG self.user = User(mysql_handler, LOG) self.picture = Picture(mysql_handler, LOG) return def get_self_info(self, user_phone): user_info = self.user.check_user_exist(user_phone) if user_info: image_info = self.picture.get_image_by_phone(user_phone, 'user') try: image_big_mame = image_info['pic_big_name'] image_sml_mame = image_info['pic_sml_name'] except: image_big_mame = None image_sml_mame = None user_info['pic_big_name'] = image_big_mame user_info['pic_sml_name'] = image_sml_mame #del user_info['login_status'] image_info = self.picture.get_image_by_phone(user_phone, 'license') try: image_big_mame = image_info['pic_big_name'] image_sml_mame = image_info['pic_sml_name'] except: image_big_mame = None image_sml_mame = None user_info['license_big_name'] = image_big_mame user_info['license_sml_name'] = image_sml_mame return user_info
def get(self): user = users.get_current_user() if not user: return self.redirect('/admin/index') page = self.request.get('page') zoomFlg = self.request.get('zoomFlg') searchLabel = self.request.get('searchLabel') try: page = int(page) - 1 except: page = 0 if searchLabel != "": datas = Picture.gql("WHERE label =:1", searchLabel) else: datas = Picture.all() paginator = ObjectPaginator(datas, PAGE) if page >= paginator.pages: page = paginator.pages - 1 params = { "datas": paginator.get_page(page), "pages": range(1, paginator.pages + 1), "page": page + 1, 'zoomFlg': zoomFlg, 'searchLabel': searchLabel } fpath = os.path.join(os.path.dirname(__file__), 'template/admin/picture', 'list.html') html = template.render(fpath, params) self.response.out.write(html) return
def post(self): try: user = users.get_current_user() if user is None: return self.redirect('/index') else: logout_link = users.create_logout_url(PROTOCOLHTTP + DOMAIN + "/index") cookie = SimpleCookie(os.environ.get('HTTP_COOKIE', '')) picturHandlerePage = self.request.get('picturHandlerePage') cookie['picturHandlerePage'] = picturHandlerePage.encode('utf-8') cookie['picturHandlerePage']['expires'] = 3600 print cookie.output() pictureIdList = self.request.POST.getall("pictureid") for pil in pictureIdList: label = self.request.get("label" + pil) if len(label) > 10: raise RuntimeError("labelMax error") data = Picture.get_by_id(long(pil)) data.label = label data.put() return self.redirect('/user/picture/list') except: self.errorFunc()
def initialize(self, mysql_handler, redis_handler, LOG): self.mysql_handler = mysql_handler self.redis_handler = redis_handler self.LOG = LOG self.user = User(mysql_handler, LOG) self.picture = Picture(mysql_handler, LOG) return
def get(self): user = users.get_current_user() if user is None: return self.redirect('/admin/index') if self.request.get('pictureid'): pictureid = self.request.get('pictureid') img = memcache.get(pictureid) if img is None: img = Picture.get_by_id(long(pictureid)) memcache.add(pictureid, img, 20) #if img.user.email != user.email(): # img='' if img: newimg = images.Image(img.binary) newimg.resize(width=80, height=80) newimg.im_feeling_lucky() if img.mime == 'image/png': smallimg = newimg.execute_transforms( output_encoding=images.PNG) else: img.mime == 'image/jpeg' smallimg = newimg.execute_transforms( output_encoding=images.JPEG) self.response.headers['Content-Type'] = img.mime self.response.out.write(smallimg) else: self.error(404) else: self.error(404)
def initialize(self, mysql_handler, LOG): super(UserHandler, self).initialize() self.mysql_handler = mysql_handler self.LOG = LOG self.user = User(mysql_handler, LOG) self.picture = Picture(mysql_handler, LOG) self.rsp_handler = CommResponse() self.image_path = None return
def initialize(self, mysql_handler, LOG): self.mysql_handler = mysql_handler self.LOG = LOG self.user = User(mysql_handler, LOG) self.device = Device(mysql_handler, LOG) self.favorite = Favorite(mysql_handler, LOG) self.picture = Picture(mysql_handler, LOG) self.device_attribute = DeviceAttribute(mysql_handler, LOG) self.rsp_handler = CommResponse() return
def post(self): user = users.get_current_user() if not user: return self.redirect('/admin/index') pictureid = self.request.get('pictureid') datas = Picture.get_by_id(long(pictureid)) params = {'datas': datas} fpath = os.path.join(os.path.dirname(__file__), 'template/admin/picture', 'update.html') html = template.render(fpath, params) self.response.out.write(html)
def registerPicture(self, binary, name, mime, user): email = user.email() userData = db.GqlQuery("SELECT * FROM User WHERE email='" + email + "'") data = Picture() data.name = name data.mime = mime for user in userData: id = user.key().id() user = User.get_by_id(long(id)) data.user = user data.binary = db.Blob(binary) data.put()
def initialize(self, mysql_handler, LOG): self.mysql_handler = mysql_handler self.LOG = LOG self.user = User(mysql_handler, LOG) self.order = Order(mysql_handler, LOG) self.evaluation = Evaluation(mysql_handler, LOG) self.device = Device(mysql_handler, LOG) self.picture = Picture(mysql_handler, LOG) self.device_attribute = DeviceAttribute(mysql_handler, LOG) self.rsp_handler = CommResponse() return
def initialize(self, service_config, mysql_handler, LOG): super(UserHandler, self).initialize() self.image_path = service_config['image_license_path'] self.mysql_handler = mysql_handler self.LOG = LOG self.user = User(mysql_handler, LOG) self.picture = Picture(mysql_handler, LOG) self.compressHandler = CompressHandler( service_config['compress_width'], service_config['compress_height'], service_config['compress_quality'] ) self.rsp_handler = CommResponse() return
def post(self): user = users.get_current_user() if not user: return self.redirect('/admin/index') pictureIdList = self.request.POST.getall("pictureid") for pil in pictureIdList: data = Picture.get_by_id(long(pil)) data.delete() fpath = os.path.join(os.path.dirname(__file__), 'template/admin/picture', 'deleteend.html') html = template.render(fpath, '') self.response.out.write(html) return
def post(self): try: user = users.get_current_user() if user is None: return self.redirect('/index') else: logout_link = users.create_logout_url(PROTOCOLHTTP + DOMAIN + "/index") cookie = SimpleCookie(os.environ.get('HTTP_COOKIE', '')) picturHandlerePage = self.request.get('picturHandlerePage') cookie['picturHandlerePage'] = picturHandlerePage.encode('utf-8') cookie['picturHandlerePage']['expires'] = 3600 print cookie.output() email = user.email() userData = db.GqlQuery("SELECT * FROM User WHERE email='" + email + "'") for user in userData: id = user.key().id() user = User.get_by_id(long(id)) pictureIdList = self.request.POST.getall("pictureid") sumBinary = 0 for pil in pictureIdList: picture = Picture.get_by_id(long(pil)) sumBinary = sumBinary + len(picture.binary) / 1000 PcaDatas = PictureConnectAlbum.gql( "WHERE picture = :1 ORDER BY picture", picture) for PcaData in PcaDatas: albumid = PcaData.album.key().id() albumData = Album.get_by_id(long(albumid)) cnt = albumData.picture_counter - 1 albumData.picture_counter = cnt albumData.put() picture.delete() contentPicture = user.contentPicture contentPicture = contentPicture - sumBinary user.contentPicture = contentPicture user.put() return self.redirect('/user/picture/list') except: self.errorFunc()
def post(self): try: user = users.get_current_user() if not user: return self.redirect('/admin/index') pictureIdList = self.request.POST.getall("pictureid") for pil in pictureIdList: label = self.request.get("label" + pil) if len(label) > 10: raise RuntimeError("labelMax error") data = Picture.get_by_id(long(pil)) data.label = label data.put() except: self.errorFunc()
def actionCalled(self): """ Dodaje child node """ parent = QApplication.instance().selectionModel if isinstance(parent, Book): newName, ok = QInputDialog.getText(None, "New Chapter name", "Enter desired new name") if ok: if parent.isValidName(newName): parent.addChild(Chapter(newName)) else: while not parent.isValidName(newName): dialog = QMessageBox() dialog.setWindowTitle("Error") dialog.setText("That name is not valid") dialog.setWindowIcon(QIcon("src/notification.png")) dialog.setModal(True) dialog.exec_() newName, cancel = QInputDialog.getText( None, "New Chapter name", "Enter desired new name") if not cancel: break else: if parent.isValidName(newName): parent.addChild(Chapter(newName)) break if isinstance(parent, Chapter): if len(parent.getChildren()) > 0: parent.addChild( Page(parent.getChildren()[-1].getName()[:-1] + str(int(parent.getChildren()[-1].getName()[-1:]) + 1))) else: parent.addChild(Page("Strana1")) if isinstance(parent, Page): item, ok = QInputDialog.getItem(QInputDialog(), "Add an element", "Choose one option:", ["Add text", "Add picture"], 0, False) if ok: if item == "Add text": tmpList = [] for child in parent.getChildren(): if isinstance(child, Text): tmpList.append(child) if len(tmpList) > 0: parent.addChild( Text(tmpList[-1].getName()[:-1] + str(int(tmpList[-1].getName()[-1:]) + 1))) else: parent.addChild(Text("Text1")) if item == "Add picture": image = QFileDialog.getOpenFileName(None, 'OpenFile', '') if image[1]: path = image[0] if path != None: tmpPic = Picture(path.split("/")[-1]) tmpPic.setPicture(path) parent.addChild(tmpPic)
class LicenseUploadHandler(UserHandler): def initialize(self, service_config, mysql_handler, LOG): super(UserHandler, self).initialize() self.image_path = service_config['image_license_path'] self.mysql_handler = mysql_handler self.LOG = LOG self.user = User(mysql_handler, LOG) self.picture = Picture(mysql_handler, LOG) self.compressHandler = CompressHandler( service_config['compress_width'], service_config['compress_height'], service_config['compress_quality'] ) self.rsp_handler = CommResponse() return def recv_file(self, save_file_path, image_name, compress_name): if not os.path.exists(save_file_path): os.makedirs(save_file_path) recv_file_name = os.path.join(save_file_path, '%s' % image_name) save_file = self.request.files['file_image'][0] fin = open(recv_file_name, "wb") fin.write(save_file["body"]) fin.close() self.compressHandler.compress_file(recv_file_name, os.path.join(save_file_path, '%s' % compress_name)) return def post(self): self.LOG.debug('this is %s' % self.__class__.__name__) user_phone = self.get_argument('user_phone', None) user_login_mobile_uuid = self.get_argument('user_login_mobile_uuid', None) if not user_phone: self.LOG.error('parameters error.') self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None) self.write(self.rsp_msg) return if not self.user.check_login_status(user_phone, user_login_mobile_uuid): self.LOG.error('user [%s] not login.' % user_phone) self.mysql_handler.rollback_db() self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None) self.write(self.rsp_msg) return image_big_name = '%s_license_big.jpg' % str(user_phone) image_sml_name = '%s_license_sml.jpg' % str(user_phone) self.picture.del_image(user_phone, 'license') (ret, num, id) = self.picture.add_image(user_phone, 'license', image_big_name, image_sml_name, self.image_path) if not ret: self.LOG.error('add image to mysql failed.') self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None) self.mysql_handler.rollback_db() self.write(self.rsp_msg) return self.recv_file(self.image_path, image_big_name, image_sml_name) self.LOG.info('user [%s] upload license successful.' % user_phone) self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', None) self.mysql_handler.commit_db() self.write(self.rsp_msg) return
class DownloadHandler(UserHandler): def initialize(self, mysql_handler, LOG): super(UserHandler, self).initialize() self.mysql_handler = mysql_handler self.LOG = LOG self.user = User(mysql_handler, LOG) self.picture = Picture(mysql_handler, LOG) self.rsp_handler = CommResponse() self.image_path = None return def post(self): self.LOG.debug('this is %s' % self.__class__.__name__) self.LOG.debug(self.request.body) try: request_json = json.loads(self.request.body) user_phone = request_json['user_phone'] user_login_mobile_uuid = request_json['user_login_mobile_uuid'] image_type = request_json['type_image'] image_file = request_json['file_image'] except Exception as e: self.LOG.error('parameters error.') self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None) self.write(self.rsp_msg) return if not self.user.check_login_status(user_phone, user_login_mobile_uuid): self.LOG.error('user [%s] not login.' % user_phone) self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None) self.mysql_handler.rollback_db() self.write(self.rsp_msg) return try: image_file.index('big') image_name = str(image_file) except: image_name = image_file.replace('sml', 'big') image_info = self.picture.get_image_by_name(image_type, image_name) if not image_info: self.LOG.error('image file [%s] is not exist in mysql.' % image_file) self.rsp_msg = self.rsp_handler.generate_rsp_msg('21003', None) self.mysql_handler.rollback_db() self.write(self.rsp_msg) return local_file = os.path.join(image_info[0]['pic_path'], image_file) if not os.path.isfile(local_file): self.LOG.error('image file [%s] is not exist in disk.' % image_file) self.rsp_msg = self.rsp_handler.generate_rsp_msg('21003', None) self.mysql_handler.rollback_db() self.write(self.rsp_msg) return self.set_header('Content-Type', 'application/octet-stream') self.set_header('Content-Disposition', 'attachment; filename=' + image_info[0]['pic_big_name']) with open(local_file, 'rb') as file_handler: while True: data = file_handler.read(4096) if not data: break self.write(data) self.LOG.info('user [%s] download [%s] successful.' % (user_phone, image_file)) self.finish() return
class ListHandler(tornado.web.RequestHandler): def initialize(self, mysql_handler, LOG): self.mysql_handler = mysql_handler self.LOG = LOG self.user = User(mysql_handler, LOG) self.order = Order(mysql_handler, LOG) self.evaluation = Evaluation(mysql_handler, LOG) self.device = Device(mysql_handler, LOG) self.picture = Picture(mysql_handler, LOG) self.device_attribute = DeviceAttribute(mysql_handler, LOG) self.rsp_handler = CommResponse() return def post(self): self.LOG.info('this is %s' % self.__class__.__name__) self.LOG.debug(self.request.headers) self.LOG.debug(self.request.body) try: request_json = json.loads(self.request.body) user_phone = request_json['user_phone'] user_login_mobile_uuid = request_json['user_login_mobile_uuid'] user_role = request_json['order_info']['role'] except Exception as e: self.LOG.error('parameters error.') self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None) self.write(self.rsp_msg) return if not self.user.check_login_status(user_phone, user_login_mobile_uuid): self.LOG.error('user [%s] not login.' % user_phone) self.mysql_handler.rollback_db() self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None) self.write(self.rsp_msg) return if user_role == 'buyer': condition = {'order_buyer': user_phone} elif user_role == 'seller': condition = {'order_seller': user_phone} else: self.LOG.debug('user role [%s] invalid' % user_role) self.rsp_msg = self.rsp_handler.generate_rsp_msg('21011', None) self.mysql_handler.rollback_db() self.write(self.rsp_msg) return orders = self.order.get_order(condition) if not orders: self.LOG.error('user [%s] as role [%s] has no orders.' % (user_phone, user_role)) self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', {'rsp_data': {'orders':[]}}) self.mysql_handler.commit_db() self.write(self.rsp_msg) return for order in orders: device_info = {} device_info = self.device.get_device_by_number(order['order_device']) if not device_info: device_info = {} else: device_attributes = self.device_attribute.get_attribute_by_number(device_info['device_number']) device_info['device_attributes'] = device_attributes if device_attributes else [] device_pictures = self.picture.get_image_by_number(device_info['device_number'], 'device') if device_pictures: for picture in device_pictures: del picture['pic_owner_mark'] del picture['create_time'] del picture['pic_path'] del picture['pic_owner_type'] device_info['device_pictures'] = device_pictures if device_pictures else [] order['device_info'] = dict(device_info.items()) evaluation_info = self.evaluation.get_evaluation(order['order_number']) order['evaluation_text'] = evaluation_info['evaluation_text'] if evaluation_info else '' order['evaluation_time'] = evaluation_info['evaluation_time'] if evaluation_info else '' order['evaluation_level'] = evaluation_info['evaluation_level'] if evaluation_info else 0 order['feedback_text'] = evaluation_info['feedback_text'] if evaluation_info else '' order['feedback_time'] = evaluation_info['feedback_time'] if evaluation_info else '' rsp_data = { 'rsp_data': {'orders': orders} } self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', rsp_data) self.mysql_handler.commit_db() self.write(self.rsp_msg) return
def get(self): user = users.get_current_user() if user is None: return self.redirect('/index') else: logout_link = users.create_logout_url(PROTOCOLHTTP + DOMAIN + "/index") page = self.request.get('page') zoomFlg = self.request.get('zoomFlg') searchLabel = self.request.get('searchLabel') picturHandlerePage = self.request.get('picturHandlerePage') delFlg = self.request.get('delFlg') cookie = SimpleCookie(os.environ.get('HTTP_COOKIE', '')) if delFlg != "1": if searchLabel != "": cookie['picturHandlerePage'] = "" cookie['searchLabel'] = searchLabel.encode('utf-8') cookie['searchLabel']['expires'] = 3600 print cookie.output() else: if cookie.has_key('searchLabel'): searchLabel = cookie['searchLabel'].value.decode('utf-8') else: searchLabel = "" picturHandlerePage = "" cookie['searchLabel'] = "" cookie['picturHandlerePage'] = "" print cookie.output() #############PICTURE####################### if picturHandlerePage == '': if cookie.has_key('picturHandlerePage'): picturHandlerePage = cookie['picturHandlerePage'].value.decode( 'utf-8') else: cookie['picturHandlerePage'] = picturHandlerePage.encode('utf-8') cookie['picturHandlerePage']['expires'] = 3600 print cookie.output() try: picturHandlerePage = int(picturHandlerePage) - 1 except: picturHandlerePage = 0 email = user.email() userData = db.GqlQuery("SELECT * FROM User WHERE email='" + email + "'") for user in userData: userid = user.key().id() userDatas = User.get_by_id(long(userid)) userPictureDatas = userDatas.picture_set datas = list() keyList = list() for PictureData in userPictureDatas: keyList.append(PictureData.key().id()) if searchLabel != "": PictureDatas = Picture.gql("WHERE label =:1", searchLabel) for PictureData in PictureDatas: if PictureData.key().id() in keyList: datas.append(PictureData) else: for upd in userPictureDatas: datas.append(upd) datas.sort(key=operator.attrgetter('registerDate')) datas.reverse() pictureCount = len(datas) pagerFlg = 0 if pictureCount > PAGE: pagerFlg = 1 lastPage = int(math.ceil(float(pictureCount) / PAGE)) if picturHandlerePage > lastPage: picturHandlerePage = lastPage #pager #now page picturepage+1 #last page paginator.pages+1 page1 = 1 if picturHandlerePage + 1 > 2: page1 = picturHandlerePage + 1 - 1 elif picturHandlerePage + 1 > 3: page1 = picturHandlerePage + 1 - 2 if picturHandlerePage + 1 == lastPage + 1: page1 = page1 - 3 elif picturHandlerePage == lastPage + 1: page1 = page1 - 2 if page1 < 2: page1 = 2 pages = range(page1 - 1, lastPage + 1) paginator = ObjectPaginator(datas, PAGE) if picturHandlerePage >= paginator.pages: picturHandlerePage = paginator.pages - 1 if user: loginFlg = 1 params = { "datas": paginator.get_page(picturHandlerePage), "pages": pages, "page": picturHandlerePage + 1, "prev": picturHandlerePage, "next": picturHandlerePage + 2, "pagerFlg": pagerFlg, "lastpage": lastPage, 'zoomFlg': zoomFlg, 'searchLabel': searchLabel, 'loginFlg': loginFlg, 'logout_link': logout_link } fpath = os.path.join(os.path.dirname(__file__), 'template/user/picture', 'list.html') html = template.render(fpath, params) self.response.out.write(html) return
class ShowHandler(tornado.web.RequestHandler): def initialize(self, mysql_handler, LOG): self.mysql_handler = mysql_handler self.LOG = LOG self.user = User(mysql_handler, LOG) self.device = Device(mysql_handler, LOG) self.favorite = Favorite(mysql_handler, LOG) self.picture = Picture(mysql_handler, LOG) self.device_attribute = DeviceAttribute(mysql_handler, LOG) self.rsp_handler = CommResponse() return def post(self): self.LOG.debug('this is %s' % self.__class__.__name__) try: request_json = json.loads(self.request.body) user_phone = request_json['user_phone'] user_login_mobile_uuid = request_json['user_login_mobile_uuid'] collection_type = request_json['collection_type'] except Exception as e: self.LOG.error('parameters error.') self.rsp_msg = self.rsp_handler.generate_rsp_msg('21001', None) self.write(self.rsp_msg) return if not self.user.check_login_status(user_phone, user_login_mobile_uuid): self.LOG.error('user [%s] not login.' % user_phone) self.rsp_msg = self.rsp_handler.generate_rsp_msg('21006', None) self.mysql_handler.rollback_db() self.write(self.rsp_msg) return collections = self.favorite.get_collection(user_phone, collection_type) if not collections: self.LOG.error('user [%s] has no collections.' % user_phone) self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', {'rsp_data': {'collections':[]}}) self.mysql_handler.rollback_db() self.write(self.rsp_msg) return result = [] targets = [collection['collection_mark'] for collection in collections] if collection_type == 'user': users = self.user.get_user_by_phones(targets) for user in users: image_info = self.picture.get_image_by_phone(user['user_phone'], 'user') try: image_big_mame = image_info['pic_big_name'] image_sml_mame = image_info['pic_sml_name'] except: image_big_mame = None image_sml_mame = None user['pic_big_name'] = image_big_mame user['pic_sml_name'] = image_sml_mame del user['user_login_mobile_uuid'] del user['user_phone_mno'] result = users elif collection_type == 'device': devices = self.device.get_device_by_numbers(targets) for device in devices: attributes = self.device_attribute.get_attribute_by_number(device['device_number']) device['device_attributes'] = attributes if attributes else [] pictures = self.picture.get_image_by_number(device['device_number'], 'device') if pictures: for picture in pictures: del picture['pic_owner_mark'] del picture['create_time'] del picture['pic_path'] del picture['pic_owner_type'] device['device_pictures'] = pictures if pictures else [] device['user_phone'] result = devices else: self.LOG.error('collection_type [%s] is error.' % collection_type) self.rsp_msg = self.rsp_handler.generate_rsp_msg('21999', None) self.mysql_handler.rollback_db() self.write(self.rsp_msg) return self.rsp_msg = self.rsp_handler.generate_rsp_msg('200', {'rsp_data': {'collections':result}}) self.mysql_handler.commit_db() self.write(self.rsp_msg) return