def comment(request, pk): ''' Adds new comment. ''' obj = get_object_or_404(Unit, pk=pk) obj.check_acl(request) if request.POST.get('type', '') == 'source': lang = None else: lang = obj.translation.language form = CommentForm(request.POST) if form.is_valid(): Comment.objects.add( obj, request.user, lang, form.cleaned_data['comment'] ) messages.info(request, _('Posted new comment')) else: messages.error(request, _('Failed to add comment!')) return HttpResponseRedirect(obj.get_absolute_url())
def comment(request, pk): ''' Adds new comment. ''' translation = get_object_or_404(Unit, pk=pk) translation.check_acl(request) if request.POST.get('type', '') == 'source': lang = None else: lang = translation.translation.language form = CommentForm(request.POST) if form.is_valid(): Comment.objects.add( translation, request.user, lang, form.cleaned_data['comment'] ) messages.info(request, _('Posted new comment')) else: messages.error(request, _('Failed to add comment!')) return redirect(request.POST.get('next', translation))
def comment(request, pk): """ Adds new comment. """ obj = get_object_or_404(Unit, pk=pk) obj.check_acl(request) if request.POST.get("type", "") == "source": lang = None else: lang = obj.translation.language form = CommentForm(request.POST) if form.is_valid(): Comment.objects.add(obj, request.user, lang, form.cleaned_data["comment"]) messages.info(request, _("Posted new comment")) else: messages.error(request, _("Failed to add comment!")) return HttpResponseRedirect(obj.get_absolute_url())
def translate(request, project, subproject, lang): ''' Generic entry point for translating, suggesting and searching. ''' obj = get_translation(request, project, subproject, lang) # Check locks project_locked, user_locked, own_lock = obj.is_locked(request, True) locked = project_locked or user_locked # Search results search_result = search(obj, request) # Handle redirects if isinstance(search_result, HttpResponse): return search_result # Get numer of results num_results = len(search_result['ids']) # Search offset try: offset = int(request.GET.get('offset', search_result.get('offset', 0))) except ValueError: offset = 0 # Check boundaries if offset < 0 or offset >= num_results: messages.info(request, _('You have reached end of translating.')) # Delete search del request.session['search_%s' % search_result['search_id']] # Redirect to translation return HttpResponseRedirect(obj.get_absolute_url()) # Some URLs we will most likely use base_unit_url = '%s?sid=%s&offset=' % ( obj.get_translate_url(), search_result['search_id'], ) this_unit_url = base_unit_url + str(offset) next_unit_url = base_unit_url + str(offset + 1) response = None # Any form submitted? if request.method == 'POST' and not project_locked: response = handle_translate( obj, request, user_locked, this_unit_url, next_unit_url ) # Handle translation merging elif 'merge' in request.GET and not locked: response = handle_merge(obj, request, next_unit_url) # Handle accepting/deleting suggestions elif not locked and ('accept' in request.GET or 'delete' in request.GET): response = handle_suggestions(obj, request, this_unit_url) # Pass possible redirect further if response is not None: return response # Grab actual unit try: unit = obj.unit_set.get(pk=search_result['ids'][offset]) except Unit.DoesNotExist: # Can happen when using SID for other translation messages.error(request, _('Invalid search string!')) return HttpResponseRedirect(obj.get_absolute_url()) # Show secondary languages for logged in users if request.user.is_authenticated(): profile = request.user.get_profile() secondary_langs = profile.secondary_languages.exclude( id=unit.translation.language.id ) project = unit.translation.subproject.project secondary = get_distinct_translations( Unit.objects.filter( checksum=unit.checksum, translated=True, translation__subproject__project=project, translation__language__in=secondary_langs, ) ) antispam = None else: secondary = None antispam = AntispamForm() # Prepare form form = TranslationForm(initial={ 'checksum': unit.checksum, 'target': (unit.translation.language, unit.get_target_plurals()), 'fuzzy': unit.fuzzy, }) return render_to_response( 'translate.html', RequestContext( request, { 'this_unit_url': this_unit_url, 'first_unit_url': base_unit_url + '0', 'last_unit_url': base_unit_url + str(num_results - 1), 'next_unit_url': next_unit_url, 'prev_unit_url': base_unit_url + str(offset - 1), 'object': obj, 'unit': unit, 'last_changes': unit.change_set.all()[:10], 'last_changes_rss': reverse( 'rss-translation', kwargs=obj.get_kwargs(), ), 'last_changes_url': urlencode(obj.get_kwargs()), 'total': obj.unit_set.all().count(), 'search_id': search_result['search_id'], 'offset': offset, 'filter_name': search_result['name'], 'filter_count': num_results, 'filter_pos': offset + 1, 'form': form, 'antispam': antispam, 'comment_form': CommentForm(), 'search_form': SearchForm(), 'update_lock': own_lock, 'secondary': secondary, 'locked': locked, 'user_locked': user_locked, 'project_locked': project_locked, }, ) )
def comment(request, pk): ''' Adds new comment. ''' obj = get_object_or_404(Unit, pk=pk) obj.check_acl(request) if request.POST.get('type', '') == 'source': lang = None else: lang = obj.translation.language form = CommentForm(request.POST) if form.is_valid(): new_comment = Comment.objects.create( user=request.user, checksum=obj.checksum, project=obj.translation.subproject.project, comment=form.cleaned_data['comment'], language=lang ) Change.objects.create( unit=obj, action=Change.ACTION_COMMENT, translation=obj.translation, user=request.user ) # Invalidate counts cache if lang is None: obj.translation.invalidate_cache('sourcecomments') else: obj.translation.invalidate_cache('targetcomments') messages.info(request, _('Posted new comment')) # Notify subscribed users subscriptions = Profile.objects.subscribed_new_comment( obj.translation.subproject.project, lang, request.user ) for subscription in subscriptions: subscription.notify_new_comment(obj, new_comment) # Notify upstream report_source_bugs = obj.translation.subproject.report_source_bugs if lang is None and report_source_bugs != '': send_notification_email( 'en', report_source_bugs, 'new_comment', obj.translation, { 'unit': obj, 'comment': new_comment, 'subproject': obj.translation.subproject, }, from_email=request.user.email, ) else: messages.error(request, _('Failed to add comment!')) return HttpResponseRedirect(obj.get_absolute_url())