示例#1
0
 def process(self, request):
     timedelta_args = {
         self.cleaned_data['duration_unit']: int(self.cleaned_data['duration_value']),
     }
     deadline = datetime.datetime.now() + datetime.timedelta(**timedelta_args)
     promise = Promise(
         text=self.cleaned_data['promise_text'],
         deadline=deadline,
         creator=request.user.profile,
     )
     promise.save()
     return promise
    def handle(self, *args, **kwargs):
        connection.flushdb()

        name_list = [
            "fabio",
            "lincoln",
            "suneel",
            "henry",
            "vin",
            "laura",
            "gabriel",
            "ben",
            "nytia",
            "joe",
            "zach",
            "adam",
            "alice",
            "david",
            "carl",
            "steve",
        ]

        stuff = [
            "learn to play gitar",
            "learn to play piano",
            "workout",
            "code more",
            "code less",
            "work less",
            "work more",
        ]

        for name in name_list:
            try:
                user = User.objects.create_user(username=name, password="******")
            except IntegrityError:
                user = User.objects.get(username=name)

            profile = Profile.objects.get(user=user)
            msg = "I, {}, promise that I'll {}"
            stuff_copy = stuff[:]

            for x in range(randint(2, 4)):
                chosen_stuff = choice(stuff_copy)
                stuff_copy.remove(chosen_stuff)
                deadline = datetime.datetime.now() + datetime.timedelta(days=x + randint(2, 5))

                promise = Promise(text=msg.format(name, chosen_stuff), deadline=deadline, creator=profile)
                promise.save()