def perform_suggestion(unit, form, request): """Handle suggesion saving.""" if form.cleaned_data['target'][0] == '': messages.error(request, _('Your suggestion is empty!')) # Stay on same entry return False if not request.user.has_perm('suggestion.add', unit.translation): # Need privilege to add messages.error( request, _('You don\'t have privileges to add suggestions!') ) # Stay on same entry return False if not request.user.is_authenticated: # Spam check if is_spam('\n'.join(form.cleaned_data['target']), request): messages.error( request, _('Your suggestion has been identified as spam!') ) return False # Create the suggestion result = Suggestion.objects.add( unit, join_plural(form.cleaned_data['target']), request, request.user.has_perm('suggestion.vote', unit) ) if not result: messages.error(request, _('Your suggestion already exists!')) return result
def perform_suggestion(unit, form, request): """Handle suggesion saving.""" if form.cleaned_data["target"][0] == "": messages.error(request, _("Your suggestion is empty!")) # Stay on same entry return False if not request.user.has_perm("suggestion.add", unit): # Need privilege to add messages.error(request, _("You don't have privileges to add suggestions!")) # Stay on same entry return False if not request.user.is_authenticated: # Spam check if is_spam("\n".join(form.cleaned_data["target"]), request): messages.error(request, _("Your suggestion has been identified as spam!")) return False # Create the suggestion result = Suggestion.objects.add( unit, join_plural(form.cleaned_data["target"]), request, request.user.has_perm("suggestion.vote", unit), ) if not result: messages.error(request, _("Your suggestion already exists!")) return result
def perform_suggestion(unit, form, request): """Handle suggesion saving.""" if form.cleaned_data['target'][0] == '': messages.error(request, _('Your suggestion is empty!')) # Stay on same entry return False elif not can_suggest(request.user, unit.translation): # Need privilege to add messages.error( request, _('You don\'t have privileges to add suggestions!') ) # Stay on same entry return False elif not request.user.is_authenticated: # Spam check if is_spam('\n'.join(form.cleaned_data['target']), request): messages.error( request, _('Your suggestion has been identified as spam!') ) return False # Invite user to become translator if there is nobody else # and the project is accepting translations translation = unit.translation if (not translation.subproject.suggestion_voting or not translation.subproject.suggestion_autoaccept): recent_changes = Change.objects.content(True).filter( translation=translation, ).exclude( user=None ) if not recent_changes.exists(): messages.info(request, _( 'There is currently no active translator for this ' 'translation, please consider becoming a translator ' 'as your suggestion might otherwise remain unreviewed.' )) messages.info(request, mark_safe( '<a href="{0}">{1}</a>'.format( escape(get_doc_url('user/translating')), escape(_( 'See our documentation for more information ' 'on translating using Weblate.' )), ) )) # Create the suggestion result = Suggestion.objects.add( unit, join_plural(form.cleaned_data['target']), request, can_vote_suggestion(request.user, unit) ) if not result: messages.error(request, _('Your suggestion already exists!')) return result
def perform_suggestion(unit, form, request): """Handle suggesion saving.""" if form.cleaned_data['target'][0] == '': messages.error(request, _('Your suggestion is empty!')) # Stay on same entry return False elif not request.user.has_perm('suggestion.add', unit.translation): # Need privilege to add messages.error( request, _('You don\'t have privileges to add suggestions!') ) # Stay on same entry return False elif not request.user.is_authenticated: # Spam check if is_spam('\n'.join(form.cleaned_data['target']), request): messages.error( request, _('Your suggestion has been identified as spam!') ) return False # Invite user to become translator if there is nobody else # and the project is accepting translations translation = unit.translation if (not translation.component.suggestion_voting or not translation.component.suggestion_autoaccept): recent_changes = Change.objects.content(True).filter( translation=translation, ).exclude( user=None ) if not recent_changes.exists(): messages.info(request, _( 'There is currently no active translator for this ' 'translation, please consider becoming a translator ' 'as your suggestion might otherwise remain unreviewed.' )) messages.info(request, mark_safe( '<a href="{0}">{1}</a>'.format( escape(get_doc_url('user/translating')), escape(_( 'See our documentation for more information ' 'on translating using Weblate.' )), ) )) # Create the suggestion result = Suggestion.objects.add( unit, join_plural(form.cleaned_data['target']), request, request.user.has_perm('suggestion.vote', unit) ) if not result: messages.error(request, _('Your suggestion already exists!')) return result
def test_akismet_nospam(self): self.mock_akismet("false") self.assertFalse(is_spam("text", HttpRequest()))
def test_akismet_spam(self): self.mock_akismet("true") self.assertTrue(is_spam("text", HttpRequest()))
def test_disabled(self): self.assertFalse(is_spam("text", HttpRequest()))
def test_akismet_nospam(self): self.mock_akismet('false') self.assertFalse(is_spam('text', HttpRequest()))
def test_akismet_spam(self): self.mock_akismet('true') self.assertTrue(is_spam('text', HttpRequest()))
def test_akismet_definite_spam(self): self.mock_akismet("true", headers={"X-Akismet-Pro-Tip": "discard"}) self.assertTrue(is_spam("text", HttpRequest()))
def test_disabled(self): self.assertFalse(is_spam('text', HttpRequest()))