def test_REST_getUsers(self): url = '%s/users' % (SERVER_URL) response = urllib2.urlopen(url).read() users = odict(json.loads(response)).users user1 = odict(users[0]) self.assertEqual(user1.id, ID) self.assertEqual(user1.fullname, FULLNAME) self.assertEqual(user1.created, CREATED) self.assertEqual(user1.uri, URI)
def test_REST_getMessageUser(self): url = '%s/messages/%s' % (SERVER_URL, MESSAGE_ID) response = urllib2.urlopen(url).read() message = odict(json.loads(response)) self.assertEqual(message.user['id'], MESSAGE_USER_ID) self.assertEqual(message.user['fullname'], MESSAGE_USER_FULLNAME)
def _loadData(self): '''Read a single Db Record and add it to self.__dict__ So the following examples syntax will work: user.first_name, message.id message.created ''' if is_int(self.id): filter = '%s=%s' % (self.primary_key, self.id) else: # id is an sql where_clause filter = self.id self.setFilters(filter) results = self.getTable() if not results: raise DataRecordNotFound('%s table: Record not found, %s: %s' % (self.table.title(), self.primary_key, self.id)) # store data in a dictionary self.data = odict(results[0]) # store data as properties of self self.__dict__.update(results[0])
def __init__(self, params, reportColumns): self.params = params self.reportColumns = reportColumns self.sql_params = odict(base_table=params.base_table, base_table_alias=params.base_table_alias) self.where_aliases = [] self.aliases = [] self.prepped = False
def test_REST_getMessage(self): url = '%s/messages/%s' % (SERVER_URL, MESSAGE_ID) response = urllib2.urlopen(url).read() message = odict(json.loads(response)) self.assertEqual(message.id, MESSAGE_ID) self.assertEqual(message.user_id, MESSAGE_USER_ID) self.assertEqual(message.text, MESSAGE_TEXT) self.assertEqual(message.created, MESSAGE_CREATED)
def test_REST_getUser(self): url = '%s/users/%s' % (SERVER_URL, ID) response = urllib2.urlopen(url).read() user = odict(json.loads(response)) self.assertEqual(user.id, ID) self.assertEqual(user.first_name, FIRST_NAME) self.assertEqual(user.last_name, LAST_NAME) self.assertEqual(user.fullname, FULLNAME) self.assertEqual(str(user.created), CREATED)
def _consolidateAndSetDefaultsPics(self): '''Gather all Pics defined in all Pages into data.pics Add defaults for name, caption, and description ''' data = self.data # init a collection of all pics data.pics = odict() # Loop thru each page for page_name in data.pages: # convert data[page_name] to odict data[page_name] = odict(data[page_name]) # does page have html? if 'html' in data[page_name]: data[page_name].html = odict(data[page_name].html) else: data[page_name].html = None # does page have pics: if 'pics' not in data[page_name]: data[page_name].pics = [] continue # make pics a list of odicts rather than of dics: for i, pic in enumerate(data[page_name].pics): data[page_name].pics[i] = odict(pic) # add annotated fields, and consolidate into data.pics for i, pic in enumerate(data[page_name].pics): if 'name' not in pic: pic.name = pic['filename'].split('.')[0] if 'caption' not in pic or not pic.caption: pic.caption = '' if 'description' not in pic: pic.description = '' pic.page_name = page_name data.pics[pic.name] = pic
def _getMessageCard(self, message, search=None): message = odict(message) image = getUserImage(message.user_id) user_icon = div(img(src=image, width='70px', class_='img-thumbnail'), class_='userIcon') username = div(message.author, class_='messageAuthor') reason = div(message.reason, class_='messageReason') date = div(message.created, class_='messageDate') name_link = a(username, href='//%s/profile.py?u=%s' % (self.conf.baseurl, encrypt_int(message.user_id))) username_and_date = div(name_link + reason + date, class_='usernameAndDate') text = urlize(message.text, trim_url_limit=50, nofollow=True, target='_blank') text = self._highlightKeyTerms(text, search) messageLikes = MessageLikes(message) messageComments = MessageComments(message) footer = \ messageLikes.html_widget(self.page.session.user) + \ messageComments.html_widget() # hack need to instantiate m for each mesage: url_previews = '' for preview in Message(message.id).url_previews: preview2 = copy(preview) preview2['thumbnail_width'] = min(preview2['thumbnail_width'], 500) if not preview2['thumbnail_url']: preview2['thumbnail_url'] = '' url_previews += self.url_preview_html.format(**preview2) o = '' o += user_icon + username_and_date o += div(text, class_='messageText') o += url_previews o += div(footer, class_='messageFooter') o += messageLikes.html_likersSection() o += messageComments.html_commentsSection(self.page.session.user, search=search) return div(o, class_='messageCard', id='message_card_%s' % message.id)
def process(self, args): args = odict(args) cmd = args.cmd.lower() if cmd == 'getlists': return self.getLists(args.relational) elif cmd == 'getlistmetadata': return self.getListMetaData(args.list_id) elif cmd == 'exportlist': return self.exportList(args.list_id) elif cmd == 'insertupdaterelationaltable': return self.InsertUpdateRelationalTable(args.list_id, args.csvfile) else: return 'Unrecognized cmd:', cmd
def _loadData(self): '''Read a single Db Record and add it to self.__dict__ So the following examples syntax will work: user.first_name, message.id message.created ''' self.setFilters('%s=%s' % (self.primary_key, self.id)) results = self.getTable() if not results: raise DataRecordError( '%s table: Record not found, %s: %s' % (self.table.title(), self.primary_key, self.id)) # store data in a dictionary self.data = odict(results[0]) # store data as properties of self self.__dict__.update(results[0])
def _gatherMetadata(self, subdir, data): '''Given the name of a media subdirectory Return a data dictionary media's metadata, a actions list a warning list ''' SKIPPERS = ['200px', 'vpics.yaml'] # init actions = [] warnings = [] if not data: # default site_name to subdirname site_name = subdir.split('/')[-1].replace('_', ' ').title() data = odict(site_name = site_name, site_message = '', media_url = 'NEED_TO_SET_THIS_IN_vpics.yaml', pages = []) actions.append('Added site_name: %s' % site_name) # get pages from subdirectories for file in os.listdir(subdir): if file.startswith(CONF_NAME): continue # append pages to data if nec.: if os.path.isdir("%s/%s" % (subdir, file)): if file not in data.pages: data.pages.append(file) else: warnings.append('Unrecognized file: "%s" is not a directory' % file) # get images and phtml files for each page for page in data.pages: # init page_dir = "%s/%s" % (subdir, page) thumbnail_dir = "%s/%s/%s" % (subdir, page, THUMBNAILS) page_filenames = [] if page in data: page_filenames = [x['filename'] for x in data[page]['pics']] if page not in data: data[page] = odict(pics=[], html={}) # check directory exists: if not os.path.isdir(page_dir): del data[page] del data.pages[data.pages.index(page)] actions.append('Removed page "%s" - Subdirectory no longer ' 'found' % page) continue # loop thru subdirectory files in reverse order and prepend them # This allows # 1. inital alphabetical listing # 2. newest files to the top when added for file in os.listdir(page_dir): if file in SKIPPERS: continue ext = file.split('.')[-1] # html pages: if ext in ('html', 'phtml'): if 'filename' in data[page].html: if data[page].html['filename'] != file: warnings.append('Page "%s" already has a phtml ' 'file: "%s". Skipping "%s"' % (page, data[page].html.filename, file)) else: # add html file data[page].html = odict(filename=file) actions.append('Page "%s": added html filename: %s' % (page, file)) # Pictures elif ext in ('png', 'jpg', 'jpeg'): if file not in page_filenames: pic = odict(name=file.replace('.'+ext, ''), filename=file, caption='', description='') data[page].pics.insert(0, pic) actions.append('Page "%s": added pic: %s' % (page, file)) # Unknowns else: warnings.append('Unrecognized file extention: "%s". ' 'File: "%s/%s/%s"' % (ext, subdir, page, file)) # look for thumbnail dir if not data[page].html and data[page].pics and \ not os.path.exists(thumbnail_dir): warnings.append('Thumbnail directory for page "%s" ' 'not found: %s' % (page, thumbnail_dir)) # Page Clean up pages = copy.copy(data.pages) for page in pages: # remove empty pages from data if ('html' not in data[page] or not data[page]['html']) and \ ('pics' not in data[page] or not data[page]['pics']): del data[page] del data.pages[data.pages.index(page)] warnings.append('Page %s is empty, not including in config' % page) continue # remove pics from pages with html if ('html' in data[page] and data[page]['html']): data[page]['pics'] = {} return data, actions, warnings