def addTags(obj, tags):
    """Adds tags from a supplied list to an object of type Profile or Post.
    Returns nothing.
    
    Creates a new Tag object if tag is new to the system.
    Will not create duplicates but will add to interest of pre-existing Tag objects.
    """
    passed = ""
    for tag in tags:
        if len(tag) < System.maxTag:
            cleanTag = ' '.join(tag.split())
            if Tag.objects.filter(name=cleanTag).count():
                t = Tag.objects.filter(name=cleanTag.lower()).order_by('?')[0]
                t.interest += 1
                t.save()
            else:
                t = Tag(name=cleanTag.lower(), interest=1)
                t.save()
            if isinstance(obj, Post):
                obj.post_profile.tags.add(t)  
                obj.post_profile.save()  
            obj.tags.add(t)
            passed += cleanTag + ', '
    obj.save()
    return passed[:-2]
 def test_create_tag(self):
     count_tags = Tag.objects.count()
     tag = Tag(name='Linux-по-русски')
     tag.full_clean()
     tag.save()
     self.assertEqual(Tag.objects.count(), count_tags + 1)
     self.assertEqual(tag.name, 'Linux-по-русски')
Beispiel #3
0
def update(tagsstr):
  tags_strlist = tagsstr_to_taglist(tagsstr)
  tags = list(Tag.objects.filter(text__in=tags_strlist))
  existing_strlist = map(lambda tag: tag.text, tags)
  for tag_str in set(tags_strlist).difference(set(existing_strlist)):
    # TODO howto save in one query?
    tag = Tag()
    tag.text = tag_str
    tag.save()
    tags.append(tag)
  return tags
Beispiel #4
0
def update(tagsstr):
    tags_strlist = tagsstr_to_taglist(tagsstr)
    tags = list(Tag.objects.filter(text__in=tags_strlist))
    existing_strlist = map(lambda tag: tag.text, tags)
    for tag_str in set(tags_strlist).difference(set(existing_strlist)):
        # TODO howto save in one query?
        tag = Tag()
        tag.text = tag_str
        tag.save()
        tags.append(tag)
    return tags
def setupOpen(pop):

    #SETUP ABANDONED PROFILES
    if pop > 1:
        populate(pop)
    #profiles = Profile.objects.all()
    #for p in profiles:
    #    makeFriends(p)
    
    #SETUP TAGS
    for t in initialTags():
        d = Tag(name=t)
        d.save()
        
    #MAKE RANGER
    ranger = Profile(
        fname='Ranger',
        lname='Lyman',
        gender=Gender.female,
        age=30,
        location='Indianapolis, Indiana',
        last_login=timezone.now(),
        species=Species.system,
        img_number=1,
        energy=1983,
        visible=True
    )
    ranger.save()
    rangerPost = "Thank you for visiting the openspace wilderness. I am here to assist you as well as post occasional updates and additional info about the park. Have fun exploring, and be careful out there in the wilds."
    makeTaggedPost(ranger, rangerPost, 'protected')
    
    #SEED Visitor
    makeAnonymous()
    
    #SEED PREY PROFILES
    for p in initialPreyProfiles():
        newProfile = Profile(
            fname=p['fname'],
            lname=p['lname'],
            gender=p['gender'],
            age=p['age'],
            location=p['location'],
            last_login=timezone.now(),
            species=Species.forager,
            energy=System.energy,
            visible=False
        )
        newProfile.save()
        assignImages(newProfile)
        makeBirthPost(newProfile)