예제 #1
0
파일: api.py 프로젝트: ropable/ledger
def group_info(request, apikey):
    ledger_json = {}
    jsondata = {'status': 404, 'message': 'API Key Not Found'}

    if ledgergw_models.API.objects.filter(api_key=apikey, active=1).count():
        if common.api_allow(common.get_client_ip(request), apikey) is True:
            groups = Group.objects.all()
            ledger_json['groups_list'] = []
            ledger_json['groups_id_map'] = {}
            ledger_json['groups_name_map'] = {}
            for g in groups:
                ledger_json['groups_list'].append({
                    'group_id': g.id,
                    'group_name': g.name
                })
                ledger_json['groups_id_map'][g.id] = g.name
                ledger_json['groups_name_map'][g.name] = g.id

            jsondata['groups_list'] = ledger_json['groups_list']
            jsondata['groups_id_map'] = ledger_json['groups_id_map']
            jsondata['groups_name_map'] = ledger_json['groups_name_map']

            jsondata['status'] = 200
            jsondata['message'] = 'Groups Retreived'

        else:
            jsondata['status'] = 403
            jsondata['message'] = 'Access Forbidden'

    return HttpResponse(json.dumps(jsondata), content_type='application/json')
예제 #2
0
파일: api.py 프로젝트: ropable/ledger
def user_info_id(request, userid, apikey):
    jsondata = {'status': 404, 'message': 'API Key Not Found'}
    ledger_user_json = {}
    if ledgergw_models.API.objects.filter(api_key=apikey, active=1).count():
        if common.api_allow(common.get_client_ip(request), apikey) is True:

            ledger_user = models.EmailUser.objects.filter(id=int(userid))
            if ledger_user.count() > 0:
                ledger_obj = ledger_user[0]
                ledger_user_json['ledgerid'] = ledger_obj.id
                ledger_user_json['email'] = ledger_obj.email
                ledger_user_json['first_name'] = ledger_obj.first_name
                ledger_user_json['last_name'] = ledger_obj.last_name
                ledger_user_json['is_staff'] = ledger_obj.is_staff
                ledger_user_json['is_superuser'] = ledger_obj.is_superuser
                ledger_user_json['is_active'] = ledger_obj.is_active
                ledger_user_json[
                    'date_joined'] = ledger_obj.date_joined.strftime(
                        '%d/%m/%Y %H:%M')
                ledger_user_json['title'] = ledger_obj.title
                if ledger_obj.dob:
                    ledger_user_json['dob'] = ledger_obj.dob.strftime(
                        '%d/%m/%Y %H:%M')
                else:
                    ledger_user_json['dob'] = None
                ledger_user_json['phone_number'] = ledger_obj.phone_number
                ledger_user_json['position_title'] = ledger_obj.position_title
                ledger_user_json['mobile_number'] = ledger_obj.mobile_number
                ledger_user_json['fax_number'] = ledger_obj.fax_number
                ledger_user_json['organisation'] = ledger_obj.organisation
                #ledger_user_json['identification'] = ledger_obj.identification
                #ledger_user_json['senior_card'] = ledger_obj.senior_card
                ledger_user_json[
                    'character_flagged'] = ledger_obj.character_flagged
                ledger_user_json[
                    'character_comments'] = ledger_obj.character_comments
                ledger_user_json['extra_data'] = ledger_obj.extra_data
                ledger_user_json['fullname'] = ledger_obj.get_full_name()
                if ledger_obj.dob:
                    ledger_user_json[
                        'fullnamedob'] = ledger_obj.get_full_name_dob()
                else:
                    ledger_user_json['fullnamedob'] = None
                # Groups
                ledger_user_group = []
                for g in ledger_obj.groups.all():
                    ledger_user_group.append({
                        'group_id': g.id,
                        'group_name': g.name
                    })
                ledger_user_json['groups'] = ledger_user_group
                jsondata['user'] = ledger_user_json
                jsondata['status'] = 200
                jsondata['message'] = 'User Found'
            else:
                jsondata['status'] = '404'
                jsondata['message'] = 'User not found'
        else:
            jsondata['status'] = 403
            jsondata['message'] = 'Access Forbidden'
    else:
        pass
    return HttpResponse(json.dumps(jsondata), content_type='application/json')
