Exemplo n.º 1
0
def search(request, template_name="invoices/search.html"):
    query = u''
    invoice_type = u''
    start_dt = None
    end_dt = None
    event = None
    event_id = None
    
    has_index = get_setting('site', 'global', 'searchindex')
    form = InvoiceSearchForm(request.GET)
    
    if form.is_valid():
        query = form.cleaned_data.get('q')
        invoice_type = form.cleaned_data.get('invoice_type')
        start_dt = form.cleaned_data.get('start_dt')
        end_dt = form.cleaned_data.get('end_dt')
        event = form.cleaned_data.get('event')
        event_id = form.cleaned_data.get('event_id')
    
    bill_to_email = request.GET.get('bill_to_email', None)

    if has_index and query:
        invoices = Invoice.objects.search(query)
    else:
        invoices = Invoice.objects.all()
        if bill_to_email:
            invoices = invoices.filter(bill_to_email=bill_to_email)
    
    if invoice_type:
        content_type = ContentType.objects.filter(app_label=invoice_type)
        invoices = invoices.filter(object_type__in=content_type)
        if invoice_type == 'events':
            # Set event filters
            event_set = set()
            if event:
                event_set.add(event.pk)
            if event_id:
                event_set.add(event_id)
            if event or event_id:
                invoices = invoices.filter(registration__event__pk__in=event_set)
            
    if start_dt:
        invoices = invoices.filter(create_dt__gte=datetime.combine(start_dt, time.min))
     
    if end_dt:
        invoices = invoices.filter(create_dt__lte=datetime.combine(end_dt, time.max))
    
    if request.user.profile.is_superuser or has_perm(request.user, 'invoices.view_invoice'):
        invoices = invoices.order_by('-create_dt')
    else:
        if request.user.is_authenticated():
            from django.db.models import Q
            invoices = invoices.filter(Q(creator=request.user) | Q(owner=request.user)).order_by('-create_dt')
        else:
            raise Http403
    EventLog.objects.log()
    return render_to_response(template_name, {'invoices': invoices, 'query': query, 'form':form,}, 
        context_instance=RequestContext(request))
Exemplo n.º 2
0
def search(request, template_name="invoices/search.html"):
    start_amount = None
    end_amount = None
    tendered = None
    balance = None
    last_name = None
    start_dt = None
    end_dt = None
    search_criteria = None
    search_text = None
    search_method = None
    invoice_type = u''
    event = None
    event_id = None

    form = InvoiceSearchForm(request.GET)

    if form.is_valid():
        start_dt = form.cleaned_data.get('start_dt')
        end_dt = form.cleaned_data.get('end_dt')
        start_amount = form.cleaned_data.get('start_amount')
        end_amount = form.cleaned_data.get('end_amount')
        tendered = form.cleaned_data.get('tendered')
        balance = form.cleaned_data.get('balance')
        last_name = form.cleaned_data.get('last_name')
        search_criteria = form.cleaned_data.get('search_criteria')
        search_text = form.cleaned_data.get('search_text')
        search_method = form.cleaned_data.get('search_method')
        invoice_type = form.cleaned_data.get('invoice_type')
        event = form.cleaned_data.get('event')
        event_id = form.cleaned_data.get('event_id')

    if tendered:
        if 'void' in tendered:
            invoices = Invoice.objects.void()
        else:
            invoices = Invoice.objects.filter(status_detail=tendered)
    else:
        invoices = Invoice.objects.all()

    if start_dt:
        invoices = invoices.filter(create_dt__gte=datetime.combine(start_dt, time.min))
    if end_dt:
        invoices = invoices.filter(create_dt__lte=datetime.combine(end_dt, time.max))

    if start_amount:
        invoices = invoices.filter(total__gte=start_amount)
    if end_amount:
        invoices = invoices.filter(total__lte=end_amount)

    if balance == '0':
        invoices = invoices.filter(balance=0)
    elif balance == '1':
        invoices = invoices.filter(balance__gt=0)

    if last_name:
        invoices = invoices.filter(bill_to_last_name__iexact=last_name)

    owner = None
    if search_criteria and search_text:
        if search_criteria == 'owner_id':
            search_criteria = 'owner__id'
            try:
                search_text = int(search_text)
                [owner] = User.objects.filter(id=search_text)[:1] or [None]
            except:
                search_text = 0

        if search_method == 'starts_with':
            if isinstance(search_text, str):
                search_type = '__istartswith'
            else:
                search_type = '__startswith'
        elif search_method == 'contains':
            if isinstance(search_text, str):
                search_type = '__icontains'
            else:
                search_type = '__contains'
        else:
            if isinstance(search_text, str):
                search_type = '__iexact'
            else:
                search_type = '__exact'

        if all([search_criteria == 'owner__id',
                search_method == 'exact',
                owner]):
            invoices = invoices.filter(Q(bill_to_email__iexact=owner.email)
                               | Q(owner_id=owner.id))
        else:
            search_filter = {'%s%s' % (search_criteria,
                                       search_type): search_text}
            invoices = invoices.filter(**search_filter)

    if invoice_type:
        content_type = ContentType.objects.filter(app_label=invoice_type)
        invoices = invoices.filter(object_type__in=content_type)
        if invoice_type == 'events':
            # Set event filters
            event_set = set()
            if event:
                event_set.add(event.pk)
            if event_id:
                event_set.add(event_id)
            if event or event_id:
                invoices = invoices.filter(registration__event__pk__in=event_set)

    if request.user.profile.is_superuser or has_perm(request.user, 'invoices.view_invoice'):
        invoices = invoices.order_by('-create_dt')
    else:
        invoices = invoices.filter(Q(creator=request.user) |
                                   Q(owner=request.user) |
                                   Q(bill_to_email__iexact=request.user.email)
                                   ).order_by('-create_dt')
    EventLog.objects.log()
    return render_to_resp(request=request, template_name=template_name,
        context={'invoices': invoices, 'form':form,})
