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) if request.method == 'POST': form = RevisionForm(request.POST) else: form = RevisionForm() if form.is_valid(): try: project_api.revise_project( project['uri'], form.cleaned_data['improvement'], form.cleaned_data.get('work_url', None) ) except Exception as e: messages.error(request, _(e.args[0])) return http.HttpResponseRedirect(reverse('project_view', args=(project_id,))) context = { 'badge': badge, 'project': project, 'form': form } return render_to_response( 'project/revise.html', context, context_instance=RequestContext(request) )
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) )
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,)))
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)