def __init__(self, username, *args, **kwargs): super(AddObjectForm, self).__init__(*args, **kwargs) self.fields['object_type'].choices = [ (c, c) for c in ObjectTypes.values(sort=True) ] self.fields['object_type'].widget.attrs = {'class': 'object-types'} self.fields['source'].choices = [ (c.name, c.name) for c in get_source_names(True, True, username) ] self.fields['source'].initial = get_user_organization(username)
def __init__(self, username, *args, **kwargs): super(AddObjectForm, self).__init__(*args, **kwargs) self.fields['object_type'].choices = [ (c,c) for c in ObjectTypes.values(sort=True) ] self.fields['object_type'].widget.attrs = {'class':'object-types'} self.fields['source'].choices = [(c.name, c.name) for c in get_source_names(True, True, username)] self.fields['source'].initial = get_user_organization(username)
def get_object_type_dropdown(request): """ Get the list of object types for UI dropdowns. Should be an AJAX POST. :param request: The Django request. :type request: :class:`django.http.HttpRequest` :returns: :class:`django.http.HttpResponse` """ if request.method == 'POST' and request.is_ajax(): dd_types = ObjectTypes.values(sort=True) dd_final = {} for obj_type in dd_types: dd_final[obj_type] = obj_type result = {'types': dd_final} return HttpResponse(json.dumps(result), content_type="application/json") else: error = "Expected AJAX POST" return render_to_response("error.html", {"error": error}, RequestContext(request))
def get_object_type_dropdown(request): """ Get the list of object types for UI dropdowns. Should be an AJAX POST. :param request: The Django request. :type request: :class:`django.http.HttpRequest` :returns: :class:`django.http.HttpResponse` """ if request.method == 'POST' and request.is_ajax(): dd_types = ObjectTypes.values(sort=True) dd_final = {} for obj_type in dd_types: dd_final[obj_type] = obj_type result = {'types': dd_final} return HttpResponse(json.dumps(result), content_type="application/json") else: error = "Expected AJAX POST" return render_to_response("error.html", {"error" : error }, RequestContext(request))