示例#1
0
class UserModel(Mapping):
    token = TextField()
    name = TextField()
    email = TextField()
    credit = IntegerField(default = 0)
    cardNumber = TextField()
    Collector = ListField(DictField(FullCollectorModel))

    def isAnon(self):
        return self.token is None
    def getCredits(self):
        return self.credit
    def toJSON(self, stringify = True):
        json = self.unwrap(sparse = True).copy()
        json['Collector'] = [{'id': c['id'], 'firstName':c['firstName'], 'lastName':c['lastName']} for c in json.pop("Collector", []) if c.get('id')]
        return simplejson.dumps(json)
    def hasSavedDetails(self):
        return bool(self.cardNumber)
    def discardSavedDetails(self):
        self.cardNumber = None
        return True
    def getCreditWithPlan(self, plan):
        return self.credit + plan.credit

    @reify
    def collectorMap(self):
        return {c.id: c for c in self.Collector}
    def getCollector(self, id):
        return self.collectorMap.get(int(id))
    def hasCollector(self, collector):
        return isinstance(self.collectorMap.get(collector.id), CollectorModel)

    def getCreditValidity(self, request):
        return i18n.format_date(datetime.now() + timedelta(356), request)
示例#2
0
class PaymentOptionModel(Mapping):
    PERIOD = 'year'
    credit = IntegerField()
    price = IntegerField()
    token = TextField()
    preferred = BooleanField()
    label = TextField()

    def getValue(self, request): return self.token
    def getKey(self, request): return self.token

    def getCredits(self):
        return self.credit
    def getFormattedPrice(self, request):
        return i18n.format_currency(self.price / 100, 'EUR', request)
    def getSavedAmount(self, request):
        return i18n.format_currency(10 * self.credit - self.price / 100, 'EUR', request)
    def getPerCreditAmount(self, request):
        return i18n.format_currency(int(self.price / 100 / self.credit), 'EUR', request)
示例#3
0
class PaymentOptionModel(Mapping):
    PERIOD = 'year'
    credit = IntegerField()
    price = IntegerField()
    token = TextField()
    #preferred = BooleanField()
    label = TextField()

    def getValue(self, request): return self.token
    def getKey(self, request): return self.token

    @property
    def preferred(self):
        return self.credit == 25

    @property
    def is_custom_qty(self):
        return self.credit == 1

    def getRecommendedCredits(self, cart):
        noProfiles = len(cart.getItems())
        return noProfiles if noProfiles and self.is_custom_qty else self.credit

    def getRecommendedPrice(self, request):
        noProfiles = len(request.root.cart.getItems())
        if noProfiles and self.is_custom_qty:
            return i18n.format_currency(self.price * noProfiles / 100.0, 'USD', request)
        else:
            return i18n.format_currency(self.price / 100, 'USD', request)


    def getCredits(self):
        return self.credit
    def getFormattedPrice(self, request):
        return i18n.format_currency(self.price / 100, 'USD', request)



    def getSavedAmount(self, request):
        return i18n.format_currency(10 * self.credit - self.price / 100, 'USD', request)
    def getPerCreditAmount(self, request):
        return i18n.format_currency(int(self.price / 100 / self.credit), 'USD', request)
示例#4
0
class CollectionModel(Mapping):
    id = IntegerField()
    name = TextField()
    totalWorks = IntegerField()
    totalWorksAprx = BooleanField()
    totalArtists = IntegerField()
    totalArtistsAprx = BooleanField()
    foundation = TextField()
    url = TextField()
    year = TextField()
    started = TextField()
    Genre = ListField(DictField(GenreModel))
    Theme = ListField(DictField(ThemeModel))
    Medium = ListField(DictField(MediumModel))
    Origin = ListField(DictField(OriginModel))

    Artist = ListField(DictField(ArtistModel))
    Region = ListField(DictField(CollectionRegionModel))
    Publisher = ListField(DictField(PublisherModel))

    def getNoArtists(self):
        if self.totalArtistsAprx:
            return u'>{}'.format(self.totalArtists)
        else:
            return unicode(self.totalArtists or '')

    def getNoArtworks(self):
        if self.totalWorksAprx:
            return u'>{}'.format(self.totalWorks)
        else:
            return unicode(self.totalWorks or '')

    def hasArtists(self):
        return len(self.Artist) > 0

    @reify
    def artworkList(self):
        return [aw for a in self.Artist for aw in a.ArtWork]

    def hasArtworks(self):
        return len(self.artworkList)
示例#5
0
class ArtistModel(Mapping):
    id = IntegerField()
    name = TextField()
    year = TextField()
    ArtWork = ListField(DictField(ArtworkModel))
    def getLabel(self, request):
        if self.year:
            return u'{} ({})'.format(self.name, self.year)
        else:
            return self.name

    def toQuery(self):
        return {'label': self.name, 'value': self.id}
示例#6
0
class DirectorModel(Mapping):
    id = IntegerField()
    firstName = TextField()
    lastName = TextField()
    origName = TextField()
    title = TextField()
    gender = TextField()
    position = TextField()
    email = TextField()
    facebook = TextField()
    linkedin = TextField()

    def getLabel(self, request):
        return u'{} {}'.format(self.firstName, self.lastName)
示例#7
0
class TopMuseumModel(NamedModel):
    id = IntegerField()
    city = TextField()
    country = TextField()
    postCode = TextField()
    line1 = TextField()
    line2 = TextField()
    city = TextField()

    def getLabel(self, request):
        return u"{0.name} ({0.city})".format(self)

    def getKey(self, request):
        return u'{}-{}'.format(self.name, self.city)
示例#8
0
class SimpleCollectorModel(Mapping):
    id = IntegerField()
    status = TextField()
    updated = DateTimeField()
    isContactable = BooleanField()
    hasCollection = BooleanField()
    initials = TextField()
    picture = TextField()
    ranking = TextField(default=0)
    points = TextField(default=0)
    followers = TextField(default=0)
    completness = TextField(default=0)
    Address = ListField(DictField(AddressModel))

    def getName(self):
        return self.initials

    def getAddress(self):
        if not len(self.Address): return ''
        addr = self.Address[0]
        if not addr.City or not addr.Country: return ''
        return u"{city}, {country}".format(city=addr.City.name,
                                           country=addr.Country.name)

    def getUpdated(self):
        if self.updated:
            return u'{:0>2}/{}'.format(self.updated.month, self.updated.year)
        else:
            return ''

    def getRank(self):
        return self.ranking

    def getPoints(self):
        return self.points

    def getSubscribers(self):
        return self.followers

    def getCompletion(self):
        return self.completness
示例#9
0
class LinkedCollectorModel(Mapping):
    id = IntegerField()
    firstName = TextField()
    lastName = TextField()
    relation = TextField()

    def getName(self):
        result = u'{0.firstName} {0.lastName}'.format(self)
        if self.relation:
            result += u" ({})".format(self.relation)
        return result

    def getNameWithPrivacy(self):
        result = u'{0.firstName} {0.lastName}'.format(self)
        if self.relation:
            if self.relation == u'other':
                return ''
            result += u" ({})".format(self.relation)
        return result

    def getJson(self):
        return saxutils.quoteattr(simplejson.dumps(self.unwrap()))
示例#10
0
class PaymentModel(Mapping):
    paymentRef = TextField()
    amount = IntegerField()
    currency = TextField()
    shopperRef = TextField()
    shopperEmail = TextField()
示例#11
0
class ReviewedCollectorsModel(Mapping):
    no = IntegerField()