From cf10fe19e8b6f8c3d7970e80cc1b90a2d36f36cf Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 29 Aug 2012 11:37:17 -0700 Subject: [PATCH] extensive commit (see note) The following changes are included: - Added support for GPC data type. - Added eager import of ``rattail.sil`` in ``before_render`` hook. - Removed ``rattail.pyramid.util`` module. - Added initial batch support: views, templates, creation from Product grid. - Added batch params template for ``PrintLabels`` provider. - Added support for ``rattail.LabelProfile`` class. - Improved Product grid to include filter/sort on Vendor. --- rattail/pyramid/forms.py | 67 +- rattail/pyramid/subscribers.py | 3 + rattail/pyramid/templates/batches/base.mako | 2 - rattail/pyramid/templates/batches/batch.mako | 14 - .../pyramid/templates/batches/columns.mako | 9 - rattail/pyramid/templates/batches/crud.mako | 8 + .../pyramid/templates/batches/details.mako | 12 - .../templates/batches/dictionaries.mako | 11 - .../pyramid/templates/batches/dictionary.mako | 9 - .../templates/batches/dictionary_columns.mako | 8 - rattail/pyramid/templates/batches/index.mako | 35 +- rattail/pyramid/templates/batches/params.mako | 42 + .../batches/params/print_labels.mako | 19 + rattail/pyramid/templates/batches/read.mako | 40 + .../pyramid/templates/batches/rows/crud.mako | 8 + .../pyramid/templates/batches/rows/index.mako | 46 + .../pyramid/templates/batches/sil_column.mako | 9 - .../templates/batches/sil_columns.mako | 10 - .../templates/batches/supported_fields.mako | 24 - .../pyramid/templates/batches/terminal.mako | 9 - .../pyramid/templates/batches/terminals.mako | 11 - .../templates/labels/profiles/crud.mako | 26 + .../templates/labels/profiles/index.mako | 11 + .../templates/labels/profiles/printer.mako | 48 + .../templates/labels/profiles/read.mako | 32 + rattail/pyramid/templates/products/batch.mako | 27 + rattail/pyramid/templates/products/index.mako | 32 +- rattail/pyramid/util.py | 96 -- rattail/pyramid/views/batches.py | 1033 ----------------- rattail/pyramid/views/batches/__init__.py | 35 + rattail/pyramid/views/batches/core.py | 174 +++ .../pyramid/views/batches/params/__init__.py | 52 + .../pyramid/views/batches/params/labels.py | 51 + rattail/pyramid/views/batches/rows.py | 219 ++++ rattail/pyramid/views/labels.py | 172 +++ rattail/pyramid/views/products.py | 291 ++--- 36 files changed, 1166 insertions(+), 1529 deletions(-) delete mode 100644 rattail/pyramid/templates/batches/base.mako delete mode 100644 rattail/pyramid/templates/batches/batch.mako delete mode 100644 rattail/pyramid/templates/batches/columns.mako create mode 100644 rattail/pyramid/templates/batches/crud.mako delete mode 100644 rattail/pyramid/templates/batches/details.mako delete mode 100644 rattail/pyramid/templates/batches/dictionaries.mako delete mode 100644 rattail/pyramid/templates/batches/dictionary.mako delete mode 100644 rattail/pyramid/templates/batches/dictionary_columns.mako create mode 100644 rattail/pyramid/templates/batches/params.mako create mode 100644 rattail/pyramid/templates/batches/params/print_labels.mako create mode 100644 rattail/pyramid/templates/batches/read.mako create mode 100644 rattail/pyramid/templates/batches/rows/crud.mako create mode 100644 rattail/pyramid/templates/batches/rows/index.mako delete mode 100644 rattail/pyramid/templates/batches/sil_column.mako delete mode 100644 rattail/pyramid/templates/batches/sil_columns.mako delete mode 100644 rattail/pyramid/templates/batches/supported_fields.mako delete mode 100644 rattail/pyramid/templates/batches/terminal.mako delete mode 100644 rattail/pyramid/templates/batches/terminals.mako create mode 100644 rattail/pyramid/templates/labels/profiles/crud.mako create mode 100644 rattail/pyramid/templates/labels/profiles/index.mako create mode 100644 rattail/pyramid/templates/labels/profiles/printer.mako create mode 100644 rattail/pyramid/templates/labels/profiles/read.mako create mode 100644 rattail/pyramid/templates/products/batch.mako delete mode 100644 rattail/pyramid/util.py delete mode 100644 rattail/pyramid/views/batches.py create mode 100644 rattail/pyramid/views/batches/__init__.py create mode 100644 rattail/pyramid/views/batches/core.py create mode 100644 rattail/pyramid/views/batches/params/__init__.py create mode 100644 rattail/pyramid/views/batches/params/labels.py create mode 100644 rattail/pyramid/views/batches/rows.py create mode 100644 rattail/pyramid/views/labels.py diff --git a/rattail/pyramid/forms.py b/rattail/pyramid/forms.py index c768327b..f0f23e74 100644 --- a/rattail/pyramid/forms.py +++ b/rattail/pyramid/forms.py @@ -29,39 +29,23 @@ from webhelpers.html import literal import formalchemy -# from formalchemy.fields import SelectFieldRenderer -import edbob -from edbob.pyramid import Session from edbob.pyramid.forms import pretty_datetime import rattail -__all__ = ['PriceFieldRenderer', 'RegularPriceFieldRenderer', 'UpcFieldRenderer'] - - -class BatchIdFieldRenderer(formalchemy.FieldRenderer): +class GPCFieldRenderer(formalchemy.TextFieldRenderer): """ - Renders the :attr:`rattail.Batch.batch_id` field. + Renderer for :class:`rattail.barcodes.GPC` fields. """ - def render_readonly(self, **kwargs): - value = self.raw_value - if value is None: - return '' - return '%08u' % int(value) + @property + def length(self): + # Hm, should maybe consider hard-coding this...? + return len(str(rattail.GPC(0))) -# class BatchTerminalFieldRenderer(SelectFieldRenderer): -# """ -# Renders a field whose value is a relationship to a -# :class:`rattail.BatchTerminal` instance. -# """ - -# def render(self, options, **kwargs): - - class PriceFieldRenderer(formalchemy.FieldRenderer): """ Renderer for fields which reference a :class:`ProductPrice` instance. @@ -98,42 +82,3 @@ class PriceWithExpirationFieldRenderer(PriceFieldRenderer): if price.ends: res += '  (%s)' % pretty_datetime(price.ends, from_='utc') return res - - -class UpcFieldRenderer(formalchemy.TextFieldRenderer): - """ - Handles rendering for the product UPC field. - """ - - def render_readonly(self, **kwargs): - value = self.raw_value - if not value: - return '' - if isinstance(value, basestring): - if value.isdigit(): - value = int(value) - if isinstance(value, (int, long)): - return '%013u' % value - return self.stringify_value(value, as_html=True) - - -def unique_batch_terminal_id(value, field=None): - """ - .. highlight:: python - - Validator for the :class:`rattail.BatchTerminal` class to ensure that SIL - IDs are not duplicated. For example:: - - from rattail.pyramid.forms import unique_batch_terminal_id - - # fieldset = some_batch_terminal_fieldset_factory() - fieldset.sil_id.set(validate=unique_batch_terminal_id) - """ - - if value: - q = Session.query(rattail.BatchTerminal) - q = q.filter(rattail.BatchTerminal.sil_id == value) - if field.parent.edit: - q = q.filter(rattail.BatchTerminal.uuid != field.parent.model.uuid) - if q.count(): - raise formalchemy.ValidationError("SIL ID value must be unique within the system") diff --git a/rattail/pyramid/subscribers.py b/rattail/pyramid/subscribers.py index d2219dba..b28ab180 100644 --- a/rattail/pyramid/subscribers.py +++ b/rattail/pyramid/subscribers.py @@ -41,6 +41,9 @@ def before_render(event): # Import labels module so it's available if/when needed. import rattail.labels + # Import SIL module so it's available if/when needed. + import rattail.sil + request = event.get('request') or threadlocal.get_current_request() renderer_globals = event diff --git a/rattail/pyramid/templates/batches/base.mako b/rattail/pyramid/templates/batches/base.mako deleted file mode 100644 index 27f7dd90..00000000 --- a/rattail/pyramid/templates/batches/base.mako +++ /dev/null @@ -1,2 +0,0 @@ -<%inherit file="/base.mako" /> -${parent.body()} diff --git a/rattail/pyramid/templates/batches/batch.mako b/rattail/pyramid/templates/batches/batch.mako deleted file mode 100644 index 3997c7e5..00000000 --- a/rattail/pyramid/templates/batches/batch.mako +++ /dev/null @@ -1,14 +0,0 @@ -<%inherit file="/batches/base.mako" /> -<%inherit file="/crud.mako" /> - -<%def name="crud_name()">Batch - -<%def name="menu()"> -

