def text_history(request, key): text = get_text_by_keys_or_404(key) if request.method == 'POST': v1_key = request.POST.get('newkey', None) v2_key = request.POST.get('oldkey', None) if v1_key and v2_key: return redirect(request, 'text-history-compare', args=[text.key, v2_key, v1_key]) text_versions = text.get_versions() paginate_by = get_int(request.GET, 'paginate', TEXT_PAGINATION) last_last_version = text_versions[1] if len(text_versions) > 1 else None first_version = text_versions[len(text_versions) - 1] context = { 'text': text, 'last_version': text.last_text_version, 'last_last_version': last_last_version, 'first_version': first_version } return object_list( request, text_versions, template_name='site/text_history.html', paginate_by=paginate_by, extra_context=context, )
def text_settings(request, key): text = get_text_by_keys_or_404(key) text_version = text.get_latest_version() if request.method == 'POST': form = SettingsTextForm(request.POST, instance = text_version) if form.is_valid(): form.save() display_message(request, _(u'Text settings updated')) return redirect(request, 'text-view', args=[text.key]) else: form = SettingsTextForm(instance = text_version) template_dict = {'text' : text, 'form' : form} return render_to_response('site/text_settings.html', template_dict , context_instance=RequestContext(request))
def text_history(request, key): text = get_text_by_keys_or_404(key) if request.method == 'POST': v1_key = request.POST.get('newkey',None) v2_key = request.POST.get('oldkey',None) if v1_key and v2_key: return redirect(request, 'text-history-compare', args=[text.key, v2_key, v1_key ]) text_versions = text.get_versions() paginate_by = get_int(request.GET,'paginate',TEXT_PAGINATION) last_last_version = text_versions[1] if len(text_versions)>1 else None first_version = text_versions[len(text_versions) - 1] context = {'text':text, 'last_version':text.last_text_version, 'last_last_version':last_last_version, 'first_version':first_version} return object_list(request, text_versions, template_name = 'site/text_history.html', paginate_by = paginate_by, extra_context=context, )
def text_edit(request, key, adminkey=None): text = get_text_by_keys_or_404(key) text_version = text.get_latest_version() if request.method == 'POST': if request.user.is_authenticated(): form = EditTextForm(request.POST) else: form = EditTextFormAnon(request.POST) if form.is_valid(): if request.POST.get('new_version'): new_version = form.save_new_version(text, request) register_activity(request, "text_edited_new_version", text=text, text_version=new_version) else: form.save_into_text(text, request) register_activity(request, "text_edited", text=text) return redirect(request, 'text-view', args=[text.key]) else: default_data = { 'content': text_version.content, 'title': text_version.title, 'format': text_version.format, 'tags': text_version.tags, 'new_version': NEW_TEXT_VERSION_ON_EDIT, 'note': '', 'keep_comments': True, 'cancel_modified_scopes': True, } if request.user.is_authenticated(): form = EditTextForm(default_data) else: form = EditTextFormAnon(default_data) template_dict = {'text': text, 'form': form} return render_to_response('site/text_edit.html', template_dict, context_instance=RequestContext(request))
def text_edit(request, key, adminkey=None): text = get_text_by_keys_or_404(key) text_version = text.get_latest_version() if request.method == 'POST': if request.user.is_authenticated(): form = EditTextForm(request.POST) else: form = EditTextFormAnon(request.POST) if form.is_valid(): if request.POST.get('new_version'): new_version = form.save_new_version(text, request) register_activity(request, "text_edited_new_version", text=text, text_version=new_version) else: form.save_into_text(text, request) register_activity(request, "text_edited", text=text) return redirect(request, 'text-view', args=[text.key]) else: default_data = { 'content': text_version.content, 'title': text_version.title, 'format': text_version.format, 'tags': text_version.tags, 'new_version': NEW_TEXT_VERSION_ON_EDIT, 'note' : '', 'keep_comments' : True, 'cancel_modified_scopes' : True, } if request.user.is_authenticated(): form = EditTextForm(default_data) else: form = EditTextFormAnon(default_data) template_dict = {'text' : text, 'form' : form} return render_to_response('site/text_edit.html', template_dict , context_instance=RequestContext(request))