Example #1
0
 def test_slug_unique(self):
     """Comprueba que el slug sea único."""
     category = Category(
         name="Categoría 1",
         description="Descripción categoría 1",
         image=tempfile.NamedTemporaryFile(suffix=".jpg").name)
     with self.assertRaises(IntegrityError):
         category.save()
Example #2
0
def app_db_initialization():
    product_categories = [
        'Assortments', 'Bottle Rockets', 'Cakes - 200g', 'Cakes - 500g',
        'Cakes - NOAB', 'Firecrackers', 'Fountains', 'Novelties',
        'Reloadable Shells', 'Roman Candles', 'Single Shot Tubes', 'Skyrockets'
    ]
    for category in product_categories:
        new_category = Category(name=category)
        new_category.save()  #todo remove
Example #3
0
def cats(request):
    cat_req = urlopen("https://www.eventbriteapi.com/v3/categories/?token=A3KV5OGJFN7YWZI6JLIC")
    json_in = cat_req.read()
    decoded = json.loads(json_in)
    for cat1 in decoded['categories']:
        p = Category(cat_id = cat1['id'], short_name = cat1['short_name'])
        p.save()
        
    #return user to now-populated index page
    return HttpResponseRedirect(reverse('events:index'))
Example #4
0
    def save_category(self, syncher, graph, subject, data_source,
                      category_labels, save_set):
        category = syncher.get(subject)
        if not category:
            category = Category(data_source=self.data_source, url=subject)
            category._changed = True
            category._created = True
        else:
            category._created = False

        for _, literal in graph.preferredLabel(subject):
            with active_language(literal.language):
                if category.name != str(literal):
                    category.name = str(literal)
                    category._changed = True

        if category._changed:
            category.save()

        category.alt_labels.add(category_labels.get(str(subject), []))

        if not getattr(category, '_found', False):
            syncher.mark(category)
        return category
Example #5
0
    def save_category(self, syncher, graph, subject, data_source, category_labels, save_set):
        category = syncher.get(subject)
        if not category:
            category = Category(
                data_source=self.data_source, url=subject)
            category._changed = True
            category._created = True
        else:
            category._created = False

        for _, literal in graph.preferredLabel(subject):
            with active_language(literal.language):
                if category.name != str(literal):
                    category.name = str(literal)
                    category._changed = True

        if category._changed:
            category.save()

        category.alt_labels.add(category_labels.get(str(subject), []))

        if not getattr(category, '_found', False):
            syncher.mark(category)
        return category