Пример #1
0
def cyno_alts_data(request):
    try:
        params = extract_datatable_params(request)
        corp_id = request.GET.get('corp')
    except KeyError:
        return HttpResponseBadRequest()

    if corp_id:
        try:
            query = Corporation.objects.get(
                corporationID=int(corp_id)).members.filter(is_cyno_alt=True)
        except Corporation.DoesNotExist:
            query = Corporation.objects.mine().members.filter(is_cyno_alt=True)
        except ValueError:
            # corp_id cannot be casted to int, we take all corps
            query = Member.objects.exclude(corp=None).filter(is_cyno_alt=True)
    else:
        query = Corporation.objects.mine().members.all()

    total_members,\
    filtered_members,\
    members = get_members(query=query,
                          first_id=params.first_id,
                          last_id=params.last_id,
                          search_str=params.search,
                          sort_by=params.column,
                          asc=params.asc,
                          for_csv=params.format == 'csv')

    if params.format == 'csv':
        return datatable_csv_data(members, filename='members.csv')
    else:
        return datatable_ajax_data(members, params.sEcho, total_members,
                                   filtered_members)
Пример #2
0
def cyno_alts_data(request):
    try:
        params = extract_datatable_params(request)
        corp_id = request.GET.get("corp")
    except KeyError:
        return HttpResponseBadRequest()

    if corp_id:
        try:
            query = Corporation.objects.get(corporationID=int(corp_id)).members.filter(is_cyno_alt=True)
        except Corporation.DoesNotExist:
            query = Corporation.objects.mine().members.filter(is_cyno_alt=True)
        except ValueError:
            # corp_id cannot be casted to int, we take all corps
            query = Member.objects.exclude(corp=None).filter(is_cyno_alt=True)
    else:
        query = Corporation.objects.mine().members.all()

    total_members, filtered_members, members = get_members(
        query=query,
        first_id=params.first_id,
        last_id=params.last_id,
        search_str=params.search,
        sort_by=params.column,
        asc=params.asc,
        for_csv=params.format == "csv",
    )

    if params.format == "csv":
        return datatable_csv_data(members, filename="members.csv")
    else:
        return datatable_ajax_data(members, params.sEcho, total_members, filtered_members)
Пример #3
0
def members_data(request):
    try:
        params = extract_datatable_params(request)
        ships = request.GET.get('show_ships', 'all')
        corp_id = request.GET.get('corp')
    except KeyError:
        return HttpResponseBadRequest()
    
    if corp_id:
        try:
            query = Corporation.objects.get(corporationID=int(corp_id)).members.all()
        except Corporation.DoesNotExist:
            query = Corporation.objects.mine().members.all()
        except ValueError:
            # corp_id cannot be casted to int, we take all corps
            query = Member.objects.exclude(corp=None)
    else:
        query = Corporation.objects.mine().members.all()
    
    if ships == 'supers':
        query = query.filter(ship__in=SUPER_CAPITALS)
    
    total_members,\
    filtered_members,\
    members = get_members(query=query,
                          first_id=params.first_id,
                          last_id=params.last_id,
                          search_str=params.search,
                          sort_by=params.column,
                          asc=params.asc,
                          for_csv=params.format == 'csv')
    
    if params.format == 'csv':
        return datatable_csv_data(members, filename='members.csv')
    else:
        return datatable_ajax_data(members, params.sEcho, total_members, filtered_members)
