I have a model class of which I want two fields to be a choice fields, so to populate those choices I am using an enum as listed below
#models.py
class Transaction(models.Model):
trasaction_status = models.CharField(max_length=255, choices=TransactionStatus.choices())
transaction_type = models.CharField(max_length=255, choices=TransactionType.choices())
#enums.py
class TransactionType(Enum):
IN = "IN",
OUT = "OUT"
@classmethod
def choices(cls):
print(tuple((i.name, i.value) for i in cls))
return tuple((i.name, i.value) for i in cls)
class TransactionStatus(Enum):
INITIATED = "INITIATED",
PENDING = "PENDING",
COMPLETED = "COMPLETED",
FAILED = "FAILED"
ERROR …Run Code Online (Sandbox Code Playgroud) 我有一个具有以下架构的表:
| ID | BUNDLE_ID | IS_ADMIN |
Run Code Online (Sandbox Code Playgroud)
我需要根据某些标准从上表中选择具有 AND 子句的数据,即
IF @FLAG = 1
SELECT *
FROM TABLE A
WHERE A.IS_ADMIN = 1 AND BUNDLE_ID IN (3, 5)
ELSE
SELECT *
FROM TABLE A
WHERE A.IS_ADMIN = 1 AND BUNDLE_ID IN (1, 2)
Run Code Online (Sandbox Code Playgroud)
我可以在单个查询中实现这一点吗?
我对 Python 还很陌生,并开始接触 Kafka。所以我设置了一个 Kafka 代理,我正在尝试使用confluent-kafka与它通信。我已经能够使用它生成和使用简单的消息,但是,我有一些 django 对象需要序列化并将其发送到 kafka。
以前我使用kafka-python,我可以在上面发送和使用 json 消息,但是我遇到了一些奇怪的问题。
#Producer.py
def send_message(topic,message) :
try :
try :
p.produce(topic,message,callback=delivery_callback)
except BufferError as b :
sys.stderr.write('%% Local producer queue is full (%d messages awaiting delivery): try again\n' %len(p))
# Serve delivery callback queue.
# NOTE: Since produce() is an asynchronous API this poll() call
# will most likely not serve the delivery callback for the
# last produce()d message.
p.poll(0)
# Wait until all messages …Run Code Online (Sandbox Code Playgroud) 我有三个编辑文本字段.在这些字段中,我想仅为第一个字段显示软输入键盘,而在后两个字段中禁用这些字段,这些是日期和时间字段.
Edit-Text 1 //Show the keyboard
Edit-Text 2 and 3 //Hide the keyboard
Run Code Online (Sandbox Code Playgroud)
通过使用下面的代码,我可以禁用字段2和3的键盘,但是当用户将焦点放在字段1时,键盘会出现,但是当用户点击字段2或3时,键盘不会隐藏.尽管字段2或3是首先敲击没有键盘出现.
//Code to disable soft input keyboard
public static void disableSoftInputFromAppearing(EditText editText) {
if (Build.VERSION.SDK_INT >= 11) {
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setTextIsSelectable(true);
} else {
editText.setRawInputType(InputType.TYPE_NULL);
editText.setFocusable(true);
}
Run Code Online (Sandbox Code Playgroud)
如果软键盘已经打开,如何隐藏它?
我有两个Rails模型,即Invoice和Invoice_details.一个Invoice_details属于对发票和发票有许多Invoice_details. 我无法使用Invoice中的accepts_nested_attributes_for通过Invoice模型保存Invoice_details.
我收到以下错误:
(0.2ms) BEGIN
(0.2ms) ROLLBACK
Completed 422 Unprocessable Entity in 25ms (ActiveRecord: 4.0ms)
ActiveRecord::RecordInvalid (Validation failed: Invoice details invoice must exist):
app/controllers/api/v1/invoices_controller.rb:17:in `create'
Run Code Online (Sandbox Code Playgroud)
以下是代码段invoice.rb:
class Invoice < ApplicationRecord
has_many :invoice_details
accepts_nested_attributes_for :invoice_details
end
Run Code Online (Sandbox Code Playgroud)
代码段invoice_details.rb:
class InvoiceDetail < ApplicationRecord
belongs_to :invoice
end
Run Code Online (Sandbox Code Playgroud)
该Controller代码:
class Api::V1::InvoicesController < ApplicationController
respond_to :json
def index
comp_id = params[:comp_id]
if comp_id …Run Code Online (Sandbox Code Playgroud) 我正在集成Outlook API,并且为了进行HTTP调用,我使用的是Retrofit版本2.3.0和okHttp3版本3.9.1。 但是,当我进行HTTP调用时,例如:
// Create a logging interceptor to log request and responses
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel( HttpLoggingInterceptor.Level.BODY );
OkHttpClient client = new OkHttpClient.Builder().addInterceptor( interceptor ).build();
// Create and configure the Retrofit object
Retrofit retrofit = new Retrofit.Builder().baseUrl( authority ).client( client ).addConverterFactory( JacksonConverterFactory.create() ).build();
// Generate the token service
TokenService tokenService = retrofit.create( TokenService.class );
try
{
return tokenService.getAccessTokenFromAuthCode( tenantId, getAppId(), getAppPassword(), "authorization_code", authCode, getRedirectUrl() ).execute().body();
}
catch ( IOException e )
{
TokenResponse error = new …Run Code Online (Sandbox Code Playgroud) 我使用 django crontab 设置了一个 cron 作业。根据文档中的定义,我在 cron.py 中定义了一个测试作业,并在 settings.py 中将其定义为以 1 分钟间隔运行。
#cron.py
def test_cron_run():
print("\n\nHello World....!! ",timezone.now())
#settings.py
INSTALLED_APPS = [
'material.theme.cyan',
'material',
'material.admin',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp',
'django_crontab',
]
CRONJOBS = [
('*/1 * * * *', 'myapp.cron.test_cron_run','>>'+os.path.join(BASE_DIR,'log/debug7.log')),
]
Run Code Online (Sandbox Code Playgroud)
我通过运行添加了 cron 作业python3 manage.py crontab add。此外,该作业也被添加,因为我可以看到我是否运行,python3 manage.py crontab show
但是我看不到正在生成的任何日志文件。有什么办法可以调试这个,操作系统日志之类的吗?
我有一个基于 Django 的 Web 应用程序,我试图在这个名为kafka-python的库的帮助下集成 Kafka 。但是,当我尝试向特定主题发送消息时,我收到超时错误,指出:
Traceback (most recent call last):
File "/home/paras/vertex/vertex-1.6/vertex-portal-backend/vertex_app/kafka_service.py", line 67, in send_message
x = producer.send(topic, json_data)
File "/home/paras/.local/lib/python3.6/site-packages/kafka/producer/kafka.py", line 555, in send
self._wait_on_metadata(topic, self.config['max_block_ms'] / 1000.0)
File "/home/paras/.local/lib/python3.6/site-packages/kafka/producer/kafka.py", line 682, in _wait_on_metadata
"Failed to update metadata after %.1f secs." % (max_wait,))
kafka.errors.KafkaTimeoutError: KafkaTimeoutError: Failed to update metadata after 60.0 secs.
Run Code Online (Sandbox Code Playgroud)
生产消息:
def put_order_into_kafka(order,obj) :
try :
if order is None or offering is None :
raise Exception("Unable to put order into queue …Run Code Online (Sandbox Code Playgroud) 我有一个基于 Web 的应用程序,后端构建在Rails 5上。我在前端使用AngularJS。我没有使用Asset Pipeline来提供任何静态内容,我的所有脚本(JS&CSS)都加载到了index.html文件中,public directory然后我使用 angular 的ng-route来进一步管理位置。
问题出现的时候,我的一个HTML页面,我需要包括图像使用HTML图像标记,问题是,服务器无法找到图像文件。
<img src="assets/images/logo.jpg" style="padding-bottom:20px;" />
Run Code Online (Sandbox Code Playgroud)
我尝试将图像保留在app/assets/images和public/assets/images 目录中,但在所有实例中,我都收到路由错误,指出在我的 rails 服务器控制台中找不到路由。
参考几个堆栈溢出答案,我在我的 config development.rb 文件中尝试了这一行:
config.public_file_server.enabled = true
Run Code Online (Sandbox Code Playgroud)
但它没有用。那么如何在不使用 Rails Assetpipeline 的情况下提供图像?
我对 Python 还很陌生。所以我有一个基于 Flask 的 REST API。所以我有一个字典,如下所示:
dict = {'left': 0.17037454, 'right': 0.82339555, '_unknown_': 0.0059609693}
Run Code Online (Sandbox Code Playgroud)
我需要将其添加到我的 json 响应对象中,如下所示:
message = {
'status': 200,
'message': 'OK',
'scores': dict
}
resp = jsonify(message)
resp.status_code = 200
print(resp)
return resp
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
....\x.py", line 179, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: 0.027647732 is not JSON serializable
Run Code Online (Sandbox Code Playgroud)
有人可以帮我弄这个吗?谢谢。
django ×4
python ×4
apache-kafka ×2
python-3.x ×2
android ×1
angularjs ×1
cron ×1
django-cron ×1
enums ×1
flask ×1
javascript ×1
json ×1
kafka-python ×1
keyboard ×1
maven ×1
okhttp3 ×1
okio ×1
retrofit2 ×1
ruby ×1
spring ×1
sql ×1
sql-server ×1