${h.link_to("Back to Batches", url('batches.list'))}

- % if fieldset.edit: -

${h.link_to("View Batch Details", url('batch.details', uuid=fieldset.model.uuid))}

-

${h.link_to("Execute this Batch", url('batch.execute', uuid=fieldset.model.uuid))}

- % endif - - -${parent.body()} diff --git a/rattail/pyramid/templates/batches/columns.mako b/rattail/pyramid/templates/batches/columns.mako deleted file mode 100644 index 332298ca..00000000 --- a/rattail/pyramid/templates/batches/columns.mako +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - -
Columns - ${columns|n} -
diff --git a/rattail/pyramid/templates/batches/crud.mako b/rattail/pyramid/templates/batches/crud.mako new file mode 100644 index 00000000..165b02be --- /dev/null +++ b/rattail/pyramid/templates/batches/crud.mako @@ -0,0 +1,8 @@ +<%inherit file="/crud.mako" /> + +<%def name="context_menu_items()"> +
  • ${h.link_to("Back to Batches", url('batches'))}
  • +
  • ${h.link_to("View Batch Rows", url('batch.rows', uuid=form.fieldset.model.uuid))}
  • + + +${parent.body()} diff --git a/rattail/pyramid/templates/batches/details.mako b/rattail/pyramid/templates/batches/details.mako deleted file mode 100644 index db8d7e15..00000000 --- a/rattail/pyramid/templates/batches/details.mako +++ /dev/null @@ -1,12 +0,0 @@ -<%inherit file="/batches/base.mako" /> -<%inherit file="/index.mako" /> - -<%def name="title()">Batch : ${batch.name} - -<%def name="menu()"> -

    ${h.link_to("Back to Batches", url('batches.list'))}

    -

    ${h.link_to("View Batch Properties", url('batch.edit', uuid=batch.uuid))}

    -

    ${h.link_to("Execute this Batch", url('batch.execute', uuid=batch.uuid))}

    - - -${parent.body()} diff --git a/rattail/pyramid/templates/batches/dictionaries.mako b/rattail/pyramid/templates/batches/dictionaries.mako deleted file mode 100644 index b1b8899b..00000000 --- a/rattail/pyramid/templates/batches/dictionaries.mako +++ /dev/null @@ -1,11 +0,0 @@ -<%inherit file="/batches/base.mako" /> -<%inherit file="/index.mako" /> - -<%def name="title()">Batch Dictionaries - -<%def name="menu()"> -

    ${h.link_to("Back to Batches", url('batches.list'))}

    -##

    ${h.link_to("Create a New Dictionary", url('batch_dictionary'))}

    - - -${parent.body()} diff --git a/rattail/pyramid/templates/batches/dictionary.mako b/rattail/pyramid/templates/batches/dictionary.mako deleted file mode 100644 index 90ddf9be..00000000 --- a/rattail/pyramid/templates/batches/dictionary.mako +++ /dev/null @@ -1,9 +0,0 @@ -<%inherit file="/batches/base.mako" /> -<%inherit file="/crud.mako" /> - -<%def name="menu()"> -

    ${h.link_to("Back to Batches", url('batches.list'))}

    -

    ${h.link_to("Back to Dictionaries", url('batch_dictionaries'))}

    - - -${parent.body()} diff --git a/rattail/pyramid/templates/batches/dictionary_columns.mako b/rattail/pyramid/templates/batches/dictionary_columns.mako deleted file mode 100644 index 78f353e5..00000000 --- a/rattail/pyramid/templates/batches/dictionary_columns.mako +++ /dev/null @@ -1,8 +0,0 @@ - - - - - -
    Supported Columns - ${grid|n} -
    \ No newline at end of file diff --git a/rattail/pyramid/templates/batches/index.mako b/rattail/pyramid/templates/batches/index.mako index 6e568008..8b426e03 100644 --- a/rattail/pyramid/templates/batches/index.mako +++ b/rattail/pyramid/templates/batches/index.mako @@ -1,38 +1,5 @@ -<%inherit file="/batches/base.mako" /> -<%inherit file="/index.mako" /> +<%inherit file="/grid.mako" /> <%def name="title()">Batches -<%def name="head_tags()"> - - - - -<%def name="menu()"> -##

    ${h.link_to("Create a New Batch", url('batch.new'))}

    -

    ${h.link_to("Manage Terminals", url('batch_terminals'))}

    -

    ${h.link_to("View Dictionaries", url('batch_dictionaries'))}

    -

    ${h.link_to("SIL Columns", url('sil_columns'))}

    - - ${parent.body()} diff --git a/rattail/pyramid/templates/batches/params.mako b/rattail/pyramid/templates/batches/params.mako new file mode 100644 index 00000000..48a494fa --- /dev/null +++ b/rattail/pyramid/templates/batches/params.mako @@ -0,0 +1,42 @@ +<%inherit file="/base.mako" /> + +<%def name="title()">Batch Parameters + +<%def name="head_tags()"> + ${parent.head_tags()} + + + +<%def name="batch_params()"> + +

    Please provide the following values for your new batch:

    +
    + +
    + + ${h.form(request.get_referrer())} + ${h.hidden('provider', value=provider)} + ${h.hidden('params', value='True')} + + ${self.batch_params()} + +
    + + +
    + + ${h.end_form()} + +
    diff --git a/rattail/pyramid/templates/batches/params/print_labels.mako b/rattail/pyramid/templates/batches/params/print_labels.mako new file mode 100644 index 00000000..c559c767 --- /dev/null +++ b/rattail/pyramid/templates/batches/params/print_labels.mako @@ -0,0 +1,19 @@ +<%inherit file="/batches/params.mako" /> + +<%def name="batch_params()"> + +
    + +
    + ${h.select('profile', None, label_profiles)} +
    +
    + +
    + +
    ${h.text('quantity', value=1)}
    +
    + + + +${parent.body()} diff --git a/rattail/pyramid/templates/batches/read.mako b/rattail/pyramid/templates/batches/read.mako new file mode 100644 index 00000000..3ce97fea --- /dev/null +++ b/rattail/pyramid/templates/batches/read.mako @@ -0,0 +1,40 @@ +<%inherit file="/batches/crud.mako" /> + +<%def name="context_menu_items()"> + ${parent.context_menu_items()} +
  • ${h.link_to("Edit this Batch", url('batch.update', uuid=form.fieldset.model.uuid))}
  • +
  • ${h.link_to("Delete this Batch", url('batch.delete', uuid=form.fieldset.model.uuid))}
  • + + +${parent.body()} + +<% batch = form.fieldset.model %> + +

    Columns

    + +
    + + + + + + + + + + + + + % for i, column in enumerate(batch.columns, 1): + + + + + + + + + % endfor + +
    NameSIL NameDisplay NameDescriptionData TypeVisible
    ${column.name}${column.sil_name}${column.display_name}${column.description}${column.data_type}${column.visible}
    +
    diff --git a/rattail/pyramid/templates/batches/rows/crud.mako b/rattail/pyramid/templates/batches/rows/crud.mako new file mode 100644 index 00000000..c5a0daf0 --- /dev/null +++ b/rattail/pyramid/templates/batches/rows/crud.mako @@ -0,0 +1,8 @@ +<%inherit file="/crud.mako" /> + +<%def name="context_menu_items()"> +
  • ${h.link_to("Back to Batch", url('batch', uuid=form.fieldset.model.batch.uuid))}
  • +
  • ${h.link_to("Back to Batch Rows", url('batch.rows', uuid=form.fieldset.model.batch.uuid))}
  • + + +${parent.body()} diff --git a/rattail/pyramid/templates/batches/rows/index.mako b/rattail/pyramid/templates/batches/rows/index.mako new file mode 100644 index 00000000..17c72786 --- /dev/null +++ b/rattail/pyramid/templates/batches/rows/index.mako @@ -0,0 +1,46 @@ +<%inherit file="/grid.mako" /> + +<%def name="title()">Batch Rows : ${batch.description} + +<%def name="head_tags()"> + ${parent.head_tags()} + + + +<%def name="context_menu_items()"> +
  • ${h.link_to("Back to Batches", url('batches'))}
  • +
  • ${h.link_to("Back to Batch", url('batch', uuid=batch.uuid))}
  • + + +<%def name="tools()"> +
    + + +
    + + +${parent.body()} diff --git a/rattail/pyramid/templates/batches/sil_column.mako b/rattail/pyramid/templates/batches/sil_column.mako deleted file mode 100644 index 95eac5e4..00000000 --- a/rattail/pyramid/templates/batches/sil_column.mako +++ /dev/null @@ -1,9 +0,0 @@ -<%inherit file="/batches/base.mako" /> -<%inherit file="/crud.mako" /> - -<%def name="menu()"> -

    ${h.link_to("Back to Batches", url('batches.list'))}

    -

    ${h.link_to("Back to SIL Columns", url('sil_columns'))}

    - - -${parent.body()} diff --git a/rattail/pyramid/templates/batches/sil_columns.mako b/rattail/pyramid/templates/batches/sil_columns.mako deleted file mode 100644 index ab8a6a64..00000000 --- a/rattail/pyramid/templates/batches/sil_columns.mako +++ /dev/null @@ -1,10 +0,0 @@ -<%inherit file="/batches/base.mako" /> -<%inherit file="/index.mako" /> - -<%def name="title()">SIL Columns - -<%def name="menu()"> -

    ${h.link_to("Back to Batches", url('batches.list'))}

    - - -${parent.body()} diff --git a/rattail/pyramid/templates/batches/supported_fields.mako b/rattail/pyramid/templates/batches/supported_fields.mako deleted file mode 100644 index aba8b077..00000000 --- a/rattail/pyramid/templates/batches/supported_fields.mako +++ /dev/null @@ -1,24 +0,0 @@ - - - - - -## - - -

    Supported Fields

    ${h.link_to("Update Field List", '#', id='update-fields')}
    - -${grid|n} - -## diff --git a/rattail/pyramid/templates/batches/terminal.mako b/rattail/pyramid/templates/batches/terminal.mako deleted file mode 100644 index 4f5d4697..00000000 --- a/rattail/pyramid/templates/batches/terminal.mako +++ /dev/null @@ -1,9 +0,0 @@ -<%inherit file="/batches/base.mako" /> -<%inherit file="/crud.mako" /> - -<%def name="menu()"> -

    ${h.link_to("Back to Batches", url('batches.list'))}

    -

    ${h.link_to("Back to Batch Terminals", url('batch_terminals'))}

    - - -${parent.body()} diff --git a/rattail/pyramid/templates/batches/terminals.mako b/rattail/pyramid/templates/batches/terminals.mako deleted file mode 100644 index a579c556..00000000 --- a/rattail/pyramid/templates/batches/terminals.mako +++ /dev/null @@ -1,11 +0,0 @@ -<%inherit file="/batches/base.mako" /> -<%inherit file="/index.mako" /> - -<%def name="title()">Batch Terminals - -<%def name="menu()"> -

    ${h.link_to("Back to Batches", url('batches.list'))}

    -

    ${h.link_to("Create a New Terminal", url('batch_terminal.new'))}

    - - -${parent.body()} diff --git a/rattail/pyramid/templates/labels/profiles/crud.mako b/rattail/pyramid/templates/labels/profiles/crud.mako new file mode 100644 index 00000000..e394346b --- /dev/null +++ b/rattail/pyramid/templates/labels/profiles/crud.mako @@ -0,0 +1,26 @@ +<%inherit file="/crud.mako" /> + +<%def name="head_tags()"> + ${parent.head_tags()} + + + +<%def name="context_menu_items()"> +
  • ${h.link_to("Back to Label Profiles", url('label_profiles'))}
  • + % if form.updating: + <% profile = form.fieldset.model %> + <% printer = profile.get_printer() %> + % if printer.required_settings: +
  • ${h.link_to("Edit Printer Settings", url('label_profile.printer_settings', uuid=profile.uuid))}
  • + % endif +
  • ${h.link_to("View this Label Profile", url('label_profile.read', uuid=profile.uuid))}
  • + % endif + + +${parent.body()} diff --git a/rattail/pyramid/templates/labels/profiles/index.mako b/rattail/pyramid/templates/labels/profiles/index.mako new file mode 100644 index 00000000..a5383fbe --- /dev/null +++ b/rattail/pyramid/templates/labels/profiles/index.mako @@ -0,0 +1,11 @@ +<%inherit file="/grid.mako" /> + +<%def name="title()">Label Profiles + +<%def name="context_menu_items()"> + % if request.has_perm('label_profiles.create'): +
  • ${h.link_to("Create a new Label Profile", url('label_profile.create'))}
  • + % endif + + +${parent.body()} diff --git a/rattail/pyramid/templates/labels/profiles/printer.mako b/rattail/pyramid/templates/labels/profiles/printer.mako new file mode 100644 index 00000000..9b1c5545 --- /dev/null +++ b/rattail/pyramid/templates/labels/profiles/printer.mako @@ -0,0 +1,48 @@ +<%inherit file="/base.mako" /> + +<%def name="title()">Printer Settings + +<%def name="context_menu_items()"> +
  • ${h.link_to("Back to Label Profiles", url('label_profiles'))}
  • +
  • ${h.link_to("View this Label Profile", url('label_profile.read', uuid=profile.uuid))}
  • +
  • ${h.link_to("Edit this Label Profile", url('label_profile.update', uuid=profile.uuid))}
  • + + +
    + + + +
    + +
    + +
    ${profile.description}
    +
    + +
    + +
    ${profile.printer_spec}
    +
    + + ${h.form(request.current_route_url())} + + % for name, display in printer.required_settings.iteritems(): +
    + +
    + ${h.text(name, value=profile.get_printer_setting(name))} +
    +
    + % endfor + +
    + ${h.submit('update', "Update")} + +
    + + ${h.end_form()} +
    + +
    diff --git a/rattail/pyramid/templates/labels/profiles/read.mako b/rattail/pyramid/templates/labels/profiles/read.mako new file mode 100644 index 00000000..c3e2cec7 --- /dev/null +++ b/rattail/pyramid/templates/labels/profiles/read.mako @@ -0,0 +1,32 @@ +<%inherit file="/labels/profiles/crud.mako" /> + +<%def name="context_menu_items()"> +
  • ${h.link_to("Back to Label Profiles", url('label_profiles'))}
  • + % if form.readonly and request.has_perm('label_profiles.update'): + <% profile = form.fieldset.model %> + <% printer = profile.get_printer() %> +
  • ${h.link_to("Edit this Label Profile", url('label_profile.update', uuid=form.fieldset.model.uuid))}
  • + % if printer.required_settings: +
  • ${h.link_to("Edit Printer Settings", url('label_profile.printer_settings', uuid=profile.uuid))}
  • + % endif + % endif + + +${parent.body()} + +<% profile = form.fieldset.model %> +<% printer = profile.get_printer() %> + +% if printer.required_settings: +

    Printer Settings

    + +
    + % for name, display in printer.required_settings.iteritems(): +
    + +
    ${profile.get_printer_setting(name) or ''}
    +
    + % endfor +
    + +% endif diff --git a/rattail/pyramid/templates/products/batch.mako b/rattail/pyramid/templates/products/batch.mako new file mode 100644 index 00000000..335c8574 --- /dev/null +++ b/rattail/pyramid/templates/products/batch.mako @@ -0,0 +1,27 @@ +<%inherit file="/base.mako" /> + +<%def name="title()">Create Products Batch + +<%def name="context_menu_items()"> +
  • ${h.link_to("Back to Products", url('products'))}
  • + + +
    + + ${h.form(request.current_route_url())} + +
    + +
    + ${h.select('provider', None, providers)} +
    +
    + +
    + ${h.submit('create', "Create Batch")} + +
    + + ${h.end_form()} + +
    diff --git a/rattail/pyramid/templates/products/index.mako b/rattail/pyramid/templates/products/index.mako index 36992e85..dc09241c 100644 --- a/rattail/pyramid/templates/products/index.mako +++ b/rattail/pyramid/templates/products/index.mako @@ -33,7 +33,7 @@ } - % if edbob.config.getboolean('rattail.labels', 'enabled', default=False): + % if label_profiles and request.has_perm('products.print_labels'):