예제 #1
0
파일: views.py 프로젝트: mchampanis/core-hq
def snapshot_info(request, domain):
    domain = Domain.get_by_name(domain)
    user_sees_meta = request.couch_user.is_previewer()
    if user_sees_meta:
        form = DomainMetadataForm(initial={
            'default_timezone': domain.default_timezone,
            'case_sharing': json.dumps(domain.case_sharing),
            'city': domain.city,
            'country': domain.country,
            'region': domain.region,
            'project_type': domain.project_type,
            'customer_type': domain.customer_type,
            'is_test': json.dumps(domain.is_test),
            'description': domain.description,
            'is_shared': domain.is_shared,
            'license': domain.license
        })
    else:
        form = DomainGlobalSettingsForm(initial={
            'default_timezone': domain.default_timezone,
            'case_sharing': json.dumps(domain.case_sharing),

            })
    fields = []
    for field in form.visible_fields():
        value = field.value()
        if value:
            if value == 'false':
                value = False
            if value == 'true':
                value = True
            if isinstance(value, bool):
                value = 'Yes' if value else 'No'
            fields.append({'label': field.label, 'value': value})
    return render_to_response(request, 'domain/snapshot_info.html', {'domain': domain.name,
                                                                     'fields': fields,
                                                                     "languages": request.project.readable_languages(),
                                                                     "applications": request.project.applications()})
예제 #2
0
def project_settings(request, domain, template="domain/admin/project_settings.html"):
    domain = Domain.get_by_name(domain)
    user_sees_meta = request.couch_user.is_previewer()

    if request.method == "POST" and \
       'billing_info_form' not in request.POST and \
       'deployment_info_form' not in request.POST:
        # deal with saving the settings data
        if user_sees_meta:
            form = DomainMetadataForm(request.POST, user=request.couch_user, domain=domain.name)
        else:
            form = DomainGlobalSettingsForm(request.POST)
        if form.is_valid():
            if form.save(request, domain):
                messages.success(request, "Project settings saved!")
            else:
                messages.error(request, "There seems to have been an error saving your settings. Please try again!")
    else:
        if user_sees_meta:
            form = DomainMetadataForm(user=request.couch_user, domain=domain.name, initial={
                'default_timezone': domain.default_timezone,
                'case_sharing': json.dumps(domain.case_sharing),
                'project_type': domain.project_type,
                'customer_type': domain.customer_type,
                'is_test': json.dumps(domain.is_test),
                'commconnect_enabled': domain.commconnect_enabled,
                'survey_management_enabled': domain.survey_management_enabled,
                'sms_case_registration_enabled': domain.sms_case_registration_enabled,
                'sms_case_registration_type': domain.sms_case_registration_type,
                'sms_case_registration_owner_id': domain.sms_case_registration_owner_id,
                'sms_case_registration_user_id': domain.sms_case_registration_user_id,
                'default_sms_backend_id': domain.default_sms_backend_id,
                'commtrack_enabled': domain.commtrack_enabled,
                'call_center_enabled': domain.call_center_config.enabled,
                'call_center_case_owner': domain.call_center_config.case_owner_id,
                'call_center_case_type': domain.call_center_config.case_type,
                'restrict_superusers': domain.restrict_superusers,
            })
        else:
            form = DomainGlobalSettingsForm(initial={
                'default_timezone': domain.default_timezone,
                'case_sharing': json.dumps(domain.case_sharing)
            })

    if request.method == 'POST' and 'deployment_info_form' in request.POST:
        deployment_form = DomainDeploymentForm(request.POST)
        if deployment_form.is_valid():
            if deployment_form.save(domain):
                messages.success(request, "The deployment information for project %s was successfully updated!" % domain.name)
            else:
                messages.error(request, "There seems to have been an error. Please try again!")
    else:
        deployment_form = DomainDeploymentForm(initial={
            'city': domain.deployment.city,
            'country': domain.deployment.country,
            'region': domain.deployment.region,
            'deployment_date': domain.deployment.date.date if domain.deployment.date else "",
            'description': domain.deployment.description,
            'public': 'true' if domain.deployment.public else 'false'
        })

    try:
        from hqbilling.forms import DomainBillingInfoForm
        # really trying to make corehq not dependent on hqbilling here
        if request.method == 'POST' and 'billing_info_form' in request.POST:
            billing_info_form = DomainBillingInfoForm(request.POST)
            if billing_info_form.is_valid():
                billing_info_form.save(domain)
                messages.info(request, "The billing address for project %s was successfully updated!" % domain.name)
        else:
            initial = dict(phone_number=domain.billing_number, currency_code=domain.currency_code)
            initial.update(domain.billing_address._doc)
            billing_info_form = DomainBillingInfoForm(initial=initial)
        billing_info_partial = 'hqbilling/domain/forms/billing_info.html'
        billing_enabled=True
    except ImportError:
        billing_enabled=False
        billing_info_form = None
        billing_info_partial = None

    return render(request, template, dict(
        domain=domain.name,
        form=form,
        deployment_form=deployment_form,
        languages=domain.readable_languages(),
        applications=domain.applications(),
        commtrack_enabled=domain.commtrack_enabled,  # ideally the template gets access to the domain doc through
            # some other means. otherwise it has to be supplied to every view reachable in that sidebar (every
            # view whose template extends users_base.html); mike says he's refactoring all of this imminently, so
            # i will not worry about it until he is done
        call_center_enabled=domain.call_center_config.enabled,
        restrict_superusers=domain.restrict_superusers,
        autocomplete_fields=('project_type', 'phone_model', 'user_type', 'city', 'country', 'region'),
        billing_info_form=billing_info_form,
        billing_info_partial=billing_info_partial,
        billing_enabled=billing_enabled
    ))
