Exemplo n.º 1
0
    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
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
 def reverseImage(self):
     return splitByLanguage(
         self.googleData['Imagen Reverso | Reverse Image'], self.language)
Exemplo n.º 4
0
 def obverseImage(self):
     return splitByLanguage(
         self.googleData['Imagen Anverso | Obverse Image'], self.language)
Exemplo n.º 5
0
 def name(self):
     return splitByLanguage(self.googleData['Nombre | Name'], self.language)
Exemplo n.º 6
0
 def mintLink(self):
     return splitByLanguage(
         self.googleData['Link de la Ceca | Mint\'s Link'], self.language)
Exemplo n.º 7
0
 def link(self):
     return splitByLanguage(self.googleData['Link'], self.language)
Exemplo n.º 8
0
 def type(self):
     return splitByLanguage(self.googleData['Tipo | Type'], self.language)
Exemplo n.º 9
0
 def denomination(self):
     return splitByLanguage(self.googleData['Denominación | Denomination'],
                            self.language)
Exemplo n.º 10
0
 def date(self):
     return splitByLanguage(
         self.googleData['Fecha de fabricación | Date of issue'],
         self.language)
Exemplo n.º 11
0
 def country(self):
     return splitByLanguage(self.googleData['País | Country'],
                            self.language)
Exemplo n.º 12
0
 def cost(self):
     return splitByLanguage(self.googleData['Coste | Cost'], self.language)
Exemplo n.º 13
0
 def composition(self):
     return splitByLanguage(self.googleData['Composición | Composition'],
                            self.language)
Exemplo n.º 14
0
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)
Exemplo n.º 15
0
def interestingLinks(language='es'):
    site = Site(
        language,
        splitByLanguage('Links Interesantes | Interesting Links', language))

    return render_template('interesting-links.html', site=site)
Exemplo n.º 16
0
 def serialNumber(self):
     return splitByLanguage(
         self.googleData['Número de Serie | Serial numbers'], self.language)
Exemplo n.º 17
0
 def seriesNumber(self):
     return splitByLanguage(
         self.googleData['Año de la serie | Series number'], self.language)
Exemplo n.º 18
0
 def diameter(self):
     return splitByLanguage(self.googleData['Diámetro | Diameter'],
                            self.language)
Exemplo n.º 19
0
 def value(self):
     return splitByLanguage(self.googleData['Valor | Value'], self.language)
Exemplo n.º 20
0
 def grading(self):
     return splitByLanguage(self.googleData['Estado | Grading'],
                            self.language)