def send_account_confirmation(commcare_user): from corehq.apps.hqwebapp.tasks import send_html_email_async from corehq.apps.users.views.mobile import CommCareUserConfirmAccountView url = absolute_reverse(CommCareUserConfirmAccountView.urlname, args=[commcare_user.domain, commcare_user.get_id]) template_params = { 'domain': commcare_user.domain, 'username': commcare_user.raw_username, 'url': url, 'url_prefix': get_static_url_prefix(), 'hq_name': commcare_hq_names()['commcare_hq_names']['COMMCARE_HQ_NAME'] } lang = guess_domain_language(commcare_user.domain) with override(lang): text_content = render_to_string( "registration/email/mobile_worker_confirm_account.txt", template_params) html_content = render_to_string( "registration/email/mobile_worker_confirm_account.html", template_params) subject = _( f'Confirm your CommCare account for {commcare_user.domain}') send_html_email_async.delay(subject, commcare_user.email, html_content, text_content=text_content, email_from=settings.DEFAULT_FROM_EMAIL)
def _login(req, domain_name, custom_login_page, extra_context=None): extra_context = extra_context or {} if req.user.is_authenticated and req.method == "GET": redirect_to = req.GET.get('next', '') if redirect_to: return HttpResponseRedirect(redirect_to) if not domain_name: return HttpResponseRedirect(reverse('homepage')) else: return HttpResponseRedirect(reverse('domain_homepage', args=[domain_name])) if req.method == 'POST' and domain_name and '@' not in req.POST.get('auth-username', '@'): with mutable_querydict(req.POST): req.POST['auth-username'] = format_username(req.POST['auth-username'], domain_name) if 'auth-username' in req.POST: couch_user = CouchUser.get_by_username(req.POST['auth-username'].lower()) if couch_user: new_lang = couch_user.language old_lang = req.session.get(LANGUAGE_SESSION_KEY) update_session_language(req, old_lang, new_lang) req.base_template = settings.BASE_TEMPLATE context = {} template_name = custom_login_page if custom_login_page else 'login_and_password/login.html' if not custom_login_page and domain_name: domain_obj = Domain.get_by_name(domain_name) req_params = req.GET if req.method == 'GET' else req.POST context.update({ 'domain': domain_name, 'hr_name': domain_obj.display_name(), 'next': req_params.get('next', '/a/%s/' % domain_name), 'allow_domain_requests': domain_obj.allow_domain_requests, 'current_page': {'page_name': _('Welcome back to %s!') % domain_obj.display_name()}, }) else: commcare_hq_name = commcare_hq_names(req)['commcare_hq_names']["COMMCARE_HQ_NAME"] context.update({ 'current_page': {'page_name': _('Welcome back to %s!') % commcare_hq_name}, }) if settings.SERVER_ENVIRONMENT in settings.ICDS_ENVS: auth_view = CloudCareLoginView else: auth_view = HQLoginView if not domain_name else CloudCareLoginView demo_workflow_ab_v2 = ab_tests.SessionAbTest(ab_tests.DEMO_WORKFLOW_V2, req) if settings.IS_SAAS_ENVIRONMENT: context['demo_workflow_ab_v2'] = demo_workflow_ab_v2.context context.update(extra_context) response = auth_view.as_view(template_name=template_name, extra_context=context)(req) if settings.IS_SAAS_ENVIRONMENT: demo_workflow_ab_v2.update_response(response) return response
def _generate_help_message(): completion_help = mark_safe_lazy(gettext_lazy( # nosec: no user input "<strong>Completion</strong> time is when the form is completed on the phone.")) submission_help = mark_safe_lazy(gettext_lazy( # nosec: no user input "<strong>Submission</strong> time is when {hq_name} receives the form.".format( hq_name=commcare_hq_names()['commcare_hq_names']['COMMCARE_HQ_NAME']))) return format_html("{}<br />{}", completion_help, submission_help)
class CompletionOrSubmissionTimeFilter(BaseSingleOptionFilter): slug = "sub_time" label = ugettext_lazy("Filter Dates By") css_class = "span2" help_text = mark_safe( "%s<br />%s" % (ugettext_lazy( "<strong>Completion</strong> time is when the form is completed on the phone."), ugettext_lazy( "<strong>Submission</strong> time is when {hq_name} receives the form.".format( hq_name=commcare_hq_names()['commcare_hq_names']['COMMCARE_HQ_NAME'])))) default_text = ugettext_lazy("Completion Time") @property def options(self): return [ ('submission', _('Submission Time')), ]
def _get_default_tiles(request): can_edit_data = lambda request: (request.couch_user.can_edit_data() or request.couch_user.can_access_any_exports()) can_edit_apps = lambda request: (request.couch_user.is_web_user() or request.couch_user.can_edit_apps()) can_view_reports = lambda request: user_can_view_reports(request.project, request.couch_user) can_edit_users = lambda request: (request.couch_user.can_edit_commcare_users() or request.couch_user.can_edit_web_users()) def can_edit_locations_not_users(request): if not has_privilege(request, privileges.LOCATIONS): return False user = request.couch_user return not can_edit_users(request) and ( user.can_edit_locations() or user_can_edit_location_types(user, request.domain) ) can_view_commtrack_setup = lambda request: (request.project.commtrack_enabled) def can_view_exchange(request): return ( can_edit_apps(request) and not settings.ENTERPRISE_MODE and not get_domain_master_link(request.domain) # this isn't a linked domain ) def _can_access_sms(request): return has_privilege(request, privileges.OUTBOUND_SMS) def _can_access_reminders(request): return has_privilege(request, privileges.REMINDERS_FRAMEWORK) can_use_messaging = lambda request: ( (_can_access_reminders(request) or _can_access_sms(request)) and not request.couch_user.is_commcare_user() and request.couch_user.can_edit_data() ) is_billing_admin = lambda request: request.couch_user.can_edit_billing() apps_link = lambda urlname, req: ( '' if domain_has_apps(request.domain) else reverse(urlname, args=[request.domain]) ) commcare_name = commcare_hq_names(request)['commcare_hq_names']['COMMCARE_NAME'] return [ Tile( request, title=_('Applications'), slug='applications', icon='fcc fcc-applications', paginator_class=AppsPaginator, visibility_check=can_edit_apps, urlname='default_new_app', url_generator=apps_link, help_text=_('Build, update, and deploy applications'), ), Tile( request, title=_('Reports'), slug='reports', icon='fcc fcc-reports', paginator_class=ReportsPaginator, urlname='reports_home', visibility_check=can_view_reports, help_text=_('View worker monitoring reports and inspect project data'), ), Tile( request, title=_('{cc_name} Supply Setup').format(cc_name=commcare_name), slug='commtrack_setup', icon='fcc fcc-commtrack', urlname='default_commtrack_setup', visibility_check=can_view_commtrack_setup, help_text=_("Update {cc_name} Supply Settings").format(cc_name=commcare_name), ), Tile( request, title=_('Data'), slug='data', icon='fcc fcc-data', paginator_class=DataPaginator, urlname="data_interfaces_default", visibility_check=can_edit_data, help_text=_('Export and manage data'), ), Tile( request, title=_('Users'), slug='users', icon='fcc fcc-users', urlname=DefaultProjectUserSettingsView.urlname, visibility_check=can_edit_users, help_text=_('Manage accounts for mobile workers and CommCareHQ users'), ), Tile( request, title=_('Organization'), slug='locations', icon='fcc fcc-users', urlname='default_locations_view', visibility_check=can_edit_locations_not_users, help_text=_('Manage the Organization Hierarchy'), ), Tile( request, title=_('Messaging'), slug='messaging', icon='fcc fcc-messaging', urlname='sms_default', visibility_check=can_use_messaging, help_text=_('Configure and schedule SMS messages and keywords'), ), Tile( request, title=_('Exchange'), slug='exchange', icon='fcc fcc-exchange', urlname='appstore', visibility_check=can_view_exchange, url_generator=lambda urlname, req: reverse(urlname), help_text=_('Download and share CommCare applications with other users around the world'), ), Tile( request, title=_('Settings'), slug='settings', icon='fcc fcc-settings', urlname=DefaultProjectSettingsView.urlname, visibility_check=is_billing_admin, help_text=_('Set project-wide settings and manage subscriptions'), ), Tile( request, title=_('Help Site'), slug='help', icon='fcc fcc-help', url='http://help.commcarehq.org/', help_text=_("Visit CommCare's knowledge base"), ), ]
def _login(req, domain_name): if req.user.is_authenticated and req.method == "GET": redirect_to = req.GET.get('next', '') if redirect_to: return HttpResponseRedirect(redirect_to) if not domain_name: return HttpResponseRedirect(reverse('homepage')) else: return HttpResponseRedirect(reverse('domain_homepage', args=[domain_name])) if req.method == 'POST' and domain_name and '@' not in req.POST.get('auth-username', '@'): with mutable_querydict(req.POST): req.POST['auth-username'] = format_username(req.POST['auth-username'], domain_name) if 'auth-username' in req.POST: couch_user = CouchUser.get_by_username(req.POST['auth-username'].lower()) if couch_user: new_lang = couch_user.language old_lang = req.session.get(LANGUAGE_SESSION_KEY) update_session_language(req, old_lang, new_lang) req.base_template = settings.BASE_TEMPLATE context = {} template_name = 'login_and_password/login.html' custom_landing_page = settings.CUSTOM_LANDING_TEMPLATE if custom_landing_page: if isinstance(custom_landing_page, six.string_types): soft_assert_type_text(custom_landing_page) template_name = custom_landing_page else: template_name = custom_landing_page.get(req.get_host()) if template_name is None: template_name = custom_landing_page.get('default', template_name) elif domain_name: domain_obj = Domain.get_by_name(domain_name) req_params = req.GET if req.method == 'GET' else req.POST context.update({ 'domain': domain_name, 'hr_name': domain_obj.display_name(), 'next': req_params.get('next', '/a/%s/' % domain_name), 'allow_domain_requests': domain_obj.allow_domain_requests, 'current_page': {'page_name': _('Welcome back to %s!') % domain_obj.display_name()}, }) else: commcare_hq_name = commcare_hq_names(req)['commcare_hq_names']["COMMCARE_HQ_NAME"] context.update({ 'current_page': {'page_name': _('Welcome back to %s!') % commcare_hq_name}, }) if settings.SERVER_ENVIRONMENT in settings.ICDS_ENVS: auth_view = CloudCareLoginView else: auth_view = HQLoginView if not domain_name else CloudCareLoginView demo_workflow_ab_v2 = ab_tests.SessionAbTest(ab_tests.DEMO_WORKFLOW_V2, req) if settings.IS_SAAS_ENVIRONMENT: context['demo_workflow_ab_v2'] = demo_workflow_ab_v2.context response = auth_view.as_view(template_name=template_name, extra_context=context)(req) if settings.IS_SAAS_ENVIRONMENT: demo_workflow_ab_v2.update_response(response) return response