Commit Graph

3058 Commits

Author SHA1 Message Date
Gary Walborn
9cd3753746 Adds ability to validate and normalize metadata.
I felt that it would be very handy to be able to validate
user-supplied metadata.  It occurred to me that if a metadata
type had an explicit list of options, it would need no validation.
Therefore, the "lookup" field of a metadata type could be overloaded
to provide EITHER a list of items that could be selected by the user
OR a function to provide data validation.  The system, therefore,
would need to be able to discriminate between a lookup function
and a validation function.

    To this end, I created a global variable
('METADATA_AVAILABLE_VALIDATORS') to contain a dictionary of
available validation functions.  If the name specified in
'metadata_type.lookup' is present in METADATA_AVAILABLE_VALIDATORS,
the system treats the function as a validator.  Otherwise, the
function is treated as a generator of an iterable value providing
the choices for the user.

  Django contains a pre-existing mechanism to support field
validation.  A validator has a single argument (the data to
be validated).  If the argument to the validator is valid,
the validator simply returns.  If there is a problem with
the data, the validator raises a 'ValidationError' exception
and passes an error message which is then displayed by Django
as a mouseover tip in the browser. Validators to be used
with Mayan-EDMS may follow this convention (i.e., take a
single argument and raise an exception if the validation
fails).  The validators in Mayan-EDMS, however, may actually
do more!

  If a validator function RETURNS a value, that value is used
in place of the original data.  This allows the validator to
make data conform to a valid value or to "normalize" a value
before it is stored in the database.  This allows for more
uniform metadata and improves the ability to index on the
metadata values.  Lets take at a look at an example of this
functionality.

  Assume that a document requires a date (perhaps, an
"original posting date").  We can have a 'metadata_type" of
"original_posting_date", and we can create a validator with
the name "is_valid_posting_date".  The validator function
(which is placed in a module read by the settings routine),
contains the function:

def is_valid_posting_date(value):
   from dateutil import parser
   import datetime
   from django.core.exceptions import ValidationError

   try:
      dt = parser.parse(value)
   except ValueError:
      raise ValidationError('Invalid date')
   return dt.date().isoformat()

This is placed in a dictionary in the user's
settings file, thus:

import my_settings
METADATA_AVAILABLE_VALIDATORS = {
  'is_valid_posting_date':my_settings.is_valid_posting_date }

The user creates a metadata type called "original_posting_date"
with a label of "Original Posting Date" and a 'lookup' value
of "is_valid_posting_date".  When the metadata form is filled
in and submitted, the date value is validated by our validator.
Since the python 'parser' function accepts many kinds of input,
the user can enter (for example) '9/1/2014', '2014/10/2',
or even 'Feb 4, 2001'.  If the user enters something that
does not (as far as python is concerned) represent a valid date,
the system will raise a "ValidationError" and the form will
be re-displayed with an appropriate error message.  If, however,
the data is valid, the valid of the field (and, hence, stored
in the database) will be "normalized" to ISO format YYYY-MM-DD.
This allows consistent lookup and indexing regardless of the
users particular idiosyncracies.
2014-09-22 12:30:15 -04:00
Roberto Rosario
def792790c A beautiful hack for an unknown problem: hidden imports. Hide the import for DocumentSerializer otherwise an unexplained ImportError is raised 2014-09-21 23:17:10 -04:00
Roberto Rosario
b709426043 Add id to the document serializer, add required=False to the document type <-> document serialierz relation 2014-09-21 23:15:55 -04:00
Roberto Rosario
f29aeabcfb Add folder app API endpoint 2014-09-21 19:24:00 -04:00
Roberto Rosario
942ad7b93e Add user model API endpoints 2014-09-21 19:23:37 -04:00
Roberto Rosario
364376f04a Specify document type fields and add the id field 2014-09-21 19:22:48 -04:00
Roberto Rosario
eb3e7a10c9 Abstract the way tag documents are retrieved 2014-09-21 16:38:52 -04:00
Roberto Rosario
e522da3632 Add retrieving all documents of document type via API 2014-09-21 15:22:12 -04:00
Roberto Rosario
97de4f615c Add Document model related name to the Document Type model to allow retrieving all documents of a document type 2014-09-21 15:21:39 -04:00
Roberto Rosario
050ae8c168 Add Document type list API view and endpoint 2014-09-21 15:21:19 -04:00
Roberto Rosario
2e4cd173c6 Add document type detail API endpoint 2014-09-21 15:13:56 -04:00
Roberto Rosario
e9f733e266 Fix typo 2014-09-21 14:59:43 -04:00
Roberto Rosario
2878bac07d Add CORS support to allow cross origin API requests 2014-09-21 14:59:11 -04:00
Roberto Rosario
bc663cb882 Remove literal Folder column declaration and convert to model column registration 2014-09-14 14:39:26 -04:00
Roberto Rosario
4793a64a7f Convert folder_list view to a Mayan generic class based view 2014-09-14 14:33:26 -04:00
Roberto Rosario
b8fe8639ec If an user has a global permission then return entire queryset 2014-09-14 14:32:46 -04:00
Roberto Rosario
d264aac97e Update tests 2014-09-14 08:51:23 -04:00
Roberto Rosario
0fde78558a Merge pull request #43 from mbehrle/feature/mimetypes
Adding more office MIME types to office_converter.
2014-09-14 08:42:21 -04:00
Roberto Rosario
922c63447e Merge pull request #44 from mbehrle/feature/docs
Feature/docs
2014-09-14 08:41:13 -04:00
Mathias Behrle
08c9e4a4e3 Adding more office MIME types to office_converter.
- Without those types the graphics backend will throw 'Unkwon file format' on OCR.
- S.a.
  http://stackoverflow.com/questions/4212861/what-is-a-correct-mime-type-for-docx-pptx-etc
