def handle(self, *args, **options): results = Check.objects.filter( check='same' ).values( 'contentsum' ).annotate( Count('contentsum') ).filter( contentsum__count__gt=1 ).order_by( '-contentsum__count' ) for item in results: check = Check.objects.filter( check='same', contentsum=item['contentsum'] )[0] units = get_related_units(check) if not units.exists(): continue self.stdout.write( u'{0:5d} {1}'.format( item['contentsum__count'], units[0].source, ) )
def test_check_flags(self): """Setting of Source check_flags changes checks for related units.""" self.assertEqual(Check.objects.count(), 3) check = Check.objects.all()[0] unit = get_related_units(check)[0] source = unit.source_info source.check_flags = 'ignore-{0}'.format(check.check) source.save() self.assertEqual(Check.objects.count(), 0)
def delete_log(self, user, change=Change.ACTION_SUGGESTION_DELETE): """Delete with logging change""" from weblate.trans.models import get_related_units allunits = get_related_units(self) for unit in allunits: Change.objects.create(unit=unit, action=change, translation=unit.translation, user=user, target=self.target, author=user) self.delete()
def delete_comment(request, pk): """ Deletes comment. """ comment_obj = get_object_or_404(Comment, pk=pk) comment_obj.project.check_acl(request) units = get_related_units(comment_obj) if units.exists(): fallback_url = units[0].get_absolute_url() else: fallback_url = comment_obj.project.get_absolute_url() comment_obj.delete() messages.info(request, _('Translation comment has been deleted.')) return redirect(request.POST.get('next', fallback_url))
def add(self, unit, target, request, vote=False): """Create new suggestion for this unit.""" user = request.user same = self.filter( target=target, content_hash=unit.content_hash, language=unit.translation.language, project=unit.translation.subproject.project, ) if same.exists() or (unit.target == target and not unit.fuzzy): return False # Create the suggestion suggestion = self.create(target=target, content_hash=unit.content_hash, language=unit.translation.language, project=unit.translation.subproject.project, user=user) # Record in change from weblate.trans.models import get_related_units allunits = get_related_units(suggestion) for aunit in allunits: Change.objects.create(unit=aunit, action=Change.ACTION_SUGGESTION, translation=aunit.translation, user=user, target=target, author=user) # Add unit vote if vote: suggestion.add_vote(unit.translation, request, True) # Notify subscribed users notify_new_suggestion(unit, suggestion, user) # Update suggestion stats if user is not None: user.profile.suggested += 1 user.profile.save() return True
def delete_comment(request, pk): """Delete comment.""" comment_obj = get_object_or_404(Comment, pk=pk) check_access(request, comment_obj.project) if not can_delete_comment(request.user, comment_obj): raise PermissionDenied() units = get_related_units(comment_obj) if units.exists(): fallback_url = units[0].get_absolute_url() else: fallback_url = comment_obj.project.get_absolute_url() comment_obj.delete() messages.info(request, _('Translation comment has been deleted.')) return redirect_next(request.POST.get('next'), fallback_url)
def delete_comment(request, pk): """Delete comment.""" comment_obj = get_object_or_404(Comment, pk=pk) check_access(request, comment_obj.project) if not can_delete_comment(request.user, comment_obj.project): raise PermissionDenied() units = get_related_units(comment_obj) if units.exists(): fallback_url = units[0].get_absolute_url() else: fallback_url = comment_obj.project.get_absolute_url() comment_obj.delete() messages.info(request, _('Translation comment has been deleted.')) return redirect_next(request.POST.get('next'), fallback_url)
def handle(self, *args, **options): results = {} if options['list_all']: checks = Check.objects.all() else: checks = Check.objects.filter(ignore=True) for check in checks: name = '%s-%s' % (check.check, check.contentsum) units = get_related_units(check) if not units.exists(): continue if name in results: results[name]['count'] += 1 else: results[name] = { 'count': 1, 'check': check.check, 'source': units[0].source, } results = sorted(results.values(), key=lambda x: -x['count']) for result in results[:options['count']]: self.stdout.write('%(count)5d %(check)20s %(source)s' % result)
def handle(self, *args, **options): results = {} if options['list_all']: checks = Check.objects.all() else: checks = Check.objects.filter(ignore=True) for check in checks: name = '{0}-{1}'.format(check.check, check.content_hash) units = get_related_units(check) if not units.exists(): continue if name in results: results[name]['count'] += 1 else: results[name] = { 'count': 1, 'check': check.check, 'source': units[0].source, } results = sorted(results.values(), key=lambda x: -x['count']) for result in results[:options['count']]: self.stdout.write( '{count:5d} {check:20} {source}'.format(**result))
def handle(self, *args, **options): results = {} if options['list_all']: checks = Check.objects.all() else: checks = Check.objects.filter(ignore=True) for check in checks: name = '{0}-{1}'.format(check.check, check.content_hash) units = get_related_units(check) if not units.exists(): continue if name in results: results[name]['count'] += 1 else: results[name] = { 'count': 1, 'check': check.check, 'source': units[0].source, } results = sorted(results.values(), key=lambda x: -x['count']) for result in results[:options['count']]: self.stdout.write( '{count:5d} {check:20} {source}'.format(**result) )