예제 #1
0
def getting_started_page(request):
    data = {}
    data['current_nav'] = ''
    
    message_data = get_system_message(request) #get the message List
    data =  dict(data.items() + message_data.items())   #merge message list to data
    
    requestProcessor = HttpRequestProcessor(request)
    return requestProcessor.render_to_response(request,'website/info/getting_started_page.html', data, '')
예제 #2
0
def getting_started_page(request):
    data = {}
    data['current_nav'] = ''
    
    message_data = get_system_message(request) #get the message List
    data =  dict(data.items() + message_data.items())   #merge message list to data
    
    requestProcessor = HttpRequestProcessor(request)
    return requestProcessor.render_to_response(request,'website/info/getting_started_page.html', data, '')
예제 #3
0
def news(request):
    data = {}
    data['current_nav'] = 'news'
    data['pressreleases'] = PressRelease.objects.all().order_by('published')
    data['articles'] = Article.objects.all().order_by('published')
    data['events'] = Event.objects.all().filter(expiration__gte=datetime.now()).order_by('published')

    message_data = get_system_message(request) #get the message List
    data =  dict(data.items() + message_data.items())   #merge message list to data

    requestProcessor = HttpRequestProcessor(request)
    return requestProcessor.render_to_response(request,'website/info/news.html', data, '')
예제 #4
0
def home(request):
    user = request.user
    requestProcessor = HttpRequestProcessor(request)
    data = {}
    data['accept_tou'] = ''
    data['home'] = 'True'
    dajax = Dajax()

    ajax = requestProcessor.getParameter('ajax')
    if (ajax != None):

        #default response for all ajax
        return HttpResponse(dajax.json())

    data['login'] = '******'

    if user.is_authenticated():
        data['login'] = '******'
    elif user.is_active == False:
        data['login_status'] = 'account_locked'

    message_data = get_system_message(request)  #get the message List
    data = dict(data.items() +
                message_data.items())  #merge message list to data

    data['recently_updated_jurs'] = JurisdictionRating.recently_updated()

    data['popular_jurs'] = JurisdictionRating.most_popular()

    invitation_key = requestProcessor.getParameter('invitation_key')
    if invitation_key != '' and invitation_key != None:
        data['action_key'] = 'create_account'
        data['invitation_key'] = invitation_key
        if user.is_authenticated():
            logout(request)

        return requestProcessor.render_to_response(request,
                                                   'website/home.html', data,
                                                   '')

    action = requestProcessor.getParameter('action')
    if action != '' and action != None:
        data['action_key'] = action
    next_url = requestProcessor.getParameter('next')
    data['caller'] = 'sign_in_home'
    data['current_nav'] = 'home'

    if user.is_authenticated() and (next_url != None and next_url != ''):
        return redirect(next_url)
    else:
        return requestProcessor.render_to_response(request,
                                                   'website/home.html', data,
                                                   '')
예제 #5
0
def jurisdiction_browse_by_states(request):
    data = {}
    requestProcessor = HttpRequestProcessor(request)
    
    #message_key = requestProcessor.getParameter('message_key')
    #messageUtil = MessageUtil(message_key)
    #data['system_message_type'] = messageUtil.get_system_message_type()   # optional
    #data['system_message_text'] = messageUtil.get_system_message_text()   
    
    message_data = get_system_message(request) #get the message List
    data =  dict(data.items() + message_data.items())   #merge message list to data
            
    data['page_title'] = "Browse Jurisdictions"
      
    #data['state_list'] = US_STATES
    return requestProcessor.render_to_response(request,'website/jurisdictions/jurisdiction_state_browse.html', data, '')
