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)
class ArtworkModel(Mapping): title = TextField() year = TextField() material = TextField() medium = TextField() width = DecimalField() height = DecimalField() depth = DecimalField() measurement = TextField() def getMeasure(self): return 'cm' if self.measurement == 'METRIC' else 'in' @reify def size(self): m = '' if self.width: w = self.width m += u'w: {} '.format(int(w) if w ==int(w) else w) if self.height: h = self.height m += u'h: {} '.format(int(h) if h ==int(h) else h) if self.depth: d = self.depth m += u'd: {} '.format(int(d) if d ==int(d) else d) if m: m += self.getMeasure() return m def getLabel(self, request): if self.year: return u'{} ({})'.format(self.title, self.year) else: return self.title
class AddressModel(Mapping): line1 = TextField() line2 = TextField() line3 = TextField() postCode = TextField() Country = DictField(LocationModel) Region = DictField(LocationModel) City = DictField(LocationModel) website = TextField() def getLines(self, request): return '<br/>'.join([ getattr(self, v) for v in ['line1', 'line2', 'line3'] if getattr(self, v, None) ]) def getCityPostCode(self, request): if self.postCode and self.City: return u'{}, {}'.format(self.City.name, self.postCode) elif self.postCode: return self.postCode elif self.City: return self.City.name else: return '' def getRegion(self, request): return self.Region.name if self.Region else '' def getCountry(self, request): return self.Country.name if self.Country else ''
class UniversityModel(Mapping): name = TextField() city = TextField() def getLabel(self, request): if self.city: return u'{0.name}, {0.city}'.format(self) else: return self.name
class GenderModel(Mapping): key = TextField() label = TextField() def getKey(self, request): return self.key def getLabel(self, request): return self.label
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}
class ArtAdvisorModel(Mapping): lastName = TextField() firstName = TextField() origName = TextField() title = TextField() gender = TextField() company = TextField() email = TextField() facebook = TextField() linkedin = TextField() def getLabel(self, request): return u'{} {}'.format(self.firstName, self.lastName)
class NullConfigModel(Mapping): name = TextField() def getKey(self, request): return '' def getLabel(self, request): return '---'
class AdminUser(Mapping): token = TextField() name = TextField() email = TextField() Country = ListField(DictField(CountryModel)) type = TextField() def isAnon(self): return self.token is None def isAdmin(self): return self.token and self.type == 'REVIEWER' def hasCountries(self): return len(self.Country) def getCountryDisplay(self): return ', '.join(map(attrgetter('name'), self.Country))
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)
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)
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)
class NetworkModel(Mapping): ICONS = { 'Facebook': 'icon icon-facebook', 'Twitter': 'icon icon-twitter', 'Linkedin': 'icon icon-linkedin', 'Xing': 'icon icon-xing', 'Weibo': 'icon icon-weibo', 'Renren': 'icon icon-renren' } name = TextField() url = TextField() def getLabel(self, request): return self.name def getIcon(self, request): return self.ICONS.get(self.name, 'no-icon') def getAddress(self, request): return self.url
class NamedModel(Mapping): name = TextField() def getKey(self, request): return self.name def getLabel(self, request): return self.name def toQuery(self): return {'value': self.name, 'label': self.name}
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)
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()))
class BoardMemberModel(AddressModel): museum = TextField() other_name = TextField() position = TextField() year = TextField() def getMusem(self, request): if not getattr(self, 'topMuseum', None): setattr(self, 'topMuseum', request.root.config.topMuseumMap.get(self.museum)) return self.topMuseum def getLines(self, request): if self.museum and self.getMusem(request): museum = self.getMusem(request) return '<br/>'.join([ getattr(museum, v) for v in ['line1', 'line2'] if getattr(museum, v, None) ]) return super(BoardMemberModel, self).getLines(request) def getCityPostCode(self, request): if self.museum and self.getMusem(request): museum = self.getMusem(request) return u'{}, {}'.format(museum.city, museum.postCode) return super(BoardMemberModel, self).getCityPostCode(request) def getRegion(self, request): if self.museum and self.getMusem(request): return '' return super(BoardMemberModel, self).getRegion(request) def getCountry(self, request): if self.museum and self.getMusem(request): museum = self.getMusem(request) return museum.country or '' return super(BoardMemberModel, self).getCountry(request)
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)
class SourceModel(Mapping): """ { "type": "Book", "url": "asdfa", "-name": "asdf", "publisher": "ASDF", "title": "asdf", "author": "zsdfa", "date": "01.01.1979", "year": "1234" }, { "type": "magazine", "url": "as4r56dfa", "name": "as235df", "publisher": "AS2345DF", "title": "a243sdf", "author": "zsdf2435a", "date": "01.01.1979", "year": "1234w43" } """ type = TextField() url = TextField() name = TextField() title = TextField() author = TextField() date = TextField() year = TextField() publisher = TextField() def isURL(self): return self.type == 'Internet/Blogs/Online Mag' def getSourceLine(self): fields = [ 'url', 'name', 'title', 'author', 'publisher', 'year', 'date' ] return ', '.join( [getattr(self, k) for k in fields if getattr(self, k, None)])
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
class NewsItemModel(Mapping): source = TextField() value = TextField() created = DateTimeField()
class PublisherModel(Mapping): title = TextField() year = TextField() publisher = TextField()
class CollectionRegionModel(Mapping): name = TextField()
class SocietyMemberModel(AddressModel): societyName = TextField() position = TextField() year = TextField()
class CooperationModel(AddressModel): type = TextField() comment = TextField() year = TextField() institution = TextField()
class LoanModel(AddressModel): name = TextField() comment = TextField() year = TextField() institution = TextField()
class CompanyModel(AddressModel): name = TextField() position = TextField() industry = TextField() website = TextField(name='url')
class MuseumModel(AddressModel): telephone = TextField() year = TextField() url = TextField() permanentSpace = TextField()
class CollectorModel(SimpleCollectorModel): feederName = TextField() title = TextField() firstName = TextField() lastName = TextField() origName = TextField() dob = TextField() nationality = TextField() Title = TextField() Gender = TextField() wikipedia = TextField() Interest = ListField(DictField(InterestModel)) Email = ListField(DictField(EmailModel)) Network = ListField(DictField(NetworkModel)) Company = ListField(DictField(CompanyModel)) Industry = ListField(DictField(IndustryModel)) University = ListField(DictField(UniversityModel)) Collection = DictField(CollectionModel) Source = ListField(DictField(SourceModel)) LinkedCollector = DictField(LinkedCollectorModel) Fact = ListField(DictField(OtherFactModel)) inActive = BooleanField() def isActive(self): return not self.inActive def getName(self): return u'{firstName} {lastName}'.format(firstName=self.firstName, lastName=self.lastName) def getNameWTitle(self): result = self.getName() if self.title: result = u"{} {}".format(self.title, result) return result def getStatusLabel(self): return STATUS[self.status] def canSubmitforReview(self, user): return self.status == 'INPROGRESS' def canReview(self, user): return self.status == 'SUBMITTED' and user.isAdmin() def isSubmitted(self): return self.status == 'SUBMITTED' def isReviewed(self): return self.status == 'REVIEWED' def getGenreList(self): if self.Collection: return ', '.join([g.name for g in self.Collection.Genre]) else: return '' def getPicture(self, request): if self.picture: return request.getStaticUrl(self.picture) else: return u"{}img/nopic-128px.png".format(request.root.static_prefix) def getDOB(self, request): return self.dob def hasFacts(self): return len(self.Fact) > 0 def hasBusiness(self): return len(self.Company) + len(self.Industry) > 0
class OtherFactModel(Mapping): value = TextField()