def render(request, template, vars=None): baseVars = {} baseVars["debug"] = settings.DEBUG baseVars["FACEBOOK_API_KEY"] = settings.FACEBOOK_API_KEY baseVars["FACEBOOK_SECRET_KEY"] = settings.FACEBOOK_SECRET_KEY baseVars["USER_FILES_URL"] = StringUtils.addTrailingSlash( settings_local.USER_FILES_URL) baseVars["USER_FILES_THUMBS_BIG"] = StringUtils.addTrailingSlash( settings_local.USER_FILES_THUMBS_BIG) baseVars["USER_FILES_THUMBS_MEDIUM"] = StringUtils.addTrailingSlash( settings_local.USER_FILES_THUMBS_MEDIUM) baseVars["USER_FILES_THUMBS_SMALL"] = StringUtils.addTrailingSlash( settings_local.USER_FILES_THUMBS_SMALL) baseVars["USER_FILES_THUMBS_TINY"] = StringUtils.addTrailingSlash( settings_local.USER_FILES_THUMBS_TINY) baseVars["POLL_FILES_URL"] = StringUtils.addTrailingSlash( settings_local.POLL_FILES_URL) baseVars["POLL_RESULTS_MAGIC_THRESH"] = consts.POLL_RESULTS_MAGIC_THRESH baseVars["SITE_NAME"] = consts.SITE_NAME baseVars["leader_board_ad"] = adfactory.get_leaderboard() baseVars["med_square_ad"] = adfactory.get_medium_square() baseVars[ "POLL_VOTES_BEFORE_PERMANENTLY_ACTIVE"] = consts.POLL_VOTES_BEFORE_PERMANENTLY_ACTIVE tags = Tag.objects.filter().order_by( '-poll_count')[:100] #@UndefinedVariable baseVars["header_tags"] = tags if request.user.is_authenticated(): user = request.user baseVars["user"] = user us = UserService(user) data = us.getUserData() msgCount = PollsterMessage.objects.filter( read=False, to_user=request.user).count() #@UndefinedVariable baseVars["newMail"] = msgCount > 0 baseVars["newMailCnt"] = msgCount baseVars["profile_pic"] = data.profile_pic # if conflict between child class and base class vars then child wins # so child can override base vars if vars: baseVars.update(vars) return render_to_response(template, baseVars)
def uploadFile(file, upload_path=None, thumbnails=None): uploadPath = upload_path uploadPath = StringUtils.addTrailingSlash(uploadPath) uploadPath += file.name.lower() uploadPath = FileUtils.getUniqueFileName(uploadPath) # get extension ext = uploadPath[uploadPath.rfind('.'):] #pathtupe ROCKS pathTuple = os.path.split(uploadPath) # check whitelists! if consts.IMAGES_WHITE_LIST.count( ext.lower()) > 0 or consts.OTHER_FILES_WHITE_LIST.count( ext.lower()) > 0: # write file destination = open(uploadPath, 'wb+') for chunk in file.chunks(): destination.write(chunk) destination.close() # if it's an image let's make a thumbnail YAY!!!!!!!!! if consts.IMAGES_WHITE_LIST.count(ext) > 0: for path, width, height in thumbnails: thumbPath = pathTuple[0] + "/" + path + pathTuple[1] # create thumbnails img = Image.open(uploadPath) img.thumbnail((width, height), Image.ANTIALIAS) img.save(thumbPath) else: logging.getLogger("FileUtils").warning( "invalid file type attempting to be uploaded: " + str(ext)) return None return pathTuple[1]
def get_next_url(self, question): url = StringUtils.cleanForUrl(question) return self.get_next_url_h(url)
def cleanName(name): return StringUtils.cleanWordForUrl(name)