예제 #3
0
def project_settings(request,
                     domain,
                     template="domain/admin/project_settings.html"):
    domain = Domain.get_by_name(domain)
    user_sees_meta = request.couch_user.is_previewer()

    if request.method == "POST" and \
       'billing_info_form' not in request.POST and \
       'deployment_info_form' not in request.POST:
        # deal with saving the settings data
        if user_sees_meta:
            form = DomainMetadataForm(request.POST,
                                      user=request.couch_user,
                                      domain=domain.name)
        else:
            form = DomainGlobalSettingsForm(request.POST)
        if form.is_valid():
            if form.save(request, domain):
                messages.success(request, "Project settings saved!")
            else:
                messages.error(
                    request,
                    "There seems to have been an error saving your settings. Please try again!"
                )
    else:
        if user_sees_meta:
            form = DomainMetadataForm(
                user=request.couch_user,
                domain=domain.name,
                initial={
                    'default_timezone': domain.default_timezone,
                    'case_sharing': json.dumps(domain.case_sharing),
                    'project_type': domain.project_type,
                    'customer_type': domain.customer_type,
                    'is_test': json.dumps(domain.is_test),
                    'survey_management_enabled':
                    domain.survey_management_enabled,
                    'sms_case_registration_enabled':
                    domain.sms_case_registration_enabled,
                    'sms_case_registration_type':
                    domain.sms_case_registration_type,
                    'sms_case_registration_owner_id':
                    domain.sms_case_registration_owner_id,
                    'sms_case_registration_user_id':
                    domain.sms_case_registration_user_id,
                    'default_sms_backend_id': domain.default_sms_backend_id,
                    'commtrack_enabled': domain.commtrack_enabled,
                })
        else:
            form = DomainGlobalSettingsForm(
                initial={
                    'default_timezone': domain.default_timezone,
                    'case_sharing': json.dumps(domain.case_sharing)
                })

    if request.method == 'POST' and 'deployment_info_form' in request.POST:
        deployment_form = DomainDeploymentForm(request.POST)
        if deployment_form.is_valid():
            if deployment_form.save(domain):
                messages.success(
                    request,
                    "The deployment information for project %s was successfully updated!"
                    % domain.name)
            else:
                messages.error(
                    request,
                    "There seems to have been an error. Please try again!")
    else:
        deployment_form = DomainDeploymentForm(
            initial={
                'city':
                domain.deployment.city,
                'country':
                domain.deployment.country,
                'region':
                domain.deployment.region,
                'deployment_date':
                domain.deployment.date.date if domain.deployment.date else "",
                'description':
                domain.deployment.description,
                'public':
                'true' if domain.deployment.public else 'false'
            })

    try:
        from hqbilling.forms import DomainBillingInfoForm
        # really trying to make corehq not dependent on hqbilling here
        if request.method == 'POST' and 'billing_info_form' in request.POST:
            billing_info_form = DomainBillingInfoForm(request.POST)
            if billing_info_form.is_valid():
                billing_info_form.save(domain)
                messages.info(
                    request,
                    "The billing address for project %s was successfully updated!"
                    % domain.name)
        else:
            initial = dict(phone_number=domain.billing_number,
                           currency_code=domain.currency_code)
            initial.update(domain.billing_address._doc)
            billing_info_form = DomainBillingInfoForm(initial=initial)
        billing_info_partial = 'hqbilling/domain/forms/billing_info.html'
        billing_enabled = True
    except ImportError:
        billing_enabled = False
        billing_info_form = None
        billing_info_partial = None

    return render(
        request,
        template,
        dict(
            domain=domain.name,
            form=form,
            deployment_form=deployment_form,
            languages=domain.readable_languages(),
            applications=domain.applications(),
            commtrack_enabled=domain.
            commtrack_enabled,  # ideally the template gets access to the domain doc through
            # some other means. otherwise it has to be supplied to every view reachable in that sidebar (every
            # view whose template extends users_base.html); mike says he's refactoring all of this imminently, so
            # i will not worry about it until he is done
            autocomplete_fields=('project_type', 'phone_model', 'user_type',
                                 'city', 'country', 'region'),
            billing_info_form=billing_info_form,
            billing_info_partial=billing_info_partial,
            billing_enabled=billing_enabled))
