def oembed(request): # Extract GET parameters url = request.GET.get('url', None) if not settings.DEBUG: valid_url = check_if_url_is_valid(url) if not valid_url: return HttpResponseNotFound(status=404) url = set_url_to_relative(url) maxwidth = request.GET.get('maxwidth', '100%') maxheight = request.GET.get('maxheight', 180) username = request.GET.get('username', None) badge_id = get_badge_id_from_parameter_url(url) badge = get_badge_by_id(badge_id) author_url = badge['author_uri'] author_name = uri2username(badge['author_uri']) image_url = get_image(badge['image_uri'])['url'].split('/')[-1] response_badge = create_response_from_template( id=badge['id'], title=badge['title'], badge_url=url, badge_image=image_url, badge_description=badge['description'], badge_requirements=badge['requirements'], author_url=author_url, author_name=author_name, maxwidth=maxwidth, maxheight=maxheight, username=username, ) json_badge = json.dumps(response_badge) return HttpResponse(json_badge, mimetype="application/json")
def load_test_data(data_file): df = open(data_file, 'r') root = os.path.dirname(os.path.abspath(data_file)) test_data = simplejson.load(df) for badge in test_data['badges']: p2pu_user_api.save_user( p2pu_user_api.uri2username(badge['author_uri']), 'http://placehold.it/150x150', '*****@*****.**' % p2pu_user_api.uri2username(badge['author_uri']), ) with open(os.path.join(root, badge['image']), 'rb') as image_file: image = media_api.upload_image( File(image_file), badge['author_uri'], media_root=settings.MEDIA_ROOT, delete_original=False) badge['image_uri'] = image['uri'] del badge['image'] badge = badge_api.create_badge(**badge) badge_api.publish_badge(badge['uri']) print(badge) df.close()
def delete(request, badge_id): """ Setting badge attribute 'deleted' to True """ user_uri = request.session['user']['uri'] try: badge_api.delete_badge(badge_api.id2uri(badge_id), user_uri) messages.success(request, _('Success! You have deleted your badge')) except badge_api.NotTheAuthorError: messages.error(request, _('Error! You are not the author of the badge!')) except badge_api.HasProjectsAttachedError: messages.error(request, _('Error! Badge has projects attached!')) return http.HttpResponseRedirect( reverse('dashboard', args=(p2pu_user_api.uri2username(user_uri),)) )