def search(request,org_id=0,hospital_id=0): if isUserLogged(request): args = {} usr_details = request.session['usr_details'] args['usr_details'] = usr_details return render_to_response('org_search.html',args) else: return userSessionExpired()
def org_details(request,org_id=0): if isUserLogged(request): args = {} usr_details = request.session['usr_details'] if 'setting' in request.GET : result = request.GET['setting'] args['result'] = result organisation = None department = None settings = None apikey = None if org_id != 0: orgID = org_id try: organisation = Organisation.objects.get(org_id = orgID) department = Department.objects.filter(department_org = orgID) settings = organisation.org_settings apikey = list(Apikey.objects.filter(apikey_org = org_id)) except: logger.exception("Organisation ID "+str(orgID)+" not found") if settings is not None: args['subscription'] = app_utils.get_subscription_type(settings.orgsettings_subscription) args['billing_cycle'] = app_utils.get_billing_cycle(settings.orgsettings_billing_cycle) args['isMarketPlace'] = settings.orgsettings_marketplace args['email'] = settings.orgsettings_email args['email_smtp'] = settings.orgsettings_email_smtp args['voice_rate'] = settings.orgsettings_voice_rate args['video_rate'] = settings.orgsettings_video_rate args['subscription_rate'] = settings.orgsettings_subscription_rate args['status'] = settings.orgsettings_status args['isSettings'] = True args['isVoice'] = False args['isVideo'] = False if organisation.org_settings.orgsettings_subscription == 'C': args['isVoice'] = True else: args['isVoice'] = True args['isVideo'] = True else: args['isSettings'] = False if len(apikey) == 0: args['apikey'] = None else: args['apikey'] = apikey[0] args['org'] = organisation args['depts'] = department formOrgChoice = CYMOrganisationSelectionForm() args['usr_details'] = usr_details args['formOrgChoice'] = formOrgChoice return render_to_response('org_details.html',args) else: return userSessionExpired()
def mp_dashboard(request): if isUserLogged(request): args = {} usr_details = request.session['usr_details'] args['usr_details'] = usr_details mpSetting = Marketplace.objects.all() mp = None if len(mpSetting) != 0: mp = mpSetting[0] args['mp_apikey'] = mp.apikey return render_to_response('mp_dashboard.html',args) else: return userSessionExpired()
def login(request): args = {} if isUserLogged(request): return HttpResponseRedirect('/cym/dashboard') else: error = None if request.POST: formLogin = CYMUserLoginForm(request.POST) if formLogin.is_valid(): username = formLogin.cleaned_data['user_name'] password = formLogin.cleaned_data['password'] obj = None try: obj = User.objects.get(usr_email__iexact = username) except (KeyError, User.DoesNotExist): error = "Username or password incorrect" logger.exception("User does not exists "+username) args.update(csrf(request)) args['formLogin'] = formLogin args['error'] = error return render_to_response('login.html',args) if app_utils.checkPassword(password,obj.usr_password): try: createUserSession(request,obj) return HttpResponseRedirect('/cym/dashboard') except: error = "Session error occurred" logger.exception("Session creation error occured for user "+username) args.update(csrf(request)) args['formLogin'] = formLogin args['error'] = error return render_to_response('login.html',args) else: logger.info("Incorrect password for user "+username) error = "Username or password incorrect" else: print ("*********Form invalid") else: formLogin = CYMUserLoginForm() request.session.set_test_cookie() if 'sessionError' in request.GET: if request.GET['sessionError'] == '100': args['sessionError'] = True args.update(csrf(request)) args['formLogin'] = formLogin args['error'] = error return render_to_response('login.html',args)
def org_create_apikey(request,org_id=0): error = None args = {} if isUserLogged(request): usr_details = request.session['usr_details'] try: organisation = Organisation.objects.get(org_id = org_id) key = generateAPIKey() apikey = Apikey(apikey_org = organisation,apikey_key = key) try: apikey.save() except: traceback.print_exc() error = "Key Generation Failed! Try Again." except(KeyError, Organisation.DoesNotExist): error = "Username or password incorrect" args['error'] = error args['usr_details'] = usr_details return HttpResponseRedirect('/cym/organisationdetails/'+str(org_id)+'/') else: return userSessionExpired()
def mp_generateapikey(request): if isUserLogged(request): args = {} usr_details = request.session['usr_details'] args['usr_details'] = usr_details key = generateAPIKey() print (key) mpSetting = Marketplace.objects.all() mp = None if len(mpSetting) == 0: print("No settings") mp = Marketplace() else: mp = mpSetting[0] mp.apikey = key try: print("Saving key") mp.save() print "Saved key" except IntegrityError: traceback.print_exc() return HttpResponseRedirect('/cym/marketplace/') else: return userSessionExpired()
def usr_usrgroupnew(request): error = None formError = False args = {} if isUserLogged(request): if request.POST: groupCreationForm = CYMUserGroupCreationForm(request.POST) if groupCreationForm.is_valid(): try: group = groupCreationForm.save() usr_details = request.session['usr_details'] args['usr_details'] = usr_details # print(groupCreationForm.cleaned_data['grp_name']) if group.groupTotalPermissionLevel( ) == MAX_PERMISSION_LEVEL: group.is_super = True group.save() users = list( User.objects.filter(usr_group__in=Group.objects.filter( is_super=True)).values('usr_email')) mail_dict = MAIL_DATA_DICT # MAIL_DATA_DICT = { # TYPE : None, # TO : None, # CC : None, # BCC : None, # FROM : None, # MESSAGE : None, # DETAILS : None # } usr = [] if users is not None and len(users) != 0: for user in users: usr.append(user['usr_email']) print(usr) mail_dict[TYPE] = MAIL_CYM_GROUP mail_dict[TO] = usr grp = {} grp['Group Name'] = groupCreationForm.cleaned_data[ 'grp_name'] grp['Org level'] = get_permission( groupCreationForm.cleaned_data['grp_org']) grp['Hospital level'] = get_permission( groupCreationForm.cleaned_data['grp_hospital']) grp['Doctor level'] = get_permission( groupCreationForm.cleaned_data['grp_doctor']) grp['Patient level'] = get_permission( groupCreationForm.cleaned_data['grp_patients']) grp['Call level'] = get_permission( groupCreationForm.cleaned_data['grp_call']) grp['Transaction level'] = get_permission( groupCreationForm.cleaned_data['grp_transaction']) grp['User level'] = get_permission( groupCreationForm.cleaned_data['grp_user']) mail_dict[DETAILS] = grp mailer = EmailHandler(mail_dict) logger.info("Sending mail for CYM Group creation") mailer.send_mail() return render_to_response('usr_group.html', args) except: print '********* form invalid' error = 'Error creating group. Please try again' traceback.print_exc() formError = True usr_details = request.session['usr_details'] args['formError'] = formError args['error'] = error args['usr_details'] = usr_details return render_to_response('usr_group.html', args) else: print '********form incomplete' error = 'Group creation form incomplete. Please try again!' formError = True usr_details = request.session['usr_details'] args['formError'] = formError args['error'] = error args['usr_details'] = usr_details return render_to_response('usr_group.html', args) else: groupCreationForm = CYMUserGroupCreationForm() args.update(csrf(request)) args['groupCreationForm'] = groupCreationForm return render_to_response('usr_newgroup.html', args) else: html = '<div class="modal-body" id="modal-body-createGroup">User Session Expired! <a href="/cymlogin/?sessionError=100">Login</a></div>' return HttpResponse(html)
def org_edit_settings(request, org_id=0): error = None formError = False args = {} if isUserLogged(request): if org_id == 0: html = '<div class="modal-body" id="modal-body-createGroup">Bad Request! Try Again</div>' return HttpResponse(html) org = Organisation.objects.get(org_id=org_id) settings = None if request.POST: orgSettingsForm = CYMOrgSettingsForm(request.POST) if orgSettingsForm.is_valid(): if org.org_settings is None: settings = OrgSettings() else: settings = org.org_settings settings.orgsettings_status = orgSettingsForm.cleaned_data[ 'orgsettings_status'] settings.orgsettings_billing_cycle = orgSettingsForm.cleaned_data[ 'orgsettings_billing_cycle'] settings.orgsettings_email = orgSettingsForm.cleaned_data[ 'orgsettings_email'] settings.orgsettings_email_smtp = orgSettingsForm.cleaned_data[ 'orgsettings_email_smtp'] settings.orgsettings_subscription = orgSettingsForm.cleaned_data[ 'orgsettings_subscription'] settings.orgsettings_subscription_rate = orgSettingsForm.cleaned_data[ 'orgsettings_subscription_rate'] settings.orgsettings_voice_rate = orgSettingsForm.cleaned_data[ 'orgsettings_voice_rate'] settings.orgsettings_video_rate = orgSettingsForm.cleaned_data[ 'orgsettings_video_rate'] settings.orgsettings_marketplace = orgSettingsForm.cleaned_data[ 'orgsettings_marketplace'] org.org_active = orgSettingsForm.cleaned_data[ 'orgsettings_status'] try: with transaction.atomic(): settings.save() if org.org_settings is None: org.org_settings = settings org.save() usr_details = request.session['usr_details'] return HttpResponseRedirect('/cym/organisationdetails/' + str(org_id) + '/?setting=updated') except: print '********* form invalid' error = 'Error updating settings. Please try again' formError = True usr_details = request.session['usr_details'] args['formError'] = formError args['error'] = error args['usr_details'] = usr_details return HttpResponseRedirect('/cym/organisationdetails/' + str(org_id) + '/?setting=error') else: print '********form incomplete' error = 'Settings form incomplete. Please try again!' formError = True usr_details = request.session['usr_details'] args['formError'] = formError args['error'] = error args['usr_details'] = usr_details return HttpResponseRedirect('/cym/organisationdetails/' + str(org_id) + '/?setting=incomplete') else: if org.org_settings is None: orgSettingsForm = CYMOrgSettingsForm() else: orgSettingsForm = CYMOrgSettingsForm(instance=org.org_settings) args.update(csrf(request)) args['orgSettingsForm'] = orgSettingsForm args['orgid'] = org_id return render_to_response('org_settings_edit.html', args) else: html = '<div class="modal-body" id="modal-body-createGroup">User Session Expired! <a href="/cymlogin/?sessionError=100">Login</a></div>' return HttpResponse(html)
def usr_usernew(request): error = None formError = False args = {} if isUserLogged(request): if request.POST: userCreationForm = CYMUserCreationForm(request.POST) if userCreationForm.is_valid(): try: user = User() user.usr_first_name = userCreationForm.cleaned_data[ 'usr_first_name'] user.usr_last_name = userCreationForm.cleaned_data[ 'usr_last_name'] user.usr_email = userCreationForm.cleaned_data['usr_email'] user.usr_phone = userCreationForm.cleaned_data['usr_phone'] randPass = app_utils.generateRandomPassword() user.usr_password = app_utils.getPasswordHash(randPass) user.usr_group = userCreationForm.cleaned_data['usr_group'] user.save() # userCreationForm.save() usr_details = request.session['usr_details'] args['usr_details'] = usr_details mail_dict = MAIL_DATA_DICT # MAIL_DATA_DICT = { # TYPE : None, # TO : None, # CC : None, # BCC : None, # FROM : None, # MESSAGE : None, # DETAILS : None # } mail_dict[TYPE] = MAIL_CYM_USER mail_dict[TO] = [user.usr_email] details = { "User Name": user.usr_email, "Password": randPass, "Group": user.usr_group.grp_name } mail_dict[DETAILS] = details mailer = EmailHandler(mail_dict) logger.info("Sending mail for CYM user creation " + user.usr_email) mailer.send_mail() return render_to_response('usr_user.html', args) except: print '********* form invalid' traceback.print_exc() error = 'Error creating user. Please try again' formError = True usr_details = request.session['usr_details'] args['formError'] = formError args['error'] = error args['usr_details'] = usr_details return render_to_response('usr_user.html', args) else: print '********* form incomplete' error = 'User creation form incomplete. Please try again!' formError = True usr_details = request.session['usr_details'] args['formError'] = formError args['error'] = error args['usr_details'] = usr_details return render_to_response('usr_user.html', args) else: userCreationForm = CYMUserCreationForm() args.update(csrf(request)) args['userCreationForm'] = userCreationForm return render_to_response('usr_newuser.html', args) else: html = '<div class="modal-body" id="modal-body-createGroup">User Session Expired! <a href="/cymlogin/?sessionError=100">Login</a></div>' return HttpResponse(html)
def org_dashboard(request): if isUserLogged(request): usr_details = request.session['usr_details'] return render_to_response('org_dashboard.html',usr_details) else: return userSessionExpired()
def usr_group(request): if isUserLogged(request): usr_details = request.session['usr_details'] return render_to_response('usr_group.html', usr_details) else: return userSessionExpired()
def org_new(request): error = None args = {} if isUserLogged(request): usr_details = request.session['usr_details'] if request.POST: formOrg = CYMOrganisationCreationForm(request.POST) formAddress = AddressForm(request.POST) if formOrg.is_valid() & formAddress.is_valid(): address = Address() organisation = Organisation() settings = OrgSettings() address.address_line1 = formAddress.cleaned_data['address_line1'] address.address_line2 = formAddress.cleaned_data['address_line2'] address.address_city = formAddress.cleaned_data['address_city'] address.address_state = formAddress.cleaned_data['address_state'] pin = formAddress.cleaned_data['address_pincode'] address.address_pincode = pin address.address_status = True organisation.org_name = formOrg.cleaned_data['org_name'] organisation.org_brand = formOrg.cleaned_data['org_brand'] organisation.org_phone = formOrg.cleaned_data['org_phone'] organisation.org_active = formOrg.cleaned_data['org_active'] organisation.org_emailid = formOrg.cleaned_data['org_emailid'] settings.orgsettings_status = formOrg.cleaned_data['org_active'] try: with transaction.atomic(): address.save() settings.save() organisation.org_address = address organisation.org_settings = settings organisation.save() organisation.org_billing_id = organisation.org_id identifier = str(organisation.org_id) + '_' + organisation.org_brand organisation.org_identifier = identifier.replace(" ", "") organisation.save() success = createSuperUserAndGroup(organisation.org_emailid,organisation.org_phone,organisation,'Super Admin',organisation.org_identifier) if success: print 'Super User Created' else: print 'Error while creating super user' send_mail_to_org_admin(organisation) args['usr_details'] = usr_details args['new_org_added'] = organisation.org_name args['new_org_id'] = organisation.org_id return render_to_response('org_dashboard.html',args) except IntegrityError: traceback.print_exc() error = 'Error creating new organisation' else: error = 'Error creating new organisation. Invalid form!' else: formOrg = CYMOrganisationCreationForm() formAddress = AddressForm() args.update(csrf(request)) args['formOrg'] = formOrg args['formAddress'] = formAddress args['usr_details'] = usr_details args['error'] = error return render_to_response('org_new.html',args) else: return userSessionExpired()