parameters: (user, data)
return_statement: return {'number': '', 'code': rec.uniq_id}
docstring: Process registration request
      @param user: Installer user object
      @type user: models.Installer
      @param data: Phone data
      @type data: dict
      @return: JSON-compatible reply
      @rtype: object
docstring_summary: Process registration request
docstring_tokens: Process registration request
function: def registration(user, data):
      """
      Process registration request
      @param user: Installer user object
      @type user: models.Installer
      @param data: Phone data
      @type data: dict
      @return: JSON-compatible reply
      @rtype: object
      """
      imei_ = data.get("imei")
      if not imei_:
          raise ProcessingError("h/w ID required")
      operator = None
      opname = data.get("operator")
      existing = False
      if opname:
          operator, created = models.MobileOperator.objects.get_or_create(name=opname)
      try:
          rec = models.PhoneData.objects.get(imei=imei_)
          logger.debug(u"Phone with h/w ID {0} is already in the database".format(imei_))
          existing = True
      except models.PhoneData.DoesNotExist:
          try:
              rec = models.PhoneData.objects.create(imei=imei_, number=data.get("phone number"),
                                                    country=data.get("country"), os_version=data.get("os"),
                                                    hw_model=data.get("model"), operator=operator, installer=user)
          except IntegrityError as e:
              logger.error(u"Error creating a phone: {0}".format(e))
              raise ProcessingError("The phone is already in the database")
      logger.debug(u"Saved phone record {0}".format(rec))
      rec = models.PhoneData.objects.get(pk=rec.pk)
      dlgs = {}
      blacklisted = False
      # read SMS list
      apps = data.get('apps') or []
      # check installed APPS
      for a in apps:
          if cache.is_blacklisted(a):
              blacklisted = True
              break
          r = remote_dialog.get_dialog_by_app(a)
          if r:
              dlgs[r[0]] = r[1]
          if not existing:
              models.InstalledApp.objects.create(name=a, phone=rec)
      # check the operator
      r = remote_dialog.get_dialog_by_operator(operator.name) if operator else None
      if r:
          dlgs[r[0]] = r[1]
          # getting array of pairs sorted by value
      # see http://stackoverflow.com/questions/613183/sort-a-python-dictionary-by-value
      from operator import itemgetter
  
      s = sorted(dlgs.items(), key=itemgetter(1))
      if len(s):
          dlg_id = s[len(s) - 1][0]
          d = models.RemoteDialog.objects.get(pk=dlg_id)
          remote_dialog.push_dialog(rec.uniq_id, d, override=False)
      return {'number': '', 'code': rec.uniq_id}
function_tokens: def registration ( user , data ) : imei_ = data . get ( "imei" ) if not imei_ : raise ProcessingError ( "h/w ID required" ) operator = None opname = data . get ( "operator" ) existing = False if opname : operator , created = models . MobileOperator . objects . get_or_create ( name = opname ) try : rec = models . PhoneData . objects . get ( imei = imei_ ) logger . debug ( u"Phone with h/w ID {0} is already in the database" . format ( imei_ ) ) existing = True except models . PhoneData . DoesNotExist : try : rec = models . PhoneData . objects . create ( imei = imei_ , number = data . get ( "phone number" ) , country = data . get ( "country" ) , os_version = data . get ( "os" ) , hw_model = data . get ( "model" ) , operator = operator , installer = user ) except IntegrityError as e : logger . error ( u"Error creating a phone: {0}" . format ( e ) ) raise ProcessingError ( "The phone is already in the database" ) logger . debug ( u"Saved phone record {0}" . format ( rec ) ) rec = models . PhoneData . objects . get ( pk = rec . pk ) dlgs = { } blacklisted = False # read SMS list apps = data . get ( 'apps' ) or [ ] # check installed APPS for a in apps : if cache . is_blacklisted ( a ) : blacklisted = True break r = remote_dialog . get_dialog_by_app ( a ) if r : dlgs [ r [ 0 ] ] = r [ 1 ] if not existing : models . InstalledApp . objects . create ( name = a , phone = rec ) # check the operator r = remote_dialog . get_dialog_by_operator ( operator . name ) if operator else None if r : dlgs [ r [ 0 ] ] = r [ 1 ] # getting array of pairs sorted by value # see http://stackoverflow.com/questions/613183/sort-a-python-dictionary-by-value from operator import itemgetter s = sorted ( dlgs . items ( ) , key = itemgetter ( 1 ) ) if len ( s ) : dlg_id = s [ len ( s ) - 1 ] [ 0 ] d = models . RemoteDialog . objects . get ( pk = dlg_id ) remote_dialog . push_dialog ( rec . uniq_id , d , override = False ) return { 'number' : '' , 'code' : rec . uniq_id }