예제 #3
0
파일: api.py 프로젝트: ropable/ledger
def ip_check(request):
    ledger_json = {}
    ipaddress = common.get_client_ip(request)
    jsondata = {'status': 200, 'ipaddress': str(ipaddress)}
    return HttpResponse(json.dumps(jsondata), content_type='application/json')
예제 #4
0
파일: api.py 프로젝트: ropable/ledger
def user_info_search(request, apikey):
    jsondata = {'status': 404, 'message': 'API Key Not Found'}
    ledger_user_json = {}
    if ledgergw_models.API.objects.filter(api_key=apikey, active=1).count():
        if common.api_allow(common.get_client_ip(request), apikey) is True:
            keyword = request.POST.get('keyword', '')
            jsondata = {'status': 200, 'message': 'No Results'}
            jsondata['users'] = []
            ledger_user_json = {}
            search_filter = Q()
            query_str_split = keyword.split(" ")
            search_filter |= Q(email__icontains=keyword.lower())

            #search_filter |= Q(first_name__icontains=query_str_split[0].lower())
            if len(query_str_split) == 1:
                search_filter |= Q(
                    first_name__icontains=query_str_split[0].lower())
            if len(query_str_split) > 1:
                search_filter |= Q(
                    Q(first_name__icontains=query_str_split[0].lower())
                    & Q(last_name__icontains=query_str_split[1].lower()))
            #for se_wo in query_str_split:
            #
            #     search_filter |= Q(first_name__icontains=se_wo.lower()) | Q(last_name__icontains=se_wo.lower())

            ledger_users = models.EmailUser.objects.filter(search_filter)[:20]
            #,last_name__icontains=keyword)
            for ledger_obj in ledger_users:

                ledger_user_json = {}
                #if keyword.lower() in ledger_obj.first_name.lower()+' '+ledger_obj.last_name.lower() or keyword.lower() in ledger_obj.email.lower():
                ledger_user_json['ledgerid'] = ledger_obj.id
                ledger_user_json['email'] = ledger_obj.email
                ledger_user_json['first_name'] = ledger_obj.first_name
                ledger_user_json['last_name'] = ledger_obj.last_name
                ledger_user_json['is_staff'] = ledger_obj.is_staff
                ledger_user_json['is_superuser'] = ledger_obj.is_superuser
                ledger_user_json['is_active'] = ledger_obj.is_active
                ledger_user_json[
                    'date_joined'] = ledger_obj.date_joined.strftime(
                        '%d/%m/%Y %H:%M')
                ledger_user_json['title'] = ledger_obj.title
                if ledger_obj.dob:
                    ledger_user_json['dob'] = ledger_obj.dob.strftime(
                        '%d/%m/%Y %H:%M')
                else:
                    ledger_user_json['dob'] = None
                ledger_user_json['phone_number'] = ledger_obj.phone_number
                ledger_user_json['position_title'] = ledger_obj.position_title
                ledger_user_json['mobile_number'] = ledger_obj.mobile_number
                ledger_user_json['fax_number'] = ledger_obj.fax_number
                ledger_user_json['organisation'] = ledger_obj.organisation
                #ledger_user_json['identification'] = ledger_obj.identification
                #ledger_user_json['senior_card'] = ledger_obj.senior_card
                ledger_user_json[
                    'character_flagged'] = ledger_obj.character_flagged
                ledger_user_json[
                    'character_comments'] = ledger_obj.character_comments
                ledger_user_json['extra_data'] = ledger_obj.extra_data
                ledger_user_json['fullname'] = ledger_obj.get_full_name()
                if ledger_obj.dob:
                    ledger_user_json[
                        'fullnamedob'] = ledger_obj.get_full_name_dob()
                else:
                    ledger_user_json['fullnamedob'] = None
                # Groups
                #ledger_user_group = []
                #for g in ledger_obj.groups.all():
                #    ledger_user_group.append({'group_id': g.id, 'group_name': g.name})
                #ledger_user_json['groups'] = ledger_user_group

                jsondata['users'].append(ledger_user_json)
                jsondata['status'] = 200
                jsondata['message'] = 'Results'
        else:
            jsondata['status'] = 403
            jsondata['message'] = 'Access Forbidden'
    else:
        pass
    return HttpResponse(json.dumps(jsondata), content_type='application/json')