Esempio n. 1
0
class Minion_User(Model):
    userId = Field(data_type=STRING, hash_key=True)
    userName = Field(data_type=STRING, range_key=True)
    TrainingStatusID = Field(data_type=set_(NUMBER))
    password = Field(data_type=STRING)
    name = Field(data_type=STRING)
    dob = Field(data_type=datetime)
    gender = Field()
    phoneNumber = Field()
    email = Field()
    address = Field()
    city = Field()
    state = Field()
    country = Field()
    date_signup = Field(data_type=datetime)
    last_accessed_date = Field(data_type=NUMBER, index='ts-index')
    is_active = Field(data_type=NUMBER)
    secret_token = Field(data_type=STRING)
    secret_token_exp = Field(data_type=NUMBER)
    client_ip = Field(data_type=STRING)
    signuptype = Field(data_type=STRING)

    def __init__(self, userid='', username='', password='', email=''):
        super(Minion_User, self).__init__()
        self.userId = userid
        self.userName = username
        self.password = password
        self.email = email

    #list of attributes that are sent to user, when user info is retrieved
    user_attr = ['userName','name','dob','gender','phoneNumber','email','address',\
    'city','state','country','date_signup','last_accessed_date', 'is_active', 'signuptype']
Esempio n. 2
0
 def test_coerce_binary_set(self):
     """ Coerce to binary set """
     field = Field(data_type=set_(six.binary_type), coerce=True)
     ret = field.coerce([six.u('hello')])
     self.assertEqual(ret, set([b'hello']))
Esempio n. 3
0
 def test_coerce_number_set_fail(self):
     """ Coerce to number set fails """
     field = Field(data_type=set_(int))
     with self.assertRaises(TypeError):
         field.coerce([2, '4'])
Esempio n. 4
0
 def test_coerce_number_set(self):
     """ Coerce to number set """
     field = Field(data_type=set_(int), coerce=True)
     ret = field.coerce([2, '4'])
     self.assertEqual(ret, set([2, 4]))
