示例#1
0
def validar(request):
	if request.method == 'POST':
		form = AnimalForm(request.POST)

		if form.is_valid(): #valida o tamanho e o tipo do campo de acordo com o que foi determinado
			animal = Animal(**form.cleaned_data) #esse cleaned_data transforma campos em branco para campos NULL, o ** significa lista
			animal.save()

			animal = Animal.objects.all().order_by('nome') #select * from
			
			return render(request,'validar.html',{'form':form, 'animal':animal})
		else:
			return render(request,'index.html',{'form':form})
示例#2
0
 def handle(self, *args, **options):
     print "start\n get data from" + self.url
     data = urllib2.urlopen(self.url)
     j = json.load(data)
     j = j["result"]["records"]
     counter = 0
     for i in j:
         a1 = Animal.objects.filter(accept_num=i["AcceptNum"])
         if not a1:
             counter += 1
             print "new ->"
             print(i["Name"]).encode('utf-8')
             print i["AcceptNum"]
             url = i["ImageName"]
             url_file = url.split("/")[-1]
             f = urllib2.urlopen(url)
             data = f.read()
             with open("src/media/" + url_file, "wb") as code:
                 code.write(data)
             print thumbnail("src/media/" + url_file, "248x350")
             print thumbnail("src/media/" + url_file, "248x350", True)
             a = Animal(
                 name=i["Name"],
                 sex=i["Sex"],
                 type=i["Type"],
                 build=i["Build"],
                 age=i["Age"],
                 variety=i["Variety"],
                 reason=i["Reason"],
                 accept_num=i["AcceptNum"],
                 chip_num=i["ChipNum"],
                 is_sterilization=i["IsSterilization"],
                 hair_type=i["HairType"],
                 note=i["Note"],
                 resettlement=i["Resettlement"],
                 phone=i["Phone"],
                 email=i["Email"],
                 childre_anlong=i["ChildreAnlong"],
                 animal_anlong=i["AnimalAnlong"],
                 bodyweight=i["Bodyweight"],
                 image_name=i["ImageName"],
                 image_file=url_file,
             )
             a.save()
     print "total %s pet updated" % counter
     self.stdout.write('end\n')
示例#3
0
 def handle(self, *args, **options):
     print "start\n get data from" + self.url
     data = urllib2.urlopen(self.url)
     j = json.load(data)
     j = j["result"]["records"]
     counter = 0
     for i in j:
         a1 = Animal.objects.filter(accept_num=i["AcceptNum"])
         if not a1:
             counter += 1
             print "new ->"
             print (i["Name"]).encode("utf-8")
             print i["AcceptNum"]
             url = i["ImageName"]
             url_file = url.split("/")[-1]
             f = urllib2.urlopen(url)
             data = f.read()
             with open("src/media/" + url_file, "wb") as code:
                 code.write(data)
             print thumbnail("src/media/" + url_file, "248x350")
             print thumbnail("src/media/" + url_file, "248x350", True)
             a = Animal(
                 name=i["Name"],
                 sex=i["Sex"],
                 type=i["Type"],
                 build=i["Build"],
                 age=i["Age"],
                 variety=i["Variety"],
                 reason=i["Reason"],
                 accept_num=i["AcceptNum"],
                 chip_num=i["ChipNum"],
                 is_sterilization=i["IsSterilization"],
                 hair_type=i["HairType"],
                 note=i["Note"],
                 resettlement=i["Resettlement"],
                 phone=i["Phone"],
                 email=i["Email"],
                 childre_anlong=i["ChildreAnlong"],
                 animal_anlong=i["AnimalAnlong"],
                 bodyweight=i["Bodyweight"],
                 image_name=i["ImageName"],
                 image_file=url_file,
             )
             a.save()
     print "total %s pet updated" % counter
     self.stdout.write("end\n")
示例#4
0
 def handle(self, *args, **options):
     print self.url
     data = urllib2.urlopen(self.url)
     j = json.load(data)
     for i in j:
         print (i["Name"]).encode('utf-8')
         a1 = Animal.objects.filter(accept_num=i["AcceptNum"])
         print a1
         if not a1:
             url = i["ImageName"]
             url_file = url.split("/")[-1]
             f = urllib2.urlopen(url)
             data = f.read()
             with open("src/media/" + url_file, "wb") as code:
                 code.write(data)
             f.path = "src/media/" + url_file
             f.url = url_file
             print self.thumbnail(f, "248x350")
             print self.thumbnail(f, "248x350", True)
             a = Animal(name=i["Name"],
                        sex=i["Sex"],
                        type=i["Type"],
                        build=i["Build"],
                        age=i["Age"],
                        variety=i["Variety"],
                        reason=i["Reason"],
                        accept_num=i["AcceptNum"],
                        chip_num=i["ChipNum"],
                        is_sterilization=i["IsSterilization"],
                        hair_type=i["HairType"],
                        note=i["Note"],
                        resettlement=i["Resettlement"],
                        phone=i["Phone"],
                        email=i["Email"],
                        childre_anlong=i["ChildreAnlong"],
                        animal_anlong=i["AnimalAnlong"],
                        bodyweight=i["Bodyweight"],
                        image_name=i["ImageName"],
                        image_file=url_file,)
             a.save()
     self.stdout.write('end\n')