Exemplo n.º 3
0
def search(request, template_name="invoices/search.html"):
    start_amount = None
    end_amount = None
    tendered = None
    balance = None
    last_name = None
    start_dt = None
    end_dt = None
    search_criteria = None
    search_text = None
    search_method = None
    invoice_type = u''
    event = None
    event_id = None

    form = InvoiceSearchForm(request.GET)

    if form.is_valid():
        start_dt = form.cleaned_data.get('start_dt')
        end_dt = form.cleaned_data.get('end_dt')
        start_amount = form.cleaned_data.get('start_amount')
        end_amount = form.cleaned_data.get('end_amount')
        tendered = form.cleaned_data.get('tendered')
        balance = form.cleaned_data.get('balance')
        last_name = form.cleaned_data.get('last_name')
        search_criteria = form.cleaned_data.get('search_criteria')
        search_text = form.cleaned_data.get('search_text')
        search_method = form.cleaned_data.get('search_method')
        invoice_type = form.cleaned_data.get('invoice_type')
        event = form.cleaned_data.get('event')
        event_id = form.cleaned_data.get('event_id')

    if tendered:
        if 'void' in tendered:
            invoices = Invoice.objects.void()
        else:
            invoices = Invoice.objects.filter(status_detail=tendered)
    else:
        invoices = Invoice.objects.all()

    if start_dt:
        invoices = invoices.filter(create_dt__gte=datetime.combine(start_dt, time.min))
    if end_dt:
        invoices = invoices.filter(create_dt__lte=datetime.combine(end_dt, time.max))

    if start_amount:
        invoices = invoices.filter(total__gte=start_amount)
    if end_amount:
        invoices = invoices.filter(total__lte=end_amount)

    if balance == '0':
        invoices = invoices.filter(balance=0)
    elif balance == '1':
        invoices = invoices.filter(balance__gt=0)

    if last_name:
        invoices = invoices.filter(bill_to_last_name__iexact=last_name)

    owner = None
    if search_criteria and search_text:
        if search_criteria == 'owner_id':
            search_criteria = 'owner__id'
            try:
                search_text = int(search_text)
                [owner] = User.objects.filter(id=search_text)[:1] or [None]
            except:
                search_text = 0

        if search_method == 'starts_with':
            if isinstance(search_text, basestring):
                search_type = '__istartswith'
            else:
                search_type = '__startswith'
        elif search_method == 'contains':
            if isinstance(search_text, basestring):
                search_type = '__icontains'
            else:
                search_type = '__contains'
        else:
            if isinstance(search_text, basestring):
                search_type = '__iexact'
            else:
                search_type = '__exact'

        if all([search_criteria == 'owner__id',
                search_method == 'exact',
                owner]):
            invoices = invoices.filter(Q(bill_to_email__iexact=owner.email)
                               | Q(owner_id=owner.id))
        else:
            search_filter = {'%s%s' % (search_criteria,
                                       search_type): search_text}
            invoices = invoices.filter(**search_filter)

    if invoice_type:
        content_type = ContentType.objects.filter(app_label=invoice_type)
        invoices = invoices.filter(object_type__in=content_type)
        if invoice_type == 'events':
            # Set event filters
            event_set = set()
            if event:
                event_set.add(event.pk)
            if event_id:
                event_set.add(event_id)
            if event or event_id:
                invoices = invoices.filter(registration__event__pk__in=event_set)

    if request.user.profile.is_superuser or has_perm(request.user, 'invoices.view_invoice'):
        invoices = invoices.order_by('-create_dt')
    else:
        invoices = invoices.filter(Q(creator=request.user) |
                                   Q(owner=request.user) |
                                   Q(bill_to_email__iexact=request.user.email)
                                   ).order_by('-create_dt')
    EventLog.objects.log()
    return render_to_response(template_name, {'invoices': invoices, 'form':form,},
        context_instance=RequestContext(request))
