def post(self): self.response.headers ['Content-type'] = "text/html;charset=utf-8" try: bbs = db.get(self.request.get("bbs_key")) user = users.get_current_user() if(bbs.bbs_mode==BbsConst.BBS_MODE_ONLY_ADMIN): if(OwnerCheck.check(bbs,user)): self.response.out.write("[error]") return if(self.request.get("thread_key")): thread=db.get(self.request.get("thread_key")) timage=thread.image_key if(OwnerCheck.check(bbs,user)): if(thread.delete_key=="" or thread.delete_key!=self.request.get("delete_key")): self.response.out.write("[error]") return else: timage=ThreadImage() timage.bbs_key=db.get(self.request.get("bbs_key")) timage.image=db.Blob(self.request.get("image")) timage.thumbnail=db.Blob(self.request.get("thumbnail")) #削除するチャンクのリスト old_chunk_list_key=copy.deepcopy(timage.chunk_list_key) #Chunkに分割して入れる timage.moper=None timage.chunk_list_key=ChunkManager.upload(self.request.get("moper"),db.get(self.request.get("bbs_key"))) timage.gif_thumbnail=db.Blob(self.request.get("gif_thumbnail")) timage.illust_mode=2; timage.width=int(self.request.get("canvas_width")) timage.height=int(self.request.get("canvas_height")) timage.put() ImageFile.invalidate_cache(str(timage.key())) self.response.out.write(""+str(timage.key())) #古いデータの削除 if(old_chunk_list_key): ChunkManager.delete(old_chunk_list_key) except: self.response.out.write("[error]") return #投稿数の更新 if(user): ApiUser.invalidate_thread_count(user.user_id())
def update_thread(self,bbs,thread,user): compiled_line = re.compile("\r\n|\r|\n") title = self.request.get('thread_title') title=self.escape_comment(title) thread.title = title thread.author=self.request.get('thread_author') category = self.request.get("thread_category") thread.category=category CategoryList.add_new_category(bbs,category) event_id = self.request.get("event_id") thread.event_id=event_id summary = self.request.get('thread_summary') summary = compiled_line.sub(r'', summary) thread.summary = summary postscript = self.request.get('thread_postscript') postscript = compiled_line.sub(r'', postscript) thread.postscript = postscript new_show_in_portal = int(self.request.get('dont_show_in_portal')) if((thread.violate_photo and not new_show_in_portal) or (not thread.violate_photo and new_show_in_portal)): ApiFeed.invalidate_cache() thread.violate_photo = new_show_in_portal self.link_to_profile(thread,user) thread.adult=int(self.request.get("regulation")) #thread.hidden_in_list = int(self.request.get('hidden_in_list')) try: thread.comment_cnt = int(self.request.get('comment_cnt')) except: Alert.alert_msg_with_write(self,"コメント数は数値である必要があります。"); return True thread.search_index_version=0 #インデックス更新 thread.put() if(thread.user_id): ApiUser.invalidate_thread_count(thread.user_id) return False
def delete_thread_core(thread): #イラストの総数の更新リクエスト thread.bbs_key.cached_threads_num=None thread.bbs_key.put() if(thread.user_id): ApiUser.invalidate_thread_count(thread.user_id) #レスの削除 entry_query=Entry.all().filter("thread_key =",thread) for entry in entry_query: if(entry.illust_reply_image_key): entry.illust_reply_image_key.delete() #画像の削除 if(thread.image_key): if(thread.image_key.chunk_list_key): for key in thread.image_key.chunk_list_key: db.get(key).delete() thread.image_key.delete() thread.delete()
def get(self): user = users.get_current_user() user_name=ShowEntry.get_user_name(user) bbs_list=[] if(user): user_id=user.user_id() bookmark_bbs_list=ApiBookmark.bookmark_get_bbs_list(self,user_id) rental_bbs_list=ApiUser.user_get_bbs_list(self,user_id) if(rental_bbs_list): bbs_list.extend(rental_bbs_list) if(bookmark_bbs_list): bbs_list.extend(bookmark_bbs_list) sample_bbs={ "title":"サンプルお絵描き掲示板", "key":MappingId.mapping("sample") } bbs_list.append(sample_bbs) temp_key=self.request.get("temp_key") args=None if(temp_key): temp=db.get(temp_key) if(temp.args): args=temp.args target_bbs=self.get_target_bbs(args); if(target_bbs): bbs_list=target_bbs template_values={ 'host':"./", 'is_iphone':CssDesign.is_iphone(self), 'is_tablet':CssDesign.is_tablet(self), 'is_english':CssDesign.is_english(self), 'temp_key':temp_key, 'redirect_url':self.request.path+"?temp_key="+temp_key, 'user':user, 'bbs_list':bbs_list, 'args':args, 'user_name':user_name } render=template_select.render("/html/upload_temp.html", template_values) self.response.out.write(render)
def get(self): SetUtf8.set() #Query文字列を取得 query=self.request.query_string; #RESULT result_dic={} request_no=0 #APIリクエストに分解 api_list=query.split(":") for api in api_list: #APIの引数を取得 args=api.split("&") #引数をDictionaryに分解 api_args={} for arg in args: params=arg.split("=") if(len(params)>=2): api_args[params[0]]=params[1] #呼び出しAPIのクラス名を決定 if(api_args.has_key("class")): #ダミーリクエストハンドラーを作成 req=HttpHandlerHook() req.request.args=api_args req.request.host=self.request.host #API呼び出し dic=None if(api_args["class"]=="api_bookmark"): dic=ApiBookmark.get_core(req) if(api_args["class"]=="api_user"): dic=ApiUser.get_core(req) if(api_args["class"]=="api_feed"): dic=ApiFeed.get_core(req) if(dic==None): logging.error("UnknownClass:"+api_args["class"]) else: result_dic["request"+str(request_no)]=dic request_no=request_no+1 ApiObject.write_json_core(self,result_dic)
def post(self): is_flash=self.request.get('mode')=="illust" or self.request.get('mode')=="illust_all"; is_english=CssDesign.is_english(self) if(self.request.get('thread_title')==""): if(is_english): self.write_status(is_flash,"Please input title"); else: self.write_status(is_flash,"スレッドタイトルを入力して下さい。"); return if(self.request.get('author')==""): if(is_english): self.write_status(is_flash,"Please input author"); else: self.write_status(is_flash,"投稿者名を入力して下さい。"); return permission_error_str="スレッドを作成する権限がありません。" if(is_english): permission_error_str="Permission denied" login_require="ログインが必要です。" if(is_english): login_require="Login require" bbs = db.get(self.request.get("bbs_key")) user = users.get_current_user() if(not user and self.request.get('mode')=="illust_all"): self.write_status(is_flash,login_require); return if(bbs.bbs_mode==BbsConst.BBS_MODE_ONLY_ADMIN): if(OwnerCheck.check(bbs,user)): self.write_status(is_flash,permission_error_str); return if(bbs.bbs_mode==BbsConst.BBS_MODE_NO_IMAGE): if(bbs.disable_create_new_thread==1): if(OwnerCheck.check(bbs,user)): self.write_status(is_flash,permission_error_str); return if(bbs.disable_create_new_thread==2): if(not user): self.write_status(is_flash,permission_error_str); return if(SpamCheck.check_all(self,self.request.get('thread_title'),self.request.get("remote_host"),user,bbs,is_flash,is_english)): return homepage_addr="" if(self.request.get('homepage_addr') and self.request.get('homepage_addr')!="http://"): homepage_addr=self.request.get('homepage_addr') overwrite_mode=False if(self.request.get("thread_key")): #上書きモード #上書きの場合 overwrite_mode=True new_thread=db.get(self.request.get("thread_key")) if(OwnerCheck.check(bbs,user)): if((not user) or (not new_thread.user_id) or new_thread.user_id!=user.user_id()): if(self.request.get("delete_key")!=new_thread.delete_key or new_thread.delete_key==""): self.write_status(is_flash,"上書きをする権限がありません。"); return; else: #新規作成の場合 new_thread = MesThread() new_thread.put() #キーの確保 new_thread.score = None new_thread.comment_cnt=0 bbs.illust_n=bbs.illust_n+1 bbs.cached_threads_num=None #キャッシュ更新リクエスト bbs.put() #上書きモードの場合は作成日を更新しない new_thread.create_date=datetime.datetime.today() #更新日は更新する new_thread.date=datetime.datetime.today() #各種設定値を書き込み new_thread.illust_mode = int(self.request.get('illust_mode')) new_thread.title = cgi.escape(self.request.get('thread_title')) if(self.request.get('mode')=="illust_all"): new_thread.summary = self.request.get('comment') else: new_thread.summary = cgi.escape(self.request.get('comment')) new_thread.bbs_key = db.Key(self.request.get('bbs_key')) new_thread.summary=EscapeComment.escape_br(new_thread.summary) new_thread.homepage_addr=homepage_addr new_thread.author=self.request.get('author') if(self.request.get("draw_time")): new_thread.draw_time=int(self.request.get("draw_time")) if(self.request.get("delete_key")): new_thread.delete_key=self.request.get("delete_key") if(self.request.get("category")): new_thread.category=self.request.get("category") CategoryList.add_new_category(bbs,new_thread.category) if(self.request.get("event_id")): new_thread.event_id=self.request.get("event_id") if(self.request.get("regulation")): new_thread.adult=int(self.request.get("regulation")) if(self.request.get("dont_show_in_portal")): new_thread.violate_photo=1 if(self.request.get("is_png")): new_thread.is_png=1 else: new_thread.is_png=0 #プロフィールにリンクするか link_to_profile=StackFeed.is_link_to_profile(self) if(link_to_profile and user): new_thread.user_id=user.user_id() #通常投稿モード(MOPER) if(self.request.get('mode')=="illust"): new_thread.image_key=db.get(self.request.get('thread_image')) new_thread.mail=self.request.get('thread_mail') compiled_line = re.compile("(http://[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)") new_thread.summary = compiled_line.sub(r'<a href=\1 TARGET="_blank">\1</a>', new_thread.summary) if(user): new_thread.user_id=user.user_id() #必ずプロフィールにマップ #一括投稿モード(新エディタ) timage=None if((self.request.get('mode')=="illust_all" or self.request.get('mode')=="illust_temp") and new_thread.illust_mode!=BbsConst.ILLUSTMODE_TEXT): timage=ThreadImage() timage.bbs_key=db.get(self.request.get("bbs_key")) if(self.request.get('mode')=="illust_temp"): try: temp_image=db.get(self.request.get("temp_illust_key")) except: temp_image=None if(not temp_image): self.write_status(is_flash,"画像データが見つかりません。") return timage.image=temp_image.image timage.thumbnail=temp_image.thumbnail else: if(self.request.get("base64") and self.request.get("base64")=="1"): timage.image=db.Blob(base64.b64decode(self.request.get("image"))) timage.thumbnail=db.Blob(base64.b64decode(self.request.get("thumbnail"))) new_thread.is_ipad=1 else: timage.image=db.Blob(self.request.get("image")) timage.thumbnail=db.Blob(self.request.get("thumbnail")) if(len(timage.image)<=0 or len(timage.thumbnail)<=0): self.write_status(is_flash,"画像データが不正です。"); return timage.illust_mode=new_thread.illust_mode timage.is_png=new_thread.is_png timage.thumbnail2=None try: timage.put() except: if(is_english): self.write_status(is_flash,"Too big image"); else: self.write_status(is_flash,"画像の容量が大きすぎます。"); return new_thread.image_key=timage ImageFile.invalidate_cache(str(timage.key())) #url assign MappingThreadId.assign(bbs,new_thread,False) #IPアドレスを書き込み new_thread.remote_addr=self.request.remote_addr new_thread.remote_host=self.request.get("remote_host") new_thread.thumbnail2_version=0 new_thread.search_index_version=0 #put if(not SyncPut.put_sync(new_thread)): message="イラストの投稿は成功しましたが表示が遅延しています。反映まで数分お待ちください。" memcache.set(BbsConst.OBJECT_BBS_MESSAGE_HEADER+str(bbs.key()),message,BbsConst.OBJECT_BBS_MESSAGE_CACHE_TIME) #サムネイル更新 if(timage): if(new_thread.adult==0): bbs.cached_thumbnail_key=str(timage.key()) bbs.put() #新着イラストのキャッシュ無効化 RecentCommentCache.invalidate(bbs) #ステータスを出力 if(is_flash): self.write_status(is_flash,"success") else: self.redirect(str('./bbs_index?bbs_key='+self.request.get('bbs_key'))) #feed if(not link_to_profile): user=None url=self.get_thread_url(bbs,new_thread) if(not overwrite_mode): try: StackFeed.feed_new_thread(user,bbs,new_thread) except: logging.error("new thread stack feed add error") #submit thread count if(user): ApiUser.invalidate_thread_count(user.user_id()) #news ApiFeed.invalidate_cache() #Rss RssFeed.invalidate_cache(str(bbs.key()))
def _user_page(self,user,user_id,page,request_page_mode,redirect_api,contents_only): illust_enable=False submit_illust_exist=True submit_moper_exist=True bookmark_illust_exist=True thread_list=None #プロフィール bookmark=None if(user_id): bookmark=ApiObject.get_bookmark_of_user_id(user_id) #イラストの存在を検出 submit_illust_count=ApiUser.user_get_is_submit_thread_exist(self,user_id,bookmark) submit_moper_count=ApiUser.user_get_is_submit_moper_exist(self,user_id,bookmark) bookmark_illust_count=ApiBookmark.bookmark_get_is_bookmark_thread_exist(self,user_id,bookmark) if(bookmark_illust_count==0): bookmark_illust_exist=False if(submit_illust_count==0): submit_illust_exist=False if(submit_moper_count==0): submit_moper_exist=False #マイユーザか view_mode=1 if(user): if(user_id==user.user_id()): view_mode=0 #管理モード if(self.request.get("admin")): if(OwnerCheck.is_admin(user)): view_mode=0 #タブ tab=Pinterest._decide_default_tab(self,bookmark_illust_exist,submit_illust_exist,submit_moper_exist,view_mode,bookmark,user,request_page_mode) #フィード数の消化 new_feed_count=Pinterest._get_new_feed_count(user,view_mode,bookmark) new_my_feed_count=Pinterest._get_new_my_feed_count(user,view_mode,bookmark) if(tab=="feed"): bookmark=Pinterest._consume_feed(user,view_mode,bookmark) #プロフィールを編集 edit_profile=Pinterest.get_profile_for_edit(bookmark,view_mode) #編集モードかどうか edit_mode=0 if(self.request.get("edit")): edit_mode=int(self.request.get("edit")) bookmark_bbs_list=None rental_bbs_list=None bookmark_mute_bbs_list=None if(tab=="bbs"): thread_list=None illust_enable=False bookmark_bbs_list=ApiBookmark.bookmark_get_bbs_list(self,user_id) bookmark_mute_bbs_list=ApiBookmark.bookmark_get_mute_bbs_list(self,user_id) rental_bbs_list=ApiUser.user_get_bbs_list(self,user_id) timeline=None timeline_unit=0 use_masonry=True is_timeline_enable=0 infinite_scroll_selecter=".item" if(tab=="feed" or tab=="timeline"): thread_list=None is_timeline_enable=1 illust_enable=False if(tab=="feed" and not view_mode): timeline=ApiUser.user_get_home_timeline(self,user_id) else: timeline=ApiUser.user_get_timeline(self,user_id) timeline_unit=len(timeline) use_masonry=False infinite_scroll_selecter=".feed" only_one_page=False if(tab=="bookmark"): thread_list=ApiBookmark.bookmark_get_thread_list(self,user_id,bookmark) if(bookmark_illust_count<=BbsConst.PINTEREST_MYPAGE_PAGE_UNIT): only_one_page=True if(tab=="submit" or tab=="moper"): #イラストが消去されている場合を考慮してスレッドが見つかるまでページを進める if(tab=="submit"): max_page_src=submit_illust_count else: max_page_src=submit_moper_count max_page=(max_page_src+BbsConst.PINTEREST_MYPAGE_PAGE_UNIT-1)/BbsConst.PINTEREST_MYPAGE_PAGE_UNIT thread_list=[] original_page=page while(page<=max_page): limit=BbsConst.PINTEREST_MYPAGE_PAGE_UNIT offset=limit*(page-1) illust_mode=BbsConst.ILLUSTMODE_ILLUST if(tab=="moper"): illust_mode=BbsConst.ILLUSTMODE_MOPER thread_list=ApiUser.user_get_thread_list_core(self,user_id,offset,limit,illust_mode) if(len(thread_list)>=1): break page=page+1 if(max_page<=1): only_one_page=True submit_illust_list=thread_list if(len(thread_list)==0 and original_page==1): ApiUser.invalidate_thread_count(user_id) #削除した場合に0になったことを考慮 page_mode="user" view_user=ApiUser.user_get_user(self,user_id,bookmark) view_user_profile=ApiUser.user_get_profile(self,user_id,bookmark) tag_list=None next_query="user_id="+user_id+"&tab="+tab+"&edit="+str(edit_mode) if(only_one_page): next_query=None only_icon=True if(edit_mode): only_icon=False follow=ApiUser.user_get_follow(self,user_id,only_icon,bookmark) follower=ApiUser.user_get_follower(self,user_id,only_icon) following=Pinterest.is_following(user,user_id,view_mode) age=Pinterest.get_age(bookmark) mute_user_list=[] mute_bbs_list=[] if(bookmark): mute_user_list=bookmark.get_mute_user_list() mute_bbs_list=bookmark.get_mute_bbs_list() #詳細情報の存在 detail_exist=False if(bookmark): if(bookmark.sex or age): detail_exist=True if(bookmark.birthday_month or bookmark.birthday_day or bookmark.birthday_year): detail_exist=True if(bookmark.homepage or bookmark.mail or bookmark.twitter_id): detail_exist=True #凍結 if(bookmark and bookmark.frozen): thread_list=None #アイコンの規約違反 violate_icon=False if(bookmark): if(bookmark.thumbnail_created==2): violate_icon=True is_flat=True is_english=CssDesign.is_english(self) template_values = { 'user': user, 'thread_list': thread_list, 'redirect_url': self.request.path, 'page': page, 'next_page': page+1, 'next_query': next_query, 'page_mode': page_mode, 'tag': None, 'view_user': view_user, 'view_user_profile': view_user_profile, 'user_id': user_id, 'follow': follow, 'follower': follower, 'muting': mute_user_list, 'mute_user_list': mute_user_list, 'mute_bbs_list': mute_bbs_list, 'view_mode': view_mode, 'edit_mode': edit_mode, 'tab': tab, 'bookmark': bookmark, 'is_timeline_enable': is_timeline_enable, 'following':following, 'bookmark_bbs_list': bookmark_bbs_list, 'bookmark_mute_bbs_list': bookmark_mute_bbs_list, 'rental_bbs_list': rental_bbs_list, 'illust_enable': illust_enable, 'edit_profile': edit_profile, 'redirect_url': self.request.path, 'new_feed_count': new_feed_count, 'new_my_feed_count': new_my_feed_count, 'submit_illust_exist': submit_illust_exist, 'submit_moper_exist': submit_moper_exist, 'bookmark_illust_exist': bookmark_illust_exist, 'regist_finish': (request_page_mode==Pinterest.PAGE_MODE_REGIST), 'redirect_api': redirect_api, 'age': age, 'contents_only': contents_only, 'search': None, 'top_page': False, 'detail_exist': detail_exist, 'is_admin': OwnerCheck.is_admin(user), 'use_masonry': use_masonry, 'timeline': timeline, 'timeline_unit': timeline_unit, 'infinite_scroll_selecter': infinite_scroll_selecter, 'flat_ui': is_flat, 'violate_icon': violate_icon, 'is_english': is_english } Pinterest._render_page(self,template_values)