Пример #4
0
def mail_list_data(request):
    
    try:
        params = extract_datatable_params(request)
        REQ = request.GET if request.method == 'GET' else request.POST
    except:
        return HttpResponseBadRequest()
    total_count = Mail.objects.all().count()

    recfilter = False
    #These are mutually exclusive
    if REQ.get('ally') != '0':
        recipients = Recipient.objects.filter(object_id=REQ.get('ally'))
        recfilter = True
    elif REQ.get('corp') != '0':
        recipients = Recipient.objects.filter(object_id=REQ.get('corp'))
        recfilter = True
    elif REQ.get('maillist') != '0':
        recipients = Recipient.objects.filter(object_id=REQ.get('maillist'))
        recfilter = True
    elif REQ.get('to'):
        recipients = []
        mem = Member.objects.filter(name__contains=REQ.get('to'))
        recipients += Recipient.objects.filter(object_id__in=mem)
        cor = Corporation.objects.filter(corporationName__contains=REQ.get('to'))
        recipients += Recipient.objects.filter(object_id__in=cor)
        all = Alliance.objects.filter(name__contains=REQ.get('to'))
        recipients += Recipient.objects.filter(object_id__in=all)
        recfilter = True
    else:
        recipients = []

    if recfilter == True:
        mail = Mail.objects.filter(recipients__in=recipients).distinct().order_by(COLUMNS[params.column]['db_field'])
    else:
        mail = Mail.objects.all().order_by(COLUMNS[params.column]['db_field'])

    if REQ.get('from'):
        mail = mail.filter(sender__name__contains=REQ.get('from'))

    if not params.asc:
        mail = mail.reverse()

    mail_list = []
    if params.format == 'csv':
        for message in mail[params.first_id:params.last_id]:
            recp = []
            for target in message.recipients.all():
                recp.append(str(target))
            if len(recp) > 1:
                recipients = ', '.join(recp)
            else:
                recipients = recp[0]
            mail_list.append([print_time_min(message.sentDate),
                              message.sender.name,
                              recipients,
                              message.title,
                              message.body])
        return datatable_csv_data(mail_list, filename='mails.csv')
    else:
        for message in mail[params.first_id:params.last_id]:
            recp = []
            for target in message.recipients.all():
                recp.append(str(target))
            if len(recp) > 1:
                recipients = ', '.join(recp)
            else:
                recipients = recp[0]
            mail_list.append([print_time_min(message.sentDate),
                              message.sender.name,
                              recipients,
                              message.modal_link,
                              message.messageID])
        return datatable_ajax_data(mail_list, params.sEcho, total_count, len(mail))
Пример #5
0
def mail_list_data(request):

    try:
        params = extract_datatable_params(request)
        REQ = request.GET if request.method == 'GET' else request.POST
    except:
        return HttpResponseBadRequest()
    total_count = Mail.objects.all().count()

    recfilter = False
    #These are mutually exclusive
    if REQ.get('ally') != '0':
        recipients = Recipient.objects.filter(object_id=REQ.get('ally'))
        recfilter = True
    elif REQ.get('corp') != '0':
        recipients = Recipient.objects.filter(object_id=REQ.get('corp'))
        recfilter = True
    elif REQ.get('maillist') != '0':
        recipients = Recipient.objects.filter(object_id=REQ.get('maillist'))
        recfilter = True
    elif REQ.get('to'):
        recipients = []
        mem = Member.objects.filter(name__contains=REQ.get('to'))
        recipients += Recipient.objects.filter(object_id__in=mem)
        cor = Corporation.objects.filter(
            corporationName__contains=REQ.get('to'))
        recipients += Recipient.objects.filter(object_id__in=cor)
        all = Alliance.objects.filter(name__contains=REQ.get('to'))
        recipients += Recipient.objects.filter(object_id__in=all)
        recfilter = True
    else:
        recipients = []

    if recfilter == True:
        mail = Mail.objects.filter(
            recipients__in=recipients).distinct().order_by(
                COLUMNS[params.column]['db_field'])
    else:
        mail = Mail.objects.all().order_by(COLUMNS[params.column]['db_field'])

    if REQ.get('from'):
        mail = mail.filter(sender__name__contains=REQ.get('from'))

    if not params.asc:
        mail = mail.reverse()

    mail_list = []
    if params.format == 'csv':
        for message in mail[params.first_id:params.last_id]:
            recp = []
            for target in message.recipients.all():
                recp.append(str(target))
            if len(recp) > 1:
                recipients = ', '.join(recp)
            else:
                recipients = recp[0]
            mail_list.append([
                print_time_min(message.sentDate), message.sender.name,
                recipients, message.title, message.body
            ])
        return datatable_csv_data(mail_list, filename='mails.csv')
    else:
        for message in mail[params.first_id:params.last_id]:
            recp = []
            for target in message.recipients.all():
                recp.append(str(target))
            if len(recp) > 1:
                recipients = ', '.join(recp)
            else:
                recipients = recp[0]
            mail_list.append([
                print_time_min(message.sentDate), message.sender.name,
                recipients, message.modal_link, message.messageID
            ])
        return datatable_ajax_data(mail_list, params.sEcho, total_count,
                                   len(mail))