Exemplo n.º 4
0
def search(request, template_name="invoices/search.html"):
    start_amount = None
    end_amount = None
    tendered = None
    balance = None
    last_name = None
    start_dt = None
    end_dt = None
    search_criteria = None
    search_text = None
    search_method = None
    invoice_type = u''
    event = None
    event_id = None
    object_type_id = None

    form = InvoiceSearchForm(request.GET)
    if form.is_valid():
        start_dt = form.cleaned_data.get('start_dt')
        end_dt = form.cleaned_data.get('end_dt')
        start_amount = form.cleaned_data.get('start_amount')
        end_amount = form.cleaned_data.get('end_amount')
        tendered = form.cleaned_data.get('tendered')
        balance = form.cleaned_data.get('balance')
        last_name = form.cleaned_data.get('last_name')
        search_criteria = form.cleaned_data.get('search_criteria')
        search_text = form.cleaned_data.get('search_text')
        search_method = form.cleaned_data.get('search_method')
        invoice_type = form.cleaned_data.get('invoice_type')
        event = form.cleaned_data.get('event')
        event_id = form.cleaned_data.get('event_id')
        object_type_id = form.cleaned_data.get('object_type_id')

    if tendered:
        if 'void' in tendered:
            invoices = Invoice.objects.void()
        else:
            invoices = Invoice.objects.filter(status_detail=tendered)
    else:
        invoices = Invoice.objects.all()

    if start_dt:
        invoices = invoices.filter(
            create_dt__gte=datetime.combine(start_dt, time.min))
    if end_dt:
        invoices = invoices.filter(
            create_dt__lte=datetime.combine(end_dt, time.max))

    if start_amount:
        invoices = invoices.filter(total__gte=start_amount)
    if end_amount:
        invoices = invoices.filter(total__lte=end_amount)

    if balance == '0':
        invoices = invoices.filter(balance=0)
    elif balance == '1':
        invoices = invoices.filter(balance__gt=0)

    if last_name:
        invoices = invoices.filter(bill_to_last_name__iexact=last_name)

    owner = None
    if search_criteria and search_text:
        if search_criteria == 'owner_id':
            search_criteria = 'owner__id'
            try:
                search_text = int(search_text)
                [owner] = User.objects.filter(id=search_text)[:1] or [None]
            except:
                search_text = 0

        if search_method == 'starts_with':
            if isinstance(search_text, str):
                search_type = '__istartswith'
            else:
                search_type = '__startswith'
        elif search_method == 'contains':
            if isinstance(search_text, str):
                search_type = '__icontains'
            else:
                search_type = '__contains'
        else:
            if isinstance(search_text, str):
                search_type = '__iexact'
            else:
                search_type = '__exact'

        if all(
            [search_criteria == 'owner__id', search_method == 'exact', owner]):
            invoices = invoices.filter(
                Q(bill_to_email__iexact=owner.email)
                | Q(owner_id=owner.id))
        else:
            search_filter = {
                '%s%s' % (search_criteria, search_type): search_text
            }
            invoices = invoices.filter(**search_filter)

    if invoice_type:
        if invoice_type == 'unknown':
            invoices = invoices.filter(object_type=None)
        else:
            content_type = ContentType.objects.filter(app_label=invoice_type)
            invoices = invoices.filter(object_type__in=content_type)
        if invoice_type == 'events':
            # Set event filters
            event_set = set()
            if event:
                event_set.add(event.pk)
            if event_id:
                event_set.add(event_id)
            if event or event_id:
                invoices = invoices.filter(
                    registration__event__pk__in=event_set)
    if object_type_id:
        [content_type
         ] = ContentType.objects.filter(id=object_type_id)[:1] or [None]
        if content_type:
            invoices = invoices.filter(object_type=content_type)

    # exclude FREE membership and corp membership invoices, if specified in the setting.
    if get_setting("module", "invoices", "hidefreememinvoices"):
        invoices = invoices.exclude(
            total=0,
            object_type__in=ContentType.objects.filter(
                app_label__in=['corporate_memberships', 'memberships']))

    if request.user.profile.is_superuser or has_perm(request.user,
                                                     'invoices.view_invoice'):
        invoices = invoices.order_by('-create_dt')
    else:
        invoices = invoices.filter(
            Q(creator=request.user) | Q(owner=request.user)
            | Q(bill_to_email__iexact=request.user.email)).order_by(
                '-create_dt')

    if 'export' in request.GET:
        EventLog.objects.log(
            description="invoices export from invoices search")

        response = StreamingHttpResponse(
            streaming_content=(iter_invoices(invoices)),
            content_type='text/csv',
        )
        response[
            'Content-Disposition'] = f'attachment;filename=invoices_export_{ttime.time()}.csv'
        return response

    EventLog.objects.log()

    return render_to_resp(request=request,
                          template_name=template_name,
                          context={
                              'invoices': invoices,
                              'form': form,
                          })
