def edit_textwiki(request): resource_database = get_resource_database() if request.method == 'POST': handle_blueprint_post(request, Wikitext) resource = None if hasattr(request, 'ductus') and getattr(request.ductus, 'resource', None): resource = request.ductus.resource # handle old creole content: make it look like ductus-html5 so we can edit it # content is not saved to creole anymore, only to ductus-html5 if resource.blob.markup_language == 'creole-1.0': resource.blob.markup_language = 'ductus-html5' resource.text = creole(resource.text, resource.blob.natural_language) return render_to_response('textwiki/edit_wiki.html', { 'resource_json': resource, 'writable_directories': get_writable_directories_for_user(request.user), }, context_instance=RequestContext(request))
def edit_flashcard_deck(request): if request.method == 'POST': return handle_blueprint_post(request, FlashcardDeck) resource_or_template = None if hasattr(request, 'ductus') and getattr(request.ductus, 'resource', None): resource_or_template = request.ductus.resource elif request.GET.get('template') in flashcard_templates: resource_or_template = flashcard_templates[request.GET['template']]() # add any provided tag(s) to the template object for tag in request.GET.getlist('tag'): try: tag_value_attribute_validator(tag) except ValidationError: pass # the given tag is invalid, so ignore it else: tag_elt = resource_or_template.tags.new_item() tag_elt.value = tag resource_or_template.tags.array.append(tag_elt) return render_to_response('flashcards/edit_flashcard_deck.html', { 'writable_directories': get_writable_directories_for_user(request.user), 'resource_or_template': resource_or_template, 'available_audio_formats': available_audio_formats, }, RequestContext(request))
def edit_flashcard_deck(request): if request.method == 'POST': return handle_blueprint_post(request, FlashcardDeck) resource_or_template = None if hasattr(request, 'ductus') and getattr(request.ductus, 'resource', None): resource_or_template = request.ductus.resource elif request.GET.get('template') in flashcard_templates: resource_or_template = flashcard_templates[request.GET['template']]() # add any provided tag(s) to the template object for tag in request.GET.getlist('tag'): try: tag_value_attribute_validator(tag) except ValidationError: pass # the given tag is invalid, so ignore it else: tag_elt = resource_or_template.tags.new_item() tag_elt.value = tag resource_or_template.tags.array.append(tag_elt) return render_to_response( 'flashcards/edit_flashcard_deck.html', { 'writable_directories': get_writable_directories_for_user( request.user), 'resource_or_template': resource_or_template, 'available_audio_formats': available_audio_formats, }, RequestContext(request))
def five_sec_widget(request, pagename): """display a `five seconds widget` as specified by the query parameters. Also handle POST requests from the widget, saving blueprints and performing related updates. """ if request.method == 'POST': new_fc_urn = handle_blueprint_post(request, Flashcard) # temp hack for FSI, manually update the lesson we took the flashcard from from django.utils.safestring import mark_safe from ductus.resource.ductmodels import BlueprintSaveContext from ductus.wiki.views import _fully_handle_blueprint_post try: url = request.POST['fsi_url'] card_index = int(request.POST['fsi_index']) except KeyError: raise ValidationError( "the widget should provide FSI specific fields") page = WikiPage.objects.get(name=url) revision = page.get_latest_revision() urn = 'urn:' + revision.urn resource_database = get_resource_database() old_fcd = resource_database.get_resource_object(urn) fcd_bp = json.loads(resource_json(old_fcd)) # remove href and add a @patch statement so that the blueprint updates the database fcd_bp['resource']['@patch'] = urn del fcd_bp['href'] # set the flashcard href saved above fcd_bp['resource']['cards']['array'][card_index][ 'href'] = new_fc_urn.urn # remove all 'resource' keys in the blueprint as ResourceElement ignores the hrefs otherwise for fc in fcd_bp['resource']['cards']['array']: del fc['resource'] for interaction in fcd_bp['resource']['interactions']['array']: del interaction['resource'] request.POST = request.POST.copy() request.POST['blueprint'] = json.dumps(fcd_bp) request.POST['log_message'] = '5sec widget (subtitle)' prefix, pagename = url.split(':') response = _fully_handle_blueprint_post(request, prefix, pagename) return response # define what to do when GETing /special/five-sec-widget?method=something if request.method == 'GET': methods = { 'get-audio-to-subtitle': fsw_get_audio_to_subtitle, 'get-phrase-to-record': fsw_get_phrase_to_record, } try: return methods[request.GET.get('method', None)](request) except KeyError: pass return render_to_response('flashcards/five_sec_widget.html', {}, RequestContext(request))
def five_sec_widget(request, pagename): """display a `five seconds widget` as specified by the query parameters. Also handle POST requests from the widget, saving blueprints and performing related updates. """ if request.method == 'POST': new_fc_urn = handle_blueprint_post(request, Flashcard) # temp hack for FSI, manually update the lesson we took the flashcard from from django.utils.safestring import mark_safe from ductus.resource.ductmodels import BlueprintSaveContext from ductus.wiki.views import _fully_handle_blueprint_post try: url = request.POST['fsi_url'] card_index = int(request.POST['fsi_index']) except KeyError: raise ValidationError("the widget should provide FSI specific fields") page = WikiPage.objects.get(name=url) revision = page.get_latest_revision() urn = 'urn:' + revision.urn resource_database = get_resource_database() old_fcd = resource_database.get_resource_object(urn) fcd_bp = json.loads(resource_json(old_fcd)) # remove href and add a @patch statement so that the blueprint updates the database fcd_bp['resource']['@patch'] = urn del fcd_bp['href'] # set the flashcard href saved above fcd_bp['resource']['cards']['array'][card_index]['href'] = new_fc_urn.urn # remove all 'resource' keys in the blueprint as ResourceElement ignores the hrefs otherwise for fc in fcd_bp['resource']['cards']['array']: del fc['resource'] for interaction in fcd_bp['resource']['interactions']['array']: del interaction['resource'] request.POST = request.POST.copy() request.POST['blueprint'] = json.dumps(fcd_bp) request.POST['log_message'] = '5sec widget (subtitle)' prefix, pagename = url.split(':') response = _fully_handle_blueprint_post(request, prefix, pagename) return response # define what to do when GETing /special/five-sec-widget?method=something if request.method == 'GET': methods = { 'get-audio-to-subtitle': fsw_get_audio_to_subtitle, 'get-phrase-to-record': fsw_get_phrase_to_record, } try: return methods[request.GET.get('method', None)](request) except KeyError: pass return render_to_response('flashcards/five_sec_widget.html', { }, RequestContext(request))