def makeBuildAbandoned(blogNo):
    """Function specifically for fully populating the database from all recovered blogs."""
    blogId, url, lastUpdate, posts = pullBlogFilter(blogNo)
    if blogId:
        fn, ln, gn = nameGenerate()
        profile = Profile(
            fname = fn,
            lname = ln,
            gender = gn,
            age = ageGenerate(),
            location = locationGenerate(),
            species = Species.abandoned,
            blog_id = blogId,
            blog_url = url,
            last_login = lastUpdate
        )
        profile.position = profile.id
        assignImages(profile)
        for post in posts:
            newPost = Post(
                post_profile=profile,
                date_published=post[1],
                post_content=re.sub('<[^<]+?>', '', post[2])
            )
            newPost.save()
        return profile
    return None
def makeProfile(speciesType):
    """Creates and returns a new Profile object of provided speciesType.
    
    This will generate first name, last name, gender, age, and location and create
    a new Profile object. If the Profile is of species type 'abandoned' it will be
    populated with the data from a particular recovered blog from the reserves.
    
    If the Profile is of a different (active) species type it will swap positions
    with a pre-existing Profile object, be set to visible = False, given an initial
    energy value and have a Post created in honor of its birth.
    """
    fn, ln, gn = nameGenerate()
    profile = Profile(
        fname = fn,
        lname = ln,
        gender = gn,
        age = ageGenerate(),
        location = locationGenerate(),
        species = speciesType
    )
    assignImages(profile) #contains a profile.save()
    if speciesType == Species.abandoned:
        profile.blog_id, profile.blog_url, profile.last_login = makePosts(profile)
        profile.position = profile.id
        profile.save()
    else:
        swapPosition(profile, Profile.objects.all().order_by('?')[0])
        profile.last_login = timezone.now()
        profile.visible = False
        profile.energy = System.energy
        profile.save()
        makeBirthPost(profile)
    return profile
Exemplo n.º 3
0
    def test_profile(self):
        from apps.profiles.models import Profile

        p = Profile()
        self.assertEqual(len(p.my_packages()), 0)

        r = MockGithubRepo()
        self.assertEqual(p.url_for_repo(r), None)
Exemplo n.º 4
0
def user_create_handler(sender, instance, created, **kwargs):
    """
    post create user 后创建一对一的 profile/invite/collection
    """
    if created:
        # 创建 profile
        profile = Profile(user=instance)
        profile.save()
        # 创建 invite
        invite = Invite(user=instance)
        invite.save()
        # 创建 collection
        collection = Collection(user=instance)
        collection.save()
        # 超级管理员才能 创建 merchant
        if instance.is_superuser:
            merchant = Merchant(name=instance.username + '_商户')
            merchant.save()
            instance.merchant = merchant
            instance.save()
Exemplo n.º 5
0
    def post(self, request, format=None):
        """
        Creates a new profile
        """
        serializer = self.serializer_class(data=request.data)
        if serializer.is_valid():

            # Getting serialized data
            request_data = serializer.data
            if not User.objects.filter(email=request_data['email']):
                try:
                    with transaction.atomic():
                        # Creating user
                        user = User()
                        user.email = request_data['email']
                        user.set_password(request_data['password'])
                        user.save()

                        # Creating profile
                        profile = Profile()
                        profile.user = user
                        profile.first_name = request_data['first_name']
                        profile.last_name = request_data['last_name']
                        profile.documents = request_data['documents']

                        profile.save()
                        return Response({"id": profile.id},
                                        status=status.HTTP_201_CREATED)
                except Exception as e:
                    return Response(
                        {
                            "type": "internal_server_error",
                            "detail": str(e)
                        },
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)
            else:
                return Response({"type": "profile_already_exist"},
                                status=status.HTTP_409_CONFLICT)

        else:
            return Response(
                {
                    "type": "validation_error",
                    "errors": serializer.errors
                },
                status=status.HTTP_400_BAD_REQUEST)
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)