def edit(self): id = self.params.get('id') self.user_db = UserDb.get_by_id(int(id)) if self.user_db.service_type == 'c': self.config = yaml.load(self.user_db.config) self.render(template="inquiry_edit") pass
def create(self): res = {"status": "success"} # try: udb = UserDb.get_by_id(int(self.params.get("db_id"))) if udb: v = UserView.newInstance(udb) res = {"status": "success", "cv_id": v.key().id(), "r": "/"} else: res = {"status": "error", "msg": "missing user db"} # except Exception, ex: # # 例外メッセージを表示する # res= {"status":"error","msg":"Exception: %s" % ex} self.render(json=self.to_json(res))
def shared_treeview(self): self.user_dbs= [] dbs = {} for u in db.GqlQuery("SELECT * FROM ShareUser WHERE email = :1",self.user.email()): id = u.share_view_id.user_db_id.key().id() if id in dbs: dbs[id].append(u) else: dbs[id] = [u] # keyでループ for id in dbs.keys(): udb = UserDb.get_by_id(id) self.user_dbs.append({'db':udb,'share_users':dbs[id]})
def delete(self): if self.request.method.upper() != "POST": return id = self.params.get('id') g = UserDb.get_by_id(int(id)) if g.user != self.user: data = {'status':'error','msg':'権限がありません'} self.render(json=self.to_json(data)) return data = {'status':'success'} if g: # 紐づくデータは、リンク関係を切るー>ゴミ箱をつくってそこに入れる # という仕様は面倒なのでまずは削除してしまう q = ProfileCore.all() q.filter("user_db_id = ",g) for p in q: p.delete() #p.user_db_id = None #p.put() q = Inquiry.all() q.filter("user_db_id = ",g) for p in q: p.delete() #p.user_db_id = None #p.put() # 紐づくViewを全て削除 q = UserView.all() q.filter("user_db_id = ",g) for p in q: p.delete() g.delete() data = {'status':'success','r':'/'} if self.v_id and id == self.v_id: self.response.headers.add_header('Set-Cookie','cv_id=-1 ;expires=Fri, 5-Oct-1979 08:10:00 GMT') self.render(json=self.to_json(data))
def shared_member_list(self): #自分のDBをとりだす dbs = UserDb.all() dbs.filter('user ='******'user_db_id = ',db) for v in views: # shareしているユーザの取得 share_users = ShareUser.all() share_users.filter(' share_view_id = ',v) for su in share_users: if su.email in members: members[su.email].append(su) else: members[su.email]=[su] self.member_list = [] for m in members.keys(): self.member_list.append({'email':m,'share_views':members[m]})
def create(self): data = {'status':'success'} if self.request.method.upper() != "POST": data = {'status':'error','msg':'forbidden method '} self.render(json=self.to_json(data)) return udb = UserDb(user=self.user,service_type=self.params.get('service_type','p')) udb.put() id = udb.key().id() name = u'DB(' + str(id) + ')' if udb.service_type == 'c': name = u'問い合せDB(' + str(id) + ')' udb.config = yaml.dump({'recipients':udb.user.email(),'form_config':UserDbMaster.getFormConfig()}) udb.name = name udb.put() # ついでにビューもつくってしまう v = UserView.newInstance(udb) # カレントのビューをこれにするためにクッキーにセット data={'status':'success','r':'/','cv_id':str(v.key().id())} self.render(json=self.to_json(data))
def update(self): if self.request.method.upper() != "POST": return #logging.debug("[GroupsController#update] (params)="+ self.to_json(self.params) +")") id = self.params.get('edit_db_id') self.udb = UserDb.get_by_id(int(id)) self.udb.name = self.params.get('edit_db_name') if self.udb.service_type != 'c': self.udb.put() data = {'status':'success'} self.render(json=self.to_json(data)) else: # iq_open iq_open = self.params.get('iq_open','') # recipients recipients = self.params.get('recipients',self.udb.user.email()) # columns form_config = copy.deepcopy(self.udb.getProperty('form_config')) for col in form_config: if col['type'] == 'hidden': continue key = "disp_%s" % col['name'] val = self.params.get(key,'None') if val == 'yes': col['checked']= 'checked' else: col['checked']= '' self.config = {'iq_open':iq_open,'recipients':recipients,'form_config':form_config} self.udb.config = yaml.dump(self.config) self.udb.put() self.render(template="inquiry_update")
def edit_mail_template(self): id = self.params.get('id') self.user_db = UserDb.get_by_id(int(id)) if self.request.method.upper() == "GET": values={'id':'{{id}}','db_name':'{{db_name}}','name':'{{name}}','reply_content':'{{reply_content}}'} self.id = '{{id}}' self.db_name = '{{db_name}}' self.name = '{{name}}' self.reply_content = '{{reply_content}}' self.confirm_mail_subject = self.user_db.getProperty('confirm_mail_subject') if not self.confirm_mail_subject: self.confirm_mail_subject = self.render_txt(template='confirm_mail_subject',values=values) self.confirm_mail_body = self.user_db.getProperty('confirm_mail_body') if not self.confirm_mail_body: self.confirm_mail_body = self.render_txt(template='confirm_mail_body',values=values) self.reply_mail_subject = self.user_db.getProperty('reply_mail_subject') if not self.reply_mail_subject: self.reply_mail_subject = self.render_txt(template='reply_mail_subject',values=values) self.reply_mail_body = self.user_db.getProperty('reply_mail_body') if not self.reply_mail_body: self.reply_mail_body = self.render_txt(template='reply_mail_body',values=values) if self.request.method.upper() == "POST": self.config = yaml.load(self.user_db.config) self.config['confirm_mail_subject'] = self.params.get('confirm_mail_subject') self.config['confirm_mail_body'] = self.params.get('confirm_mail_body') self.config['reply_mail_subject'] = self.params.get('reply_mail_subject') self.config['reply_mail_body'] = self.params.get('reply_mail_body') self.user_db.config = yaml.dump(self.config) self.user_db.put() self.render(template='update_mail_template')
def import_csv(self): if self.request.method.upper() == "GET": pass if self.request.method.upper() == "POST": data={'status':'success','msg':'アップロードが完了しました','r':'/'} if not self.user: self.render(json=self.to_json({'status':'error','msg':'不正なリクエスト'})) return # いったんワークエリアにデータをコピー bin = self.params.get('file') if not bin: self.render(json=self.to_json({'status':'error','msg':'ファイルを指定してください'})) return fname = self.request.body_file.vars['file'].filename udb = UserDb(user=self.user,name=unicode(fname,self.__guess_charset(fname))) udb.put() # ついでにビューもつくってしまう (viewのカラムのcheckedを一反外す) v = UserView(user_db_id = udb) v.put() # カレントのビューをこれにするためにcv_idをセット data['cv_id']=str(v.key().id()) # viewのカラムのcheckedを一反外し、csvにあるカラムのみ有効にする config = copy.deepcopy(ProfileCore.disp_columns) for col in config: if col['type'] != 'hidden': col['checked'] = '' #try: lines = [] colinfo = None for line in bin.splitlines(): if line[0] == '#' or line[0:2] == '"#': continue # カラム情報の取得 if not colinfo: for row in csv.reader(line): for e in row: if colinfo == None: colinfo = [] colinfo.append(e) # カラムにcheckedをいれる for col in config: if col['name'] == e: col['checked'] = 'checked' break #data['msg'] = '|'.join(colinfo) v.config = yaml.dump(config) v.put() else: rec = ProfileCore(user_db_id=udb,user=self.user) rec.put() cols = copy.deepcopy(colinfo) wk = [] for row in csv.reader(line): for e in row: name = cols.pop(0) if name: setattr(rec,name,unicode(e,self.__guess_charset(e))) #wk.append("(%s,%s)" % (name,e)) #data['msg'] = '|'.join(wk) rec.put() #except Exception, ex: # data = {'status':'error','msg':'ファイルの読み込みに失敗しました'} self.render(json=self.to_json(data)) pass