Exemplo n.º 5
0
def search(request, template_name="invoices/search.html"):
    start_amount = None
    end_amount = None
    tendered = None
    balance = None
    last_name = None
    start_dt = None
    end_dt = None
    search_criteria = None
    search_text = None
    search_method = None
    invoice_type = ""
    event = None
    event_id = None

    form = InvoiceSearchForm(request.GET)

    if form.is_valid():
        start_dt = form.cleaned_data.get("start_dt")
        end_dt = form.cleaned_data.get("end_dt")
        start_amount = form.cleaned_data.get("start_amount")
        end_amount = form.cleaned_data.get("end_amount")
        tendered = form.cleaned_data.get("tendered")
        balance = form.cleaned_data.get("balance")
        last_name = form.cleaned_data.get("last_name")
        search_criteria = form.cleaned_data.get("search_criteria")
        search_text = form.cleaned_data.get("search_text")
        search_method = form.cleaned_data.get("search_method")
        invoice_type = form.cleaned_data.get("invoice_type")
        event = form.cleaned_data.get("event")
        event_id = form.cleaned_data.get("event_id")

    if tendered:
        if "void" in tendered:
            invoices = Invoice.objects.void()
        else:
            invoices = Invoice.objects.filter(status_detail=tendered)
    else:
        invoices = Invoice.objects.all()

    if start_dt:
        invoices = invoices.filter(create_dt__gte=datetime.combine(start_dt, time.min))
    if end_dt:
        invoices = invoices.filter(create_dt__lte=datetime.combine(end_dt, time.max))

    if start_amount:
        invoices = invoices.filter(total__gte=start_amount)
    if end_amount:
        invoices = invoices.filter(total__lte=end_amount)

    if balance == "0":
        invoices = invoices.filter(balance=0)
    elif balance == "1":
        invoices = invoices.filter(balance__gt=0)

    if last_name:
        invoices = invoices.filter(bill_to_last_name__iexact=last_name)

    owner = None
    if search_criteria and search_text:
        if search_criteria == "owner_id":
            search_criteria = "owner__id"
            try:
                search_text = int(search_text)
                [owner] = User.objects.filter(id=search_text)[:1] or [None]
            except:
                search_text = 0

        if search_method == "starts_with":
            if isinstance(search_text, basestring):
                search_type = "__istartswith"
            else:
                search_type = "__startswith"
        elif search_method == "contains":
            if isinstance(search_text, basestring):
                search_type = "__icontains"
            else:
                search_type = "__contains"
        else:
            if isinstance(search_text, basestring):
                search_type = "__iexact"
            else:
                search_type = "__exact"

        if all([search_criteria == "owner__id", search_method == "exact", owner]):
            invoices = invoices.filter(Q(bill_to_email__iexact=owner.email) | Q(owner_id=owner.id))
        else:
            search_filter = {"%s%s" % (search_criteria, search_type): search_text}
            invoices = invoices.filter(**search_filter)

    if invoice_type:
        content_type = ContentType.objects.filter(app_label=invoice_type)
        invoices = invoices.filter(object_type__in=content_type)
        if invoice_type == "events":
            # Set event filters
            event_set = set()
            if event:
                event_set.add(event.pk)
            if event_id:
                event_set.add(event_id)
            if event or event_id:
                invoices = invoices.filter(registration__event__pk__in=event_set)

    if request.user.profile.is_superuser or has_perm(request.user, "invoices.view_invoice"):
        invoices = invoices.order_by("-create_dt")
    else:
        invoices = invoices.filter(
            Q(creator=request.user) | Q(owner=request.user) | Q(bill_to_email__iexact=request.user.email)
        ).order_by("-create_dt")
    EventLog.objects.log()
    return render_to_response(
        template_name, {"invoices": invoices, "form": form}, context_instance=RequestContext(request)
    )
