def index(request):
    em = EmergencyMessage.objects.get()
    return render(
        request, 'search/index.jinja', {
            'emergency_message':
            em.message_cy if display_in_welsh() else em.message,
            'show': em.show
        })
def searchby(request):
    url = 'search:'
    searchby = request.GET.get('searchby')

    if searchby == 'list':
        url = 'courts:'
        if display_in_welsh():
            searchby = 'welsh_list'

    url = url + searchby
    return HttpResponseRedirect(reverse(url))
Ejemplo n.º 3
0
def searchby(request):
    url = 'search:'
    searchby = request.GET.get('searchby')

    if searchby == 'list':
        url = 'courts:'
        if display_in_welsh():
            searchby = 'welsh_list'

    url = url + searchby
    return HttpResponseRedirect(reverse(url))
Ejemplo n.º 4
0
def court(request, slug):
    try:
        the_court = Court.objects.get(slug=slug)
    except Court.DoesNotExist:
        raise Http404

    return render(request, 'courts/court.jinja', {
        'court': format_court(the_court),
        'query': request.GET.get('q', ''),
        'aol': request.GET.get('aol', 'All'),
        'spoe': request.GET.get('spoe', None),
        'postcode': request.GET.get('postcode', ''),
        'courtcode': request.GET.get('courtcode', False),
        'feature_leaflet_enabled': settings.FEATURE_LEAFLETS_ENABLED,
        'show_welsh_notice': display_in_welsh() and not the_court.welsh_enabled
    })
def court(request, slug):
    try:
        the_court = Court.objects.get(slug=slug)
    except Court.DoesNotExist:
        raise Http404

    return render(
        request, 'courts/court.jinja', {
            'court': format_court(the_court),
            'query': request.GET.get('q', ''),
            'aol': request.GET.get('aol', 'All'),
            'spoe': request.GET.get('spoe', None),
            'postcode': request.GET.get('postcode', ''),
            'courtcode': request.GET.get('courtcode', False),
            'feature_leaflet_enabled': settings.FEATURE_LEAFLETS_ENABLED,
            'show_welsh_notice': display_in_welsh()
            and not the_court.welsh_enabled
        })
def __format_results(results):
    """
    create a list of courts from search results that we can send to templates
    """
    courts = []
    for result in results:

        addresses = result.courtaddress_set.all().order_by("-pk")
        address = False
        if addresses != []:
            for a in addresses:
                if a.address_type.name == 'Postal':
                    address = a
                    break
                else:
                    address = addresses[0]

        if address:
            welsh = display_court_in_welsh(address.court)
            visible_address = {
                'address_lines': [
                    line for line in translate_attribute(
                        address, 'address', welsh).split('\n') if line != ''
                ],
                'postcode':
                address.postcode,
                'town':
                translate_attribute(address, 'town_name', welsh),
                'type':
                address.address_type,
            }
        else:
            visible_address = {}

        areas_of_law = [{
            'name':
            aol.name if not aol.alt_name else translate_type(
                AreaOfLaw, aol.alt_name, display_in_welsh(), 'alt_name'),
            'external_link':
            aol.external_link,
            'display_url':
            aol.display_url_cy if display_in_welsh() else aol.display_url,
            'external_link_desc':
            translate_type(AreaOfLaw, aol.external_link_desc,
                           display_in_welsh(), 'external_link_desc')
        } for aol in result.areas_of_law.all()]

        court = {
            'name':
            translate_attribute(result, 'name',
                                display_court_in_welsh(result)),
            'lat':
            result.lat,
            'lon':
            result.lon,
            'number':
            result.number,
            'cci_code':
            result.cci_code,
            'magistrate_code':
            result.magistrate_code,
            'slug':
            result.slug,
            'types':
            sorted([
                court_type.court_type.name
                for court_type in result.courtcourttype_set.all()
            ]),
            'address':
            visible_address,
            'areas_of_law':
            areas_of_law,
            'displayed':
            result.displayed,
            'hide_aols':
            result.hide_aols
        }

        dx_contacts = result.courtcontact_set.filter(contact__name='DX')
        if dx_contacts.count() > 0:
            court['dx_number'] = dx_contacts.first().contact.number

        if hasattr(result, 'distance') and result.distance:
            court['distance'] = round(result.distance, 2)

        courts.append(court)
    return courts
