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