2014-09-13 21:03:17 +02:00
Mathias Behrle
75e99d62bb Updating apache contrib files.
Thanks to Gary Walborn for providing examples.
2014-09-13 21:00:53 +02:00
Mathias Behrle
29b5f36605 Adding sample ini file for nginx with uwsgi. 2014-09-13 21:00:31 +02:00
Mathias Behrle
cc999a8f27 Adding sample ini file for uwsgi. 2014-09-13 20:59:59 +02:00
Roberto Rosario
9f6cc1ef33 Convert the folder documents view and the tag folders view to class based views 2014-09-13 02:24:39 -04:00
Roberto Rosario
ce9e8b609e Convert the document_list view to a class based view 2014-09-13 02:24:09 -04:00
Roberto Rosario
bc97b6a4ef Add get_extra_context method to ExtraContextMixin 2014-09-13 02:23:14 -04:00
Roberto Rosario
b27d6e57be Split MayanViewM into MayanView and ExtraContextViewMixin, add object permission check to the SimpleObjectLiveView 2014-09-13 01:37:30 -04:00
Roberto Rosario
0cb9a78df4 Remove blind capitalization of messages 2014-09-13 01:24:39 -04:00
Roberto Rosario
3a4b983f9d Fix links namespaces 2014-09-13 00:38:20 -04:00
Roberto Rosario
8f8f58b73f Import from the correct module 2014-09-13 00:37:57 -04:00
Roberto Rosario
3770695af8 Move django_gpg literals to their own module 2014-09-13 00:37:35 -04:00
Roberto Rosario
2e1c6ea8c9 Update contributing instructions 2014-09-13 00:24:13 -04:00
Roberto Rosario
3a4d824a43 Capitalize messages of documents app modules __init__ and links 2014-09-11 13:05:13 -04:00
Roberto Rosario
e207a80ff3 Capitalize ACLS app messages 2014-09-11 13:00:17 -04:00
Roberto Rosario
6e293dd15c Remove remarked code 2014-09-11 13:00:06 -04:00
Roberto Rosario
b761037d99 Move all settings files from <app>/conf/settings.py to <app>/settings.py 2014-09-11 05:02:40 -04:00
Roberto Rosario
c8d1b7bed7 Capitalize documents app models traslatable strings as per issue #12 2014-09-09 04:05:21 -04:00
Roberto Rosario
2e02c58b6f Add missing namespace in url tag 2014-09-09 03:59:20 -04:00
Roberto Rosario
d901a80f63 Change composed empty list message with a simple generic message, issue #12 @mbehrle 2014-09-09 03:58:03 -04:00
Roberto Rosario
25b2563999 Add missing view namespace 2014-09-09 03:57:49 -04:00
Roberto Rosario
f5bef4b52d Add app url namespacing to the common and main apps, fix missing namespace in the registration app, remove explict reverse_lazy for the LOGIN_URL and LOGIN_REDIRECT_URL these are expected to be views or URLs (failover) 2014-09-09 03:51:23 -04:00
Roberto Rosario
7dfacc624c Add namespace to tests views 2014-09-07 22:20:33 -04:00
Roberto Rosario
aaf8855403 Add development branch to travis config file 2014-09-06 17:30:10 -04:00
Roberto Rosario
1050fc71af Fix tag properties reference 2014-09-06 17:29:15 -04:00
Roberto Rosario
77acb809b9 Update view references to include namespaces 2014-09-06 17:28:40 -04:00
Roberto Rosario
5559e55a65 Update converter url to include namespaces, move links to a separate module 2014-09-06 17:27:52 -04:00
Roberto Rosario
a32c36d727 Fix tag properties reference 2014-09-06 17:27:33 -04:00
Roberto Rosario
76b2cdefcc Move app url namespaces updates 2014-09-06 16:30:12 -04:00
Roberto Rosario
5d5d9e45b8 Remove MAIN_SIDE_BAR_SEARCH from the documentation, update release notes for 1.1 2014-09-06 15:44:22 -04:00
Roberto Rosario
214c1e5430 Remove the MAIN_SIDE_BAR_SEARCH configuration option, move search app menu links to the search app 2014-09-06 15:43:48 -04:00