def get(self): uname = self.get_current_user() user = User.get_user_by_name(uname) order = get_order() story = Story.get_by_porder(order) sid = self.get_argument("sid",None) if sid is not None: story=Story.get_by_sid(sid) article = Article.get_all_Astory(200) usedStory = Story.get_all_story() temp = [] for one in usedStory: if one.porder > 0 and one.porder <= order: temp.append(one) usedStory = temp reArticles = Article.get_all(200) Rarticle = sorted(reArticles,BaseHandler.rank) Ruser = User.get_all_user(100) if len(Rarticle) > 6: Rarticle=Rarticle[:6] if len(usedStory)>3: usedStory=usedStory[:3] if len(Ruser)>9: Ruser=Ruser[:9] self.render("story.html",user=user,Rarticle=Rarticle,Article=article,usedStory=usedStory,Ruser=Ruser,story=story)
def post(self): sid = self.get_argument('sid') root = self.get_secure_cookie('root') if root != 'suiyue': return self.redirect('/rootlogin') stories = Story.get_by_sid(sid) ext_allowed = ['gif', 'jpg', 'jpeg', 'png'] spic = stories[0].pic max_size = 2621440 save_dir = os.path.join(os.path.dirname(__file__), "../public/pic/story/") if len(stories)>0: file_name = str(stories[0].sid) error = "" if 'image' in self.request.files: pic = self.request.files['image'][0] ext = pic['filename'].split('.').pop() if ext not in ext_allowed: error="图片格式不支持" self.redirect('/control') if len(pic['body'])>max_size: error="图片太大" self.redirect('/control') spic = file_name+"."+ext with open(save_dir+spic,'wb') as up: up.write(pic['body']) Story.change_pic(sid, spic) self.redirect("/control") else: self.redirect('/control')
def post(self): uname = self.get_current_user() user = User.get_user_by_name(uname) title = self.get_argument("title") content = self.get_argument("content") pic = "default.jpg" Story.add_one_story(pic,user[0].uid,title,content) self.render("wstory.html", msg="投稿成功,谢谢你的idea",user=user)
def post(self): sid = self.get_argument('sid') porder = self.get_argument('porder') root = self.get_secure_cookie('root') if root == 'suiyue': temp = Story.get_by_porder(porder) if len(temp) > 0: Story.change_porder(temp[0].sid, 0) Story.change_porder(sid, porder) self.redirect('/control') else: self.redirect('/rootlogin')
def audio(image_id): """Content rendered endpt for audio mimetypes""" grid = Story.getgridfs() file_obj = grid.get(ObjectId(audio_id)) if file_obj.content_type not in ['audio/mp3']: abort(400) return Response(file_obj,mimetype=file_obj.content_type)
def get(self): root = self.get_secure_cookie('root') if root=='suiyue': current_order = get_order() cards = Card.get_all_card() stories = Story.get_all_story() self.render("control.html", order=current_order, cards=cards, stories=stories) else: self.redirect('/rootlogin')
def image(image_id): """Content rendered endpt for image mimetypes""" grid = Story.getgridfs() file_obj = grid.get(ObjectId(image_id)) if file_obj.content_type not in ['image/jpeg','image/png']: abort(400) if request.values.get('thumb',None): file_obj = resize_image(file_obj,(120,120)) return Response(file_obj,mimetype=file_obj.content_type)
def get(self): uname=self.get_current_user() user=User.get_user_by_name(uname) if len(user) > 0: cid = self.get_argument("cid", None) sid = self.get_argument("sid", None) Class = "free" if cid is not None: Class="card" elif sid is not None: Class="story" card=Card.get_by_cid(cid) story=Story.get_by_sid(sid) self.render("write.html",user=user,card=card,story=story,Class=Class) else: self.redirect("/login")
def post(self) -> Response: try: if request.is_json: data = request.get_json() data['uid'] = generate_uid(data) post_story = Story(**data).save() return jsonify({'id': str(post_story.id)}) else: return send_err(httplib.BAD_REQUEST) except (FieldDoesNotExist, ValidationError): return send_err(httplib.BAD_REQUEST) except: return send_err(httplib.INTERNAL_SERVER_ERROR)
def stories(): """Submit a new story/file if post, output those in range if get""" if request.method == 'POST': #save a story uploader = request.values.get('uploader') description = request.values.get('desc') lat = request.values.get('lat') lon = request.values.get('lon') files = [request.files[f] for f in request.files] story = Story.create(uploader,description,lat,lon,files) return Response([json.dumps({'flag':1,'story':story},cls=Encoder,indent=4)],mimetype='application/json') elif request.method == 'GET': #browse stories lat = float(request.values.get('lat',HERE_LAT)) lon = float(request.values.get('lon',HERE_LON)) stories = getstories(lat,lon) return Response([json.dumps({'stories':stories},cls=Encoder)],mimetype='application/json')
def get(self): story = Story.get_or_insert('Some id or so', title='A voting story again...') jinja_environment = self.jinja_environment template = jinja_environment.get_template("/index.html") self.response.out.write(template.render({'story': story}))
' my grandpa, Joachim, was born in 1912 in modern day Poland and his father ' + \ '(originally a Polish Jew) applied for German citizenship for himself, his wife ' + \ 'and his five children as they were all living in Germany. Joachim, Juliette, Ali ' + \ '(Alfred), Fredy (Friedrich) and Hans all became German. In the early 1930s, 20 something ' + \ 'Joachim (born in 1912) fled Germany for the U.K. He convinced most of his siblings to come ' + \ 'too, but Juliette stayed behind with her husband and young son. She escaped Germany but was caught ' + \ 'in Vichy France and she was killed by the Nazis. Her son and husband survived. Her grave is in Albi and was visited by ' + \ 'her brother Joachim and his wife(my grandparents) for the first time on their honeymoon in the 1950s. My grandpa Joe met ' + \ 'my grandmother Pam in Nigeria after he was sent to Egypt with the Royal West African Frontier Force, British Army. There he ' + \ 'met a Nigerian businessman who invited him to come to Nigeria and try and start a business. They had 5 children, including my ' + \ 'mum Penny. Just in case you’re interested 🙂🇪🇺' origins = Story( title='A story about my Jewish origins', description= 'Collecting our German naturalisation certificates this morning!', content=first_story, image_url= 'https://jewishculture.illinois.edu/sites/default/files/inline-images/IMG_0056.JPG', creator=gaetano) if errors: raise Exception(errors) second_story = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ' + \ 'ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi' + \ 'ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum' + \ 'dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia' + \ 'deserunt mollit anim id est laborum.' lorem = Story( title='The standard Lorem Ipsum passage, used since the 1500s',
def create_story(title, number_of_reads): story = Story() story.title = title story.number_of_reads = number_of_reads story.save()