mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 18:36:51 +00:00
FIX: sonarcloud branches, base, atms, apimanager, apicollections,
apicollectionlist modules
This commit is contained in:
parent
ac075df437
commit
bf69de8d81
@ -41,8 +41,8 @@ class ApiCollectionListView(IndexView, LoginRequiredMixin, FormView ):
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return []
|
||||
except Exception as inst:
|
||||
messages.error(self.request, "Unknown Error {}".format(type(inst).__name__))
|
||||
except Exception as err:
|
||||
messages.error(self.request, err)
|
||||
return []
|
||||
|
||||
return apicollections_list
|
||||
|
||||
@ -37,7 +37,7 @@ class IndexView(LoginRequiredMixin, FormView):
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
except BaseException as err:
|
||||
error_once_only(self.request, (Exception("Unknown Error. Details:" + str(err))))
|
||||
error_once_only(self.request, err)
|
||||
else:
|
||||
# set the default endpoint there, the first item will be the new endpoint.
|
||||
default_api_endpoint = {
|
||||
@ -73,8 +73,8 @@ class DetailView(LoginRequiredMixin, FormView):
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return super(DetailView, self).form_invalid(form)
|
||||
except BaseException as err:
|
||||
error_once_only(self.request, (Exception("Unknown Error. Details:" + str(err))))
|
||||
except Exception as err:
|
||||
error_once_only(self.request, err)
|
||||
return super(DetailView, self).form_invalid(form)
|
||||
if 'code' in api_collection_endpoint and api_collection_endpoint['code']>=400:
|
||||
messages.error(self.request, api_collection_endpoint['message'])
|
||||
@ -100,8 +100,8 @@ class DetailView(LoginRequiredMixin, FormView):
|
||||
api_collection_endpoints=response['api_collection_endpoints']
|
||||
except APIError as err:
|
||||
messages.error(self.request, result['message'])
|
||||
except BaseException as err:
|
||||
error_once_only(self.request, (Exception("Unknown Error. Details:" + str(err))))
|
||||
except Exception as err:
|
||||
error_once_only(self.request, err)
|
||||
else:
|
||||
context.update({
|
||||
'api_collection_endpoints': api_collection_endpoints,
|
||||
@ -126,7 +126,7 @@ class DeleteCollectionEndpointView(LoginRequiredMixin, FormView):
|
||||
messages.success(request, msg)
|
||||
except APIError as err:
|
||||
messages.error(request, err)
|
||||
except BaseException as err:
|
||||
except Exception as err:
|
||||
messages.error(self.request, 'Unknown Error', err)
|
||||
redirect_url = reverse('my-api-collection-detail',kwargs={"api_collection_id":kwargs['api_collection_id']})
|
||||
return HttpResponseRedirect(redirect_url)
|
||||
|
||||
@ -308,10 +308,7 @@ CALLBACK_BASE_URL = ""
|
||||
UNDEFINED = "<undefined>"
|
||||
|
||||
# Local settings can replace any value ABOVE
|
||||
try:
|
||||
from apimanager.local_settings import * # noqa
|
||||
except ImportError:
|
||||
pass
|
||||
from apimanager.local_settings import BASE_DIR, EXCLUDE_APPS, EXCLUDE_FUNCTIONS, EXCLUDE_URL_PATTERN, API_EXPLORER_APP_NAME, API_DATEFORMAT, SECRET_KEY, API_HOST, OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET # noqa
|
||||
# EVERYTHING BELOW HERE WILL *NOT* BE OVERWRITTEN BY LOCALSETTINGS!
|
||||
# DO NOT TRY TO DO SO YOU WILL BE IGNORED!
|
||||
|
||||
|
||||
@ -15,6 +15,8 @@ from obp.api import API, APIError
|
||||
from .forms import CreateAtmForm
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
CHOOSE = "Choose..."
|
||||
|
||||
class IndexAtmsView(LoginRequiredMixin, FormView):
|
||||
|
||||
"""Index view for ATMs"""
|
||||
@ -33,12 +35,12 @@ class IndexAtmsView(LoginRequiredMixin, FormView):
|
||||
fields = form.fields
|
||||
try:
|
||||
fields['bank_id'].choices = self.api.get_bank_id_choices()
|
||||
fields['is_accessible'].choices = [('',_('Choose...')),(True, True), (False, False)]
|
||||
fields['has_deposit_capability'].choices = [('',_('Choose...')),(True, True), (False, False)]
|
||||
fields['supported_languages'].choices = [('',_('Choose...')),("en", "en"), ("fr", "fr"), ("de", "de")]
|
||||
fields['notes'].choices = [('',_('Choose...')),("String1", "String1"), ("String2", "String2")]
|
||||
fields['supported_currencies'].choices = [('',_('Choose...')),("EUR", "EUR"), ("MXN", "MXN"), ("USD", "USD")]
|
||||
fields['location_categories'].choices = [('',_('Choose...')),("ATBI", "ATBI"), ("ATBE", "ATBE")]
|
||||
fields['is_accessible'].choices = [('',_(CHOOSE)),(True, True), (False, False)]
|
||||
fields['has_deposit_capability'].choices = [('',_(CHOOSE)),(True, True), (False, False)]
|
||||
fields['supported_languages'].choices = [('',_(CHOOSE)),("en", "en"), ("fr", "fr"), ("de", "de")]
|
||||
fields['notes'].choices = [('',_(CHOOSE)),("String1", "String1"), ("String2", "String2")]
|
||||
fields['supported_currencies'].choices = [('',_(CHOOSE)),("EUR", "EUR"), ("MXN", "MXN"), ("USD", "USD")]
|
||||
fields['location_categories'].choices = [('',_(CHOOSE)),("ATBI", "ATBI"), ("ATBE", "ATBE")]
|
||||
fields['lobby'].initial = json.dumps({
|
||||
"monday": [
|
||||
{
|
||||
@ -111,16 +113,8 @@ class IndexAtmsView(LoginRequiredMixin, FormView):
|
||||
"bank_id": data["bank_id"],
|
||||
"name": data["name"],
|
||||
"address": json.loads(data['address']),
|
||||
"location": {
|
||||
"latitude": float(data["location_latitude"]) if data["location_latitude"] is not None else "",
|
||||
"longitude": float(data["location_longitude"]) if data["location_longitude"] is not None else ""
|
||||
},
|
||||
"meta": {
|
||||
"license": {
|
||||
"id": "ODbL-1.0",
|
||||
"name": data["meta_license_name"] if data["meta_license_name"]!="" else "license name"
|
||||
}
|
||||
},
|
||||
"location": self._location(data),
|
||||
"meta": self._meta(data),
|
||||
"monday": {
|
||||
"opening_time": "",
|
||||
"closing_time": ""
|
||||
@ -149,30 +143,22 @@ class IndexAtmsView(LoginRequiredMixin, FormView):
|
||||
"opening_time": "",
|
||||
"closing_time": ""
|
||||
},
|
||||
"is_accessible": data["is_accessible"] if data["is_accessible"]!="" else "false",
|
||||
"located_at": data["located_at"] if data["located_at"]!="no-example-provided" else " ",
|
||||
"more_info": data["more_info"] if data["more_info"]!="" else "false",
|
||||
"has_deposit_capability": data["has_deposit_capability"] if data["has_deposit_capability"]!="" else "false",
|
||||
"supported_languages":[data["supported_languages"]],
|
||||
"services":[data["services"]],
|
||||
"accessibility_features":[data["accessibility_features"]],
|
||||
"supported_currencies":[data["supported_currencies"]],
|
||||
"notes":[data["notes"]],
|
||||
"location_categories":[data["location_categories"]],
|
||||
"minimum_withdrawal": data["minimum_withdrawal"] if data["minimum_withdrawal"]!="" else "false",
|
||||
"branch_identification": data["branch_identification"] if data["branch_identification"]!="" else "false",
|
||||
"site_identification": data["site_identification"] if data["site_identification"]!="" else "false",
|
||||
"site_name": data["site_name"] if data["site_name"]!="" else "false",
|
||||
"cash_withdrawal_national_fee": data["cash_withdrawal_national_fee"] if data["cash_withdrawal_national_fee"]!="" else "false",
|
||||
"cash_withdrawal_international_fee": data["cash_withdrawal_international_fee"] if data["cash_withdrawal_international_fee"]!="" else "false",
|
||||
"balance_inquiry_fee": data["balance_inquiry_fee"] if data["balance_inquiry_fee"]!="" else "false",
|
||||
**self._index_boolean_payload1(data),
|
||||
**self._index_boolean_payload2(data),
|
||||
|
||||
}
|
||||
result = self.api.post(urlpath, payload=payload)
|
||||
except APIError as err:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
messages.error(self.request, err)
|
||||
return super(IndexAtmsView, self).form_invalid(form)
|
||||
except Exception as err:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
messages.error(self.request, err)
|
||||
return super(IndexAtmsView, self).form_invalid(form)
|
||||
if 'code' in result and result['code']>=400:
|
||||
messages.error(self.request, result['message'])
|
||||
@ -181,6 +167,39 @@ class IndexAtmsView(LoginRequiredMixin, FormView):
|
||||
messages.success(self.request, msg)
|
||||
return super(IndexAtmsView, self).form_valid(form)
|
||||
|
||||
def _location(self, data):
|
||||
return {
|
||||
"latitude": float(data["location_latitude"]) if data["location_latitude"] is not None else "",
|
||||
"longitude": float(data["location_longitude"]) if data["location_longitude"] is not None else ""
|
||||
}
|
||||
|
||||
def _meta(self, data):
|
||||
return {
|
||||
"license": {
|
||||
"id": "ODbL-1.0",
|
||||
"name": data["meta_license_name"] if data["meta_license_name"]!="" else "license name"
|
||||
}
|
||||
}
|
||||
|
||||
def _index_boolean_payload1(self, data):
|
||||
return {
|
||||
"is_accessible": data["is_accessible"] if data["is_accessible"]!="" else "false",
|
||||
"located_at": data["located_at"] if data["located_at"]!="no-example-provided" else " ",
|
||||
"more_info": data["more_info"] if data["more_info"]!="" else "false",
|
||||
"has_deposit_capability": data["has_deposit_capability"] if data["has_deposit_capability"]!="" else "false",
|
||||
"minimum_withdrawal": data["minimum_withdrawal"] if data["minimum_withdrawal"]!="" else "false"
|
||||
}
|
||||
|
||||
def _index_boolean_payload2(self, data):
|
||||
return {
|
||||
"branch_identification": data["branch_identification"] if data["branch_identification"]!="" else "false",
|
||||
"site_identification": data["site_identification"] if data["site_identification"]!="" else "false",
|
||||
"site_name": data["site_name"] if data["site_name"]!="" else "false",
|
||||
"cash_withdrawal_national_fee": data["cash_withdrawal_national_fee"] if data["cash_withdrawal_national_fee"]!="" else "false",
|
||||
"cash_withdrawal_international_fee": data["cash_withdrawal_international_fee"] if data["cash_withdrawal_international_fee"]!="" else "false",
|
||||
"balance_inquiry_fee": data["balance_inquiry_fee"] if data["balance_inquiry_fee"]!="" else "false"
|
||||
}
|
||||
|
||||
class UpdateAtmsView(LoginRequiredMixin, FormView):
|
||||
template_name = "atms/update.html"
|
||||
success_url = '/atms/list'
|
||||
@ -200,8 +219,8 @@ class UpdateAtmsView(LoginRequiredMixin, FormView):
|
||||
fields['bank_id'].choices = self.api.get_bank_id_choices()
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
except:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
except Exception as err:
|
||||
messages.error(self.request, err)
|
||||
try:
|
||||
result = self.api.get(urlpath)
|
||||
fields['bank_id'].initial = self.kwargs['bank_id']
|
||||
@ -214,14 +233,6 @@ class UpdateAtmsView(LoginRequiredMixin, FormView):
|
||||
fields['meta_license_name'].initial = result['meta']['license']['name']
|
||||
fields['minimum_withdrawal'].initial = result['minimum_withdrawal']
|
||||
fields['branch_identification'].initial = result['branch_identification']
|
||||
if result['is_accessible'].lower()=='true':
|
||||
fields['is_accessible'].choices = [(True, True), (False, False)]
|
||||
else:
|
||||
fields['is_accessible'].choices = [(False, False), (True, True)]
|
||||
if result['has_deposit_capability'].lower()=='true':
|
||||
fields['has_deposit_capability'].choices = [(True, True), (False, False)]
|
||||
else:
|
||||
fields['has_deposit_capability'].choices = [(False, False), (True, True)]
|
||||
fields['has_deposit_capability'].initial = result['accessibility_features']
|
||||
fields['site_identification'].initial = result['site_identification']
|
||||
fields['site_name'].initial = result['site_name']
|
||||
@ -232,35 +243,53 @@ class UpdateAtmsView(LoginRequiredMixin, FormView):
|
||||
fields['located_at'].initial = result['located_at']
|
||||
fields['more_info'].initial = result['more_info']
|
||||
fields['located_at'].initial = result['located_at']
|
||||
if result['supported_languages'][0].lower()=='en':
|
||||
fields['supported_languages'].choices = [("en", "en"), ("fr", "fr"), ("de", "de")]
|
||||
elif result['supported_languages'][0].lower()=='fr':
|
||||
fields['supported_languages'].choices = [("fr", "fr"), ("en", "en"), ("de", "de")]
|
||||
else:
|
||||
fields['supported_languages'].choices = [("de", "de"),("fr", "fr"), ("en", "en")]
|
||||
fields['supported_languages'].initial = result['supported_languages']
|
||||
if result['supported_currencies'][0].lower()=='EUR':
|
||||
fields['supported_currencies'].choices = [("EUR", "EUR"), ("MXN", "MXN"), ("USD", "USD")]
|
||||
elif result['supported_currencies'][0].lower()=='MXN':
|
||||
fields['supported_currencies'].choices = [("MXN", "MXN"), ("EUR", "EUR"), ("USD", "USD")]
|
||||
else:
|
||||
fields['supported_currencies'].choices = [("USD", "USD"),("MXN", "MXN"), ("EUR", "EUR")]
|
||||
fields['supported_currencies'].initial = result['supported_currencies']
|
||||
if result['notes'][0].lower()=='string1':
|
||||
fields['notes'].choices = [("String1", "String1"),("String2", "String2")]
|
||||
else:
|
||||
fields['notes'].choices = [("String2", "String2"),("String1", "String1")]
|
||||
fields['notes'].initial = result['notes']
|
||||
if result['location_categories'][0].lower()=='atbi':
|
||||
fields['location_categories'].choices = [("ATBI", "ATBI"),("ATBE", "ATBE")]
|
||||
else:
|
||||
fields['location_categories'].choices = [("ATBE", "ATBE"),("ATBI", "ATBI")]
|
||||
fields['location_categories'].initial = result['location_categories']
|
||||
self._paylod_choices(result, fields)
|
||||
self._paylod_languages_and_currencies(result, fields)
|
||||
self._paylod_notes_and_categories(result, fields)
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
except Exception as err:
|
||||
messages.error(self.request, "Unknown Error {}".format(err))
|
||||
return form
|
||||
|
||||
def _paylod_choices(self, result, fields):
|
||||
if result['is_accessible'].lower()=='true':
|
||||
fields['is_accessible'].choices = [(True, True), (False, False)]
|
||||
else:
|
||||
fields['is_accessible'].choices = [(False, False), (True, True)]
|
||||
if result['has_deposit_capability'].lower()=='true':
|
||||
fields['has_deposit_capability'].choices = [(True, True), (False, False)]
|
||||
else:
|
||||
fields['has_deposit_capability'].choices = [(False, False), (True, True)]
|
||||
|
||||
def _paylod_languages_and_currencies(self, result, fields):
|
||||
if result['supported_languages'][0].lower()=='en':
|
||||
fields['supported_languages'].choices = [("en", "en"), ("fr", "fr"), ("de", "de")]
|
||||
elif result['supported_languages'][0].lower()=='fr':
|
||||
fields['supported_languages'].choices = [("fr", "fr"), ("en", "en"), ("de", "de")]
|
||||
else:
|
||||
fields['supported_languages'].choices = [("de", "de"),("fr", "fr"), ("en", "en")]
|
||||
fields['supported_languages'].initial = result['supported_languages']
|
||||
if result['supported_currencies'][0].lower()=='EUR':
|
||||
fields['supported_currencies'].choices = [("EUR", "EUR"), ("MXN", "MXN"), ("USD", "USD")]
|
||||
elif result['supported_currencies'][0].lower()=='MXN':
|
||||
fields['supported_currencies'].choices = [("MXN", "MXN"), ("EUR", "EUR"), ("USD", "USD")]
|
||||
else:
|
||||
fields['supported_currencies'].choices = [("USD", "USD"),("MXN", "MXN"), ("EUR", "EUR")]
|
||||
fields['supported_currencies'].initial = result['supported_currencies']
|
||||
|
||||
def _paylod_notes_and_categories(self, result, fields):
|
||||
if result['notes'][0].lower()=='string1':
|
||||
fields['notes'].choices = [("String1", "String1"),("String2", "String2")]
|
||||
else:
|
||||
fields['notes'].choices = [("String2", "String2"),("String1", "String1")]
|
||||
fields['notes'].initial = result['notes']
|
||||
if result['location_categories'][0].lower()=='atbi':
|
||||
fields['location_categories'].choices = [("ATBI", "ATBI"),("ATBE", "ATBE")]
|
||||
else:
|
||||
fields['location_categories'].choices = [("ATBE", "ATBE"),("ATBI", "ATBI")]
|
||||
fields['location_categories'].initial = result['location_categories']
|
||||
|
||||
def form_valid(self, form):
|
||||
data = form.cleaned_data
|
||||
urlpath = '/banks/{}/atms/{}'.format(data["bank_id"],data["atm_id"])
|
||||
@ -307,23 +336,14 @@ class UpdateAtmsView(LoginRequiredMixin, FormView):
|
||||
"opening_time": " ",
|
||||
"closing_time": " "
|
||||
},
|
||||
"is_accessible": data["is_accessible"] if data["is_accessible"]!="" else "false",
|
||||
"located_at": data["located_at"] if data["located_at"]!="no-example-provided" else " ",
|
||||
"more_info": data["more_info"] if data["more_info"]!="" else "false",
|
||||
"has_deposit_capability": data["has_deposit_capability"] if data["has_deposit_capability"]!="" else "false",
|
||||
"supported_languages":[data["supported_languages"]],
|
||||
"services":[data["services"]],
|
||||
"accessibility_features":[data["accessibility_features"]],
|
||||
"supported_currencies":[data["supported_currencies"]],
|
||||
"notes":[data["notes"]],
|
||||
"location_categories":[data["location_categories"]],
|
||||
"minimum_withdrawal": data["minimum_withdrawal"] if data["minimum_withdrawal"]!="" else "false",
|
||||
"branch_identification": data["branch_identification"] if data["branch_identification"]!="" else "false",
|
||||
"site_identification": data["site_identification"] if data["site_identification"]!="" else "false",
|
||||
"site_name": data["site_name"] if data["site_name"]!="" else "false",
|
||||
"cash_withdrawal_national_fee": data["cash_withdrawal_national_fee"] if data["cash_withdrawal_national_fee"]!="" else "false",
|
||||
"cash_withdrawal_international_fee": data["cash_withdrawal_international_fee"] if data["cash_withdrawal_international_fee"]!="" else "false",
|
||||
"balance_inquiry_fee": data["balance_inquiry_fee"] if data["balance_inquiry_fee"]!="" else "false",
|
||||
**self._update_boolean_payload1(data),
|
||||
**self._update_boolean_payload2(data)
|
||||
}
|
||||
try:
|
||||
result = self.api.put(urlpath, payload=payload)
|
||||
@ -341,6 +361,25 @@ class UpdateAtmsView(LoginRequiredMixin, FormView):
|
||||
messages.success(self.request, msg)
|
||||
return super(UpdateAtmsView, self).form_valid(form)
|
||||
|
||||
def _update_boolean_payload1(self, data):
|
||||
return {
|
||||
"is_accessible": data["is_accessible"] if data["is_accessible"]!="" else "false",
|
||||
"located_at": data["located_at"] if data["located_at"]!="no-example-provided" else " ",
|
||||
"more_info": data["more_info"] if data["more_info"]!="" else "false",
|
||||
"has_deposit_capability": data["has_deposit_capability"] if data["has_deposit_capability"]!="" else "false",
|
||||
"minimum_withdrawal": data["minimum_withdrawal"] if data["minimum_withdrawal"]!="" else "false"
|
||||
}
|
||||
|
||||
def _update_boolean_payload2(self, data):
|
||||
return {
|
||||
"branch_identification": data["branch_identification"] if data["branch_identification"]!="" else "false",
|
||||
"site_identification": data["site_identification"] if data["site_identification"]!="" else "false",
|
||||
"site_name": data["site_name"] if data["site_name"]!="" else "false",
|
||||
"cash_withdrawal_national_fee": data["cash_withdrawal_national_fee"] if data["cash_withdrawal_national_fee"]!="" else "false",
|
||||
"cash_withdrawal_international_fee": data["cash_withdrawal_international_fee"] if data["cash_withdrawal_international_fee"]!="" else "false",
|
||||
"balance_inquiry_fee": data["balance_inquiry_fee"] if data["balance_inquiry_fee"]!="" else "false"
|
||||
}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(UpdateAtmsView, self).get_context_data(**kwargs)
|
||||
self.bank_id = self.kwargs['bank_id']
|
||||
|
||||
@ -9,6 +9,7 @@ from django.contrib import messages
|
||||
from obp.api import API, APIError, LOGGER
|
||||
from django.core.cache import cache
|
||||
|
||||
USER_CURRENT = "/users/current"
|
||||
|
||||
def api_root(request):
|
||||
"""Returns the configured API_ROOT"""
|
||||
@ -36,7 +37,7 @@ def override_css_url(request):
|
||||
def api_username(request):
|
||||
"""Returns the API username/email of the logged-in user"""
|
||||
nametodisplay = 'not authenticated'
|
||||
get_current_user_api_url = '/users/current'
|
||||
get_current_user_api_url = USER_CURRENT
|
||||
#Here we can not get the user from obp-api side, so we use the django auth user id here.
|
||||
cache_key_django_user_id = request.session._session.get('_auth_user_id')
|
||||
cache_key = '{},{},{}'.format('api_username',get_current_user_api_url, cache_key_django_user_id)
|
||||
@ -49,34 +50,36 @@ def api_username(request):
|
||||
return apicaches
|
||||
else:
|
||||
if request.user.is_authenticated:
|
||||
try:
|
||||
api = API(request.session.get('obp'))
|
||||
data = api.get(get_current_user_api_url)
|
||||
username = data['username']
|
||||
email = data['email']
|
||||
provider = data['provider']
|
||||
if "google" in provider:
|
||||
nametodisplay = email
|
||||
elif "yahoo" in provider:
|
||||
nametodisplay = email
|
||||
elif "microsoft" in provider:
|
||||
nametodisplay = email
|
||||
else:
|
||||
nametodisplay = username
|
||||
apicaches=cache.set(cache_key, {'API_USERNAME': nametodisplay})
|
||||
LOGGER.warning('The cache is setting try to api_user_name:')
|
||||
LOGGER.warning('The cache is setting key is: {}'.format(cache_key))
|
||||
except APIError as err:
|
||||
messages.error(request, err)
|
||||
except Exception as err:
|
||||
messages.error(request, err)
|
||||
return {'API_USERNAME': nametodisplay}
|
||||
nametodisplay = authenticated_name(request, get_current_user_api_url)
|
||||
apicaches=cache.set(cache_key, {'API_USERNAME': nametodisplay})
|
||||
LOGGER.warning('The cache setting api_user_name is: {}'.format(nametodisplay))
|
||||
LOGGER.warning('The cache setting key is: {}'.format(cache_key))
|
||||
|
||||
def authenticated_name(request, get_current_user_api_url):
|
||||
try:
|
||||
api = API(request.session.get('obp'))
|
||||
data = api.get(get_current_user_api_url)
|
||||
username = data['username']
|
||||
email = data['email']
|
||||
provider = data['provider']
|
||||
if "google" in provider:
|
||||
nametodisplay = email
|
||||
elif "yahoo" in provider:
|
||||
nametodisplay = email
|
||||
elif "microsoft" in provider:
|
||||
nametodisplay = email
|
||||
else:
|
||||
nametodisplay = username
|
||||
return {'API_USERNAME': nametodisplay}
|
||||
except APIError as err:
|
||||
messages.error(request, err)
|
||||
except Exception as err:
|
||||
messages.error(request, err)
|
||||
|
||||
def api_user_id(request):
|
||||
"""Returns the API user id of the logged-in user"""
|
||||
user_id = 'not authenticated'
|
||||
get_current_user_api_url = '/users/current'
|
||||
get_current_user_api_url = USER_CURRENT
|
||||
#Here we can not get the user from obp-api side, so we use the django auth user id here.
|
||||
cache_key_django_user_id = request.session._session.get('_auth_user_id')
|
||||
cache_key = '{},{},{}'.format('api_user_id',get_current_user_api_url, cache_key_django_user_id)
|
||||
@ -91,7 +94,7 @@ def api_user_id(request):
|
||||
if request.user.is_authenticated:
|
||||
try:
|
||||
api = API(request.session.get('obp'))
|
||||
data = api.get('/users/current')
|
||||
data = api.get(USER_CURRENT)
|
||||
user_id = data['user_id']
|
||||
apicaches=cache.set(cache_key, {'API_USER_ID': user_id})
|
||||
LOGGER.warning('The cache is setting try to api_user_id:')
|
||||
|
||||
@ -15,6 +15,8 @@ from obp.api import API, APIError
|
||||
from .forms import CreateBranchForm
|
||||
from base.views import get_banks
|
||||
|
||||
LICENSE_NAME = "license name"
|
||||
|
||||
class IndexBranchesView(LoginRequiredMixin, FormView):
|
||||
"""Index view for branches"""
|
||||
template_name = "branches/index.html"
|
||||
@ -122,8 +124,8 @@ class IndexBranchesView(LoginRequiredMixin, FormView):
|
||||
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
except:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
except Exception as err:
|
||||
messages.error(self.request, err)
|
||||
|
||||
return form
|
||||
|
||||
@ -143,14 +145,14 @@ class IndexBranchesView(LoginRequiredMixin, FormView):
|
||||
"meta": {
|
||||
"license": {
|
||||
"id": "PDDL",
|
||||
"name": data["meta_license_name"] if data["meta_license_name"]!="" else "license name"
|
||||
"name": data["meta_license_name"] if data["meta_license_name"]!="" else LICENSE_NAME
|
||||
}
|
||||
},
|
||||
"lobby": json.loads(data['lobby']),
|
||||
"drive_up": json.loads(data["drive_up"]),
|
||||
"branch_routing": {
|
||||
"scheme": data["branch_routing_scheme"] if data["branch_routing_scheme"]!="" else "license name",
|
||||
"address": data["branch_routing_address"] if data["branch_routing_address"]!="" else "license name"
|
||||
"scheme": data["branch_routing_scheme"] if data["branch_routing_scheme"]!="" else LICENSE_NAME,
|
||||
"address": data["branch_routing_address"] if data["branch_routing_address"]!="" else LICENSE_NAME
|
||||
},
|
||||
"is_accessible": data["is_accessible"] if data["is_accessible"]!="" else "false",
|
||||
"accessibleFeatures": data["accessibleFeatures"] if data["accessibleFeatures"]!="" else "accessible features name",
|
||||
@ -163,7 +165,7 @@ class IndexBranchesView(LoginRequiredMixin, FormView):
|
||||
error_once_only(self.request, err)
|
||||
return super(IndexBranchesView, self).form_invalid(form)
|
||||
except Exception as err:
|
||||
error_once_only(self.request, "Unknown Error")
|
||||
error_once_only(self.request, err)
|
||||
return super(IndexBranchesView, self).form_invalid(form)
|
||||
if 'code' in result and result['code']>=400:
|
||||
error_once_only(self.request, result['message'])
|
||||
@ -222,8 +224,8 @@ class UpdateBranchesView(LoginRequiredMixin, FormView):
|
||||
fields['bank_id'].choices = self.api.get_bank_id_choices()
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
except:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
except Exception as err:
|
||||
messages.error(self.request, err)
|
||||
try:
|
||||
result = self.api.get(urlpath)
|
||||
fields['bank_id'].initial = self.kwargs['bank_id']
|
||||
@ -272,8 +274,8 @@ class UpdateBranchesView(LoginRequiredMixin, FormView):
|
||||
"lobby": json.loads(data["lobby"]),
|
||||
"drive_up": json.loads(data["drive_up"]),
|
||||
"branch_routing": {
|
||||
"scheme": data["branch_routing_scheme"] if data["branch_routing_scheme"] != "" else "license name",
|
||||
"address": data["branch_routing_address"] if data["branch_routing_address"] != "" else "license name"
|
||||
"scheme": data["branch_routing_scheme"] if data["branch_routing_scheme"] != "" else LICENSE_NAME,
|
||||
"address": data["branch_routing_address"] if data["branch_routing_address"] != "" else LICENSE_NAME
|
||||
},
|
||||
"is_accessible": data["is_accessible"],
|
||||
"accessibleFeatures": data["accessibleFeatures"],
|
||||
@ -289,8 +291,8 @@ class UpdateBranchesView(LoginRequiredMixin, FormView):
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return super(UpdateBranchesView, self).form_invalid(form)
|
||||
except:
|
||||
messages.error(self.request, "Unknown Error")
|
||||
except Exception as err:
|
||||
messages.error(self.request, err)
|
||||
return super(UpdateBranchesView, self).form_invalid(form)
|
||||
msg = 'Branch {} for Bank {} has been created successfully!'.format( # noqa
|
||||
data["branch_id"], data["bank_id"])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user