跳转到主要内容

利用EnterpriseWizard的REST接口的非关系型Django数据库后端。

项目描述

版本:
1.5.4
依赖项:

Python 3.4+, Django>=1.5, djangotoolbox>=1.6.2, requests>=2.2.0

主页:

https://github.com/kavdev/django-ewiz

作者:

Alex Kavanaugh <kavanaugh.development@outlook.com>

许可协议:

GNU LGPL (https://gnu.ac.cn/licenses/lgpl.html)

注意: 版本1.3+将与EnterpriseWizard的anti-sql block兼容。为了实现这一点,移除了正则表达式和大小写不敏感的查询操作。

安装

运行 pip install django-ewiz

django_ewiz 添加到 INSTALLED_APPS

INSTALLED_APPS = (
    ...
    'django_ewiz',
    ...
)

使用方法

基本使用

DATABASES 设置字典中,只需将 django_ewiz 作为 ENGINE 键即可。

'default': {
    'ENGINE': 'django_ewiz',
    'NAME': '',  # The name of the knowlegebase
    'USER': '',  # The name of the user
    'PASSWORD': '',  # The user's password
    'HOST': '',  # EnterpriseWizard's REST base url, generally 'www.example.com/ewws/'. Don't include the protocol string (e.g. 'http://').
    'PORT': '',  # Either 80 or 443 (HTTP or HTTPS requests only)
    'NUM_CONNECTIONS': '', # Default: 1, Allows multiple concurrent connections to be used when retrieving multiple tickets in a query.
},

这就完成了!所有执行的数据库操作都将被抽象化,并应该像通常的引擎一样工作(除非你想做的事情与以下选项冲突)。

支持以下查询操作

  • iexact

  • icontains

  • in

  • gt

  • gte

  • lt

  • lte

  • istartswith

  • iendswith

  • range

  • year

  • isnull

以下查询操作将转换为相应的不区分大小写的形式: (版本 1.3+)

  • exact

  • contains

  • startswith

  • endswith

以下查询操作不再受支持: (版本 1.3+)

  • regex

  • iregex

注意:并非所有票据字段都可以通过REST进行更改。将模型选项中的 editable=False 添加以移除数据库错误。

文件上传

django-ewiz支持文件上传 - 但不是直接的方式(直接上传到文件字段不会工作[将在以后进行更多研究以抽象化])

要将字段标记为文件字段,将 help_text='file' 添加为模型字段选项。由于直接修改字段将不起作用,建议添加 editable=False 以避免混淆。

file_field = CharField(help_text='file', editable=False, db_column='attached_files')

要上传文件,请使用提供的EwizAttacher类(from django_ewiz import EwizAttacher)并使用以下参数

  • settingsDict - 包含ewiz连接设置的DATABASES字典。例如,settings.DATABASES[‘default’]

  • model - 应上传文件的模型实例(模型必须包含一个且仅有一个文件字段)。例如,models.AccountRequest.objects.get(ticket_id = 1)

  • file_reference - 一个Python文件对象。如果文件来自django表单,则通过request.FILES[‘form_field_name’].file获取它

  • file_name - 所需的文件名。如果文件来自django表单,您可以通过request.FILES[‘form_field_name’].name获取其名称

文件上传示例

forms.py

from django.forms import Form, FileField

class EwizUploadForm(Form):
    uploaded_file = FileField(required=True)

models.py

from django.db.models import Model, AutoField, CharField

class AccountRequest(Model):
    ticket_id = AutoField(primary_key=True, db_column='id')
    subject_username = CharField(help_text=':')

    # Use this field only in conjunction with EwizAttacher - do not attempt to directly populate it
    file_field = CharField(help_text='file', editable=False, db_column='attached_files')

    class Meta:
        db_table = u'account_request'
        managed = False
        verbose_name = u'Account Request'

views.py

from django.conf import settings
from django.views.generic.edit import FormView

from django_ewiz import EwizAttacher

from .forms import EwizUploadForm
from .models import AccountRequest

class UploadDemoView(FormView):
    template_name = "ewizdemo.html"
    form_class = EwizUploadForm

    def form_valid(self, form):
        # Create a new account request
        ticket = AccountRequest(subject_username=self.request.user.username)
        ticket.save()

        # Grab the file
        file_reference = self.request.FILES['uploaded_file'].file

        # Upload the file
        EwizAttacher(settings_dict=settings.DATABASES['default'], model=ticket, file_reference=file_reference, file_name=self.request.user.username + u'.pdf').attach_file()

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

django-ewiz-1.5.4.tar.gz (26.9 kB 查看散列)

上传日期

构建分布

django_ewiz-1.5.4-py2.py3-none-any.whl (18.7 kB 查看散列)

上传日期 Python 2 Python 3

支持者