Example #1
0
 def update_edit(ip, e_type):
     edit = Edit(ip)
     edit.entity_id = entity.id
     edit.edit_type = e_type
     edit.edit_time = datetime.utcnow()
     db.add(edit)
     db.commit()
Example #2
0
 def update_edit(ip, e_type):
     edit = Edit(ip)
     edit.entity_id = entity.id
     edit.edit_type = e_type
     edit.edit_time = datetime.utcnow()
     db.add(edit)
     db.commit()
Example #3
0
def save_edited_image():
    # db.session.expire_all()
    req = request.get_json()

    if request.method == 'POST':
        # if ("user_id" in req) and ("org_id" in req) and ("photo" in req):
        if ("user_id" in req) and ("org_id" in req) and ("photo" in req) and (
                "date_edited" in req):
            # assume photo is in string base64 form. we need to change to longblob form
            photo_decoded = b64decode(req['photo'])

            edited = Edit(user_id=req['user_id'],
                          org_id=req['org_id'],
                          photo=photo_decoded,
                          date_edited=req['date_edited'])

            db.session.add(edited)
            db.session.commit()
            db.session.refresh(edited)
            # edited_id = edited.id
            # edited.set

            #edit_obj=db.session.query(Edit).get(edited.id)
            sql1 = '''
            UPDATE edit
            SET mark_id = mark_id + 1
            WHERE edit.edit_id = :edit_id
            '''
            param1 = {'edit_id': edited.id}
            engine.execute(text(sql1), param1)

            sql2 = '''
            UPDATE original
            SET mark_num = mark_num + 1
            WHERE original.org_id = :org_id
            '''
            param2 = {'org_id': req['org_id']}
            engine.execute(text(sql2), param2)

            try:
                connection = engine.connect()
                trans = connection.begin()
                trans.commit()
            except:
                trans.rollback()
                return "commit failed, failure in system!"

            # edit_obj.set()

            #return f"'{edit_obj.mark_id}'"
            return redirect(url_for('show_all_edit'))

        else:
            return "Bad request, request should be json object that inclue key of 'user_id', 'org_id', 'photo', 'date'!"
    else:
        return f"(save_edited_image)No request received, request should be POST method"
Example #4
0
def wenda():
    form = PostForm()
    if request.method == 'POST':
        title = request.form.get('title')
        content = request.form.get('content')
        user_id = g.user.id
        edit = Edit(title=title, content=content, user_id=user_id)
        db.session.add(edit)
        db.session.commit()
        id = edit.id
        return redirect(url_for('home.wendapost', id=id))
    return render_template('testmkd.html', form=form)
def transform(request):
# Handle file upload
	if request.method == 'POST':
		print("Transform POST")
		form = EditForm(request.POST, request.FILES)
		if form.is_valid():
			dataset = request.POST['dataset']
			num_id = Edit.objects.filter(dataset = dataset).aggregate(Max('num_id')).get('num_id__max')
			if num_id == None:
				num_id = 1
			else:
				num_id += 1
			desc = request.POST['desc']
			original = request.FILES['original']
			result = original
			new_edit = Edit(num_id = num_id, dataset = dataset, desc = desc, original = original, result = result)
			new_edit.save()
			
			if dataset == 'bird':
				result = bird_model(original, desc)
				new_edit.original.save(
					os.path.basename(new_edit.original.url),
					File(open("/home/parth/College/BE_Project/BEProj/gallery/app/bird_temp.jpg", 'rb'))
				)
			
			else:
				result = fashion_model(original, desc)
			
			new_edit.result.save(
				os.path.basename(new_edit.result.url),
				File(open("/home/parth/College/BE_Project/BEProj/gallery/app/temp.jpg", 'rb'))
			)
			new_edit.save()

			# Redirect to the document list after POST
			return HttpResponseRedirect(reverse(views.transform))
	else:
		print("Transform GET")
		form = EditForm()
		try:	
			last_edit = Edit.objects.latest('id')
			return render(request, 'app/form.html', {'last_edit': last_edit, 'form': form})
		except Exception as e:
			print(e)
			return render(request, 'app/form.html', {'form': form})
def transform_old(request, id, side):
	x = Edit.objects.get(id = id)
	field_object = Edit._meta.get_field(side)
	field_value = field_object.value_from_object(x)
	if request.method == 'POST':
		print("OLD POST")
		form = OldEditForm(request.POST)
		if form.is_valid():
			dataset = x.dataset
			num_id = Edit.objects.filter(dataset = dataset).aggregate(Max('num_id')).get('num_id__max')
			if num_id == None:
				num_id = 1
			else:
				num_id += 1
			desc = request.POST['desc']

			new_edit = Edit(num_id = num_id, dataset = dataset, desc = desc)

			if side == 'original':
				picture_copy = ContentFile(x.original.read())
				picture_copy.name = x.original.name.split("/")[-1]
				new_edit.original = picture_copy
				new_edit.result = picture_copy
			
				new_edit.save()
			else:
				picture_copy = ContentFile(x.result.read())
				picture_copy.name = x.result.name.split("/")[-1]
				new_edit.original = picture_copy
				new_edit.result = picture_copy
				new_edit.save()

			original = field_value
			
			if dataset == 'bird':
				result = bird_model(original, desc)
				new_edit.original.save(
					os.path.basename(new_edit.original.url),
					File(open("/home/parth/College/BE_Project/BEProj/gallery/app/bird_temp.jpg", 'rb'))
				)
			
			else:
				result = fashion_model(original, desc)
			
			new_edit.result.save(
				os.path.basename(new_edit.result.url),
				File(open("/home/parth/College/BE_Project/BEProj/gallery/app/temp.jpg", 'rb'))
			)
			new_edit.save()
			
			print('Old edit saved')
			return HttpResponseRedirect(reverse(views.transform))
	else:
		form = OldEditForm()
		if side == 'result':
			img = x.result.url
		else:
			img = x.original.url
		return render(request, 'app/old_edit.html', {'old': img, 'form': form, 'id': id, 'side': side})