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

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