<commit_before>from django.db.models import Q
from django.contrib.auth.decorators import login_required
from django.conf.urls.defaults import *
from django.shortcuts import redirect
import django.views.generic.list_detail

from membership.models import *
from membership.forms import *

urlpatterns = patterns('',
    (r'jsi18n/$', 'django.views.i18n.javascript_catalog', {'packages': ('membership')}),
    
    url(r'persons/application/$', 'membership.views.person_application', name='person_application'),
    url(r'organizations/new/$', 'membership.views.organization_application',
        name='organization_application'),
    url(r'organizations/new/add_contact/(\w+)/$', 'membership.views.organization_application_add_contact',
        name='organization_application_add_contact'),
    url(r'organizations/new/application/review/$', 'membership.views.organization_application_review',
        name='organization_application_review'),
    url(r'organizations/new/application/save/$', 'membership.views.organization_application_save',
        name='organization_application_save'),
    url(r'memberships/application/$', 'membership.views.new_application', name='new_application'),

    url(r'testemail/$', 'membership.views.test_email', name='test_email'),

    url(r'contacts/edit/(\d+)/$', 'membership.views.contact_edit', name='contact_edit'),

    url(r'memberships/edit_inline/(\d+)/$', 'membership.views.membership_edit_inline', name='membership_edit_inline'),
    url(r'memberships/edit/(\d+)/$', 'membership.views.membership_edit', name='membership_edit'),

    url(r'memberships/delete/(\d+)/$', 'membership.views.membership_delete', name='membership_delete'),

    # url(r'memberships/new/handle_json/$', 'membership.views.handle_json', name='membership_pre-approval_handle_json'),
    url(r'memberships/.*/handle_json/$', 'membership.views.handle_json', name='memberships_handle_json'),
    url(r'memberships/handle_json/$', 'membership.views.handle_json', name='membership_handle_json'),
    url(r'handle_json/$', 'membership.views.handle_json', name='membership_handle_json'),

    url(r'static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '../membership/static/'}),
)

# FIXME: should require admin priviledge, too.
@login_required
def limited_object_list(*args, **kwargs):
    return django.views.generic.list_detail.object_list(*args, **kwargs)

@login_required
def search(request, query=None,
           template_name='membership/membership_list.html'):
    if not query:
        query = request.REQUEST.get("query", None)

    if query.startswith("#"):
        return redirect('membership_edit', query.lstrip("#"))

    person_contacts = Contact.objects
    org_contacts = Contact.objects
    for word in query.split(" "):
        # Common search parameters
        email_q = Q(email__icontains=word)
        phone_q = Q(phone__icontains=word)
        sms_q = Q(sms__icontains=word)
        common_q = email_q | phone_q | sms_q

        # Search query for people
        f_q = Q(first_name__icontains=word)<commit_msg>Duplicate removal for search terms<commit_after>from django.db.models import Q
from django.contrib.auth.decorators import login_required
from django.conf.urls.defaults import *
from django.shortcuts import redirect
import django.views.generic.list_detail

from membership.models import *
from membership.forms import *

urlpatterns = patterns('',
    (r'jsi18n/$', 'django.views.i18n.javascript_catalog', {'packages': ('membership')}),
    
    url(r'persons/application/$', 'membership.views.person_application', name='person_application'),
    url(r'organizations/new/$', 'membership.views.organization_application',
        name='organization_application'),
    url(r'organizations/new/add_contact/(\w+)/$', 'membership.views.organization_application_add_contact',
        name='organization_application_add_contact'),
    url(r'organizations/new/application/review/$', 'membership.views.organization_application_review',
        name='organization_application_review'),
    url(r'organizations/new/application/save/$', 'membership.views.organization_application_save',
        name='organization_application_save'),
    url(r'memberships/application/$', 'membership.views.new_application', name='new_application'),

    url(r'testemail/$', 'membership.views.test_email', name='test_email'),

    url(r'contacts/edit/(\d+)/$', 'membership.views.contact_edit', name='contact_edit'),

    url(r'memberships/edit_inline/(\d+)/$', 'membership.views.membership_edit_inline', name='membership_edit_inline'),
    url(r'memberships/edit/(\d+)/$', 'membership.views.membership_edit', name='membership_edit'),

    url(r'memberships/delete/(\d+)/$', 'membership.views.membership_delete', name='membership_delete'),

    # url(r'memberships/new/handle_json/$', 'membership.views.handle_json', name='membership_pre-approval_handle_json'),
    url(r'memberships/.*/handle_json/$', 'membership.views.handle_json', name='memberships_handle_json'),
    url(r'memberships/handle_json/$', 'membership.views.handle_json', name='membership_handle_json'),
    url(r'handle_json/$', 'membership.views.handle_json', name='membership_handle_json'),

    url(r'static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '../membership/static/'}),
)

# FIXME: should require admin priviledge, too.
@login_required
def limited_object_list(*args, **kwargs):
    return django.views.generic.list_detail.object_list(*args, **kwargs)

@login_required
def search(request, query=None,
           template_name='membership/membership_list.html'):
    if not query:
        query = request.REQUEST.get("query", None)

    if query.startswith("#"):
        return redirect('membership_edit', query.lstrip("#"))

    person_contacts = Contact.objects
    org_contacts = Contact.objects
    # Split into words and remove duplicates
    d = {}.fromkeys(query.split(" "))
    for word in d.keys():
        # Common search parameters
        email_q = Q(email__icontains=word)
        phone_q = Q(phone__icontains=word)
        sms_q = Q(sms__icontains=word)
        common_q = email_q | phone_q | sms_q

        # Search query for people
        f_q = Q(first_name__icontains=word)
{'fraction_non_alphanumeric': 0.1506276150627615, 'fraction_numerical': 0.001287415513356936, 'mean_word_length': 5.099116781157998, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1311008', 'n_tokens_mistral': 1959, 'n_tokens_neox': 1924, 'n_words': 279}