From d187c1ee2f42af65d074e9b6c5c3aabb583ff672 Mon Sep 17 00:00:00 2001 From: Tanshu Date: Mon, 8 Jul 2013 01:33:02 +0530 Subject: [PATCH] Added settings table to store user settings. Added settings page, view, route and controller. Added lock_date setting to prevent changes to voucher upto and including that date. The sql for this update is: CREATE TABLE settings ( "SettingID" UUID NOT NULL, "Name" VARCHAR(255) NOT NULL, "Data" BYTEA, PRIMARY KEY ("SettingID"), UNIQUE ("Name") ); INSERT INTO auth_roles ("RoleID", "Name") VALUES ('d52de0be-9388-4b0b-a359-7e122ab6e53a', 'Lock Date'); Signed-off-by: Tanshu --- brewman/brewman/__init__.py | 2 + brewman/brewman/models/__init__.py | 1 + brewman/brewman/models/master.py | 34 ++++++++++++-- brewman/brewman/static/offline.appcache | 2 +- brewman/brewman/static/partial/settings.html | 12 +++++ brewman/brewman/static/scripts/home.js | 7 +++ brewman/brewman/static/scripts/overlord.js | 2 + brewman/brewman/static/scripts/settings.js | 32 +++++++++++++ brewman/brewman/templates/angular_base.mako | 3 +- .../views/services/voucher/__init__.py | 23 +++++++-- .../views/services/voucher/save_voucher.py | 15 ++++-- .../views/services/voucher/update_voucher.py | 10 +++- brewman/brewman/views/settings.py | 47 +++++++++++++++++++ 13 files changed, 176 insertions(+), 14 deletions(-) create mode 100644 brewman/brewman/static/partial/settings.html create mode 100644 brewman/brewman/static/scripts/settings.js create mode 100644 brewman/brewman/views/settings.py diff --git a/brewman/brewman/__init__.py b/brewman/brewman/__init__.py index 1663cfd6..8d983166 100644 --- a/brewman/brewman/__init__.py +++ b/brewman/brewman/__init__.py @@ -86,6 +86,8 @@ def main(global_config, **settings): config.add_route('api_message', '/api/Message') config.add_route('api_tag_list', '/api/Tags') + config.add_route('settings', '/Settings') + config.add_route('api_lock_date', '/api/LockDate') add_route(config, 'attendance', '/Attendance', has_list=False, variable='date') diff --git a/brewman/brewman/models/__init__.py b/brewman/brewman/models/__init__.py index a1e62dd6..f79c2fe0 100644 --- a/brewman/brewman/models/__init__.py +++ b/brewman/brewman/models/__init__.py @@ -13,6 +13,7 @@ def initialize_sql(engine): # from brewman.models.voucher import Attendance, Batch, Fingerprint, Inventory, Journal, Product, SalaryDeduction, Voucher, VoucherType # from brewman.models.master import Product, AttendanceType, CostCenter, Employee, Ledger, LedgerBase, LedgerType, ProductGroup # from brewman.models.auth import Client, Group, Role, User, role_group, user_group + # from .master import DbSetting DBSession.configure(bind=engine) Base.metadata.bind = engine # Base.metadata.create_all(engine) diff --git a/brewman/brewman/models/master.py b/brewman/brewman/models/master.py index 08f729b3..8979dbbb 100644 --- a/brewman/brewman/models/master.py +++ b/brewman/brewman/models/master.py @@ -1,11 +1,12 @@ import uuid -from sqlalchemy import UniqueConstraint, Column, Integer, Unicode, Numeric, Boolean, ForeignKey, func, DateTime, desc +from sqlalchemy import UniqueConstraint, Column, Integer, Unicode, Numeric, Boolean, ForeignKey, func, DateTime, desc, PickleType from sqlalchemy.orm import relationship from brewman.models import Base, DBSession from brewman.models.guidtype import GUID __author__ = 'tanshu' + class Product(Base): __tablename__ = 'entities_products' __tableagrs__ = (UniqueConstraint('Name', 'Units')) @@ -267,7 +268,7 @@ class Employee(LedgerBase): self.joining_date = joining_date self.leaving_date = leaving_date super().__init__(code=code, name=name, type=10, is_active=is_active, is_reconcilable=False, - costcenter_id=costcenter_id) + costcenter_id=costcenter_id) def create(self): code = DBSession.query(func.max(LedgerBase.code)).filter(LedgerBase.type == self.type).one()[0] @@ -383,4 +384,31 @@ class LedgerType: list = cls.list() for item in list: if item.id == id: - return item \ No newline at end of file + return item + + +class DbSetting(Base): + __tablename__ = 'settings' + + id = Column('SettingID', GUID(), primary_key=True, default=uuid.uuid4) + name = Column('Name', Unicode(255), unique=True, nullable=False) + data = Column('Data', PickleType) + + def __init__(self, id=None, name=None, data=None): + self.id = id + self.name = name + self.data = data + + @classmethod + def by_id(cls, id): + if not isinstance(id, uuid.UUID): + id = uuid.UUID(id) + return DBSession.query(cls).filter(cls.id == id).first() + + @classmethod + def by_name(cls, name): + return DBSession.query(cls).filter(cls.name == name).first() + + @classmethod + def list(cls): + return DBSession.query(cls).order_by(cls.name).all() \ No newline at end of file diff --git a/brewman/brewman/static/offline.appcache b/brewman/brewman/static/offline.appcache index 76df45e3..018fcef9 100644 --- a/brewman/brewman/static/offline.appcache +++ b/brewman/brewman/static/offline.appcache @@ -1,6 +1,6 @@ CACHE MANIFEST -# version 2013-06-24.1 +# version 2013-06-30.1 CACHE: /partial/404.html diff --git a/brewman/brewman/static/partial/settings.html b/brewman/brewman/static/partial/settings.html new file mode 100644 index 00000000..8c2c9b3e --- /dev/null +++ b/brewman/brewman/static/partial/settings.html @@ -0,0 +1,12 @@ +
+ Settings +
+ + +
+ + + +
+
+
diff --git a/brewman/brewman/static/scripts/home.js b/brewman/brewman/static/scripts/home.js index 4de9cd94..ec5b876a 100644 --- a/brewman/brewman/static/scripts/home.js +++ b/brewman/brewman/static/scripts/home.js @@ -11,6 +11,13 @@ var HomeCtrl = ['$scope', '$location', 'messages', 'Message', function ($scope, $scope.chosen = result.Type; }); } + $scope.getTags = function (tag) { + Message.query({type: $scope.Type, tag: tag}, function (result) { + $scope.info = result.Threads; + $scope.tags = result.Tags; + $scope.chosen = result.Type; + }); + } }]; HomeCtrl.resolve = { messages: ['$q', '$route', 'Message', function ($q, $route, Message) { diff --git a/brewman/brewman/static/scripts/overlord.js b/brewman/brewman/static/scripts/overlord.js index e621658e..14f7d487 100644 --- a/brewman/brewman/static/scripts/overlord.js +++ b/brewman/brewman/static/scripts/overlord.js @@ -92,6 +92,8 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte when('/Message', {templateUrl: '/partial/message-detail.html', controller: MessageCtrl, resolve: MessageCtrl.resolve}). when('/Message/:id', {templateUrl: '/partial/message-detail.html', controller: MessageCtrl, resolve: MessageCtrl.resolve}). + when('/Settings', {templateUrl: '/partial/settings.html', controller: SettingsCtrl, resolve: SettingsCtrl.resolve}). + otherwise({templateUrl: '/partial/404.html'}); $locationProvider.html5Mode(true).hashPrefix('!'); }]) diff --git a/brewman/brewman/static/scripts/settings.js b/brewman/brewman/static/scripts/settings.js new file mode 100644 index 00000000..3fab5205 --- /dev/null +++ b/brewman/brewman/static/scripts/settings.js @@ -0,0 +1,32 @@ +'use strict'; + +var SettingsCtrl = ['$scope', '$http', 'lockDate', function ($scope, $http, lockDate) { + $scope.lockDate = lockDate.data['Lock Date']; + $scope.setLockDate = function () { + $http({method: 'POST', url: '/api/LockDate', params: {Date: $scope.lockDate}}). + success(function (data) { + $scope.lockDate = data['Lock Date']; + $scope.toasts.push({Type: 'Success', Message: ''}); + }). + error(function (errorMessage) { + $scope.toasts.push({Type: 'Error', Message: errorMessage}); + }); + }; + $scope.clearLockDate = function () { + $http({method: 'POST', url: '/api/LockDate', params: {Clear: ''}}). + success(function (data) { + $scope.lockDate = data['Lock Date']; + $scope.toasts.push({Type: 'Success', Message: ''}); + }). + error(function (errorMessage) { + $scope.toasts.push({Type: 'Error', Message: errorMessage}); + }); + }; +}] + +SettingsCtrl.resolve = { + lockDate: ['$http', function ($http) { + return $http.get('/api/LockDate', {}); + }] +}; + diff --git a/brewman/brewman/templates/angular_base.mako b/brewman/brewman/templates/angular_base.mako index 1ebc2015..84f3e429 100644 --- a/brewman/brewman/templates/angular_base.mako +++ b/brewman/brewman/templates/angular_base.mako @@ -40,6 +40,7 @@ + @@ -179,7 +180,7 @@
  • Users
  • Groups
  • Clients
  • -
  • Split Data
  • +
  • Settings