Exemplo n.º 6
0
def search(request, template_name="invoices/search.html"):
    query = u''
    invoice_type = u''
    start_dt = None
    end_dt = None
    event = None
    event_id = None

    has_index = get_setting('site', 'global', 'searchindex')
    form = InvoiceSearchForm(request.GET)

    if form.is_valid():
        query = form.cleaned_data.get('q')
        invoice_type = form.cleaned_data.get('invoice_type')
        start_dt = form.cleaned_data.get('start_dt')
        end_dt = form.cleaned_data.get('end_dt')
        event = form.cleaned_data.get('event')
        event_id = form.cleaned_data.get('event_id')

    bill_to_email = request.GET.get('bill_to_email', None)

    if has_index and query:
        invoices = Invoice.objects.search(query)
    else:
        invoices = Invoice.objects.all()
        if bill_to_email:
            invoices = invoices.filter(bill_to_email=bill_to_email)

    if invoice_type:
        content_type = ContentType.objects.filter(app_label=invoice_type)
        invoices = invoices.filter(object_type__in=content_type)
        if invoice_type == 'events':
            # Set event filters
            event_set = set()
            if event:
                event_set.add(event.pk)
            if event_id:
                event_set.add(event_id)
            if event or event_id:
                invoices = invoices.filter(
                    registration__event__pk__in=event_set)

    if start_dt:
        invoices = invoices.filter(
            create_dt__gte=datetime.combine(start_dt, time.min))

    if end_dt:
        invoices = invoices.filter(
            create_dt__lte=datetime.combine(end_dt, time.max))

    if request.user.profile.is_superuser or has_perm(request.user,
                                                     'invoices.view_invoice'):
        invoices = invoices.order_by('-create_dt')
    else:
        if request.user.is_authenticated():
            from django.db.models import Q
            invoices = invoices.filter(
                Q(creator=request.user)
                | Q(owner=request.user)).order_by('-create_dt')
        else:
            raise Http403
    EventLog.objects.log()
    return render_to_response(template_name, {
        'invoices': invoices,
        'query': query,
        'form': form,
    },
                              context_instance=RequestContext(request))