def __init__(self, *args, **kwargs): super(CertificateTemplateForm, self).__init__(*args, **kwargs) organizations = get_organizations() org_choices = [(org["id"], org["name"]) for org in organizations] org_choices.insert(0, ('', 'None')) self.fields['organization_id'] = forms.TypedChoiceField( choices=org_choices, required=False, coerce=int, empty_value=None)
def __init__(self, *args, **kwargs): super(CertificateTemplateForm, self).__init__(*args, **kwargs) organizations = get_organizations() org_choices = [(org["id"], org["name"]) for org in organizations] org_choices.insert(0, ('', 'None')) self.fields['organization_id'] = forms.TypedChoiceField( choices=org_choices, required=False, coerce=int, empty_value=None )
def __init__(self, *args, **kwargs): super(MicrositeOrganizationMappingForm, self).__init__(*args, **kwargs) organizations = get_organizations() org_choices = [(org["short_name"], org["name"]) for org in organizations] org_choices.insert(0, ('', 'None')) self.fields['organization'] = forms.TypedChoiceField( choices=org_choices, required=False, empty_value=None )
def __init__(self, *args, **kwargs): super(MicrositeOrganizationMappingForm, self).__init__(*args, **kwargs) organizations = get_organizations() org_choices = [(org["short_name"], org["name"]) for org in organizations] org_choices.insert(0, ('', 'None')) self.fields['organization'] = forms.TypedChoiceField( choices=org_choices, required=False, empty_value=None)
def get(self, request, *args, **kwargs): """Returns organization list as json.""" organizations = get_organizations() # [COLARAZ_CUSTOM] # Restrict user from creating courses with non-authorized organizations org_names_list = filter_authorized_organizations_from_list( organizations, request.user.is_superuser) return HttpResponse( dump_js_escaped_json(org_names_list), content_type='application/json; charset=utf-8')
def __init__(self, *args, **kwargs): super(CertificateTemplateForm, self).__init__(*args, **kwargs) organizations = get_organizations() org_choices = [(org["id"], org["name"]) for org in organizations] org_choices.insert(0, ('', 'None')) self.fields['organization_id'] = forms.TypedChoiceField( choices=org_choices, required=False, coerce=int, empty_value=None) languages = settings.CERTIFICATE_TEMPLATE_LANGUAGES.items() lang_choices = sorted(languages, key=itemgetter(1)) lang_choices.insert(0, (None, 'All Languages')) self.fields['language'] = forms.ChoiceField(choices=lang_choices, required=False)
def __init__(self, *args, **kwargs): super(CertificateTemplateForm, self).__init__(*args, **kwargs) organizations = get_organizations() org_choices = [(org["id"], org["name"]) for org in organizations] org_choices.insert(0, ('', 'None')) self.fields['organization_id'] = forms.TypedChoiceField( choices=org_choices, required=False, coerce=int, empty_value=None ) languages = settings.CERTIFICATE_TEMPLATE_LANGUAGES.items() lang_choices = sorted(languages, key=itemgetter(1)) lang_choices.insert(0, (None, 'All Languages')) self.fields['language'] = forms.ChoiceField( choices=lang_choices, required=False )
class CertificateTemplateForm(forms.ModelForm): """ Django admin form for CertificateTemplate model """ organizations = get_organizations() org_choices = [(org["id"], org["name"]) for org in organizations] org_choices.insert(0, ('', 'None')) organization_id = forms.TypedChoiceField(choices=org_choices, required=False, coerce=int, empty_value=None) class Meta(object): """ Meta definitions for CertificateTemplateForm """ model = CertificateTemplate
def get_enabled_organizations(request): """ Helper method to get linked organizations for request site. Returns: list: List of linked organizations for request site """ if not waffle.switch_is_active(settings.ENABLE_EDLY_ORGANIZATIONS_SWITCH): return get_organizations() try: studio_site_edx_organization = model_to_dict( request.site.edly_sub_org_for_studio.edx_organization) except EdlySubOrganization.DoesNotExist: LOGGER.exception('No EdlySubOrganization found for site %s', request.site) return [] return [studio_site_edx_organization]
def get(self, request, *args, **kwargs): """Returns organization list as json.""" organizations = get_organizations() org_names_list = [(org["short_name"]) for org in organizations] return HttpResponse(escape_json_dumps(org_names_list), content_type='application/json; charset=utf-8')
def test_get_organizations_returns_none_when_app_disabled(self): response = organizations_helpers.get_organizations() self.assertEqual(len(response), 0)
def get_orgs(): # [REDHOUSE CUSTOM] Making the Organization field as a choice field orgs = [(org, org) for org in [org_names['short_name'] for org_names in get_organizations()]] # Adding a blank entry in choices orgs.insert(0, ('', '')) return orgs