예제 #1
0
파일: views.py 프로젝트: NoriVicJr/badges
def profile(request, username ):

    context = {}
    user_uri = u'/uri/user/{0}'.format(username)
    context['draft_badges'] = badge_api.get_user_draft_badges(user_uri)
    context['earned_badges'] = badge_api.get_user_earned_badges(user_uri)
    context['created_badges'] = badge_api.get_user_created_badges(user_uri)
    context['awarded_badges'] = badge_api.get_user_awarded_badges(user_uri)
    map(fetch_badge_resources, context['draft_badges'])
    map(fetch_badge_resources, context['earned_badges'])
    map(fetch_badge_resources, context['created_badges'])
    map(fetch_badge_resources, context['awarded_badges'])

    context['feedback_your_projects'] = project_api.search_projects(author_uri=user_uri)
    map(fetch_resources, context['feedback_your_projects'])
    peer_projects = []
    feedback_latest = []
    for badge in context['earned_badges']:
        feedback_latest += project_api.get_projects_ready_for_feedback(badge['uri'])
        peer_projects += project_api.search_projects(badge_uri=badge['uri'])

    filter_func = lambda project: not project['author_uri'] == user_uri
    peer_projects = filter(filter_func, peer_projects)

    badges_under_revision = []
    context['badges_under_revision'] = None
    for project in context['feedback_your_projects']:
        badge_uri = project_api.get_badge_uri_from_project_under_revision(project['uri'])
        if badge_uri:
            badge = badge_api.get_badge(badge_uri)
            fetch_badge_resources(badge)
            badges_under_revision.append(badge)

    if badges_under_revision:
        context['badges_under_revision'] = badges_under_revision

    context['feedback_peer_projects'] = map(fetch_resources, peer_projects)
    context['feedback_latest'] = map(fetch_resources, feedback_latest)
    context['user'] = user_api.get_user(user_api.username2uri(username))
    context['can_delete'] = False

    if 'user' in request.session:
        if context['user']['username'] == request.session.get('user')['username']:
            context['can_delete'] = True

    return render_to_response(
        'dashboard/dashboard.html',
        context,
        context_instance=RequestContext(request)
    )
예제 #2
0
파일: models.py 프로젝트: ercchy/badges
def is_allowed_to_remove(badge_uri):
    from project.processors import search_projects

    projects = search_projects(badge_uri=badge_uri)

    if len(projects):
        return False
    return True
예제 #3
0
def list_projects_by_user(user_uri):
    """
    Listing all the projects that user has
    """
    projects = search_projects(author_uri=user_uri)

    for project in projects:
        badge = get_badge(project['badge_uri'])
        fetch_badge_resources(badge)
        feedback_list = get_project_feedback(project['uri'])
        fetch_resources(project, feedback_list=feedback_list)

    return projects
예제 #4
0
파일: unit.py 프로젝트: MHM5000/badges
    def test_search_projects(self):
        project_api.create_project('/uri/badge/1', '/uri/user/user1', 'Title', '/uri/image/1', 'https://url.com', 'Description', 'Reflection', ['tag1', 'tag2'])
        project_api.create_project('/uri/badge/1', '/uri/user/user2', 'Title', '/uri/image/1', 'https://url.com', 'Description', 'Reflection', ['tag1', 'tag2'])
        project_api.create_project('/uri/badge/1', '/uri/user/user3', 'Title', '/uri/image/1', 'https://url.com', 'Description', 'Reflection', ['tag1', 'tag2'])

        project_api.create_project('/uri/badge/2', '/uri/user/user1', 'Title', '/uri/image/1', 'https://url.com', 'Description', 'Reflection', ['tag1', 'tag2'])
        project_api.create_project('/uri/badge/2', '/uri/user/user4', 'Title', '/uri/image/1', 'https://url.com', 'Description', 'Reflection', ['tag1', 'tag2'])
        project_api.create_project('/uri/badge/2', '/uri/user/user5', 'Title', '/uri/image/1', 'https://url.com', 'Description', 'Reflection', ['tag1', 'tag2'])

        project_api.create_project('/uri/badge/3', '/uri/user/user1', 'Title', '/uri/image/1', 'https://url.com', 'Description', 'Reflection', ['tag1', 'tag2'])
        project_api.create_project('/uri/badge/3', '/uri/user/user6', 'Title', '/uri/image/1', 'https://url.com', 'Description', 'Reflection', ['tag1', 'tag2'])

        projects = project_api.search_projects(author_uri='/uri/user/user1')
        self.assertEqual(len(projects), 3)

        projects = project_api.search_projects(badge_uri='/uri/badge/3')
        self.assertEqual(len(projects), 2)
        
        projects = project_api.search_projects(author_uri='/uri/user/user1', badge_uri='/uri/badge/2')
        self.assertEqual(len(projects), 1)
        
        projects = project_api.search_projects(author_uri='/uri/user/user2', badge_uri='/uri/badge/3')
        self.assertEqual(len(projects), 0)
예제 #5
0
파일: models.py 프로젝트: ercchy/badges
def delete_badge(badge_uri, user_uri):
    """
    Enables owner and admin to archive badge
    """
    from project.processors import search_projects
    badge_db = Badge.objects.get(id=uri2id(badge_uri))
    projects = search_projects(badge_uri=badge_uri)
    if badge_db.author_uri != user_uri:
        raise NotTheAuthorError('You are not the author of the badge')
    if projects:
        raise HasProjectsAttachedError('Badge has projects. It can not be deleted.')

    badge_db.deleted = True
    badge_db.save()

    #TODO: Check if badge in user backpack and revoke

    return _badge2dict(badge_db)
예제 #6
0
파일: views.py 프로젝트: josmas/badges
def view(request, badge_id):
    badge = badge_api.get_badge(badge_api.id2uri(badge_id))
    fetch_badge_resources(badge)
    context = {
        'badge': badge
    }
    context['projects'] = map(fetch_resources, project_api.search_projects(badge_uri=badge['uri']))

    expert_uris = badge_api.get_badge_experts(badge['uri'])

    if request.session.get('user'):
        context['user_is_expert'] = request.session['user']['uri'] in expert_uris

    context['experts'] = map(p2pu_user_api.get_user, expert_uris)

    return render_to_response(
        'badge/view.html',
        context,
        context_instance=RequestContext(request)
    )
예제 #7
0
def send_badge_awarded_notification(badge, expert_uri):
    subject_template = 'emails/badge_awarded_subject.txt'
    text_template = 'emails/badge_awarded.txt'
    html_template = 'emails/badge_awarded.html'
    context = { 'badge': fetch_badge_resources(badge) }

    # NOT the best place to hide this dependancy!!
    from project import processors as project_api
    from project.view_helpers import fetch_resources

    project = project_api.search_projects(badge['uri'], expert_uri)
    if len(project) == 1:
        context['project'] = fetch_resources(project[0])
    projects = project_api.get_projects_ready_for_feedback(badge['uri'])
    context['projects'] = map(fetch_resources, projects[:3])
    return send_notification_i18n(
        expert_uri,
        subject_template,
        text_template,
        html_template,
        context=context
    )