예제 #6
0
def home(request):
    user = request.user
    requestProcessor = HttpRequestProcessor(request)
    data = {}
    data['accept_tou'] = '' 
    data['home'] = 'True' 
    dajax = Dajax()
    
    ajax = requestProcessor.getParameter('ajax')
    if (ajax != None):
              
        
        #default response for all ajax
        return HttpResponse(dajax.json())  

    data['login'] = '******'

    if user.is_authenticated():
        data['login'] = '******'
    elif user.is_active == False:
        data['login_status'] = 'account_locked'
        
    
    message_data = get_system_message(request) #get the message List
    data =  dict(data.items() + message_data.items())   #merge message list to data
    
    
    invitation_key = requestProcessor.getParameter('invitation_key')    
    if invitation_key != '' and invitation_key != None:
        data['action_key'] = 'create_account'
        data['invitation_key'] = invitation_key
        
    action = requestProcessor.getParameter('action')    
    if action != '' and action != None:
        data['action_key'] = action       
    next_url = requestProcessor.getParameter('next')    
    data['caller'] = 'sign_in_home'
    data['current_nav'] = 'home'
    
    if user.is_authenticated() and (next_url != None and next_url != ''):
        return redirect(next_url)
    else:
        return requestProcessor.render_to_response(request,'website/home.html', data, '')
