def test_badge_award_to_user(self): username = '******' with new_badge(username) as badge: badge.award(item_id=username) badges = Badge.get_badges(item_id=username) eq_(len(badges), 1) items = badge.get_awarded_items() eq_(len(items), 1)
def badges(self, request): name = self.name badge_items = Badge.get_badge_items() _date_badge_items = [i for i in badge_items if i.date] items_groupby_date = itertools.groupby(_date_badge_items, lambda badge_item: badge_item.date.date()) today = datetime.now().date() yesterday = today - timedelta(days=1) return st("badge/timeline.html", **locals())
def test_badge_award_to_user(self): username = "******" with new_badge(username) as badge: badge.award(item_id=username) badges = Badge.get_badges(item_id=username) eq_(len(badges), 1) items = badge.get_awarded_items() eq_(len(items), 1)
def add(request): if request.method == 'POST': name = request.get_form_var('name', '').strip() found = Badge.get_by_name(name) if found: return request.redirect('/badge/%s/' % found.id) summary = request.get_form_var('summary') filename = request.get_form_var("picfile").tmp_filename content = open(filename).read() new = Badge.add(name, summary) root = os.environ['DAE_APPROOT'] pic_path = '%s/hub/static/img/badges/%s.png' % (root, new.id) open(pic_path, 'w').write(content) return request.redirect('/badge/%s/' % new.id) return st('badge/add.html', request=request)
def add(request): if request.method == "POST": name = request.get_form_var("name", "").strip() found = Badge.get_by_name(name) if found: return request.redirect("/badge/%s/" % found.id) summary = request.get_form_var("summary") filename = request.get_form_var("picfile").tmp_filename content = open(filename).read() new = Badge.add(name, summary) root = os.environ["DAE_APPROOT"] pic_path = "%s/hub/static/img/badges/%s.png" % (root, new.id) open(pic_path, "w").write(content) return request.redirect("/badge/%s/" % new.id) return st("badge/add.html", request=request)
def badges(self, request): name = self.name badge_items = Badge.get_badge_items() _date_badge_items = [i for i in badge_items if i.date] items_groupby_date = itertools.groupby( _date_badge_items, lambda badge_item: badge_item.date.date()) today = datetime.now().date() yesterday = today - timedelta(days=1) return st('badge/timeline.html', **locals())
def get_new_badges(self): return Badge.get_new_badges(self.username)
def get_badge_items(self): return Badge.get_badge_items(self.username)
def test_new_badge(self): with new_badge() as badge: ok_(badge.name, '测试徽章') ok_(Badge.get_by_name(badge.name))
def new_badge(username=None): badge = Badge.add(name='测试徽章', summary='测试徽章的描述') yield badge badge.delete() if username: Badge.clear_new_badges(username)
def all(request): user = request.user badges = Badge.get_all_badges() return st('badge/all.html', **locals())
def clear_new_badges(self): return Badge.clear_new_badges(self.username)
def test_new_badge(self): with new_badge() as badge: ok_(badge.name, "测试徽章") ok_(Badge.get_by_name(badge.name))
def new_badge(username=None): badge = Badge.add(name="测试徽章", summary="测试徽章的描述") yield badge badge.delete() if username: Badge.clear_new_badges(username)
def _q_lookup(request, id): b = Badge.get(id) if b: return BadgeUI(b)
def all(request): user = request.user badges = Badge.get_all_badges() return st("badge/all.html", **locals())
from vilya.models.badge import Badge import os dir = os.path.join(os.path.dirname(__file__), '../../hub/static/img/badges/') badge_number = len(os.listdir(dir)) badge = Badge.add('code', 'Code Developer') badge.award('testuser') badge.award('qingfeng') badge2 = Badge.add('bugslayer', 'Bug Slayer') badge2.award('testuser') for idx in xrange(2, badge_number): badge = Badge.add("badge%s" % idx, "Badge %s" % idx) badge.award('testuser')