예제 #4
0
파일: views.py 프로젝트: mchampanis/core-hq
def project_settings(request, domain, template="domain/admin/project_settings.html"):
    class _NeverFailForm(object):
            def is_valid(self):              return True
            def save(self, request, domain): return True
    domain = Domain.get_by_name(domain)
    user_sees_meta = request.couch_user.is_previewer()

    if request.method == "POST" and 'billing_info_form' not in request.POST:
        # deal with saving the settings data
        if user_sees_meta:
            form = DomainMetadataForm(request.POST)
        else:
            form = DomainGlobalSettingsForm(request.POST)
        if form.is_valid():
            if form.save(request, domain):
                messages.success(request, "Project settings saved!")
            else:
                messages.error(request, "There seems to have been an error saving your settings. Please try again!")
    else:
        if user_sees_meta:
            form = DomainMetadataForm(initial={
                'default_timezone': domain.default_timezone,
                'case_sharing': json.dumps(domain.case_sharing),
                'city': domain.city,
                'country': domain.country,
                'region': domain.region,
                'project_type': domain.project_type,
                'customer_type': domain.customer_type,
                'is_test': json.dumps(domain.is_test),
            })
        else:
            form = DomainGlobalSettingsForm(initial={
                'default_timezone': domain.default_timezone,
                'case_sharing': json.dumps(domain.case_sharing)
                })

    try:
        from hqbilling.forms import DomainBillingInfoForm
        # really trying to make corehq not dependent on hqbilling here
        if request.method == 'POST' and 'billing_info_form' in request.POST:
            billing_info_form = DomainBillingInfoForm(request.POST)
            if billing_info_form.is_valid():
                billing_info_form.save(domain)
                messages.info(request, "The billing address for project %s was successfully updated!" % domain.name)
        else:
            initial = dict(phone_number=domain.billing_number, currency_code=domain.currency_code)
            initial.update(domain.billing_address._doc)
            billing_info_form = DomainBillingInfoForm(initial=initial)
        billing_info_partial = 'hqbilling/domain/forms/billing_info.html'
        billing_enabled=True
    except ImportError:
        billing_enabled=False
        billing_info_form = None
        billing_info_partial = None


    return render_to_response(request, template, dict(
        domain=domain.name,
        form=form,
        languages=domain.readable_languages(),
        applications=domain.applications(),
        autocomplete_fields=('project_type', 'phone_model', 'user_type', 'city', 'country', 'region'),
        billing_info_form=billing_info_form,
        billing_info_partial=billing_info_partial,
        billing_enabled=billing_enabled
    ))