Esempio n. 5
0
class AppDetails(Model):
    __metadata__ = {
        'global_indexes': [
            GlobalIndex('price-index', 'currency', 'price'),
            GlobalIndex('iphone-index', 'supportediPhone'),
            GlobalIndex('ipad-index', 'supportediPad'),
            GlobalIndex('ipod-index', 'supportediPod'),
        ],
    }
    app_id = Field(data_type=types.IntType, hash_key=True, coerce=True)
    country = Field(data_type=types.StringType, range_key=True)
    advisories = Field(data_type=types.ListType)
    artistId = Field(data_type=types.IntType, coerce=True)
    artistName = Field(data_type=types.StringType)
    artistViewUrl = Field(data_type=types.StringType)
    artworkUrl100 = Field(data_type=types.StringType)
    artworkUrl512 = Field(data_type=types.StringType)
    artworkUrl60 = Field(data_type=types.StringType)
    averageUserRating = Field(data_type=types.FloatType, coerce=True)
    averageUserRatingForCurrentVersion = Field(data_type=types.FloatType,
                                               coerce=True)
    bundleId = Field(data_type=types.StringType)
    contentAdvisoryRating = Field(data_type=types.StringType)
    currency = Field(data_type=types.StringType)
    currentVersionReleaseDate = Field(data_type=types.DateTimeType)
    description = Field(data_type=types.StringType)
    features = Field(data_type=types.ListType)
    fileSizeBytes = Field(data_type=types.IntType, coerce=True)
    formattedPrice = Field(data_type=types.StringType)
    genreIds = Field(data_type=types.ListType)
    genres = Field(data_type=types.ListType)
    ipadScreenshotUrls = Field(data_type=types.ListType)
    isGameCenterEnabled = Field(data_type=types.BoolType)
    isVppDeviceBasedLicensingEnabled = Field(data_type=types.BoolType)
    kind = Field(data_type=types.StringType)
    languageCodesISO2A = Field(data_type=types.ListType)
    minimumOsVersion = Field(data_type=types.StringType)
    price = Field(data_type=types.FloatType, coerce=True)
    primaryGenreId = Field(data_type=types.IntType, coerce=True)
    primaryGenreName = Field(data_type=types.StringType)
    releaseDate = Field(data_type=types.DateTimeType, coerce=True)
    releaseNotes = Field(data_type=types.StringType)
    screenshotUrls = Field(data_type=types.ListType)
    sellerName = Field(data_type=types.StringType)
    sellerUrl = Field(data_type=types.StringType)
    supportedDevices = Field(data_type=set_(str), coerce=True)
    supportediPad = Field(data_type=types.IntType, default=0)
    supportediPads = Field(data_type=set_(str))
    supportediPhone = Field(data_type=types.IntType, default=0)
    supportediPhones = Field(data_type=set_(str))
    supportediPod = Field(data_type=types.IntType, default=0)
    supportediPods = Field(data_type=set_(str))
    trackCensoredName = Field(data_type=types.StringType)
    trackContentRating = Field(data_type=types.StringType)
    trackId = Field(data_type=types.IntType, coerce=True)
    trackName = Field(data_type=types.StringType)
    trackViewUrl = Field(data_type=types.StringType)
    userRatingCount = Field(data_type=types.IntType, coerce=True)
    userRatingCountForCurrentVersion = Field(data_type=types.IntType,
                                             coerce=True)
    version = Field(data_type=types.StringType)
    wrapperType = Field(data_type=types.StringType)

    def __repr__(self):
        return "%s (%s) selling for %s %s" % (self.app_id, self.country,
                                              self.price, self.currency)

    def __init__(self, app_id, country, data=None):
        if data is None:
            data = {}

        self.app_id = app_id
        self.country = country
        for field, value in data.items():
            if 'Date' in field:
                value = strptime(value, "%Y-%m-%dT%H:%M:%SZ")
                value = datetime.fromtimestamp(mktime(value))
            setattr(self, field, value)
        if self.supportedDevices:
            self.index_devices()

    def index_devices(self):
        ipads = set()
        ipods = set()
        iphones = set()

        for device in self.supportedDevices:
            if device.startswith('iPad'):
                ipads.add(device)
            elif device.startswith('iPod'):
                ipods.add(device)
            else:
                iphones.add(device)

        if ipods:
            self.supportediPod = 1
            self.supportediPods = ipods
        if ipads:
            self.supportediPad = 1
            self.supportediPads = ipads
        if iphones:
            self.supportediPhone = 1
            self.supportediPhones = iphones

    @classmethod
    def with_price(cls, currency, lower_price, higher_price=None):
        """
        Finds all apps based on currency and price.
        If only one price is passed, finds apps with exact price.
        If higher_price is passed, finds apps within range of lower_price
        and higher_price.
        """
        if higher_price is None:
            return engine(cls).filter(
                currency=currency,
                price=lower_price).index('price-index').all()
        return engine(cls).filter(
            cls.currency == currency,
            cls.price.between_(lower_price,
                               higher_price)).index('price-index').all()

    @classmethod
    def with_supportedDevice(cls, device):
        """
        Query method that returns an array of all apps that support the given
        device name.
        Device name must start with 'iPod', 'iPad', or 'iPhone', else will
        raise an error.
        """
        if device.startswith('iPod'):
            device_type = cls.supportediPod
            device_list = cls.supportediPods
            device_index = 'ipod-index'
        elif device.startswith('iPad'):
            device_type = cls.supportediPad
            device_list = cls.supportediPads
            device_index = 'ipad-index'
        elif device.startswith('iPhone'):
            device_type = cls.supportediPhone
            device_list = cls.supportediPads
            device_index = 'iphone-index'
        else:
            return InValidDeviceName("%s is not a valid device name" % device)
        return engine(cls).filter(
            device_type == 1,
            device_list.contains_(device)).index(device_index).all()