def allowRegistration(self, event): if not event: return False if not self.registrationForm: return False now = localize(datetime.now()) if hasattr(event, 'free_registration_deadline'): registration_deadline = getattr(event, 'free_registration_deadline') if registration_deadline: if now > localize(registration_deadline): return False if now > event.end: return False if hasattr(event, 'free_registration_attendee_limit'): attendee_limit = getattr(event, 'free_registration_attendee_limit') if attendee_limit: attendeeCount = self.getAttendeeCount() if attendeeCount >= attendee_limit: return False return True
def get_entry_date(self, _): date_published_parsed = _.get('published_parsed') updated_parsed = _.get('updated_parsed') effective = _.get('effective', None) fmt = '%%Y-%%m-%%d %%H:%%M %s' % DEFAULT_TIMEZONE now = datetime.now() dateStamp = now.strftime(fmt) if effective: dateStamp = effective elif date_published_parsed: local_time = time.localtime(timegm(date_published_parsed)) dateStamp = time.strftime(fmt, local_time) elif updated_parsed and isinstance(updated_parsed, time.struct_time): dateStamp = time.strftime(fmt, updated_parsed) return localize(DateTime(dateStamp))
def min_pub_date(self): _ = DateTime() - (365.25 * self.years) _ = DateTime('%d-01-01' % _.year()) return localize(_)
def import_content(self): username = getattr(self.context, 'username', None) if username: try: data = self.get_publications_json(username) except: pass else: if data and isinstance(data, (list, tuple)): publications = [] for __ in data: _ = __.get('attributes', {}) contributors = [ "%s, %s" % ( x.get('last_name', ''), x.get('first_name', ''), ) for x in _.get('contributors', []) if x.get('last_name', '') ] try: published_on = localize( DateTime("%s 00:00:00 US/Eastern" % _['published_on'])) except: published_on = None abstract = _.get('abstract', None) if abstract: abstract = RichTextValue( raw=abstract, mimeType=u'text/html', outputMimeType='text/x-html-safe') publications.append({ 'ai_id': __.get('id', None), 'title': _.get('title', None), 'doi': _.get('doi', None), 'journal_title': _.get('journal_title', None), 'published_on': published_on, 'abstract': abstract, 'contributors': contributors, }) self.context.publications = self.sort_filter(publications) self.context.reindexObject() transaction.commit() self.log(u"Imported %d publications for %s" % (len(publications), username))
def fmt_date(x): return localize(DateTime(x.replace("T", ' ') + " US/Eastern"))
def initial_date(self): return localize(datetime.strptime(self._initial_date, '%Y-%m-%d'))
def data(self): context = self.context data = {} if ICollegeHomepage.providedBy(self.context): data = { '@context': 'http://schema.org', '@type': 'EducationalOrganization', 'address': { '@type': 'PostalAddress', 'addressLocality': 'University Park', 'addressRegion': 'PA', 'postalCode': '16802', 'streetAddress': 'Penn State University'}, 'logo': 'https://agsci.psu.edu/psu-agsciences-logo.png', 'name': 'Penn State College of Agricultural Sciences', 'sameAs': [ 'https://www.facebook.com/agsciences', 'https://www.twitter.com/agsciences', 'https://plus.google.com/+PennStateAgSciences', 'https://instagram.com/agsciences', 'https://www.linkedin.com/company/penn-state-college-of-agricultural-sciences', 'https://www.youtube.com/psuagsciences', 'https://en.wikipedia.org/wiki/Penn_State_College_of_Agricultural_Sciences'], 'telephone': '+1-814-865-7521', 'url': 'https://agsci.psu.edu' } elif IEvent.providedBy(context): data = { '@context': 'http://schema.org', '@type': 'Event', 'name': context.Title(), 'description' : context.Description(), 'startDate' : localize(context.start).isoformat(), 'endDate' : localize(context.end).isoformat(), 'url' : context.absolute_url(), 'location' : { "@type" : "Place", "address" : getattr(context, 'location', ''), "name" : getattr(context, 'location', ''), } } elif INewsItem.providedBy(context): data = { '@context': 'http://schema.org', '@type': 'Article', 'headline': context.Title(), 'description' : context.Description(), 'datePublished' : localize(context.effective()).isoformat(), 'url' : context.absolute_url(), } elif IPerson.providedBy(context): # Job Title job_titles = getattr(context, 'job_titles', []) if job_titles: job_title = job_titles[0] else: job_title = "" # Email email = getattr(context, 'email', '') # Name (first_name, middle_name, last_name) = [getattr(context, x, '') for x in ('first_name', 'middle_name', 'last_name')] # Address street_address = getattr(context, 'street_address', []) if street_address: street_address = [x for x in street_address if x] street_address = ', '.join(street_address) city = getattr(context, 'city', '') state = getattr(context, 'state', '') zip_code = getattr(context, 'zip_code', '') # Phone phone_number = getattr(context, 'phone_number', '') data = { '@context': 'http://schema.org', '@type': 'Person', 'url' : context.absolute_url(), 'email' : email, 'givenName' : first_name, 'additionalName' : middle_name, 'familyName' : last_name, 'telephone' : phone_number, 'jobTitle' : job_title, 'workLocation' : { '@type' : 'PostalAddress', 'addressCountry' : 'US', 'addressLocality' : city, 'addressRegion' : state, 'postalCode' : zip_code, 'streetAddress' : street_address, } } data['image'] = self.image if data: return json.dumps(data, indent=4)