from olcc.models import ImportRecord

"""
Inject the last import date into the request context.
"""
def last_updated(request):
    record = ImportRecord.objects.latest()
    if record:
        return {
            'last_updated': record.created_at
        }

from olcc.models import ImportRecord

"""
Inject the last import date into the request context.
"""
def last_updated(request):
    try:
        return {
            'last_updated': ImportRecord.objects.latest().created_at
        }
    except ImportRecord.DoesNotExist:
        pass

Fix a DoesNotExist bug in the olcc context processor.
Fix a DoesNotExist bug in the olcc context processor.

  from olcc.models import ImportRecord
  
  """
  Inject the last import date into the request context.
  """
  def last_updated(request):
+     try:
-     record = ImportRecord.objects.latest()
-     if record:
          return {
-             'last_updated': record.created_at
+             'last_updated': ImportRecord.objects.latest().created_at
          }
+     except ImportRecord.DoesNotExist:
+         pass
  
Fix a DoesNotExist bug in the olcc context processor.
## Code Before:
from olcc.models import ImportRecord

"""
Inject the last import date into the request context.
"""
def last_updated(request):
    record = ImportRecord.objects.latest()
    if record:
        return {
            'last_updated': record.created_at
        }

## Instruction:
Fix a DoesNotExist bug in the olcc context processor.
## Code After:
from olcc.models import ImportRecord

"""
Inject the last import date into the request context.
"""
def last_updated(request):
    try:
        return {
            'last_updated': ImportRecord.objects.latest().created_at
        }
    except ImportRecord.DoesNotExist:
        pass
