Пример #1
0
    def test_project_feedback_cycle(self):
        # create badge
        badge = badge_api.create_badge(**self.badge_values)
        badge_api.publish_badge(badge['uri'])
        user = p2pu_user_api.save_user('badgemaker', 'http://placeholdit.com/40x40', '*****@*****.**')

        # create project
        project_values = self.project_values.copy()
        project_values['badge_uri'] = badge['uri']
        project = project_api.create_project(**project_values)

        # get feedback - has to be zero, there was not any feedback submitted yet
        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 0)

        # test that project can be revised - it can not, there has not been feedback given yet
        self.assertFalse(project_api.can_revise_project(project['uri']))

        # test that error is raised when revision is given - it has to be, there was no feedback given yet
        with self.assertRaises(Exception):
            project_api.revise_project(project['uri'], 'All better')

        # test that project is ready for feedback
        self.assertTrue(project_api.ready_for_feedback(project['uri']))

        # submit feedback
        project_api.submit_feedback(project['uri'], '/uri/user/badgemaker', 'Ugly', 'Bad', 'Good')
        project_feedback = project_api.get_project_feedback(project['uri'])

        self.assertEqual(len(project_feedback), 1)
        self.assertIn('good', project_feedback[0])
        self.assertIn('bad', project_feedback[0])
        self.assertIn('ugly', project_feedback[0])
        self.assertIn('expert_uri', project_feedback[0])

        # test that multiple feedback cannont be submitted without a revision
        #self.assertFalse(project_api.ready_for_feedback(project['uri']))
        #with self.assertRaises(Exception):
        #    project_api.submit_feedback(project['uri'], '/uri/user/badgemaker', 'Ugly', 'Bad', 'Good')

        project_api.revise_project(project['uri'], 'everything is better now!!')
        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 2)

        project_api.submit_feedback(project['uri'], '/uri/user/badgemaker', 'Ugly', 'Bad', 'Good')

        project_api.revise_project(project['uri'], 'everything is better now, promise!!', work_url='http://mywork.com/new-and-improved')
        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 4)
 
        self.assertIn('improvement', project_feedback[1]) 
        self.assertIn('date_created', project_feedback[1]) 
        self.assertNotIn('work_url', project_feedback[1])

        self.assertIn('improvement', project_feedback[3]) 
        self.assertIn('work_url', project_feedback[3])
Пример #2
0
def home(request):
    featured_badges = map(fetch_badge_resources, badge_api.get_featured_badges())

    users = p2pu_user_api.get_users()
    paginator = Paginator(users, 16)
    page = request.GET.get('page')
    try:
        users = paginator.page(page)
    except PageNotAnInteger:
        users = paginator.page(1)
    except EmptyPage:
        return HttpResponse(status=404)
    if request.is_ajax():
        return render_to_response('p2pu_user/browse_users.html',
                                  {'users': users},
                                  context_instance=RequestContext(request))

    last_n_projects = project_api.last_n_projects(10)
    for project in last_n_projects:
        fetch_project_resources(project,
                                feedback_list=project_api.get_project_feedback(project['uri']))

    return render_to_response('landing/home.html', {
        'badges': featured_badges,
        'users': users,
        'projects': last_n_projects,
    }, context_instance=RequestContext(request))
Пример #3
0
def view(request, project_id):
    project = project_api.get_project(project_api.id2uri(project_id))
    project = fetch_resources(project)
    badge = badge_api.get_badge(project['badge_uri'])
    badge = fetch_badge_resources(badge)
    feedback = project_api.get_project_feedback(project['uri'])
    for fb in feedback:
        if fb.get('expert_uri'):
            fb['expert'] = p2pu_user_api.get_user(fb['expert_uri'])
    can_revise = False
    can_give_feedback = False
    if request.session.get('user'):
        user_uri = request.session['user']['uri']
        if user_uri == project['author_uri']:
            can_revise = project_api.can_revise_project(project['uri'])
        can_give_feedback = project_api.ready_for_feedback(project['uri'])
        can_give_feedback &= user_uri in badge_api.get_badge_experts(badge['uri'])

    context = {
        'project': project,
        'badge': badge,
        'feedback': feedback,
        'can_revise': can_revise,
        'can_give_feedback': can_give_feedback
    }
    return render_to_response(
        'project/view.html',
        context,
        context_instance=RequestContext(request)
    )
Пример #4
0
def review(request):
    """
    This view shows a list of projects for a user that he/she can submit feedback on
    """

    user = request.session.get('user')
    projects = []

    if user:
        user_badges = badge_api.get_user_earned_badges(user['uri'])
        for badge in user_badges:
            projects += project_api.get_projects_ready_for_feedback(badge['uri'])

    badges = []
    feedback_list = []

    if len(projects) == 0:
        badges = badge_api.get_published_badges()
    else:
        for project in projects:
            feedback_list = project_api.get_project_feedback(project['uri'])
            fetch_resources(project, feedback_list)

    return render_to_response(
        'project/review.html', {
            'projects': map(fetch_resources, projects),
            'badges': map(fetch_badge_resources, badges)
        },
        context_instance=RequestContext(request)
    )
Пример #5
0
    def test_expert_feedback_and_creator_revision(self):
        badge = badge_api.create_badge(**self.badge_values)
        badge_api.publish_badge(badge['uri'])
        user = p2pu_user_api.save_user('badgemaker', 'http://placeholdit.com/40x40', '*****@*****.**')

        project_values = self.project_values.copy()
        project_values['badge_uri'] = badge['uri']
        project = project_api.create_project(**project_values)

        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 0)
        
        with self.assertRaises(Exception):
            project_api.submit_feedback(project['uri'], '/uri/user/not_an_expert', 'Ugly', 'Bad', 'Good')

        project_api.submit_feedback(project['uri'], badge['author_uri'], 'Ugly', 'Bad', 'Good')
        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 1)
