Skip to content

Commit

Permalink
Widgets Fix from whanderley
Browse files Browse the repository at this point in the history
CMS: Add Post Status & Priority (for WACOP)
  • Loading branch information
flavour committed Jan 16, 2017
1 parent 2f2756d commit 39e2ff5
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
23345af (2017-01-16 11:56:13)
2f2756d (2017-01-16 13:29:03)
6 changes: 6 additions & 0 deletions controllers/cms.py
Expand Up @@ -63,6 +63,12 @@ def prep(r):

return s3_rest_controller(rheader=s3db.cms_rheader)

# -----------------------------------------------------------------------------
def status():
""" RESTful CRUD controller """

return s3_rest_controller()

# -----------------------------------------------------------------------------
def tag():
""" RESTful CRUD controller """
Expand Down
2 changes: 1 addition & 1 deletion modules/s3/s3widgets.py
Expand Up @@ -1690,7 +1690,7 @@ def inject_script(self, selector, options):
# # Urdu uses Arabic
# language = "ar"
if "-" in language:
parts = language.split("_", 1)
parts = language.split("-", 1)
language = "%s-%s" % (parts[0], parts[1].upper())

# datePicker regional
Expand Down
73 changes: 72 additions & 1 deletion modules/s3db/cms.py
Expand Up @@ -59,6 +59,7 @@ class S3ContentModel(S3Model):
"""

names = ("cms_series",
"cms_status",
"cms_post",
"cms_post_id",
"cms_post_module",
Expand Down Expand Up @@ -161,6 +162,54 @@ def model(self):
cms_post = "series_id",
)

# ---------------------------------------------------------------------
# Post Statuses
# - used by WACOP
#
tablename = "cms_status"
define_table(tablename,
Field("name", length=128, notnull=True, unique=True,
label = T("Name"),
requires = [IS_NOT_EMPTY(),
IS_LENGTH(128),
],
),
s3_comments(),
*s3_meta_fields())

# CRUD Strings
ADD_STATUS = T("Create Status")
crud_strings[tablename] = Storage(
label_create = ADD_STATUS,
title_display = T("Status Details"),
title_list = T("Statuses"),
title_update = T("Edit Status"),
#title_upload = T("Import Statuses"),
label_list_button = T("List Statuses"),
label_delete_button = T("Delete Status"),
msg_record_created = T("Status added"),
msg_record_modified = T("Status updated"),
msg_record_deleted = T("Status deleted"),
msg_list_empty = T("No Statuses currently registered"))

# Reusable Field
represent = S3Represent(lookup=tablename, translate=True)
#none = T("Unknown"))
status_id = S3ReusableField("status_id", "reference %s" % tablename,
comment = S3PopupLink(title = ADD_STATUS,
c = "cms",
f = "status",
),
label = T("Status"),
ondelete = "SET NULL",
represent = represent,
requires = IS_EMPTY_OR(
IS_ONE_OF(db, "cms_status.id",
represent,
sort=True)),
sortby = "name",
)

# ---------------------------------------------------------------------
# Posts
# - single blocks of [rich] text which can be embedded into a page,
Expand All @@ -174,6 +223,13 @@ def model(self):
body_represent = lambda body: XML(s3_URLise(body))
body_widget = None

# WACOP Priorities
# @ToDo: Add deployment_setting if these need to be different in other templates
post_priority_opts = {1: T("Informational"),
2: T("Important"),
3: T("Critical"),
}

tablename = "cms_post"
define_table(tablename,
self.super_link("doc_id", "doc_entity"),
Expand All @@ -192,6 +248,7 @@ def model(self):
#requires = IS_NOT_EMPTY(),
widget = body_widget,
),
s3_datetime(default = "now"),
# @ToDo: Move this to link table?
self.gis_location_id(),
# @ToDo: Move this to link table?
Expand All @@ -211,7 +268,21 @@ def model(self):
label = T("Comments permitted?"),
represent = s3_yes_no_represent,
),
s3_datetime(default = "now"),
Field("priority", "integer",
default = 1,
label = T("Priority"),
represent = lambda opt: \
post_priority_opts.get(opt,
current.messages.UNKNOWN_OPT),
requires = IS_IN_SET(post_priority_opts,
zero=None),
# Enable in template if-desired
readable = False,
writable = False,
),
status_id(readable = False,
writable = False,
),
# @ToDo: Also have a datetime for 'Expires On'
Field("expired", "boolean",
default = False,
Expand Down
4 changes: 4 additions & 0 deletions modules/templates/WACOP/cms_status.csv
@@ -0,0 +1,4 @@
Name,Comments
Active,
Complete,
Testing
1 change: 1 addition & 0 deletions modules/templates/WACOP/tasks.cfg
Expand Up @@ -45,6 +45,7 @@ org,organisation_type,default/organisation_type.csv,organisation_type.xsl
#org,office_type,default/office_type.csv,office_type.xsl
# -----------------------------------------------------------------------------
cms,series,cms_series.csv,series.xsl
cms,status,cms_status.csv,status.xsl
# -----------------------------------------------------------------------------
fire,station,fire_station.csv,station.xsl
police,station,police_station.csv,station.xsl
Expand Down
1 change: 1 addition & 0 deletions static/formats/s3csv/cms/status.csv
@@ -0,0 +1 @@
Name,Comments
32 changes: 32 additions & 0 deletions static/formats/s3csv/cms/status.xsl
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<!-- **********************************************************************
Post Statuses - CSV Import Stylesheet
CSV column...........Format..........Content
Name.................string..........Name
Comments.............string..........Comments
*********************************************************************** -->
<xsl:output method="xml"/>

<!-- ****************************************************************** -->
<xsl:template match="/">
<s3xml>
<xsl:apply-templates select="./table/row"/>
</s3xml>
</xsl:template>

<!-- ****************************************************************** -->
<xsl:template match="row">
<resource name="cms_status">
<data field="name"><xsl:value-of select="col[@field='Name']"/></data>
<data field="comments"><xsl:value-of select="col[@field='Comments']"/></data>
</resource>
</xsl:template>
<!-- ****************************************************************** -->

</xsl:stylesheet>

0 comments on commit 39e2ff5

Please sign in to comment.