Esempio n. 1
0
 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)
Esempio n. 2
0
 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())
Esempio n. 3
0
 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)
Esempio n. 4
0
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)
Esempio n. 5
0
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)
Esempio n. 6
0
 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())
Esempio n. 7
0
 def get_new_badges(self):
     return Badge.get_new_badges(self.username)
Esempio n. 8
0
 def get_badge_items(self):
     return Badge.get_badge_items(self.username)
Esempio n. 9
0
 def get_badge_items(self):
     return Badge.get_badge_items(self.username)
Esempio n. 10
0
 def test_new_badge(self):
     with new_badge() as badge:
         ok_(badge.name, '测试徽章')
         ok_(Badge.get_by_name(badge.name))
Esempio n. 11
0
def new_badge(username=None):
    badge = Badge.add(name='测试徽章', summary='测试徽章的描述')
    yield badge
    badge.delete()
    if username:
        Badge.clear_new_badges(username)
Esempio n. 12
0
def all(request):
    user = request.user
    badges = Badge.get_all_badges()
    return st('badge/all.html', **locals())
Esempio n. 13
0
 def clear_new_badges(self):
     return Badge.clear_new_badges(self.username)
Esempio n. 14
0
 def test_new_badge(self):
     with new_badge() as badge:
         ok_(badge.name, "测试徽章")
         ok_(Badge.get_by_name(badge.name))
Esempio n. 15
0
def new_badge(username=None):
    badge = Badge.add(name="测试徽章", summary="测试徽章的描述")
    yield badge
    badge.delete()
    if username:
        Badge.clear_new_badges(username)
Esempio n. 16
0
 def clear_new_badges(self):
     return Badge.clear_new_badges(self.username)
Esempio n. 17
0
 def get_new_badges(self):
     return Badge.get_new_badges(self.username)
Esempio n. 18
0
def _q_lookup(request, id):
    b = Badge.get(id)
    if b:
        return BadgeUI(b)
Esempio n. 19
0
def _q_lookup(request, id):
    b = Badge.get(id)
    if b:
        return BadgeUI(b)
Esempio n. 20
0
def all(request):
    user = request.user
    badges = Badge.get_all_badges()
    return st("badge/all.html", **locals())
Esempio n. 21
0
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')