Skip to main content

A non-relational Django database backend that utilizes EnterpriseWizard's REST interface.

Project description

Version:
1.1.19
Dependencies:

Python 2.7, Django 1.5.2+

Home page:

https://bitbucket.org/alex_kavanaugh/django-ewiz

Author:

Alex Kavanaugh <kavanaugh.development@outlook.com>

License:

GNU LGPL (http://www.gnu.org/licenses/lgpl.html)

Installation

Run pip install django-ewiz

Add django_ewiz to INSTALLED_APPS

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

Usage

Basic Usage

In the DATABASES settings dictionary, simply use django_ewiz as the ENGINE key.

'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)
},

That’s it! All database operations performed will be abstracted and should function as the usual engines do (unless what you wish to do conflicts with the options below).

The following query operations are supported:

  • exact

  • iexact

  • contains

  • icontains

  • regex

  • iregex

  • gt

  • gte

  • lt

  • lte

  • startswith

  • endswith

  • istartswith

  • iendswith

NOTE: Not all ticket fields can be changed via REST. Add editable=False as a model option to remove DatabaseErrors.

File Uploads

django-ewiz does support file uploads - just not in a direct manner (binary uploads to the file field won’t work [more research on abstracting that will be done later])

To mark a field as a file field, add help_text='file' as a model field option. Since trying to modify the field directly won’t work, adding editable=False is recommended to avoid confusion.

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

To upload a file, use the provided EwizAttacher class (from django_ewiz import EwizAttacher) with the following parameters:

  • settingsDict - the DATABASES dictionary that contains ewiz connection settings. e.g. settings.DATABASES[‘default’]

  • model - the model instance to which a file should be uploaded (the model must include one and only one file field). e.g. models.AccountRequest.objects.get(ticket_id = 1)

  • file_reference - a Python file object. If the file is coming from a django form, grab it via request.FILES[‘form_field_name’].file

  • file_name - the desired file name. If the file is coming from a django form, you can grab its name via request.FILES[‘form_field_name’].name

File Upload Example

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').attachFile()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-ewiz-1.1.19.tar.gz (43.7 kB view details)

Uploaded Source

File details

Details for the file django-ewiz-1.1.19.tar.gz.

File metadata

File hashes

Hashes for django-ewiz-1.1.19.tar.gz
Algorithm Hash digest
SHA256 629d481a61b5849264682e32e2aae1812033f92d997ef758f9b79725c897bbc2
MD5 56d37676f382bb7651d57aca1d94d3b7
BLAKE2b-256 555e20ac4d6534f6385bd900392a16cad7c93912f5c0059dbfbcf515b862541b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page