Best Python code snippet using avocado_python
main.py
Source:main.py
...38#----------------------------------------------------------39# Controller40#----------------------------------------------------------41class OAuthLogin(Home):42 def list_providers(self):43 try:44 providers = request.env['auth.oauth.provider'].sudo().search_read([('enabled', '=', True)])45 except Exception:46 providers = []47 for provider in providers:48 return_url = request.httprequest.url_root + 'auth_oauth/signin'49 state = self.get_state(provider)50 params = dict(51 response_type='token',52 client_id=provider['client_id'],53 redirect_uri=return_url,54 scope=provider['scope'],55 state=json.dumps(state),56 )57 provider['auth_link'] = "%s?%s" % (provider['auth_endpoint'], werkzeug.url_encode(params))58 return providers59 def get_state(self, provider):60 redirect = request.params.get('redirect') or 'web'61 if not redirect.startswith(('//', 'http://', 'https://')):62 redirect = '%s%s' % (request.httprequest.url_root, redirect[1:] if redirect[0] == '/' else redirect)63 state = dict(64 d=request.session.db,65 p=provider['id'],66 r=werkzeug.url_quote_plus(redirect),67 )68 token = request.params.get('token')69 if token:70 state['t'] = token71 return state72 @http.route()73 def web_login(self, *args, **kw):74 ensure_db()75 if request.httprequest.method == 'GET' and request.session.uid and request.params.get('redirect'):76 # Redirect if already logged in and redirect param is present77 return http.redirect_with_hash(request.params.get('redirect'))78 providers = self.list_providers()79 response = super(OAuthLogin, self).web_login(*args, **kw)80 if response.is_qweb:81 error = request.params.get('oauth_error')82 if error == '1':83 error = _("Sign up is not allowed on this database.")84 elif error == '2':85 error = _("Access Denied")86 elif error == '3':87 error = _("You do not have access to this database or your invitation has expired. Please ask for an invitation and be sure to follow the link in your invitation email.")88 else:89 error = None90 response.qcontext['providers'] = providers91 if error:92 response.qcontext['error'] = error93 return response94 @http.route()95 def web_auth_signup(self, *args, **kw):96 providers = self.list_providers()97 response = super(OAuthLogin, self).web_auth_signup(*args, **kw)98 response.qcontext.update(providers=providers)99 return response100 @http.route()101 def web_auth_reset_password(self, *args, **kw):102 providers = self.list_providers()103 response = super(OAuthLogin, self).web_auth_reset_password(*args, **kw)104 response.qcontext.update(providers=providers)105 return response106class OAuthController(http.Controller):107 @http.route('/auth_oauth/signin', type='http', auth='none')108 @fragment_to_query_string109 def signin(self, **kw):110 state = json.loads(kw['state'])111 dbname = state['d']112 provider = state['p']113 context = state.get('c', {})114 registry = registry_get(dbname)115 with registry.cursor() as cr:116 try:...
list_providers_pb2.py
Source:list_providers_pb2.py
1# -*- coding: utf-8 -*-2# Generated by the protocol buffer compiler. DO NOT EDIT!3# source: list_providers.proto4from google.protobuf import descriptor as _descriptor5from google.protobuf import message as _message6from google.protobuf import reflection as _reflection7from google.protobuf import symbol_database as _symbol_database8# @@protoc_insertion_point(imports)9_sym_db = _symbol_database.Default()10DESCRIPTOR = _descriptor.FileDescriptor(11 name='list_providers.proto',12 package='list_providers',13 syntax='proto3',14 serialized_options=None,15 create_key=_descriptor._internal_create_key,16 serialized_pb=b'\n\x14list_providers.proto\x12\x0elist_providers\"\x8c\x01\n\x0cProviderInfo\x12\x0c\n\x04uuid\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x02 \x01(\t\x12\x0e\n\x06vendor\x18\x03 \x01(\t\x12\x13\n\x0bversion_maj\x18\x04 \x01(\r\x12\x13\n\x0bversion_min\x18\x05 \x01(\r\x12\x13\n\x0bversion_rev\x18\x06 \x01(\r\x12\n\n\x02id\x18\x07 \x01(\r\"\x0b\n\tOperation\"9\n\x06Result\x12/\n\tproviders\x18\x01 \x03(\x0b\x32\x1c.list_providers.ProviderInfob\x06proto3'17)18_PROVIDERINFO = _descriptor.Descriptor(19 name='ProviderInfo',20 full_name='list_providers.ProviderInfo',21 filename=None,22 file=DESCRIPTOR,23 containing_type=None,24 create_key=_descriptor._internal_create_key,25 fields=[26 _descriptor.FieldDescriptor(27 name='uuid', full_name='list_providers.ProviderInfo.uuid', index=0,28 number=1, type=9, cpp_type=9, label=1,29 has_default_value=False, default_value=b"".decode('utf-8'),30 message_type=None, enum_type=None, containing_type=None,31 is_extension=False, extension_scope=None,32 serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),33 _descriptor.FieldDescriptor(34 name='description', full_name='list_providers.ProviderInfo.description', index=1,35 number=2, type=9, cpp_type=9, label=1,36 has_default_value=False, default_value=b"".decode('utf-8'),37 message_type=None, enum_type=None, containing_type=None,38 is_extension=False, extension_scope=None,39 serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),40 _descriptor.FieldDescriptor(41 name='vendor', full_name='list_providers.ProviderInfo.vendor', index=2,42 number=3, type=9, cpp_type=9, label=1,43 has_default_value=False, default_value=b"".decode('utf-8'),44 message_type=None, enum_type=None, containing_type=None,45 is_extension=False, extension_scope=None,46 serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),47 _descriptor.FieldDescriptor(48 name='version_maj', full_name='list_providers.ProviderInfo.version_maj', index=3,49 number=4, type=13, cpp_type=3, label=1,50 has_default_value=False, default_value=0,51 message_type=None, enum_type=None, containing_type=None,52 is_extension=False, extension_scope=None,53 serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),54 _descriptor.FieldDescriptor(55 name='version_min', full_name='list_providers.ProviderInfo.version_min', index=4,56 number=5, type=13, cpp_type=3, label=1,57 has_default_value=False, default_value=0,58 message_type=None, enum_type=None, containing_type=None,59 is_extension=False, extension_scope=None,60 serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),61 _descriptor.FieldDescriptor(62 name='version_rev', full_name='list_providers.ProviderInfo.version_rev', index=5,63 number=6, type=13, cpp_type=3, label=1,64 has_default_value=False, default_value=0,65 message_type=None, enum_type=None, containing_type=None,66 is_extension=False, extension_scope=None,67 serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),68 _descriptor.FieldDescriptor(69 name='id', full_name='list_providers.ProviderInfo.id', index=6,70 number=7, type=13, cpp_type=3, label=1,71 has_default_value=False, default_value=0,72 message_type=None, enum_type=None, containing_type=None,73 is_extension=False, extension_scope=None,74 serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),75 ],76 extensions=[77 ],78 nested_types=[],79 enum_types=[80 ],81 serialized_options=None,82 is_extendable=False,83 syntax='proto3',84 extension_ranges=[],85 oneofs=[86 ],87 serialized_start=41,88 serialized_end=181,89)90_OPERATION = _descriptor.Descriptor(91 name='Operation',92 full_name='list_providers.Operation',93 filename=None,94 file=DESCRIPTOR,95 containing_type=None,96 create_key=_descriptor._internal_create_key,97 fields=[98 ],99 extensions=[100 ],101 nested_types=[],102 enum_types=[103 ],104 serialized_options=None,105 is_extendable=False,106 syntax='proto3',107 extension_ranges=[],108 oneofs=[109 ],110 serialized_start=183,111 serialized_end=194,112)113_RESULT = _descriptor.Descriptor(114 name='Result',115 full_name='list_providers.Result',116 filename=None,117 file=DESCRIPTOR,118 containing_type=None,119 create_key=_descriptor._internal_create_key,120 fields=[121 _descriptor.FieldDescriptor(122 name='providers', full_name='list_providers.Result.providers', index=0,123 number=1, type=11, cpp_type=10, label=3,124 has_default_value=False, default_value=[],125 message_type=None, enum_type=None, containing_type=None,126 is_extension=False, extension_scope=None,127 serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),128 ],129 extensions=[130 ],131 nested_types=[],132 enum_types=[133 ],134 serialized_options=None,135 is_extendable=False,136 syntax='proto3',137 extension_ranges=[],138 oneofs=[139 ],140 serialized_start=196,141 serialized_end=253,142)143_RESULT.fields_by_name['providers'].message_type = _PROVIDERINFO144DESCRIPTOR.message_types_by_name['ProviderInfo'] = _PROVIDERINFO145DESCRIPTOR.message_types_by_name['Operation'] = _OPERATION146DESCRIPTOR.message_types_by_name['Result'] = _RESULT147_sym_db.RegisterFileDescriptor(DESCRIPTOR)148ProviderInfo = _reflection.GeneratedProtocolMessageType('ProviderInfo', (_message.Message,), {149 'DESCRIPTOR' : _PROVIDERINFO,150 '__module__' : 'list_providers_pb2'151 # @@protoc_insertion_point(class_scope:list_providers.ProviderInfo)152 })153_sym_db.RegisterMessage(ProviderInfo)154Operation = _reflection.GeneratedProtocolMessageType('Operation', (_message.Message,), {155 'DESCRIPTOR' : _OPERATION,156 '__module__' : 'list_providers_pb2'157 # @@protoc_insertion_point(class_scope:list_providers.Operation)158 })159_sym_db.RegisterMessage(Operation)160Result = _reflection.GeneratedProtocolMessageType('Result', (_message.Message,), {161 'DESCRIPTOR' : _RESULT,162 '__module__' : 'list_providers_pb2'163 # @@protoc_insertion_point(class_scope:list_providers.Result)164 })165_sym_db.RegisterMessage(Result)...
views.py
Source:views.py
...8from django.contrib.auth.mixins import LoginRequiredMixin9from django.contrib.auth.decorators import login_required10# Create your views here.1112 # def list_providers(request):13 # list_providers = Provider.objects.all()14 # context = {"list_providers":list_providers}15# return render(request, "list_providers.html", context = context)1617class List_providers(ListView):18 model = Provider19 template_name= 'list_providers.html'202122class Create_provider(LoginRequiredMixin,CreateView):23 model = Provider24 template_name = 'create_provider.html'25 fields = '__all__'26
...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!