def search(request): """ Performs site-wide search on units. """ search_form = SiteSearchForm(request.GET) context = { 'search_form': search_form, } if search_form.is_valid(): units = Unit.objects.search( None, search_form.cleaned_data, ).select_related( 'translation', ) # Filter results by ACL acl_projects, filtered = Project.objects.get_acl_status(request.user) if filtered: units = units.filter( translation__subproject__project__in=acl_projects ) limit = request.GET.get('limit', 50) page = request.GET.get('page', 1) paginator = Paginator(units, limit) try: units = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. units = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of # results. units = paginator.page(paginator.num_pages) context['page_obj'] = units context['title'] = _('Search for %s') % ( search_form.cleaned_data['q'] ) context['query_string'] = search_form.urlencode() context['search_query'] = search_form.cleaned_data['q'] else: messages.error(request, _('Invalid search query!')) return render( request, 'search.html', context )
def search(request): """ Performs site-wide search on units. """ search_form = SiteSearchForm(request.GET) context = { 'search_form': search_form, } if search_form.is_valid(): units = Unit.objects.search( None, search_form.cleaned_data, ).select_related('translation', ) # Filter results by ACL acl_projects, filtered = Project.objects.get_acl_status(request.user) if filtered: units = units.filter( translation__subproject__project__in=acl_projects) limit = request.GET.get('limit', 50) page = request.GET.get('page', 1) paginator = Paginator(units, limit) try: units = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. units = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of # results. units = paginator.page(paginator.num_pages) context['page_obj'] = units context['title'] = _('Search for %s') % (search_form.cleaned_data['q']) context['query_string'] = search_form.urlencode() context['search_query'] = search_form.cleaned_data['q'] else: messages.error(request, _('Invalid search query!')) return render(request, 'search.html', context)
def dashboard_user(request): """Home page of Weblate showing list of projects, stats and user links if logged in. """ user = request.user user_translations = get_user_translations(request, user) suggestions = get_suggestions(request, user, user_translations) usersubscriptions = None componentlists = list(ComponentList.objects.filter(show_dashboard=True)) for componentlist in componentlists: componentlist.translations = prefetch_stats( user_translations.filter( component__in=componentlist.components.all())) # Filter out component lists with translations # This will remove the ones where user doesn't have access to anything componentlists = [c for c in componentlists if c.translations] active_tab_id = user.profile.dashboard_view active_tab_slug = Profile.DASHBOARD_SLUGS.get(active_tab_id) if active_tab_id == Profile.DASHBOARD_COMPONENT_LIST: active_tab_slug = user.profile.dashboard_component_list.tab_slug() if user.is_authenticated: # Ensure ACL filtering applies (user could have been removed # from the project meanwhile) subscribed_projects = user.allowed_projects.filter( profile=user.profile) usersubscriptions = user_translations.filter( component__project__in=subscribed_projects) if user.profile.hide_completed: usersubscriptions = get_untranslated(usersubscriptions) user_translations = get_untranslated(user_translations) for componentlist in componentlists: componentlist.translations = get_untranslated( componentlist.translations) usersubscriptions = prefetch_stats(usersubscriptions) return render( request, 'dashboard/user.html', { 'allow_index': True, 'suggestions': suggestions, 'search_form': SiteSearchForm(), 'usersubscriptions': usersubscriptions, 'userlanguages': prefetch_stats(user_translations), 'componentlists': componentlists, 'all_componentlists': prefetch_stats(ComponentList.objects.all()), 'active_tab_slug': active_tab_slug, })
def search(request, project=None, component=None, lang=None): """Perform site-wide search on units.""" if not check_rate_limit('search', request): search_form = SiteSearchForm() else: search_form = SiteSearchForm(request.GET) context = { 'search_form': search_form, } search_kwargs = {} if component: obj = get_component(request, project, component) context['component'] = obj context['project'] = obj.project search_kwargs = {'component': obj} elif project: obj = get_project(request, project) context['project'] = obj search_kwargs = {'project': obj} else: obj = None if lang: s_language = get_object_or_404(Language, code=lang) context['language'] = s_language search_kwargs = {'language': s_language} if search_form.is_valid(): # Filter results by ACL if component: units = Unit.objects.filter(translation__component=obj) elif project: units = Unit.objects.filter(translation__component__project=obj) else: allowed_projects = request.user.allowed_projects units = Unit.objects.filter( translation__component__project__in=allowed_projects) units = units.search(search_form.cleaned_data, **search_kwargs) if lang: units = units.filter(translation__language=context['language']) page, limit = get_page_limit(request, 50) paginator = Paginator(units, limit) try: units = paginator.page(page) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of # results. units = paginator.page(paginator.num_pages) context['page_obj'] = units context['title'] = _('Search for %s') % (search_form.cleaned_data['q']) context['query_string'] = search_form.urlencode() context['search_query'] = search_form.cleaned_data['q'] else: messages.error(request, _('Invalid search query!')) return render(request, 'search.html', context)
def show_project(request, lang, project): try: obj = Language.objects.get(code=lang) except Language.DoesNotExist: obj = Language.objects.fuzzy_get(lang) if isinstance(obj, Language): return redirect(obj) raise Http404('No Language matches the given query.') pobj = get_project(request, project) last_changes = Change.objects.last_changes(request.user).filter( translation__language=obj, component__project=pobj)[:10] # Paginate translations. translation_list = obj.translation_set.prefetch().filter( component__project=pobj).order_by('component__project__slug', 'component__slug') translations = get_paginator(request, translation_list) return render( request, 'language-project.html', { 'allow_index': True, 'language': obj, 'project': pobj, 'last_changes': last_changes, 'last_changes_url': urlencode({ 'lang': obj.code, 'project': pobj.slug }), 'translations': translations, 'title': '{0} - {1}'.format(pobj, obj), 'show_only_component': True, 'search_form': SiteSearchForm(), 'licenses': ', '.join( sorted({ x for x in pobj.component_set.values_list('license', flat=True) if x })), })
def home(request): """ Home page of Weblate showing list of projects, stats and user links if logged in. """ if 'show_set_password' in request.session: messages.warning( request, _('You have activated your account, now you should set ' 'the password to be able to login next time.')) return redirect('password') wb_messages = WhiteboardMessage.objects.all() projects = Project.objects.all_acl(request.user) if projects.count() == 1: projects = SubProject.objects.filter( project=projects[0]).select_related() # Warn about not filled in username (usually caused by migration of # users from older system if not request.user.is_anonymous() and request.user.first_name == '': messages.warning(request, _('Please set your full name in your profile.')) # Some stats top_translations = Profile.objects.order_by('-translated')[:10] top_suggestions = Profile.objects.order_by('-suggested')[:10] last_changes = Change.objects.last_changes(request.user)[:10] return render( request, 'index.html', { 'projects': projects, 'top_translations': top_translations.select_related('user'), 'top_suggestions': top_suggestions.select_related('user'), 'last_changes': last_changes, 'last_changes_url': '', 'search_form': SiteSearchForm(), 'whiteboard_messages': wb_messages, })
def show_project(request, lang, project): try: obj = Language.objects.get(code=lang) except Language.DoesNotExist: obj = Language.objects.fuzzy_get(lang) if isinstance(obj, Language): return redirect(obj) raise Http404('No Language matches the given query.') pobj = get_project(request, project) last_changes = Change.objects.last_changes(request.user).filter( translation__language=obj, subproject__project=pobj )[:10] translations = obj.translation_set.enabled().filter( subproject__project=pobj ).order_by( 'subproject__project__slug', 'subproject__slug' ) return render( request, 'language-project.html', { 'allow_index': True, 'language': obj, 'project': pobj, 'last_changes': last_changes, 'last_changes_url': urlencode( {'lang': obj.code, 'project': pobj.slug} ), 'translations': translations, 'title': '{0} - {1}'.format(pobj, obj), 'show_only_component': True, 'search_form': SiteSearchForm(), } )
def home(request): """ Home page of Weblate showing list of projects, stats and user links if logged in. """ if 'show_set_password' in request.session: messages.warning( request, _('You have activated your account, now you should set ' 'the password to be able to login next time.')) return redirect('password') project_ids = Project.objects.get_acl_ids(request.user) suggestions = get_suggestions(request, request.user, project_ids) # Warn about not filled in username (usually caused by migration of # users from older system if not request.user.is_anonymous() and request.user.first_name == '': messages.warning(request, _('Please set your full name in your profile.')) # Some stats last_changes = Change.objects.last_changes(request.user) # Dashboard project/subproject view componentlists = ComponentList.objects.all() # dashboard_choices is dict with labels of choices as a keys dashboard_choices = dict(Profile.DASHBOARD_CHOICES) usersubscriptions = None userlanguages = None active_tab_id = Profile.DASHBOARD_SUGGESTIONS active_tab_slug = Profile.DASHBOARD_SLUGS.get(active_tab_id) if request.user.is_authenticated(): active_tab_id = request.user.profile.dashboard_view active_tab_slug = Profile.DASHBOARD_SLUGS.get(active_tab_id) if active_tab_id == Profile.DASHBOARD_COMPONENT_LIST: clist = request.user.profile.dashboard_component_list active_tab_slug = clist.tab_slug() dashboard_choices[active_tab_id] = clist.name # Ensure ACL filtering applies (user could have been removed # from the project meanwhile) subscribed_projects = request.user.profile.subscriptions.filter( id__in=project_ids) last_changes = last_changes.filter( subproject__project__in=subscribed_projects) components_by_language = Translation.objects.prefetch().filter( language__in=request.user.profile.languages.all(), ).order_by( 'subproject__project__name', 'subproject__name') usersubscriptions = components_by_language.filter( subproject__project__in=subscribed_projects) userlanguages = components_by_language.filter( subproject__project_id__in=project_ids) for componentlist in componentlists: componentlist.translations = components_by_language.filter( subproject__in=componentlist.components.all()) return render( request, 'index.html', { 'suggestions': suggestions, 'last_changes': last_changes[:10], 'last_changes_url': '', 'search_form': SiteSearchForm(), 'usersubscriptions': usersubscriptions, 'userlanguages': userlanguages, 'componentlists': componentlists, 'active_tab_slug': active_tab_slug, 'active_tab_label': dashboard_choices.get(active_tab_id) })
def search(request, project=None, component=None, lang=None): """Perform site-wide search on units.""" is_ratelimited = not check_rate_limit('search', request) search_form = SiteSearchForm(request.GET) context = { 'search_form': search_form, } search_kwargs = {} if component: obj = get_component(request, project, component) context['component'] = obj context['project'] = obj.project context['back_url'] = obj.get_absolute_url() search_kwargs = {'component': obj} elif project: obj = get_project(request, project) context['project'] = obj context['back_url'] = obj.get_absolute_url() search_kwargs = {'project': obj} else: obj = None context['back_url'] = None if lang: s_language = get_object_or_404(Language, code=lang) context['language'] = s_language search_kwargs = {'language': s_language} if obj: if component: context['back_url'] = obj.translation_set.get( language=s_language).get_absolute_url() else: context['back_url'] = reverse('project-language', kwargs={ 'project': project, 'lang': lang, }) else: context['back_url'] = s_language.get_absolute_url() if not is_ratelimited and request.GET and search_form.is_valid(): # Filter results by ACL if component: units = Unit.objects.filter(translation__component=obj) elif project: units = Unit.objects.filter(translation__component__project=obj) else: allowed_projects = request.user.allowed_projects units = Unit.objects.filter( translation__component__project__in=allowed_projects) units = units.search(search_form.cleaned_data, **search_kwargs) if lang: units = units.filter(translation__language=context['language']) units = get_paginator(request, units) context['show_results'] = True context['page_obj'] = units context['title'] = _('Search for %s') % (search_form.cleaned_data['q']) context['query_string'] = search_form.urlencode() context['search_query'] = search_form.cleaned_data['q'] elif is_ratelimited: messages.error(request, _('Too many search queries, please try again later.')) elif request.GET: messages.error(request, _('Invalid search query!')) show_form_errors(request, search_form) return render(request, 'search.html', context)
def home(request): """Home page of Weblate showing list of projects, stats and user links if logged in. """ if 'show_set_password' in request.session: messages.warning( request, _('You have activated your account, now you should set ' 'the password to be able to login next time.')) return redirect('password') # This is used on Hosted Weblate to handle removed translation projects. # The redirect itself is done in the http server. if 'removed' in request.GET: messages.warning( request, _('The project you were looking for has been removed, ' 'however you are welcome to contribute to other ones.')) user = request.user project_ids = Project.objects.get_acl_ids(user) user_translations = get_user_translations(request, user, project_ids) suggestions = get_suggestions(request, user, user_translations) # Warn about not filled in username (usually caused by migration of # users from older system if user.is_authenticated and user.first_name == '': messages.warning( request, mark_safe('<a href="{0}">{1}</a>'.format( reverse('profile') + '#account', escape(_('Please set your full name in your profile.'))))) usersubscriptions = None componentlists = list(ComponentList.objects.all()) for componentlist in componentlists: componentlist.translations = prefetch_stats( user_translations.filter( subproject__in=componentlist.components.all())) # Filter out component lists with translations # This will remove the ones where user doesn't have access to anything componentlists = [c for c in componentlists if c.translations] active_tab_id = user.profile.dashboard_view active_tab_slug = Profile.DASHBOARD_SLUGS.get(active_tab_id) if active_tab_id == Profile.DASHBOARD_COMPONENT_LIST: active_tab_slug = user.profile.dashboard_component_list.tab_slug() if user.is_authenticated: # Ensure ACL filtering applies (user could have been removed # from the project meanwhile) subscribed_projects = user.profile.subscriptions.filter( id__in=project_ids) usersubscriptions = user_translations.filter( subproject__project__in=subscribed_projects) if user.profile.hide_completed: usersubscriptions = get_untranslated(usersubscriptions) user_translations = get_untranslated(user_translations) for componentlist in componentlists: componentlist.translations = get_untranslated( componentlist.translations) usersubscriptions = prefetch_stats(usersubscriptions) return render( request, 'index.html', { 'allow_index': True, 'suggestions': suggestions, 'search_form': SiteSearchForm(), 'usersubscriptions': usersubscriptions, 'userlanguages': prefetch_stats(user_translations), 'componentlists': componentlists, 'active_tab_slug': active_tab_slug, })
def search(request, project=None, component=None, lang=None): """Perform site-wide search on units.""" search_form = SiteSearchForm(request.GET) context = { 'search_form': search_form, } search_kwargs = {} if component: obj = get_component(request, project, component) context['component'] = obj context['project'] = obj.project search_kwargs = {'component': obj} elif project: obj = get_project(request, project) context['project'] = obj search_kwargs = {'project': obj} else: obj = None if lang: s_language = get_object_or_404(Language, code=lang) context['language'] = s_language search_kwargs = {'language': s_language} if search_form.is_valid(): # Filter results by ACL if component: units = Unit.objects.filter(translation__component=obj) elif project: units = Unit.objects.filter(translation__component__project=obj) else: allowed_projects = request.user.allowed_projects units = Unit.objects.filter( translation__component__project__in=allowed_projects ) units = units.search( search_form.cleaned_data, **search_kwargs ) if lang: units = units.filter( translation__language=context['language'] ) page, limit = get_page_limit(request, 50) paginator = Paginator(units, limit) try: units = paginator.page(page) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of # results. units = paginator.page(paginator.num_pages) context['page_obj'] = units context['title'] = _('Search for %s') % ( search_form.cleaned_data['q'] ) context['query_string'] = search_form.urlencode() context['search_query'] = search_form.cleaned_data['q'] else: messages.error(request, _('Invalid search query!')) return render( request, 'search.html', context )
def search(request, project=None, component=None, lang=None): """Perform site-wide search on units.""" is_ratelimited = not check_rate_limit('search', request) search_form = SiteSearchForm(request.GET) context = { 'search_form': search_form, } search_kwargs = {} if component: obj = get_component(request, project, component) context['component'] = obj context['project'] = obj.project context['back_url'] = obj.get_absolute_url() search_kwargs = {'component': obj} elif project: obj = get_project(request, project) context['project'] = obj context['back_url'] = obj.get_absolute_url() search_kwargs = {'project': obj} else: obj = None context['back_url'] = None if lang: s_language = get_object_or_404(Language, code=lang) context['language'] = s_language search_kwargs = {'language': s_language} if obj: if component: context['back_url'] = obj.translation_set.get( language=s_language ).get_absolute_url() else: context['back_url'] = reverse( 'project-language', kwargs={ 'project': project, 'lang': lang, } ) else: context['back_url'] = s_language.get_absolute_url() if not is_ratelimited and request.GET and search_form.is_valid(): # Filter results by ACL if component: units = Unit.objects.filter(translation__component=obj) elif project: units = Unit.objects.filter(translation__component__project=obj) else: allowed_projects = request.user.allowed_projects units = Unit.objects.filter( translation__component__project__in=allowed_projects ) units = units.search( search_form.cleaned_data, **search_kwargs ) if lang: units = units.filter( translation__language=context['language'] ) units = get_paginator(request, units) context['show_results'] = True context['page_obj'] = units context['title'] = _('Search for %s') % ( search_form.cleaned_data['q'] ) context['query_string'] = search_form.urlencode() context['search_query'] = search_form.cleaned_data['q'] elif is_ratelimited: messages.error( request, _('Too many search queries, please try again later.') ) elif request.GET: messages.error(request, _('Invalid search query!')) show_form_errors(request, search_form) return render( request, 'search.html', context )
def search(request, project=None, subproject=None, lang=None): """Perform site-wide search on units.""" search_form = SiteSearchForm(request.GET) context = { 'search_form': search_form, } if subproject: obj = get_subproject(request, project, subproject) context['subproject'] = obj context['project'] = obj.project elif project: obj = get_project(request, project) context['project'] = obj else: obj = None if lang: context['language'] = get_object_or_404(Language, code=lang) if search_form.is_valid(): # Filter results by ACL if subproject: units = Unit.objects.filter(translation__subproject=obj) elif project: units = Unit.objects.filter(translation__subproject__project=obj) else: projects = Project.objects.get_acl_ids(request.user) units = Unit.objects.filter( translation__subproject__project_id__in=projects ) units = units.search( None, search_form.cleaned_data, ) if lang: units = units.filter( translation__language=context['language'] ) page, limit = get_page_limit(request, 50) paginator = Paginator(units, limit) try: units = paginator.page(page) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of # results. units = paginator.page(paginator.num_pages) context['page_obj'] = units context['title'] = _('Search for %s') % ( search_form.cleaned_data['q'] ) context['query_string'] = search_form.urlencode() context['search_query'] = search_form.cleaned_data['q'] else: messages.error(request, _('Invalid search query!')) return render( request, 'search.html', context )
def home(request): """Home page of Weblate showing list of projects, stats and user links if logged in. """ if 'show_set_password' in request.session: messages.warning( request, _('You have activated your account, now you should set ' 'the password to be able to login next time.')) return redirect('password') # This is used on Hosted Weblate to handle removed translation projects. # The redirect itself is done in the http server. if 'removed' in request.GET: messages.warning( request, _('The project you were looking for has been removed, ' 'however you are welcome to contribute to other ones.')) user = request.user project_ids = Project.objects.get_acl_ids(user) translations_base = get_user_translations(user, project_ids) suggestions = get_suggestions(request, user, translations_base) # Warn about not filled in username (usually caused by migration of # users from older system if not user.is_anonymous and user.first_name == '': messages.warning( request, mark_safe('<a href="{0}">{1}</a>'.format( reverse('profile') + '#account', escape(_('Please set your full name in your profile.'))))) # Some stats last_changes = Change.objects.last_changes(user) # dashboard_choices is dict with labels of choices as a keys dashboard_choices = dict(Profile.DASHBOARD_CHOICES) usersubscriptions = None components_by_language = translations_base.order_by( 'subproject__priority', 'subproject__project__name', 'subproject__name') userlanguages = components_by_language.filter( subproject__project_id__in=project_ids) componentlists = list(ComponentList.objects.all()) for componentlist in componentlists: componentlist.translations = components_by_language.filter( subproject__in=componentlist.components.all()) active_tab_id = user.profile.dashboard_view active_tab_slug = Profile.DASHBOARD_SLUGS.get(active_tab_id) if active_tab_id == Profile.DASHBOARD_COMPONENT_LIST: clist = user.profile.dashboard_component_list active_tab_slug = clist.tab_slug() dashboard_choices[active_tab_id] = clist.name if request.user.is_authenticated: # Ensure ACL filtering applies (user could have been removed # from the project meanwhile) subscribed_projects = user.profile.subscriptions.filter( id__in=project_ids) last_changes = last_changes.filter( subproject__project__in=subscribed_projects) usersubscriptions = components_by_language.filter( subproject__project__in=subscribed_projects) return render( request, 'index.html', { 'allow_index': True, 'suggestions': suggestions, 'last_changes': last_changes[:10], 'last_changes_url': '', 'search_form': SiteSearchForm(), 'usersubscriptions': usersubscriptions, 'userlanguages': userlanguages, 'componentlists': componentlists, 'active_tab_slug': active_tab_slug, 'active_tab_label': dashboard_choices.get(active_tab_id) })
def search(request, project=None, subproject=None, lang=None): """Perform site-wide search on units.""" search_form = SiteSearchForm(request.GET) context = { 'search_form': search_form, } if subproject: obj = get_subproject(request, project, subproject) context['subproject'] = obj context['project'] = obj.project elif project: obj = get_project(request, project) context['project'] = obj else: obj = None if lang: context['language'] = get_object_or_404(Language, code=lang) if search_form.is_valid(): units = Unit.objects.search( None, search_form.cleaned_data, ) # Filter results by ACL if subproject: units = units.filter(translation__subproject=obj) elif project: units = units.filter(translation__subproject__project=obj) else: projects = Project.objects.get_acl_ids(request.user) units = units.filter( translation__subproject__project_id__in=projects ) if lang: units = units.filter( translation__language=context['language'] ) limit = request.GET.get('limit', 50) page = request.GET.get('page', 1) paginator = Paginator(units, limit) try: units = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. units = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of # results. units = paginator.page(paginator.num_pages) context['page_obj'] = units context['title'] = _('Search for %s') % ( search_form.cleaned_data['q'] ) context['query_string'] = search_form.urlencode() context['search_query'] = search_form.cleaned_data['q'] else: messages.error(request, _('Invalid search query!')) return render( request, 'search.html', context )