model.py :  » Ajax » pyjamas » src » examples » employeeadmin » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Ajax » pyjamas 
pyjamas » src » examples » employeeadmin » model.py
"""
PureMVC Python Demo - wxPython Employee Admin 
By Toby de Havilland <toby.de.havilland@puremvc.org>
Copyright(c) 2007-08 Toby de Havilland, Some rights reserved.
Addapted for pyjamas: Kees Bos
"""

from puremvc.patterns.proxy import Proxy
import vo
import ApplicationConstants
from ApplicationConstants import Command,Notification

class UserProxy(Proxy):
    
    NAME = "UserProxy"
    def __init__(self):
        super(UserProxy, self).__init__(UserProxy.NAME, [])
        self.data = []
        self.addItem(vo.UserVO('lstooge',
                               'Larry', 
                               'Stooge', 
                               "larry@stooges.com", 
                               'ijk456',
                               ApplicationConstants.DEPT_ACCT))
        self.addItem(vo.UserVO('cstooge',
                               'Curly', 
                               'Stooge', 
                               "curly@stooges.com", 
                               'xyz987',
                               ApplicationConstants.DEPT_SALES))
        self.addItem(vo.UserVO('mstooge',
                               'Moe', 
                               'Stooge', 
                               "moe@stooges.com", 
                               'abc123',
                               ApplicationConstants.DEPT_PLANT))

    def getUsers(self):
        return self.data
   
    def addItem(self, item):
        self.data.append(item)

    def updateItem(self, user):
        for i in range(0,len(self.data)):
            if self.data[i].username == user.username:
                self.data[i] = user
    break

    def deleteItem(self, user):
        for i in range(0,len(self.data)):
            if self.data[i].username == user.username:
                del self.data[i]
    break

class RoleProxy(Proxy):

    NAME = "RoleProxy"
    def __init__(self):
        super(RoleProxy, self).__init__(RoleProxy.NAME, [])
        self.data = []
        self.addItem(vo.RoleVO('lstooge', 
                               [ApplicationConstants.ROLE_PAYROLL,
                                ApplicationConstants.ROLE_EMP_BENEFITS]))
        self.addItem(vo.RoleVO('cstooge', 
                               [ApplicationConstants.ROLE_ACCT_PAY,
                                ApplicationConstants.ROLE_ACCT_RCV,
                                ApplicationConstants.ROLE_GEN_LEDGER]))
        self.addItem(vo.RoleVO('mstooge', 
                               [ApplicationConstants.ROLE_INVENTORY,
                                ApplicationConstants.ROLE_PRODUCTION,
                                ApplicationConstants.ROLE_SALES,
                                ApplicationConstants.ROLE_SHIPPING]))

    def getRoles(self):
        return self.data

    def addItem(self, item):
        self.data.append(item)

    def deleteItem(self, item):
        for i in range(len(self.data)):
            if self.data[i].username == item.username:
                del self.data[i]
                break

    def doesUserHaveRole(self, user, role):
        hasRole = False;
        for i in range(len(self.data)):
            if self.data[i].username == user.username:
                userRoles = self.data[i].roles
                for j in range(len(userRoles)):
                    if userRoles[j] == role:
                        hasRole = True
                        break
        return hasRole

    def addRoleToUser(self, user, role):
        result = False;
        if not self.doesUserHaveRole(user, role):
            for i in range(0,len(self.data)):
                if self.data[i].username == user.username:
                    userRoles = self.data[i].roles
                    userRoles.append(role)
                    result = True;
                    break
        self.sendNotification(Command.ADD_ROLE_RESULT, result)

    def removeRoleFromUser(self, user, role):
        if self.doesUserHaveRole(user, role):
            for i in range(0,len(self.data)):
                if self.data[i].username == user.username:
                    userRoles = self.data[i].roles
                    for j in range(0,len(userRoles)):
                        if userRoles[j] == role:
                            del userRoles[j]
                            break

    def getUserRoles(self, username):
        userRoles = []
        for i in range(0,len(self.data)):
            if self.data[i].username == username:
                userRoles = self.data[i].roles
                break
        return userRoles
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.