def test_split_by_language_returns_expected_string(self): data = 'Spanish | English' # Split String separated by | assert splitByLanguage(data, 'es') == (data.split(' | '))[0] assert splitByLanguage(data, 'en') == (data.split(' | '))[1] # Split String without separator assert splitByLanguage('String', 'es') == 'String' # Split Int assert splitByLanguage(1992, 'es') == 1992
def home(language='es'): site = Site(language, splitByLanguage('Inicio | Home', language)) site.blowUp = True collection = Collection(site) items = collection.asItems() return render_template('home.html', site=site, items=items)
def reverseImage(self): return splitByLanguage( self.googleData['Imagen Reverso | Reverse Image'], self.language)
def obverseImage(self): return splitByLanguage( self.googleData['Imagen Anverso | Obverse Image'], self.language)
def name(self): return splitByLanguage(self.googleData['Nombre | Name'], self.language)
def mintLink(self): return splitByLanguage( self.googleData['Link de la Ceca | Mint\'s Link'], self.language)
def link(self): return splitByLanguage(self.googleData['Link'], self.language)
def type(self): return splitByLanguage(self.googleData['Tipo | Type'], self.language)
def denomination(self): return splitByLanguage(self.googleData['Denominación | Denomination'], self.language)
def date(self): return splitByLanguage( self.googleData['Fecha de fabricación | Date of issue'], self.language)
def country(self): return splitByLanguage(self.googleData['País | Country'], self.language)
def cost(self): return splitByLanguage(self.googleData['Coste | Cost'], self.language)
def composition(self): return splitByLanguage(self.googleData['Composición | Composition'], self.language)
def form(language='es'): site = Site( language, splitByLanguage( 'Añadir un Objeto a la Colección | Add an Item to the Collection', language)) collection = Collection(site) # Ensure the form is being sent. if request.method == 'POST': # Upload the images first to SmartFile and once we get the URLs for the images # we will update our Google Spreadsheet to include that URLs. if not request.files['obverse'] or not request.files['reverse']: return render_template('form-error.html', site=site) else: # Builds the folder structure to store the image. filePath = 'Items/' + splitByLanguage( request.form.get('type'), 'en') + '/' + splitByLanguage( request.form.get('country'), 'en') + '/' + splitByLanguage( request.form.get('date'), 'en') # Creates the folder if needed. collection.smartFileClient.put('/path/oper/mkdir/' + filePath) # Generates the file name based on the item name. fileName = stringToURL( splitByLanguage(request.form.get('name'), 'en')) # Updates the file name to be uploaded with the correct name. obverse = request.files['obverse'] obverse.filename = fileName + '-obverse.jpg' reverse = request.files['reverse'] reverse.filename = fileName + '-reverse.jpg' # Uploads the Obverse and Reverse images. collection.smartFileClient.post('/path/data/' + filePath, file=(obverse.filename, obverse)) collection.smartFileClient.post('/path/data/' + filePath, file=(reverse.filename, reverse)) # Generates the href for the images to be saved in the Google Spreadsheet. obverseURL = collection.smartFileClient.post('/link', path=filePath + '/' + obverse.filename) reverseURL = collection.smartFileClient.post('/link', path=filePath + '/' + reverse.filename) if ('href' in obverseURL and 'href' in reverseURL): # Insert our data in the Google Spreadsheet. insertData = [ request.form.get('type'), request.form.get('name'), obverseURL['href'] + request.files['obverse'].filename, reverseURL['href'] + request.files['reverse'].filename, request.form.get('country'), request.form.get('denomination'), request.form.get('date'), request.form.get('diameter'), request.form.get('composition'), request.form.get('series'), request.form.get('serial'), request.form.get('grading'), request.form.get('value'), request.form.get('cost'), prepareItemLink(request.form.get('type'), request.form.get('country'), request.form.get('date'), request.form.get('name')), request.form.get('mint'), ] rowCount = len(collection.googleData) # It is being inserted with +2 in the row Count to increase the total +1, but also taking into account the header row. collection.googleSheet.insert_row(insertData, rowCount + 2) return render_template('form-success.html', site=site) else: return render_template('form-error.html', site=site) return render_template('form.html', site=site)
def interestingLinks(language='es'): site = Site( language, splitByLanguage('Links Interesantes | Interesting Links', language)) return render_template('interesting-links.html', site=site)
def serialNumber(self): return splitByLanguage( self.googleData['Número de Serie | Serial numbers'], self.language)
def seriesNumber(self): return splitByLanguage( self.googleData['Año de la serie | Series number'], self.language)
def diameter(self): return splitByLanguage(self.googleData['Diámetro | Diameter'], self.language)
def value(self): return splitByLanguage(self.googleData['Valor | Value'], self.language)
def grading(self): return splitByLanguage(self.googleData['Estado | Grading'], self.language)