new_contents: # -*- coding: utf-8 -*- vim:encoding=utf-8:
  # vim: tabstop=4:shiftwidth=4:softtabstop=4:expandtab
  
  # Copyright © 2010-2012 Greek Research and Technology Network (GRNET S.A.)
  #
  # Permission to use, copy, modify, and/or distribute this software for any
  # purpose with or without fee is hereby granted, provided that the above
  # copyright notice and this permission notice appear in all copies.
  #
  # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  # TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  # FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  # OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  # USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  # OF THIS SOFTWARE.
  
  from servermon.hwdoc.models import Equipment, ServerManagement
  from django.db.models import Q
  
  def search(key):
      if key is None:
          return None
      if key.upper().replace('R','').replace('U','').isdigit():
          rackunit = key.upper().replace('R','').replace('U','')
          if len(rackunit) < 3:
              result=Equipment.objects.filter(
                                          Q(rack=rackunit)|
                                          Q(unit=rackunit)
                                          )
          else:
              result=Equipment.objects.filter(rack=rackunit[0:2], unit=rackunit[2:4])
      else:
          result=Equipment.objects.filter(
                                          Q(serial=key)|
                                          Q(model__name=key)|
                                          Q(servermanagement__mac__icontains=key)|
                                          Q(servermanagement__hostname__icontains=key.split('.')[0])
                                          )
      return result
  
subject: Split functions in a different file for hwdoc