def test_current(self): with self.app.test_request_context('/'): user1 = users.current() users.auth(self.user) user2 = users.current() self.assertTrue(user1.anonymous) self.assertEqual(user2.sysid, self.user.sysid)
def commit(): video_id = request.json['video_id'] user = users.current() video = videos.find(video_id) if not user.anonymous: watchtran.commit(user, video) user = users.current() return jsonify(chances=user.chances)
def log(): user = users.current() if user.anonymous: abort(401) query = { 'user.id': ObjectId(user.sysid) } database = connection(); videos = database.screening.find(query) history_flat = [] for video in videos: history_flat.append(dict( title = video['video']['title'], datetime = video['_id'].generation_time, date = video['_id'].generation_time.strftime('%B %d'), time = video['_id'].generation_time.strftime('%H:%M'), type = 'video' )) query = { 'author.id': ObjectId(user.sysid) } comments = database.comments.find(query) for comment in comments: history_flat.append(dict( title = comment['text'], datetime = comment['_id'].generation_time, date = comment['_id'].generation_time.strftime('%B %d'), time = comment['_id'].generation_time.strftime('%H:%M'), type = 'comment' )) history = OrderedDict() orderkey = lambda item: item['datetime'] for item in sorted(history_flat, key=orderkey, reverse=True): history.setdefault(item['date'], []).append(item) g.profile_menu['active'] = 'log' return render_template('devel/log.html', history=history)
def index(): user = users.current() if user.anonymous: from advapp.shared import _make_login_url return redirect(_make_login_url()) else: return redirect(url_for('player.show'))
def load_shared_data(): menu = {} user = users.current() menu['show_login'] = user.anonymous menu['login_url'] = _make_login_url() menu['user_profile_url'] = url_for('devel.account') menu['select_top_menu'] = dict(home=False, profile=False) g.menu = menu g.user = user
def append_like(): video_id = request.json['video_id'] comment_id = request.json['comment_id'] user = users.current() comment = comments.find(comment_id) if not user.anonymous: comments.like(comment, user) comment = comments.find(comment_id) return jsonify(likes=comment.likes)
def test_auth_existent_user_and_update_name(self): self.username = '******'.format(repr(self)) test_user = dict(name=self.username, chances=222) self.user_id = str(self.database.accounts.insert(test_user)) self.username = self.username + ' updated' with self.app.test_request_context('/'): with self._patch_webclient(): self.service.auth() user = users.current() self.assertEqual(user.name, self.username)
def append_comment(): video_id = request.json['video_id'] text = request.json['text'] position = request.json['position'] user = users.current() if user.anonymous: return jsonify(comment_id=-1) video = videos.find(video_id) comment = comments.new_comment(video, user, text, position) return jsonify(comment_id=comment.sysid)
def show(vidid): g.menu['select_top_menu']['home'] = True user = users.current() render_data = {} if vidid == 'random': render_data['mode'] = 'normal' video = videos.random() watchtran.begin(user, video) else: render_data['mode'] = 'specific' video = videos.find(vidid) # TODO: remove line below watchtran.begin(user, video) if video is None: abort(404) render_data['video'] = video render_data['user_message_size'] = USER_MESSAGE_SIZE scomments = comments.for_screening(video, user) render_data['comments'] = scomments return render_template('player/screening.html', **render_data)
def raffle(): database = connection(); allusers = list(database.accounts.find()) tokens = [] for user in allusers: tokens.extend([user['_id']] * user.get('chances', 0)) total_tokens = len(tokens) target_tokens = int(round(total_tokens * 0.1)) wons = defaultdict(int) for _ in range(target_tokens): token = random.choice(tokens) wons[token] += 1 curr_user = users.current() total_sum = random.randint(20000, 30000) token_sum = float(total_sum) / target_tokens for user in allusers: user['wons'] = wons[user['_id']] user['sum'] = int(round(user['wons'] * token_sum)) if (curr_user.sysid == str(user['_id'])): user['curr'] = True g.profile_menu['active'] = 'raffle' return render_template('devel/raffle.html', users=allusers, total_sum=total_sum)
def account(): user = users.current() if user.anonymous: abort(401) g.profile_menu['active'] = 'account' return render_template('devel/account.html')