Пример #6
0
def get_feedback_for_project_list(project_list):
    """
    Fetching all feedback that is attached to project
    """

    for project in project_list:
        feedback_list = get_project_feedback(project['uri'])
        fetch_resources(project, feedback_list=feedback_list)

    return project_list
Пример #7
0
    def test_final_feedback(self):
        badge = badge_api.create_badge(**self.badge_values)
        badge_api.publish_badge(badge['uri'])
        user = p2pu_user_api.save_user('badgemaker', 'http://placeholdit.com/40x40', '*****@*****.**')

        project_values = self.project_values.copy()
        project_values['badge_uri'] = badge['uri']
        project = project_api.create_project(**project_values)

        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 0)
        
        self.assertTrue(project_api.ready_for_feedback(project['uri']))
        project_api.submit_feedback(project['uri'], badge['author_uri'], 'Ugly', 'Bad', 'Good', True)
        project_feedback = project_api.get_project_feedback(project['uri'])
        self.assertEqual(len(project_feedback), 1)

        self.assertFalse(project_api.ready_for_feedback(project['uri']))
        self.assertFalse(project_api.can_revise_project(project['uri']))
Пример #8
0
def view(request, badge_id):
    badge = badge_api.get_badge(badge_api.id2uri(badge_id))
    fetch_badge_resources(badge)

    projects = project_api.search_projects_awarded_badges(badge_uri=badge['uri'])
    for project in projects:
        fetch_resources(project, feedback_list=project_api.get_project_feedback(project['uri']))

    expert_uris = badge_api.get_badge_experts(badge['uri'])
    user = request.session.get('user')

    if user:
        user['is_expert'] = user['uri'] in expert_uris
        user['is_author'] = _user_is_author(badge, user)
        if user['is_author']:
            user['can_delete_badge'] = badge_api.is_allowed_to_remove(badge['uri'])
        if user['is_expert']:
            user['added_to_backpack'] = badge_api.pushed_to_backpack(badge, user['uri'])

    projects_ready_for_feedback = project_api.get_projects_ready_for_feedback(badge['uri'])
    for project in projects_ready_for_feedback:
        feedback_list = project_api.get_project_feedback(project['uri'])
        fetch_resources(project, feedback_list=feedback_list)

    experts = map(p2pu_user_api.get_user, expert_uris)

    iframe = '//%s%s?rendering=normal' % (settings.ORGANISATION_URL,
                                               reverse('badge_view_embedded', args=[badge_id]))

    return render_to_response(
        'badge/badge_info/view.html', {
            'user': user,
            'badge': badge,
            'projects': projects,
            'projects_ready_for_feedback': projects_ready_for_feedback,
            'experts': experts,
            'iframe': iframe,
            'organisation_url': settings.ORGANISATION_URL,
        },
        context_instance=RequestContext(request)
    )
Пример #9
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
Пример #10
0
def list_projects_that_user_gave_feedback(user_uri):
    """
    Listing all project that user gave feedback to
    """

    projects_list = get_projects_user_gave_feedback(user_uri)

    for project in projects_list:
        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_list
Пример #11
0
def feedback(request, project_id):
    project = project_api.get_project(project_api.id2uri(project_id))
    fetch_resources(project)
    feedback = project_api.get_project_feedback(project_api.id2uri(project_id))
    badge = badge_api.get_badge(project['badge_uri'])
    fetch_badge_resources(badge)
    user_uri = request.session['user']['uri']

    if request.method == 'POST':
        form = FeedbackForm(request.POST)
    else:
        form = FeedbackForm()

    if form.is_valid():
        try:
            feedback = project_api.submit_feedback(
                project['uri'],
                user_uri,
                form.cleaned_data['good'],
                form.cleaned_data['bad'],
                form.cleaned_data['ugly'],
                form.cleaned_data.get('award_badge', form.cleaned_data.get('award_badge', False))
            )
            if feedback == project_api.submit_feedback_result.AWARDED:
                badge_api.award_badge(
                    badge['uri'],
                    project['author_uri'],
                    user_uri,
                    reverse('project_view', args=(project_id,)),
                )
                messages.success(request, _("Success! You've awarded the Badge to %s" % project['author']['username']))
            elif feedback == project_api.submit_feedback_result.REQUIRES_APPROVAL:
                messages.error(request, _("Badge can only be awarded by it's creator. "
                                          "We had notified them that you liked this project."))
        except Exception, e:
            messages.error(request, _(e[0]))
        return http.HttpResponseRedirect(reverse('project_view', args=(project_id,)))
Пример #12
0
                    user_uri,
                    reverse('project_view', args=(project_id,)),
                )
                messages.success(request, _("Success! You've awarded the Badge to %s" % project['author']['username']))
            elif feedback == project_api.submit_feedback_result.REQUIRES_APPROVAL:
                messages.error(request, _("Badge can only be awarded by it's creator. "
                                          "We had notified them that you liked this project."))
        except Exception, e:
            messages.error(request, _(e[0]))
        return http.HttpResponseRedirect(reverse('project_view', args=(project_id,)))

    context = {
        'badge': badge,
        'project': project,
        'form': form,
        'feedback': project_api.get_project_feedback(project_api.id2uri(project_id))
    }

    return render_to_response(
        'project/feedback.html',
        context,
        context_instance=RequestContext(request)
    )


@require_login
def revise(request, project_id):
    project = project_api.get_project(project_api.id2uri(project_id))
    badge = badge_api.get_badge(project['badge_uri'])
    fetch_badge_resources(badge)