def reset_post_at(self): for p in ProfileCore.all(): if p.post_at == None: p.post_at = datetime.datetime.now() p.put() else: if isinstance(p.post_at,db.DateTimeProperty) != True: p.post_at = datetime.datetime.now() p.put() self.render(text="done")
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 json(self): #id = self.params.get('id') #retrive from cookie id = self.cookies['cv_id'] if id == None: self.render(json=self.to_json([])) return self.fields = [] self.view = UserView.get_by_id(int(id)) if self.view == None: self.render(json=self.to_json([])) return # ビューの所有者とカレントのユーザが同じでなければ共有されたビュー user = self.user if self.view.user_db_id.user != self.user: sv = db.GqlQuery("SELECT * FROM ShareUser WHERE email = :1 and share_view_id = :2",self.user.email(), self.view).get() if sv: user = sv.share_view_id.user_db_id.user self.config = yaml.load(self.view.config) query = self.params.get("query") qtype = self.params.get("qtype") sortname = self.params.get("sortname") if sortname == None or sortname == '': sortname = 'id' sortorder = self.params.get("sortorder") lines = int(self.params.get("rp")) page = int(self.params.get("page")) offset = (page - 1) * lines # 絞り込み項目が選択されていれば追加 add_filters =[] if self.view: configs = yaml.load(self.view.config) for col in configs: if col['checked'] == 'checked': if col['type'] == 'radio' or col['type'] == 'select': if isinstance(getattr(ProfileCore,col['name']),db.StringProperty): val = self.params.get(col['name']) if val != None and val != '': add_filters.append({'name':col['name'],'val':val}) results = [] if (query != None and query != '' ) and ( qtype != None and qtype != ''): if qtype == 'id': p = None try: p = ProfileCore.get_by_id(int(query)) except: pass total = 0 if p != None and (p.user == user): total = 1 results.append(p) else: p = ProfileCore.all() p.filter(" user_db_id = ",self.view.user_db_id) #p.filter(" user = "******" = ",query) for f in add_filters: p.filter(f['name'] + " = ",f['val']) results=p.fetch(lines,offset) total = p.count() else: p = ProfileCore.all() p.filter(" user_db_id = ",self.view.user_db_id) #p.filter(" user = "******" = ",f['val']) is_id_sort = False if sortname != 'id' and sortname != '-id' : if sortorder.upper() == 'DESC': sortname = '-' + sortname p.order(sortname) else: is_id_sort = True results = p.fetch(lines,offset) total=p.count() if is_id_sort and (sortorder != None and sortorder.upper() == 'DESC'): results.reverse() rows = [] for rec in results: wk = {'id':rec.key().id(),"cell":[rec.key().id()]} for col in self.config: if col['checked'] == 'checked': val = getattr(rec,col['name']) if col['type'] == 'radio' or col['type'] == 'select': udm = db.GqlQuery("SELECT * FROM UserDbMaster WHERE name = :1",col['name']).get() for item in yaml.load(udm.yaml_data): if item['code'] == val: val = item['name'] if isinstance(getattr(ProfileCore,col['name']),db.DateTimeProperty): wk2 = val + datetime.timedelta(hours=9) if 'format' in col: val = wk2.strftime(col['format']) else: val = wk2.strftime('%Y/%m/%d %H:%M:%S') wk['cell'].append(val) rows.append(wk) data = {'page':page, 'total': total, 'rows': rows } self.render(json=self.to_json(data))
def export(self): id = self.params.get("id") if id == None: self.render(text="不正なリクエスト") return view = UserView.get_by_id(int(id)) # 所有者 or 権限のあるユーザかチェック canDL = False if self.user == view.user_db_id.user: canDL = True else: results = db.GqlQuery("SELECT * FROM ShareUser WHERE email = :1", self.user.email()) # results = ShareUser.all() for rec in results: if rec.share_view_id.key().id() == view.key().id(): if rec.isDownloadable(): canDL = True break if not canDL: self.render(text="不正なリクエスト(permission denied)") return results = ProfileCore.all().filter(" user_db_id =", view.user_db_id) config = yaml.load(view.config) # CSVのヘッダ情報 line = [] for col in config: if col["checked"] == "checked": # line.append('"' + col['label']+'"') line.append('"' + self.__conv(col["label"], "cp932") + '"') header = ",".join(line) + "\r\n" self.skip_rendering() res = self.getResponse() res.headers["Content-Type"] = "application/x-csv;charset:Shift_JIS" # res.headers['Content-Type'] = "application/octet-stream" if self.params.get("ie", "false") == "true": res.headers["Content-Disposition"] = "attachment; filename=" + self.params.get("filename") + ".csv" # res.out.write(header.encode('cp932')) res.out.write(header) for rec in results: line = [] for col in config: if col["checked"] == "checked": val = getattr(rec, col["name"]) # if col['type'] == 'radio' or col['type'] == 'select': # udm = db.GqlQuery("SELECT * FROM UserDbMaster WHERE name = :1",col['name']).get() # for item in yaml.load(udm.yaml_data): # if item['code'] == val: # val = item['name'] if isinstance(getattr(ProfileCore, col["name"]), db.DateTimeProperty): wk2 = val + datetime.timedelta(hours=9) if "format" in col: val = wk2.strftime(col["format"]) else: val = wk2.strftime("%Y/%m/%d %H:%M:%S") line.append('"' + val.replace('"', '""') + '"') wk = ",".join(line) + "\r\n" res.out.write(wk.encode("cp932"))