Esempio n. 1
0
def update_categories(data_import, cats_list):
    if (not data_import): return
    #clear out all existing categories for Data Import
    Categories.remove_obj(data_import)

    #now add the Categories
    if cats_list:
        for cat_id in cats_list.split(","):
            try:
                Categories.objects.get(id=cat_id.strip()).add_object(data_import)
            except (ValidationError, Categories.DoesNotExist) as e:
                pass
Esempio n. 2
0
 def post_save(self, obj, created=False):
     f = self.request.FILES.get('file', None)
     save_image(f, obj, 'image', 'name', 'location/')
     if self.custom_field_form:
         serializer = FormSchemaSerializer(
             data=self.custom_field_form)
         if serializer.is_valid():
             form_object = serializer.save(force_insert=True)
             obj.custom_field_form = form_object
             obj.save()
     if self.tags:
         for tag in self.tags:
             print tag
             Categories.objects(id=tag['id']).update_one(push__tagged=obj)
Esempio n. 3
0
 def test_for_object(self):
     di = DataImport(name="junk",
                     duplicate_content="no",
                     last_updated=datetime.now(),
                     upload_format="csv",
                     upload_type="1")
     di.save()
     cat = Categories(name="test cat", tagged=[self.loc, di])
     cat.save()
     self.assertEqual(cat.name, Categories.for_object(di)[0].name)
     self.assertEqual(1, len(Categories.for_object(di)))
     self.assertEqual(cat.name, Categories.for_object(self.loc)[0].name)
     self.assertEqual(1, len(Categories.for_object(self.loc)))
     cat.delete()
     di.delete()
Esempio n. 4
0
    def test_add_object(self):

        di = DataImport(name="junk",
                        duplicate_content="no",
                        last_updated=datetime.now(),
                        upload_format="csv",
                        upload_type="1")
        di.save()
        cat = Categories(name="test cat", tagged=[di])
        cat.save()

        tagged = Categories.objects_with("test cat")
        self.assertEqual(tagged, [di])

        cat.add_object(self.loc)

        tagged = Categories.objects_with("test cat")
        self.assertEqual(tagged, [di, self.loc])

        cat.delete()
        di.delete()
Esempio n. 5
0
def members_location_view(request, id):
    from maps.categories.models import Categories
    data['role'] = role
    data['object'] = Location.objects.get(id=id)
    data['owner'] = data['object'].created_by
    data['user'] = request.user
    try:
        data['frontforms'] = data['object'].frontend_form()[0]['field_groups']
    except IndexError:
        print('Location has no frontend forms')

    data['categories'] = Categories.for_object(data['object'])


    return render_to_response('homepage/members-location.html', data, context_instance=RequestContext(request))
Esempio n. 6
0
    def test_cats_for_obj_id(self):
        di = DataImport(name="junk",
                        duplicate_content="no",
                        last_updated=datetime.now(),
                        upload_format="csv",
                        upload_type="1")
        di.save()
        cat = Categories(name="test cat", tagged=[self.loc, di])
        cat.save()
        found_cats = Categories.for_object_id(str(di.id), "DataImport")
        self.assertEqual(1, len(found_cats))

        cat.delete()
        di.delete()
Esempio n. 7
0
 def test_cats_tagged_holds_anything(self):
     di = DataImport(name="junk",
                     duplicate_content="no",
                     last_updated=datetime.now(),
                     upload_format="csv",
                     upload_type="1")
     di.save()
     cat = Categories(name="test cat", tagged=[self.loc, di])
     cat.save()
     self.assertEqual(2, cat.number_using)
     cat.delete()
     di.delete()
Esempio n. 8
0
    def test_location_get_tags(self):
        for l in Location.objects.filter(name="loc-with-cat2"):
            l.delete()

        loc = Location(name="loc-with-cat2")
        loc.save()
        cat = Categories(name="food-test2", tagged=[loc])
        cat.save()
    
        self.assertIn(cat, loc.tags)
        self.assertEqual(1, len(loc.tags))


        loc.delete()
        cat.delete()
        
        pass
Esempio n. 9
0
    def test_update_categories(self):
        di = DataImport(name="junk",
                        duplicate_content="no",
                        last_updated=datetime.datetime.now(),
                        upload_format="csv",
                        upload_type="1")
        di.save()

        cat = Categories(name="test cat")
        cat.save()
        cat2 = Categories(name="test cat2")
        cat2.save()

        cat_list = "%s,%s" % (str(cat.id), str(cat2.id))

        self.assertEqual(0, len(Categories.objects_with("test cat")))
        self.assertEqual(0, len(Categories.objects_with("test cat2")))
        self.assertEqual(0, len(Categories.for_object(di)))

        update_categories(di, cat_list)

        self.assertEqual(1, len(Categories.objects_with("test cat")))
        self.assertEqual(1, len(Categories.objects_with("test cat2")))

        self.assertEqual(2, len(Categories.for_object(di)))
        self.assertEqual("test cat", Categories.for_object(di)[0].name)
        self.assertEqual("test cat2", Categories.for_object(di)[1].name)

        di.delete()
        cat.delete()
        cat2.delete()
Esempio n. 10
0
    def test_update_categories_work_with_invalid_category(self):
        di = DataImport(name="junk",
                        duplicate_content="no",
                        last_updated=datetime.datetime.now(),
                        upload_format="csv",
                        upload_type="1")
        di.save()
        cat = Categories(name="test cat")
        cat.save()

        cat_list = "i'm not a category,56485cb53f3aaaaaaaaaaaaa, %s" % (str(
            cat.id))

        self.assertEqual(0, len(Categories.objects_with("test cat")))
        self.assertEqual(0, len(Categories.for_object(di)))

        update_categories(di, cat_list)

        self.assertEqual(1, len(Categories.objects_with("test cat")))

        self.assertEqual(1, len(Categories.for_object(di)))
        self.assertEqual("test cat", Categories.for_object(di)[0].name)

        di.delete()
        cat.delete()
Esempio n. 11
0
 def test_cats_number_using(self):
     cat = Categories(name="test cat", tagged=[self.loc])
     cat.save()
     self.assertEqual(1, cat.number_using)
     cat.delete()
Esempio n. 12
0
 def test_cats_get_all_tagged_handles_missing(self):
     tagged = Categories.objects_with("I'm not there")
     self.assertEqual(tagged, [])
Esempio n. 13
0
    def test_remove_obj(self):
        di = DataImport(name="junk",
                        duplicate_content="no",
                        last_updated=datetime.now(),
                        upload_format="csv",
                        upload_type="1")
        di.save()
        cat = Categories(name="test cat", tagged=[self.loc, di])
        cat.save()
        cat2 = Categories(name="garfield", tagged=[self.loc])
        cat2.save()

        self.assertEqual(2, len(Categories.for_object(self.loc)))

        Categories.remove_obj(self.loc)

        self.assertEqual(0, len(Categories.for_object(self.loc)))

        di.delete()
        cat.delete()
        cat2.delete()