예제 #7
0
def get_state_jurisdictions(request, state='', sort_by='', sort_dir='', page_num=''):
    data = {}
    data['get_state_jurisdiction'] = True
    requestProcessor = HttpRequestProcessor(request)
    search_str = requestProcessor.getParameter('text_2') 
    if search_str == None or search_str == 'Search':
        search_str = ''       
    filter = requestProcessor.getParameter('filter')
    if filter == None:
        filter = 'all'
        
    only_jurisditions_with_data = requestProcessor.getParameter('only_jurisditions_with_data')        
    if only_jurisditions_with_data != None:
        data['only_jurisditions_with_data'] = int(only_jurisditions_with_data)
    else:
        ajax = requestProcessor.getParameter('ajax')
        if ajax == 'filter':
            data['only_jurisditions_with_data'] = 0
        else:
            if 'only_jurisditions_with_data' in request.session:
                data['only_jurisditions_with_data'] = request.session['only_jurisditions_with_data']
            else:
                data['only_jurisditions_with_data'] = 1
    request.session['only_jurisditions_with_data'] = data['only_jurisditions_with_data']          

    if sort_by == '' or sort_by == None:
        sort_by = 'name'
    elif sort_by == 'last':
        sort_by = 'last_contributed'

    if sort_dir == '' or sort_dir == None:
        sort_dir = 'asc'
    if sort_dir == 'asc':
        order_by_str = sort_by
    else:
        order_by_str = '-'+sort_by

    data['sort_by'] = sort_by
    data['sort_dir'] = sort_dir

    data['secondary_search_str'] = search_str
    data['filter'] = filter
        
    user = request.user
    if user.is_authenticated():
        data['nav'] = 'yes'
        data['breadcrum'] = 'no'
    else:
        data['nav'] = 'no'    
        data['breadcrum'] = 'yes'  
        #return HttpResponseRedirect("/sign_in/?next=/jurisdiction_browse/"+state+"/name/asc/1_1/")  
            
    sort_desc_img = django_settings.SORT_DESC_IMG
    sort_asc_img = django_settings.SORT_ASC_IMG
    sort_class = django_settings.SORT_CLASS
    sort_columns = {}
    sort_columns['name'] = 'asc'
    sort_columns['county'] = 'asc'
    sort_columns['last_contributed'] = 'asc'
    sort_columns['last_contributed_by'] = 'asc'
   
    data['current_nav'] = 'browse'
    href = '/jurisdiction/browse/?state=' + state

    search_params = {}

    #data['page_title'] = "Browse Jurisdiction: " + state

    if state == '':
        state = 'CA'
        
    data['state'] = state
    data['state_long_name'] = dict(US_STATES)[state]
    #type = 'S'
    #data['state_list'] = Jurisdiction.objects.filter(state__iexact=state, jurisdiction_type__iexact=type)     
    
    if filter == 'county':
        type = ['CO', 'CONP', 'SC' ]
    elif filter == 'city':
        type = ['CI', 'CINP', 'SCFO', 'U']
    elif filter == 'state':
        type = ['S']        
    else:
        type = ''

    page = requestProcessor.getParameter('page')
    if page != None and page != '':
        page_number = int(page)
    else:
        page_number = 1
    range_start = (page_number - 1) * JURISDICTION_PAGE_SIZE
    range_end = page_number * JURISDICTION_PAGE_SIZE
    data['next_page_param'] = 'page='+str(page_number + 1)
    
    objects = Jurisdiction.objects.none() 
        
        
    if search_str == '':
        if filter == 'all' or filter == '' or filter == None:
            if data['only_jurisditions_with_data'] == 1:
                objects |= Jurisdiction.objects.filter(last_contributed__isnull = False, state__iexact=state)     
                objects |= Jurisdiction.objects.filter(state__iexact=state, jurisdiction_type__in=('U', 'SCFO'), parent__last_contributed__isnull=False)   
            else:
                objects |= Jurisdiction.objects.filter(last_contributed__isnull = True, state__iexact=state)       
                    
        elif filter == 'county' or filter == 'city' or filter == 'state':
            if data['only_jurisditions_with_data'] == 1:
                objects |= Jurisdiction.objects.filter(last_contributed__isnull = False, state__iexact=state, jurisdiction_type__in=type)     
                objects |= Jurisdiction.objects.filter(state__iexact=state, jurisdiction_type__in=('U', 'SCFO'), parent__last_contributed__isnull=False)   
            else:
                objects |= Jurisdiction.objects.filter(last_contributed__isnull = True, state__iexact=state, jurisdiction_type__in=type)                  
            
            
    else:
        if filter == 'all' or filter == '' or filter == None:
            if data['only_jurisditions_with_data'] == 1:
                objects |= Jurisdiction.objects.filter(name__icontains=search_str, last_contributed__isnull = False, state__iexact=state)     
                objects |= Jurisdiction.objects.filter(name__icontains=search_str, state__iexact=state, jurisdiction_type__in=('U', 'SCFO'), parent__last_contributed__isnull=False)   
            else:
                objects |= Jurisdiction.objects.filter(name__icontains=search_str, state__iexact=state, last_contributed__isnull = True)                
                    
        elif filter == 'county' or filter == 'city' or filter == 'state':
            if data['only_jurisditions_with_data'] == 1:
                objects |= Jurisdiction.objects.filter(name__icontains=search_str, last_contributed__isnull = False, state__iexact=state, jurisdiction_type__in=type)     
                objects |= Jurisdiction.objects.filter(name__icontains=search_str, state__iexact=state, jurisdiction_type__in=('U', 'SCFO'), parent__last_contributed__isnull=False)   
            else:
                objects |= Jurisdiction.objects.filter(name__icontains=search_str, state__iexact=state, jurisdiction_type__in=type, last_contributed__isnull = True)  
                            
    if sort_by == '' or sort_by == None:
        objects = objects.order_by('name', 'county')
    else:                        
        objects = objects.order_by(order_by_str) 
    
    data['count'] = len(objects)    
    data['list'] = objects[range_start:range_end]


    #data['system_message_type'] = 'success'
    #data['system_message_text'] = 'A lot of data found for your consumption'    
    
    data['action'] = "/jurisdiction/browse/?state="+state
    data['home'] = '/'
    data['user'] = request.user 
    
    message_data = get_system_message(request) #get the message List
    data =  dict(data.items() + message_data.items())   #merge message list to data
    
    dajax = Dajax()
    ajax = requestProcessor.getParameter('ajax')
    if (ajax != None):
        #handle ajax calls
        if ajax == 'filter':
            body = requestProcessor.decode_jinga_template(request,'website/jurisdictions/jurisdiction_list.html', data, '') 
            dajax.assign('#jurisdiction_list','innerHTML', body)
            if page_number == 1: #initialize jscroll if page 1
                script = requestProcessor.decode_jinga_template(request, 'website/jurisdictions/jurisdiction_list.js', data, '')
                dajax.script(script)
                
            if int(data['only_jurisditions_with_data'])  == 1:
                message = 'Jurisdictions without data are hidden. Uncheck to show.'
            else:
                message = 'Jurisdictions without data are visible. Check to hide.'
                
            dajax.assign('#only_jurisdictions_with_data_message','innerHTML', message)
            
            return HttpResponse(dajax.json())
        
        return HttpResponse(dajax.json())
    #data['user'] = request.user
    if page_number != 1:
        #for endless scroll next page, only render the list
        return requestProcessor.render_to_response(request,'website/jurisdictions/jurisdiction_list.html', data, '')      
    else:
        return requestProcessor.render_to_response(request,'website/jurisdictions/jurisdiction_by_state.html', data, '')      
예제 #8
0
def jurisdiction_search_improved(request):    
    requestProcessor = HttpRequestProcessor(request)

    data = {'page_class': 'meta'}
    data['breadcrum'] = 'no'
    data['nav'] = 'yes'         
    data['current_nav'] = 'browse'
    #handle ajax near the end since it needs the same query in most cases
    #but need to know if it is ajax to prevent redirect to jurisdiction page
    dajax = Dajax()
    ajax = requestProcessor.getParameter('ajax')

    caller = requestProcessor.getParameter('caller')             
    if caller == '' or caller == None:
        caller = 'general_search'   
        
    data['caller'] = caller     
   
    form = None    

    primary_search_str = requestProcessor.getParameter('q')
    text_primary_search_str = requestProcessor.getParameter('text')    

    if primary_search_str == None:        
        primary_search_str = ''
        
    if text_primary_search_str == None:        
        text_primary_search_str = ''   
        
    # replace primary_search_str with q_primary_search_str if q_primary_search_str is available
    if primary_search_str == '':
        if text_primary_search_str != '':
            primary_search_str = text_primary_search_str
                                  
    data['primary_search_str'] = primary_search_str   
    
    if caller == 'state_jurisdictions':
        data['state_long_name'] = dict(US_STATES)[primary_search_str]     
    
    
    secondary_search_str = requestProcessor.getParameter('text_2') 
    if secondary_search_str == None or secondary_search_str=='Search':
        secondary_search_str = ''                                  
    data['secondary_search_str'] = secondary_search_str      

    search_level = check_search_level(primary_search_str)
    
    primary_exclude = exclude(primary_search_str)
        
    filter = requestProcessor.getParameter('filter')
    if filter == None:
        if search_level != '':
            filter = search_level
        else:
            filter = 'all'

    data['filter'] = filter   

    sort_by = requestProcessor.getParameter('sort_by')
    if sort_by == None:
        sort_by = ''                               
    data['sort_by'] = sort_by   
    
    sort_dir = requestProcessor.getParameter('sort_dir') 

    #order_by_str = pagingation_obj.get_order_by_str(sort_by, sort_dir)   
    if sort_dir == '' or sort_dir == None:
        sort_dir = 'asc'
    data['sort_dir'] = sort_dir   
  
    sort_desc_img = django_settings.SORT_DESC_IMG
    sort_asc_img = django_settings.SORT_ASC_IMG
    
    page = requestProcessor.getParameter('page')
    if page != None and page != '':
        page_number = int(page)
    else:
        page_number = 1
    range_start = (page_number - 1) * JURISDICTION_PAGE_SIZE
    range_end = page_number * JURISDICTION_PAGE_SIZE
    data['next_page_param'] = 'page='+str(page_number + 1)
    
    data['message'] = ''
    mathUtil = MathUtil()
    if mathUtil.is_number(primary_search_str) == False:
        if sort_by == '' or sort_by == None:
            sort_by = 'name'
        else:
            if sort_by == 'name':
                sort_by = 'name'
            elif sort_by == 'last':
                sort_by = 'last_contributed'
            else:
                sort_by = 'last_contributed_by'
        data['sort_by'] = sort_by

        if sort_dir == 'asc':           
            order_by_str = sort_by
            data['image_src'] = sort_asc_img
            data['sort_dir_txt'] = 'ascending' 
            data['sort_dir'] = 'asc'       
        else:
            order_by_str = '-'+sort_by
            data['image_src'] = sort_desc_img
            data['sort_dir_txt'] = 'descending'
            data['sort_dir'] = 'desc'

        data['search_by'] = 'search_by_name';
        scrubbed_primary_search_str = scrub_text_search_str(primary_search_str)
        
        sec_exclude = exclude(secondary_search_str)
            
        if primary_search_str.__len__() >= 2:
            objects_all_types = jurisdiction_text_search(primary_search_str, scrubbed_primary_search_str, secondary_search_str,filter, order_by_str, range_start, range_end, primary_exclude, sec_exclude)
            redirect_url = '/jurisdiction/'
                
            if len(objects_all_types) == 1 and ajax == None: #don't redirect if ajax
                redirect_url = redirect_url + str(objects_all_types[0].get_name_for_url()) + '/'
                return redirect(redirect_url)
            else:
                data['list'] = objects_all_types
        else:
            data['message'] = 'This search field requires at least 2 alphabetic (a-z) characters.';
    else:
        if sort_by == '' or sort_by == None or sort_by == 'distance':
            sort_by = 'distance'
        else:
            if sort_by == 'name':
                sort_by = 'name'
            elif sort_by == 'last':
                sort_by = 'last_contributed'
            else:
                sort_by = 'last_contributed_by'
        data['sort_by'] = sort_by

        if sort_dir == 'asc':           
            data['image_src'] = sort_asc_img
            data['sort_dir_txt'] = 'ascending' 
            data['sort_dir'] = 'asc'       
        else:
            data['image_src'] = sort_desc_img
            data['sort_dir_txt'] = 'descending'
            data['sort_dir'] = 'desc'

        data['search_by'] = 'search_by_zip'
        if page_number != 1:
            #for zip search, currently doesn't have endless scroll next page, return blank
            data['list'] = []
            return requestProcessor.render_to_response(request,'website/jurisdictions/jurisdiction_list.html', data, '')
        nearbyJs = {}
        #geo based approach
        zipcodes = Zipcode.objects.filter(zip_code=primary_search_str)
        
        #TODO: if zip code not found, look for next zip code up
        if len(zipcodes) < 1:
            zipcodes = Zipcode.objects.filter(zip_code__gt=primary_search_str)[0:1]
        
        if len(zipcodes) > 0:
            zipcode = zipcodes[0] #should be only one anyway
            
            geoHelper = GeoHelper()
            center = {}
            center['lat'] = zipcode.latitude
            center['lon'] = zipcode.longitude
            #zip code data problem - longitude needs to be inverted:
            center['lon'] = float(-center['lon'])
            
            nearbyJs = getNearbyJs(geoHelper, center, geoHelper.initialDistance, 1)

            nearbyJs = addDistanceToJs(geoHelper, center, nearbyJs)
            nearbyJs = sortJs(nearbyJs, sort_by, sort_dir)
            
            data['list'] = nearbyJs
        
    request.session['primary_search_str'] = primary_search_str 
    data['user'] = request.user 
    
    message_data = get_system_message(request) #get the message List
    data =  dict(data.items() + message_data.items())   #merge message list to data
       
    if (ajax != None):
        #handle ajax calls
        if ajax == 'filter':
            body = requestProcessor.decode_jinga_template(request,'website/jurisdictions/jurisdiction_list.html', data, '') 
            dajax.assign('#jurisdiction_list','innerHTML', body)
            if page_number == 1: #initialize jscroll if page 1
                script = requestProcessor.decode_jinga_template(request, 'website/jurisdictions/jurisdiction_list.js', data, '')
                dajax.script(script)
            return HttpResponse(dajax.json())
        
        return HttpResponse(dajax.json())

    if page_number != 1:
        #for endless scroll next page, only render the list
        return requestProcessor.render_to_response(request,'website/jurisdictions/jurisdiction_list.html', data, '')      
    else:
        return requestProcessor.render_to_response(request,'website/jurisdictions/jurisdiction_search_results.html', data, '')