def format_court(court):
    """
    create a courts object that we can send to templates
    """
    welsh = display_court_in_welsh(court)
    addresses = court.courtaddress_set.all().order_by('address_type__name',
                                                      '-pk')
    postal_address = None
    visiting_address = None
    for address in addresses:
        address_obj = {
            'address_lines': [
                line for line in translate_attribute(
                    address, "address", welsh).split('\n') if line != ''
            ],
            'postcode':
            address.postcode,
            'town':
            translate_attribute(address, "town_name", welsh),
            'type':
            address.address_type
        }
        if str(address.address_type) == 'Postal' or str(
                address.address_type) == 'Visit us or write to us':
            postal_address = address_obj
        else:
            visiting_address = address_obj

    if postal_address and str(
            postal_address['type']) == 'Visit us or write to us':
        visiting_address = None
    court_emails = court.emails.all().order_by('courtemail__order')
    emails = [{
        'description':
        translate_type(ContactType, email.description, welsh),
        'addresses': [email.address],
        'explanation':
        translate_attribute(email, "explanation", welsh)
    } for email in court_emails]
    contacts = [{
        'name':
        translate_type(ContactType, contact.name, welsh),
        'numbers': [contact.number],
        'explanation':
        translate_attribute(contact, "explanation", welsh),
        'in_leaflet':
        contact.in_leaflet
    } for contact in court.contacts.all().order_by('sort_order')]

    facilities = [
        {
            # Name is used for the css class name to set the x,y offsets on old style images
            'name':
            translate_type(FacilityType, facility.name, welsh),
            # Description is used for the display text
            'description':
            translate_attribute(facility, "description", welsh),
            # Image class is the generated class name (empty for new style images)
            'image_class':
            "" if facility.image_file_path else 'icon-' + facility.image,
            # The relative path to the image
            'image_src':
            facility.image_file_path if facility.image_file_path else None,
            # This description is used for the alt text
            'image_description':
            translate_type(FacilityType, facility.image_description, welsh,
                           "image_description"),
            # The relative file path of the image
            'image_file_path':
            facility.image_file_path
        } for facility in order_facilities(court.facilities.all())
    ]

    opening_times = [
        {
            # Displayed text concatenates the type with the hours
            'displayed_text':
            "%s: %s" %
            (translate_type(OpeningType, court_opening.opening_time.type,
                            welsh), court_opening.opening_time.hours)
            if court_opening.opening_time.hours else "%s" % translate_type(
                OpeningType, court_opening.opening_time.type, welsh),
        } for court_opening in CourtOpeningTime.objects.filter(
            court_id=court.id).order_by('sort')
    ]

    aols = [
        {
            #Displayed text concatenates the type with the hours
            'name':
            aol.name if not aol.alt_name else translate_type(
                AreaOfLaw, aol.alt_name, display_in_welsh(), 'alt_name'),
            'external_link':
            aol.external_link,
            'display_url':
            aol.display_url_cy if display_in_welsh() else aol.display_url,
            'external_link_desc':
            translate_type(AreaOfLaw, aol.external_link_desc,
                           display_in_welsh(), 'external_link_desc')
        } for aol in court.areas_of_law.all().order_by("name")
    ]

    court_obj = {
        'name':
        translate_attribute(court, "name", welsh),
        'displayed':
        court.displayed,
        'lat':
        court.lat,
        'lon':
        court.lon,
        'number':
        court.number,
        'cci_code':
        court.cci_code,
        'magistrate_code':
        court.magistrate_code,
        'updated_at':
        court.updated_at.strftime("%d %B %Y") if court.updated_at else '',
        'slug':
        court.slug,
        'image_file':
        court.image_file,
        'image_url': (settings.COURT_IMAGE_BASE_URL +
                      court.image_file) if court.image_file else '',
        'types': [
            court_type.court_type.name
            for court_type in court.courtcourttype_set.all()
        ],
        'postal_address':
        postal_address,
        'visiting_address':
        visiting_address,
        'opening_times':
        opening_times,
        'areas_of_law':
        aols,
        'facilities':
        facilities,
        'emails':
        emails,
        'contacts':
        contacts,
        'directions':
        translate_attribute(court, "directions", welsh)
        if court.directions else None,
        'alert':
        translate_attribute(court, "alert", welsh)
        if court.alert and court.alert.strip() != '' else None,
        'info':
        translate_attribute(court, "info", welsh),
        'hide_aols':
        court.hide_aols,
        'info_leaflet':
        translate_attribute(court, "info_leaflet", welsh),
        'juror_leaflet':
        court.juror_leaflet,
        'defence_leaflet':
        translate_attribute(court, "defence_leaflet", welsh),
        'prosecution_leaflet':
        translate_attribute(court, "prosecution_leaflet", welsh)
    }

    dx_contact = court.contacts.filter(courtcontact__contact__name='DX')
    if dx_contact.count() > 0:
        court_obj['dx_number'] = dx_contact.first().number

    return court_obj
Ejemplo n.º 8
0
def index(request):
    em = EmergencyMessage.objects.get()
    return render(request, 'search/index.jinja',
        {'emergency_message': em.message_cy if display_in_welsh() else em.message, 'show': em.show})
Ejemplo n.º 9
0
def __format_results(results):
    """
    create a list of courts from search results that we can send to templates
    """
    courts=[]
    for result in results:

        addresses = result.courtaddress_set.all().order_by("-pk")
        address = False
        if addresses != []:
            for a in addresses:
                if a.address_type.name == 'Postal':
                    address = a
                    break
                else:
                    address = addresses[0]

        if address:
            welsh = display_court_in_welsh(address.court)
            visible_address = {
                'address_lines': [line for line in translate_attribute(address, 'address', welsh).split('\n')
                                  if line != ''],
                'postcode': address.postcode,
                'town': translate_attribute(address, 'town_name', welsh),
                'type': address.address_type,
            }
        else:
            visible_address = {}

        areas_of_law = [
        {
            'name': aol.name,
            'external_link': aol.external_link,
            'display_url': aol.display_url_cy if display_in_welsh() else aol.display_url,
            'external_link_desc': translate_type(AreaOfLaw, aol.external_link_desc,
                                                 display_in_welsh(),
                                                 'external_link_desc')
        } for aol in result.areas_of_law.all()]

        court = { 'name': translate_attribute(result, 'name', display_court_in_welsh(result)),
                  'lat': result.lat,
                  'lon': result.lon,
                  'number': result.number,
                  'cci_code': result.cci_code,
                  'magistrate_code': result.magistrate_code,
                  'slug': result.slug,
                  'types': sorted([court_type.court_type.name for court_type in result.courtcourttype_set.all()]),
                  'address': visible_address,
                  'areas_of_law': areas_of_law,
                  'displayed' : result.displayed,
                  'hide_aols': result.hide_aols}
                  
        dx_contacts = result.courtcontact_set.filter(contact__name='DX')
        if dx_contacts.count() > 0:
            court['dx_number'] = dx_contacts.first().contact.number

        if hasattr(result, 'distance') and result.distance:
            court['distance'] = round(result.distance, 2)

        courts.append(court)
    return courts