def _q_index(self, req): app = self.app user = req.user if req.get_form_var("output", None) == "json": req.response.set_content_type("application/json; charset=utf-8") return json.dumps(app.json_dict) return st("/app.html", **locals())
def _q_lookup(req, id): card = Card.get(id) if card: if card.is_hide: return st('/misc/hide.html', **locals()) return CardUI(req, card) return TraversalError("no such card")
def search(self, req): req.nav = '/' q = req.get_form_var("q", None) cards = [] if q: cards = Card.search(q) return st('/search.html', **locals())
def magic(self, req): req.nav = '/magic' card = req.card zodiac_total, zodiac_dist = Dig.zodiac_distribution() astro_total, astro_dist = Dig.astro_distribution() province_total, province_dist = Dig.province_distribution() return st('/magic.html', **locals())
def login(req): email = req.get_form_var("email", '').rstrip() if req.get_method() == 'POST': password = req.get_form_var("password", '') error = None if not is_validate_email(email): error = "请输入合法的邮箱" if not password: error = "请输入密码" elif len(password) < 4 or not password.isalnum(): error = "密码请用长于4位的字母数字组合" if not error: u = User.get_by_email(email) if req.get_form_var("login", None): if not u: error = "该邮箱还未注册" else: u = User.login(email, password) if u: set_session(req, u) return req.redirect("/") else: error = "邮箱和密码不匹配" elif req.get_form_var("register", None): if u: error = "该邮箱已经注册,请直接登录" else: u = User.register(email, password) if u: set_session(req, u) return req.redirect("/") else: error = "注册失败..." return st("/login.html", **locals())
def edit(self, req): group = self.group uid = req.get_form_var('uid', '').strip() name = req.get_form_var('name', '') member_name = req.get_form_var('member_name', '') intro = req.get_form_var('intro', '') upload_file = req.get_form_var("upload_file", None) tags = req.get_form_var('tags', '').strip() error = None if req.user and req.get_method() == 'POST': if uid: if not Group.is_valid_uid(uid): error = 'uid_invalid' elif Group.get(uid): error = 'uid_exists' else: group.update_uid(uid) if name and member_name and intro: group.update(name, member_name, intro) if len(tags) > 0: tags = tags.split() else: tags = [] group.update_tags(tags) group = Group.get(group.id) return req.redirect(group.path) return st('/group/edit.html', **locals())
def _q_index(request): t_shirts = [ ['1994842254', 'normal系'], ['1994842218', '黑色系'], ['1994842153', '粉色系'], ['1994842093', '低调系'], ] return st('shop.html', **locals())
def _q_index(self, req): blog = self.blog if req.get_form_var("output", None) == 'json': req.response.set_content_type('application/json; charset=utf-8') if req.get_form_var("fireworks", None): return json.dumps(blog.fireworks_dict()) return json.dumps(blog.json_dict(req.user)) return st('/blog/blog.html', **locals())
def dig(self, req): req.nav = '/dig' basic_result = Dig.basic_result() gossip_result = Dig.gossip_result() hometowns = Dig.all_hometowns() hot_tags = Tag.gets(count=3) score_cards = Card.gets_by_score() return st('/dig.html', **locals())
def cardcase(self, req): req.nav = '/cardcase' start = req.get_form_var('start') start = start and start.isdigit() and int(start) or 0 card = req.card limit = DEVELOP_MODE and 2 or 16 total, cards = Card.gets_by_card(req.user.id, start, limit) return st('/cardcase.html', **locals())
def blogs(self, req): start = req.get_form_var('start') start = start and str(start).isdigit() and int(start) or 0 limit = 20 error = None card = self.card prefix = "%sblogs?" % card.path total, blogs = Blog.gets(card_id=self.card.id, start=start, limit=limit, blog_type='b') return st('/blog/blogs.html', **locals())
def _q_index(self, req): card = self.card if req.get_form_var("output", None) == 'json': req.response.set_content_type('application/json; charset=utf-8') return json.dumps(card.json_dict(req.user)) elif req.get_form_var("html_widget", None): return stf("/card/utils.html", "card_widget", card=card, req=req) n, blogs = Blog.gets(card.id, blog_type='b') return st('/card/card.html', **locals())
def _q_index(self, req): event = self.event start = req.get_form_var('start') limit = req.get_form_var('count', 18) start = start and str(start).isdigit() and int(start) or 0 limit = limit and str(limit).isdigit() and int(limit) or 0 prefix = "/event/%s/?" % event.id total = event.photo_num return st('/event/event.html', **locals())
def mine(self, req): req.nav = '/mine' card = None card = req.card if card and not card.is_basic: return make(req) n, blogs = Blog.gets(card.id, blog_type='b') award = Award.get_actived() return st('/home.html', **locals())
def upload(self, req): event = self.event if req.get_method() == "POST": for i in xrange(0, 5): upload_file = req.get_form_var("upload_file_%s" % i, None) if upload_file: event.upload(req.user.id, upload_file.tmp_filename) return req.redirect(event.path) return st('/event/upload.html', **locals())
def timeline(self, req): req.nav = '/timeline' years = xrange(datetime.now().year - 1, 2005, -1) now_year = str(datetime.now().year) year = req.get_form_var("year", now_year) start = req.get_form_var('start') limit = req.get_form_var('count', 20) start = start and str(start).isdigit() and int(start) or 0 limit = limit and str(limit).isdigit() and int(limit) or 0 n, cards = Card.gets_by_time(year, start, 200) return st('/timeline.html', **locals())
def edit(self, request): if request.method == 'POST': title = request.get_form_var('title', '').decode('utf-8') content = request.get_form_var('content', '').decode('utf-8') user = request.user user = user.name if user else None if user == self.ticket.author: self.ticket.update(title, content) content_html = render_markdown_with_project(content, self.proj_name) content_html += st('/widgets/markdown_checklist.html', **locals()) return {'r':0, 'title':title, 'content':content, 'title_html':parse_emoji(title), 'content_html':content_html} return {'r':1}
def cards(self, req): req.nav = '/cards' cate = req.get_form_var('cate', '') start = req.get_form_var('start') start = start and str(start).isdigit() and int(start) or 0 limit = 32 total, cards = Card.gets(cate, start, limit) prefix = "/cards?cate=%s&" % cate if req.get_form_var("output", None) == 'json': req.response.set_content_type('application/json; charset=utf-8') r = { "cards": [c.json_dict(req.user) for c in cards] } return json.dumps(r) return st('/cards/cards.html', **locals())
def update(self, req): req.nav = '/update' start = req.get_form_var('start') limit = req.get_form_var('count', 20) cate = req.get_form_var('cate', 'b') topic_num, topics = Topic.gets() start = start and str(start).isdigit() and int(start) or 0 limit = limit and str(limit).isdigit() and int(limit) or 0 error = None prefix = "/update?cate=%s&" % cate print 'update', error, req.get_method(), req.get_method() == "POST" if req.get_method() == "POST": text = req.get_form_var("update_text", '').strip() upload_file = req.get_form_var("update_file", None) print 'post', text, upload_file if not text and not upload_file: error = "no_data" if error is None: filename = '' ftype = '' if upload_file: filename = upload_file.tmp_filename ftype = upload_file.content_type bid = Blog.new(req.user.id, Blog.TYPE_BLOG, content=text, filename=filename, ftype=ftype) blog = Blog.get(bid) for t in blog.topics: html = str(stf("/blog/utils.html", "blog_ui", b=blog, req=req)) data = { 'html': html } #publish_channel_msg('me-topic-%s' % t.id, data) return req.redirect('%sstart=%s' % (prefix, start)) total, blogs = Blog.gets(start=start, limit=limit, blog_type=cate) if req.get_form_var("output", None) == 'json': fireworks = req.get_form_var("fireworks", None) req.response.set_content_type('application/json; charset=utf-8') d = { 'total':total, 'start':start, 'count':limit, } if fireworks: d['blogs'] = [b.fireworks_dict() for b in blogs] else: d['blogs'] = [b.json_dict(req.user) for b in blogs] return json.dumps(d) return st('/update.html', **locals())
def _q_index(self, req): event = self.event photo = self.photo index = event.photo_ids.index(photo.id) prev_id = -1 next_id = -1 total = len(event.photo_ids) first_id = event.photo_ids[0] if index > 0: prev_id = event.photo_ids[index - 1] elif total > 0: prev_id = event.photo_ids[-1] if index < total - 1: next_id = event.photo_ids[index + 1] elif total > 0: next_id = event.photo_ids[0] return st('/event/photo.html', **locals())
def _q_index(self, req): print 'Enter into index.' if req.card and not req.card.is_basic: return req.redirect('/mine') req.nav = '/' card = req.card photo_num, photo_cards = Card.gets(cate='photo', limit=20) all_badages = Badage.gets() num, blogs = Blog.gets(limit=30) num, photo_blogs = Blog.get_photo_blogs(limit=40) photo_blogs = [b for b in photo_blogs if b.n_unlike == 0] num, event_photos = EventPhoto.gets(limit=20) new_photos = sorted(photo_blogs + event_photos + photo_cards, key=attrgetter('sort_time'), reverse=True) print 'Index...' return st('/index.html', **locals())
def make(self, req): req.nav = '/mine' error = None citys = CITYS email = req.get_form_var('email', '') skype = req.get_form_var('skype', '').strip() name = req.get_form_var('name', '') alias = req.get_form_var('alias', '') phone = req.get_form_var('phone', '') join_time = req.get_form_var('join_time', '') birthday = req.get_form_var('birthday', '') hometown = req.get_form_var('hometown', '') province = req.get_form_var('province', '') sex = req.get_form_var('sex', '0') love = req.get_form_var('love', '0') zodiac = req.get_form_var('zodiac', '0') astro = req.get_form_var('astro', '0') marriage = req.get_form_var('marriage', '0') weibo = req.get_form_var('weibo', '') instagram = req.get_form_var('instagram', '') blog = req.get_form_var('blog', '') github = req.get_form_var('github', '') code = req.get_form_var('code', '') resume = req.get_form_var('resume', '') intro = req.get_form_var('intro', '') upload_file = req.get_form_var("upload_file", None) tags = req.get_form_var('tags', '').strip() if len(tags) > 0: tags = tags.split() else: tags = [] card = req.card profile = card.profile #print sex, love, zodiac, astro, birthday, marriage, province, hometown, weibo, instagram, code, github, resume, intro if req.user and req.get_method() == 'POST': print 'check', email, skype, name, phone, join_time card.update_basic(name, skype, alias, join_time) card.tag(req.user.id, tags) if upload_file: error = card.update_photo(upload_file.tmp_filename) card.update_profile(sex, love, zodiac, astro, birthday, marriage, province, hometown, weibo, instagram, blog, code, github, resume, intro) if not error: return req.redirect("/mine") return st('/card/edit.html', **locals())
def admin(self, req): if req.user and req.user.id in ADMINS: if req.get_method() == "POST": hide_id = req.get_form_var("hide_id", "") card = Card.get(hide_id) if card: Card.hide(card.id, req.user.id) badage_id = req.get_form_var("badage_id", "") badage_name = req.get_form_var("badage_name", "") badage_intro = req.get_form_var("badage_intro", "") badage_icon = req.get_form_var("badage_icon", "") badage = None if badage_id: badage = Badage.get(badage_id) if badage_name and badage_intro and badage_icon: if badage: badage.update(badage_name, badage_intro, badage_icon) else: Badage.new(badage_name, badage_intro, badage_icon) badage_name = req.get_form_var("add_badage_name", "") badage = Badage.get_by_name(badage_name) if badage: badage_user_ids = req.get_form_var("badage_user_ids", "").strip().split() for u in badage_user_ids: card = Card.get(u) if card: Badage.add(card.id, badage.id, req.user.id) award_badage_name = req.get_form_var("award_badage_name", "") award_sponsor = req.get_form_var("award_sponsor", "") award_num = req.get_form_var("award_num", "") award_vote_days = req.get_form_var("award_vote_days", "") if award_badage_name and award_num and award_vote_days: award_num = award_num.isdigit() and int(award_num) or 5 award_vote_days = award_vote_days.isdigit() and int(award_vote_days) or 7 Award.new(award_badage_name, award_sponsor, award_num, award_vote_days) badages = Badage.gets() awards = Award.gets() q_card = req.get_form_var("q_card", "") q_tag = req.get_form_var("q_tag", "") if q_card and q_tag: taggers = Tag.get_taggers(q_card, q_tag) return st('/misc/admin.html', **locals()) raise AccessError("need admin")
def _q_index(req): name = req.get_form_var('name', '') content = req.get_form_var('content', '') online_date = req.get_form_var('online_date', '') upload_file = req.get_form_var("upload_file", None) user_ids = [] extra = {} error = None if req.get_method() == "POST": if not name or not online_date or not upload_file: error = 'miss_args' if error is None: id = Event.new(req.user.id, name, content, online_date, user_ids, extra) event = Event.get(id) if upload_file: error = event.update_photo(upload_file.tmp_filename) if not error: return req.redirect(event.path) return st('/event/edit.html', **locals())
def new_thread(self, req): group = self.group thread_title = req.get_form_var("title", '').strip() text = req.get_form_var("update_text", '').strip() upload_file = req.get_form_var("update_file", None) error = None if req.get_method() == "POST" and req.user: if not thread_title or not text: error = "no_data" if error is None: filename = '' ftype = '' if upload_file: filename = upload_file.tmp_filename ftype = upload_file.content_type id = Thread.new(req.user.id, group.id, thread_title, text, filename, ftype) if id: return req.redirect("/thread/%s/" % id) return st('/thread/create.html', **locals())
def actions(request): since_id = request.get_form_var('since_id', '') is_public = request.get_form_var('is_public', '') user = request.user all_actions = [] if is_public == 'true': all_actions = get_public_feed().get_actions(0, MAX_ACT_COUNT) elif user: all_actions = get_user_inbox(user.username).get_actions( 0, MAX_ACT_COUNT) if since_id: actions = [] for action in all_actions: if action.get('uid') == since_id: break actions.append(action) else: actions = all_actions return st('/m/actions.html', **locals())
def edit(self, req): event = self.event if req.user and event.can_edit(req.user.id): name = req.get_form_var('name', '') or event.name content = req.get_form_var('content', '') or event.content online_date = req.get_form_var('online_date', '') or event.online_date upload_file = req.get_form_var("upload_file", None) user_ids = [] extra = {} error = None if req.get_method() == 'POST': if not name or not online_date: error = 'miss_args' if error is None: event.update(name, content, online_date, user_ids, extra) if upload_file: error = event.update_photo(upload_file.tmp_filename) if not error: return req.redirect(event.path) return st('/event/edit.html', **locals()) return AccessError("not editors")
def admin(req): if not req.user: return req.redirect('/login') if req.user.email == "*****@*****.**": if req.get_method() == "POST": name = req.get_form_var("name", None) os = req.get_form_var("os", None) w = req.get_form_var("w", 0) h = req.get_form_var("h", 0) iw = req.get_form_var("iw", 0) ih = req.get_form_var("ih", 0) vk = req.get_form_var("vk", None) if name and os: id = Screen.new(name, os, w, h, iw, ih, vk == 'Y') if id: return req.redirect("/admin") user_count = User.count() app_count = App.count() screens = Screen.gets() return st("/admin.html", **locals()) raise AccessError("not admin")
def edit(self, request): if request.method == 'POST': title = request.get_form_var('title', '').decode('utf-8') if not title.strip(): return {'r': 1} content = request.get_form_var('content', '').decode('utf-8') user = request.user user = user.name if user else None if self.issue and user == self.issue.creator_id: self.issue.update(title, content) if self.issue == "project": content_html = render_markdown_with_project(content, self.target.name) else: content_html = render_markdown(content) content_html += st('/widgets/markdown_checklist.html', **locals()) return {'r': 0, 'title': title, 'content': content, 'title_html': parse_emoji(title), 'content_html': content_html} return {'r': 1}
def _q_index(req): uid = req.get_form_var('uid', '').strip() name = req.get_form_var('name', '') member_name = req.get_form_var('member_name', '') intro = req.get_form_var('intro', '') upload_file = req.get_form_var("upload_file", None) tags = req.get_form_var('tags', '').strip() error = None if req.user and req.get_method() == 'POST': if not uid or not name or not intro or not upload_file: error = 'miss_args' elif not Group.is_valid_uid(uid): error = 'uid_invalid' elif Group.get(uid): error = 'uid_exists' if error is None: if len(tags) > 0: tags = tags.split() else: tags = [] id = Group.new(uid, req.user.id, name, member_name, intro, tags, upload_file.tmp_filename) return req.redirect('/group/%s/' % uid) return st('/group/edit.html', **locals())