How to use get_languages_list method in SeleniumBase

Best Python code snippet using SeleniumBase

views.py

Source:views.py Github

copy

Full Screen

...74 books = Book.objects.all().order_by('title')75 paginator = Paginator(books, 10)76 page_number = request.GET.get('page', 1)77 page_obj = paginator.get_page(page_number)78 context = {'page': page_obj, 'languages': Book.get_languages_list()}79 if query:80 if len(query) == 1:81 query = query[0]82 else:83 query = '&'.join(query)84 context['query'] = query85 return render(request, 'books_api/main.html', context)86def detail_book_view(request: HttpRequest, identifier: str) -> HttpResponse:87 book = get_object_or_404(Book, id=identifier)88 return render(request, 'books_api/book.html', {'book': book})89def edit_book_view(request, identifier: str):90 book = get_object_or_404(Book, id=identifier)91 date_obj = Date.objects.filter(book__id__exact=book.id)92 if request.method == 'POST':93 form_b = BookEditForm(request.POST, instance=book)94 if date_obj:95 form_d = DateEditForm(request.POST, instance=date_obj[0])96 else:97 form_d = DateEditForm(request.POST)98 form_a = AuthorEditForm(request.POST, instance=book)99 if form_b.is_valid() and form_d.is_valid() and form_a.is_valid():100 book_object = form_b.save()101 form_d.save()102 form_a.save()103 if author_input := request.POST.get('authorInput'):104 author_input = author_input.split(',')105 for author in author_input:106 author_object, created = Author.objects.get_or_create(name=author.strip())107 book_object.authors.add(author_object)108 return redirect('books_view')109 return render(request, 'books_api/book_edit.html',110 {'form_b': form_b, 'form_d': form_d, 'form_a': form_a, 'languages': Book.get_languages_list()})111 form_b = BookEditForm(instance=book)112 if date_obj:113 form_d = DateEditForm(instance=date_obj[0])114 else:115 form_d = DateEditForm()116 form_a = AuthorEditForm(instance=book)117 return render(request, 'books_api/book_edit.html',118 {'form_b': form_b, 'form_d': form_d, 'form_a': form_a, 'languages': Book.get_languages_list()})119def create_book_view(request):120 form_b, form_d, form_a = BookCreateForm(), DateEditForm(), AuthorEditForm()121 if request.method == 'POST':122 form_b, form_d, form_a = BookCreateForm(request.POST), DateEditForm(request.POST), AuthorEditForm(request.POST)123 if form_b.is_valid() and form_d.is_valid() and form_a.is_valid():124 date_object = form_d.save()125 book_object = form_b.save()126 book_object.pub_date = date_object127 if authors := request.POST.getlist('authors'):128 for pk_value in authors:129 book_object.authors.add(Author.objects.get(pk=int(pk_value)))130 if author_input := request.POST.get('authorInput'):131 author_input = author_input.split(',')132 for author in author_input:133 author_object, created = Author.objects.get_or_create(name=author.strip())134 book_object.authors.add(author_object)135 book_object.save()136 return redirect('books_view')137 return render(request, 'books_api/book_add.html',138 {'form_b': form_b, 'form_d': form_d, 'form_a': form_a, 'languages': Book.get_languages_list()})139 return render(request, 'books_api/book_add.html',140 {'form_b': form_b, 'form_d': form_d, 'form_a': form_a, 'languages': Book.get_languages_list()})141@csrf_exempt142def books_import_form_view(request):143 if request.method == "POST":144 params_values = request.POST145 api_data_scraper(params_values)146 return HttpResponseRedirect(reverse('books_view'))...

Full Screen

Full Screen

LanguageManagers.py

Source:LanguageManagers.py Github

copy

Full Screen

...18 if len(parts) > 1:19 return parts[0] + '-' + parts[1].upper()20 else:21 return parts[0]22def get_languages_list():23 """24 Returns a mapping {'lang-code': 'Lang-name', ..} with all languages25 specified in ISO639 format in languages.txt26 """27 languages = {}28 cwd = __file__.rsplit(os.path.sep, 1)[0]29 filename = os.path.join(cwd, 'languages.txt')30 for line in open(filename).readlines():31 line = line.strip()32 if line and line[0] != '#':33 code, name = line.split(' ', 1)34 languages[normalize_code(code)] = name35 return languages36def get_languages():37 """38 Returns a list of mappings39 [ {'code': 'lang-code', 'name': 'Language name'}, .. ]40 with all languages specified in ISO639 format in languages.txt41 """42 languages = get_languages_list()43 language_codes = languages.keys()44 language_codes.sort()45 return[ {'code': x, 'name': languages[x]} for x in language_codes ]46def get_iso639_name(code):47 """48 Returns the name of a language.49 Used by get_language_name in portal_i18n tool, in order to50 return the name of a language which is not a custom language51 added in portal (used as fallback or default language name for a code)52 """53 code = normalize_code(code)54 return get_languages_list().get(code, '???')55class NyPortalLanguageManager(Persistent):56 """57 Portal_i18n has an instance of this type, accessible by *get_lang_manager()*58 method. It supplies add/edit/remove/set_default operations with languages59 available in portal and it is also used to get current available60 languages, default language and manage display order.61 """62 implements(INyLanguageManagement)63 # by default, the display order is the creation order, default lang first64 custom_display_order = None65 def __init__(self, default_langs=[('en', 'English')]):66 if not isinstance(default_langs, list):67 raise ValueError("Default languages must be a list of touples"68 " (code, name)")...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...17 locale = language.split(";")[0].strip()18 q = language.split(";")[1].split("=")[1]19 locale_q_pairs.append((locale, q))20 return locale_q_pairs21def get_languages_list():22 """23 Get the list of project supported languages24 """25 return [language[0] for language in settings.LANGUAGES]26def is_supported_language(language):27 """28 Given a language check if it belongs to the supported list29 """30 return language in get_languages_list()31def language_from_header(header):32 """33 Split the accept language header and check34 if a language preference is available in the settings35 """36 preferences = parse_accept_language(header)37 languages = get_languages_list() 38 for preference in preferences:39 # iterate over the languages setting and return the first match40 if is_supported_language(preference[0]):41 return preference[0]42def get_language_code(request, serializer):43 """44 Check request and provided data to define the user language45 """46 # first check if user provided a valid language_code47 language_code = serializer.validated_data.get('language')48 if is_supported_language('language_code'):49 return language_code50 # second check if is possible to determine the language from the51 # request headers...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful