예제 #1
0
파일: base.py 프로젝트: MobyDevel/Rtm
class BaseManager(object):
    """ Base
    """

    def __init__(self, *args, **kwargs):
        """Init
        """
        self.item = None
        self.items = None
        self.options_item = None
        self.rangeItemsStart = 1
        self.rangeItemsEnd = 10
        self.order = None
        self.model = None
        self.modelLanguage = None
        self.modelOptions = None
        self.fetchOptions = None
        self.debugger = Debugger(__MNAME__, __FNAME__)
        self.context = dict()
        self.options = None

    def fetch_item(self, itemId):
        """Pobiera element
        """
        model_class = self.model.__class__

        try:
            self.item = model_class.objects.get(id=itemId)
        except Exception, e:
            self.debugger.catch_error("fetch_item: ", e)
예제 #2
0
    def __init__(self, request, *args, **kwargs):
        self.portal = PortalManager(request)
        self.manager = None
        self.extramanager = None
        self.requester = Requester(request)
        self.sheet = SheetManager()
        self.sheet.request = request
        self.sheet.admin_site = settings.DEFAULT_SITE_ID
        self.language = LanguageManager(request)
        self.data = dict()
        self.items = None
        self.urls = UrlContener()
        self.template = None
        self.activerootmenu = None
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.portal.fetch_data()
        self.language.fetch_active_languages()
        self.language.fetch_current_language(request)
        self.requester.get_messages(request)
        self.sheet.reqsite = settings.DEFAULT_SITE_ID
        self.portal.reqsite = settings.DEFAULT_SITE_ID
        self.portal.fetch_active_site(self.requester.rData['activesite'])
        self.portal.fetchOptions = { 'site': self.portal.activeSite.id, 'active': '1', 'activesite': self.portal.activeSite.id }
        self.portal.fetch_modules()
        self.permission = PermissionManager()

        #self.get_active_root_menu()
        self.permission.check_logged_user(request)
예제 #3
0
class Manager(BaseManager):
    """ ItemManager
        Odpowiada za pobieranie danych z bazy wedlug okreslonych zasad
    """

    def __init__(self, *args, **kwargs):
        """ Konstruktor
        """
        super(Manager, self).__init__(*args, **kwargs)

        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.order = 'name'
        self.model = Site()
        self.modelName = 'Site'
        self.moduleName = '__adm_Sites__'


    def fetch_items(self):
        """Pobiera elementy
        """
        model_class = self.model.__class__
        try:
            self.items = model_class.objects.all().order_by(self.order)[self.rangeItemsStart:self.rangeItemsEnd]
        except Exception,e:
            self.debugger.catch_error('fetch_items: ',e)
예제 #4
0
class ModuleManager(object):

    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.menu = None
        self.menuitems = []
        self.treemenuitems = None
        self.options = None
        self.language = None
        self.debugger = Debugger(__MNAME__,__FNAME__)

    def get_data(self, lang, site):
        self.language = lang
        self.fetch_options()
        self.fetch_menu()
        self.fetch_menu_items()

        self.treemenuitems = self.get_items_as_tree()

        newitems = []
        for item in self.menuitems:
            if item.parent is not None:
                newitems.append(item)
        self.menuitems = newitems

        safemenuitems = []
        if self.menuitems is not None:
            for item in self.menuitems:
                err = 0
                if item is not None:
                    item.get_language(lang.id)
                    item.module_model = get_module_options_model(item.registered_module.id)

                    options = None
                    try:
                        options = item.module_model.__class__.objects.filter(menuitem=item)
                        if len(options) > 0:
                            options = options[0]
                        else:
                            options = None
                    except Exception, e:
                        err = 1
                        options = None
                        self.debugger.catch_error('get_data: ', e)

                    if options is not None:
                        item.options = options
                        try:
                            item.slug = item.options.get_slug(lang.id)
                            item.url_prefix = item.options.get_url_prefix()
                            item.object_id = item.options.get_object_id()
                            item.registered_module = item.options.registered_module
                        except Exception, e:
                            err = 1
                            self.debugger.catch_error('get_data: ', e)
                    else:
                        err = 1
                if err == 0:
                    safemenuitems.append(item)
            self.menuitems = safemenuitems
예제 #5
0
class BaseManager(object):
    """ Base
    """
    def __init__(self, *args, **kwargs):
        """Init
        """
        self.item = None
        self.items = None
        self.options_item = None
        self.rangeItemsStart = 1
        self.rangeItemsEnd = 10
        self.order = None
        self.model = None
        self.modelLanguage = None
        self.modelOptions = None
        self.fetchOptions = None
        self.debugger = Debugger(__MNAME__, __FNAME__)
        self.context = dict()
        self.options = None

    def fetch_item(self, itemId):
        """Pobiera element
        """
        model_class = self.model.__class__

        try:
            self.item = model_class.objects.get(id=itemId)
        except Exception, e:
            self.debugger.catch_error('fetch_item: ', e)
예제 #6
0
class ModuleManager(object):

    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.items = []
        self.treemenuitems = None
        self.options = None
        self.language = None
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.category = None

    def get_data(self, lang, site):
        self.fetch_options()
        if self.options is not None:
            if self.options.category is not None:
                self.category = self.options.category
                self.fetch_items(lang)
                #for item in self.items:
                    

    def fetch_registered_module(self, rid):
        try:
            self.registered_module = RegisteredModule.objects.get(id=rid)
        except Exception, e:
            self.debugger.catch_error('fetch_registered_module: ', e)
예제 #7
0
    def __init__(self, request, *args, **kwargs):

        self.selectedActivity = -1
        self.painateni = None
        self.numItemsOnPage = 25
        self.contextdata = dict()
        self.activeSite = None
        self.selectedCategory = None
        self.request = request
        self.rData = {
            'selectedactivity': -1,
            'activesite': None,
            'pni': 10,
            'pages': [],
            'page': 0,
            'pprev': None,
            'pnext': 1,
            'pagesinfo': {},
            #'paginateni': 10,
            'rm': None,
            'selectedmenu': -1,
            'selectedcategory': None,
            'selectedtest': None,
            'selectedcourse': None,
            'selectedquestion': None,
            'adminall': settings.ADMINALLSITES,
            'currentdate': datetime.now()
        }
        #print self.rData
        self.debugger = Debugger(__MNAME__,__FNAME__)
        super(Requester, self).__init__(*args, **kwargs)
 def __init__(self, *args, **kwargs):
     self.registered_module = None
     self.options = None
     self.language = None
     self.categories = None
     self.debugger = Debugger(__MNAME__,__FNAME__)
     self.fetch_opt = dict()
예제 #9
0
 def __init__(self, *args, **kwargs):
     self.registered_module = None
     self.items = []
     self.treemenuitems = None
     self.options = None
     self.language = None
     self.debugger = Debugger(__MNAME__, __FNAME__)
     self.category = None
예제 #10
0
    def __init__(self, *args, **kwargs):
        """ Konstruktor
        """
        super(Manager, self).__init__(*args, **kwargs)

        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.order = 'name'
        self.model = Site()
        self.modelName = 'Site'
        self.moduleName = '__adm_Sites__'
예제 #11
0
 def __init__(self, *args, **kwargs):
     super(ModuleBaseManager, self).__init__(*args, **kwargs)
     self.registered_module = None
     self.menu = None
     self.menuitems = []
     self.treemenuitems = None
     self.options = None
     self.language = None
     self.debugger = Debugger(__MNAME__, __FNAME__)
     self.permissions = None
예제 #12
0
 def __init__(self, *args, **kwargs):
     """Init
     """
     self.user = None
     self.panel = False
     self.user_permissions = None
     self.permissions = { 'public': True, 'read': False, 'write': False, 'delete': False, 'add': False, 'own': False }
     self.admin_permissions = { 'public': False, 'read': False, 'write': False, 'delete': False, 'add': False, 'own': False }
     self.all_user_permissions = dict()
     self.debugger = Debugger(__MNAME__,__FNAME__)
     self.context = dict()
예제 #13
0
 def __init__(self, request, *args, **kwargs):
     self.sites = None
     self.activeSite = None
     self.debugger = Debugger(__MNAME__,__FNAME__)
     self.modules = None
     self.module = None
     self.module_types = None
     self.module_type = None
     self.fetchOptions = dict()
     self.reqsite = None
     self.request = request
     self.get_user_site()
예제 #14
0
 def __init__(self, request, *args, **kwargs):
     super(LanguageManager, self).__init__(*args, **kwargs)
     self.currentLanguage = None
     self.activeLanguages = None
     self.debugger = Debugger(__MNAME__, __FNAME__)
     self.fetch_current_language(request)
     self.fetch_active_languages()
     self.sheet = None
     self.fullpath = None
     self.path = None
     self.order = 'name'
     self.model = Language()
     self.modelName = 'Language'
     self.moduleName = '__adm_Language__'
예제 #15
0
 def __init__(self, *args, **kwargs):
     """Init
     """
     self.item = None
     self.items = None
     self.options_item = None
     self.rangeItemsStart = 1
     self.rangeItemsEnd = 10
     self.order = None
     self.model = None
     self.modelLanguage = None
     self.modelOptions = None
     self.fetchOptions = None
     self.debugger = Debugger(__MNAME__, __FNAME__)
     self.context = dict()
     self.options = None
예제 #16
0
 def __init__(self, *args, **kwargs):
     self.registered_module = None
     self.items = []
     self.treemenuitems = None
     self.options = None
     self.language = None
     self.debugger = Debugger(__MNAME__,__FNAME__)
     self.category = None
예제 #17
0
class PortalManager(object):
    def __init__(self, request, *args, **kwargs):
        self.sites = None
        self.activeSite = None
        self.debugger = Debugger(__MNAME__, __FNAME__)
        self.modules = None
        self.module = None
        self.module_types = None
        self.module_type = None
        self.fetchOptions = dict()
        self.reqsite = None
        self.request = request
        self.get_user_site()

    def fetch_data(self):
        try:
            self.sites = Site.objects.all()
        except Exception, e:
            self.debugger.catch_error("fetch_data: ", e)
예제 #18
0
 def __init__(self, *args, **kwargs):
     super(ModuleBaseManager, self).__init__(*args, **kwargs)
     self.registered_module = None
     self.menu = None
     self.menuitems = []
     self.treemenuitems = None
     self.options = None
     self.language = None
     self.debugger = Debugger(__MNAME__,__FNAME__)
     self.permissions = None
예제 #19
0
class ModuleManager(object):

    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.options = None
        self.language = None
        self.html = None
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.fetch_opt = dict()

    def get_data(self, lang, site):
        self.language = lang
        self.fetch_options()
        self.form = LoginForm()

    def fetch_registered_module(self, rid):
        try:
            self.registered_module = RegisteredModule.objects.get(id=rid)
        except Exception, e:
            self.debugger.catch_error('fetch_registered_module: ', e)
예제 #20
0
class ModuleManager(object):

    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.options = None
        self.language = None
        self.html = None
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.fetch_opt = dict()

    def get_data(self, lang, site):
        self.language = lang
        self.fetch_options()
        self.html = self.options.html

    def fetch_registered_module(self, rid):
        try:
            self.registered_module = RegisteredModule.objects.get(id=rid)
        except Exception, e:
            self.debugger.catch_error('fetch_registered_module: ', e)
class ModuleManager(object):

    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.options = None
        self.language = None
        self.categories = None
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.fetch_opt = dict()

    def get_data(self, lang, site):
        self.language = lang
        self.fetch_options()
        self.fetch_opt = { 'site': site.id, 'active': 1, 'activesite': site.id, 'parent__id': self.options.category.id }
        self.fetch_categories(lang, site)

    def fetch_registered_module(self, rid):
        try:
            self.registered_module = RegisteredModule.objects.get(id=rid)
        except Exception, e:
            self.debugger.catch_error('fetch_registered_module: ', e)
예제 #22
0
class PortalManager(object):


    def __init__(self, request, *args, **kwargs):
        self.sites = None
        self.activeSite = None
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.modules = None
        self.module = None
        self.module_types = None
        self.module_type = None
        self.fetchOptions = dict()
        self.reqsite = None
        self.request = request
        self.get_user_site()

    def fetch_data(self):
        try:
            self.sites = Site.objects.all()
        except Exception, e:
            self.debugger.catch_error('fetch_data: ', e)
예제 #23
0
 def __init__(self, request, *args, **kwargs):
     self.sites = None
     self.activeSite = None
     self.debugger = Debugger(__MNAME__, __FNAME__)
     self.modules = None
     self.module = None
     self.module_types = None
     self.module_type = None
     self.fetchOptions = dict()
     self.reqsite = None
     self.request = request
     self.get_user_site()
예제 #24
0
파일: language.py 프로젝트: MobyDevel/Rtm
class LanguageManager(object):

    def __init__(self, request, *args, **kwargs):
        super(LanguageManager, self).__init__(*args, **kwargs)
        self.currentLanguage = None
        self.activeLanguages = None
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.fetch_current_language(request)
        self.fetch_active_languages()
        self.sheet = None
        self.fullpath = None
        self.path = None
        self.order = 'name'
        self.model = Language()
        self.modelName = 'Language'
        self.moduleName = '__adm_Language__'

    def fetch_current_language(self, request):
        """ pobiera aktualnie ustawiony jezyk i zapisuje go do sesji """
        changedLanguage = False
        if request.method == 'GET':
            try:
                lang = request.GET['lang'] # kliknieto na zmiane jezyka
                request.session['lang'] = lang
                langSymbol = lang
                changedLanguage = True
            except Exception,e:
                self.debugger.catch_error('fetch_current_language: ',e)
                pass

        if not changedLanguage:
            """ nie bylo zmiany jezyka, sprawdz czy jezyk jest ustawiony w sesji
                jesli nie to ustaw na domyslny z pliku ustawien """
            try:
                langSymbol = request.session['lang']
            except Exception,e:
                langSymbol = settings.DEFAULTPORTALLANG
                request.session['lang'] = langSymbol
                self.debugger.catch_error('fetch_current_language: ',e)
예제 #25
0
class LanguageManager(object):
    def __init__(self, request, *args, **kwargs):
        super(LanguageManager, self).__init__(*args, **kwargs)
        self.currentLanguage = None
        self.activeLanguages = None
        self.debugger = Debugger(__MNAME__, __FNAME__)
        self.fetch_current_language(request)
        self.fetch_active_languages()
        self.sheet = None
        self.fullpath = None
        self.path = None
        self.order = 'name'
        self.model = Language()
        self.modelName = 'Language'
        self.moduleName = '__adm_Language__'

    def fetch_current_language(self, request):
        """ pobiera aktualnie ustawiony jezyk i zapisuje go do sesji """
        changedLanguage = False
        if request.method == 'GET':
            try:
                lang = request.GET['lang']  # kliknieto na zmiane jezyka
                request.session['lang'] = lang
                langSymbol = lang
                changedLanguage = True
            except Exception, e:
                self.debugger.catch_error('fetch_current_language: ', e)
                pass

        if not changedLanguage:
            """ nie bylo zmiany jezyka, sprawdz czy jezyk jest ustawiony w sesji
                jesli nie to ustaw na domyslny z pliku ustawien """
            try:
                langSymbol = request.session['lang']
            except Exception, e:
                langSymbol = settings.DEFAULTPORTALLANG
                request.session['lang'] = langSymbol
                self.debugger.catch_error('fetch_current_language: ', e)
예제 #26
0
파일: language.py 프로젝트: MobyDevel/Rtm
 def __init__(self, request, *args, **kwargs):
     super(LanguageManager, self).__init__(*args, **kwargs)
     self.currentLanguage = None
     self.activeLanguages = None
     self.debugger = Debugger(__MNAME__,__FNAME__)
     self.fetch_current_language(request)
     self.fetch_active_languages()
     self.sheet = None
     self.fullpath = None
     self.path = None
     self.order = 'name'
     self.model = Language()
     self.modelName = 'Language'
     self.moduleName = '__adm_Language__'
예제 #27
0
class ModuleManager(object):
    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.items = []
        self.treemenuitems = None
        self.options = None
        self.language = None
        self.debugger = Debugger(__MNAME__, __FNAME__)
        self.category = None

    def get_data(self, lang, site):
        self.fetch_options()
        if self.options is not None:
            if self.options.category is not None:
                self.category = self.options.category
                self.fetch_items(lang)
                #for item in self.items:

    def fetch_registered_module(self, rid):
        try:
            self.registered_module = RegisteredModule.objects.get(id=rid)
        except Exception, e:
            self.debugger.catch_error('fetch_registered_module: ', e)
예제 #28
0
파일: permission.py 프로젝트: MobyDevel/Rtm
class PermissionManager(object):
    """ Permission
    """

    def __init__(self, *args, **kwargs):
        """Init
        """
        self.user = None
        self.admin = False
        self.panel = False
        self.user_permissions = None
        self.permissions = { 'public': True, 'read': False, 'write': False, 'delete': False, 'add': False, 'own': False }
        self.admin_permissions = { 'public': False, 'read': False, 'write': False, 'delete': False, 'add': False, 'own': False }
        self.all_user_permissions = dict()
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.context = dict()
        #self.options = None

    def fetch_user(self, request):
        if request.method == 'POST':
            if request.POST.has_key('uname'):
                if request.POST.has_key('upasswd'):
                    self.check_login(request)

    def check_login(self, request):
        self.user = None
        self.panel = False
        uname = request.POST['uname']
        upasswd = request.POST['upasswd']

        if request.POST.has_key('panel'):
            options = { 'username': uname, 'password': upasswd, 'confirmed': '1' }
            try:
                users = UserProfile.objects.optfilter(options)
            except Exception,e:
                self.debugger.catch_error('fetch_user: ',e)
        else:
예제 #29
0
class PermissionManager(object):
    """ Permission
    """

    def __init__(self, *args, **kwargs):
        """Init
        """
        self.user = None
        self.panel = False
        self.user_permissions = None
        self.permissions = { 'public': True, 'read': False, 'write': False, 'delete': False, 'add': False, 'own': False }
        self.admin_permissions = { 'public': False, 'read': False, 'write': False, 'delete': False, 'add': False, 'own': False }
        self.all_user_permissions = dict()
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.context = dict()
        #self.options = None

    def fetch_user(self, request):
        if request.method == 'POST':
            if request.POST.has_key('uname'):
                if request.POST.has_key('upasswd'):
                    self.check_login(request)

    def check_login(self, request):
        self.user = None
        self.panel = False
        uname = request.POST['uname']
        upasswd = request.POST['upasswd']

        if request.POST.has_key('panel'):
            options = { 'username': uname, 'password': upasswd, 'confirmed': '1' }
            try:
                users = UserProfile.objects.optfilter(options)
            except Exception,e:
                self.debugger.catch_error('fetch_user: ',e)
        else:
예제 #30
0
class ModuleManager(object):
    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.options = None
        self.language = None
        self.categories = None
        self.debugger = Debugger(__MNAME__, __FNAME__)
        self.fetch_opt = dict()
        self.articles = None

    def get_data(self):
        self.fetch_articles()

    def fetch_articles(self):
        lang = Language.objects.get(symbol='pl')
        if self.options is not None:
            amax = 10
            if self.options.has_key('C'):
                try:
                    amax = int(self.options['C'])
                except Exception, e:
                    self.debugger.catch_error('fetch_articles: ', e)

        self.articles = Article.objects.all().order_by('-date')[:amax]
        for article in self.articles:
            article.get_language(lang)
            if article.language is not None:
                if self.options.has_key('E'):
                    try:
                        title = article.language.title.encode(
                            self.options['E'])
                        #article.language.title = title
                        text = article.language.text.encode(self.options['E'])
                        print title, ' -- ', article.language.title
                    except Exception, e:
                        self.debugger.catch_error('fetch_articles: ', e)
예제 #31
0
class ModuleManager(object):

    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.options = None
        self.language = None
        self.categories = None
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.fetch_opt = dict()
        self.articles = None

    def get_data(self):
        self.fetch_articles()

    def fetch_articles(self):
        lang = Language.objects.get(symbol='pl')
        if self.options is not None:
            amax = 10
            if self.options.has_key('C'):
                try:
                    amax = int(self.options['C'])
                except Exception,e:
                    self.debugger.catch_error('fetch_articles: ', e)

        self.articles = Article.objects.all().order_by('-date')[:amax]
        for article in self.articles:
            article.get_language(lang)
            if article.language is not None:
                if self.options.has_key('E'):
                    try:
                        title = article.language.title.encode(self.options['E'])
                        #article.language.title = title
                        text = article.language.text.encode(self.options['E'])
                        print title, ' -- ',article.language.title
                    except Exception, e:
                        self.debugger.catch_error('fetch_articles: ', e)
예제 #32
0
파일: base.py 프로젝트: MobyDevel/Rtm
 def __init__(self, *args, **kwargs):
     """Init
     """
     self.item = None
     self.items = None
     self.options_item = None
     self.rangeItemsStart = 1
     self.rangeItemsEnd = 10
     self.order = None
     self.model = None
     self.modelLanguage = None
     self.modelOptions = None
     self.fetchOptions = None
     self.debugger = Debugger(__MNAME__, __FNAME__)
     self.context = dict()
     self.options = None
예제 #33
0
파일: megamenu.py 프로젝트: MobyDevel/Rtm
 def __init__(self, *args, **kwargs):
     self.registered_module = None
     self.megamenu_items = []
     self.options = None
     self.debugger = Debugger(__MNAME__, __FNAME__)
     self.permissions = None
예제 #34
0
class ModuleManager(ModuleBaseManager):

    def __init__(self, *args, **kwargs):
        super(ModuleBaseManager, self).__init__(*args, **kwargs)
        self.registered_module = None
        self.menu = None
        self.menuitems = []
        self.treemenuitems = None
        self.options = None
        self.language = None
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.permissions = None

    def get_data(self, lang, site):
        self.language = lang
        self.fetch_options()
        self.fetch_menu()
        self.fetch_menu_items()

        self.treemenuitems = self.get_items_as_tree()

        newitems = []
        for item in self.menuitems:
            if item.parent is not None:
                newitems.append(item)
        self.menuitems = newitems

        safemenuitems = []
        if self.menuitems is not None:
            for item in self.menuitems:
                if self.permissions is not None:
                    self.permissions.permissions = None
                err = 0
                if item is not None:

                    item.get_language(lang.id)
                    item.module_model = get_module_options_model(item.registered_module.id)

                    if self.permissions is not None:
                        self.permissions.prepare_permissions(item.permissions)
                        self.permissions.compare_permissions(item, item.__class__.__name__, False)

                    options = None
                    try:
                        options = item.module_model.__class__.objects.filter(menuitem=item)
                        if len(options) > 0:
                            options = options[0]
                        else:
                            options = None
                    except Exception, e:
                        err = 1
                        options = None
                        self.debugger.catch_error('get_data: ', e)

                    if options is not None:
                        item.options = options
                        try:
                            item.slug = item.options.get_slug(lang.id)
                            item.url_prefix = item.options.get_url_prefix()
                            item.object_id = item.options.get_object_id()
                            item.registered_module = item.options.registered_module
                        except Exception, e:
                            err = 1
                            self.debugger.catch_error('get_data: ', e)
                    else:
                        err = 1
                if err == 0:
                    if self.permissions is not None:
                        if self.permissions.permissions['public'] is True:
                            safemenuitems.append(item)
                    # chwilowo!!! usunac
                    #else:
                    #    safemenuitems.append(item)
            self.menuitems = safemenuitems
예제 #35
0
class ModuleManager(object):
    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.megamenu_items = []
        self.options = None
        self.debugger = Debugger(__MNAME__, __FNAME__)
        self.permissions = None

    def get_data(self, lang, site):
        self.language = lang
        self.fetch_megamenu()
        if self.megamenu_items:
            for item in self.megamenu_items:
                item.get_language(lang.id)
                self.prepare_menu(item, lang)
                self.prepare_category(item, lang, site)

                width = 3
                if item.category is not None:
                    width = width + 310
                if item.menu is not None:
                    width = width + 200
                width = width + 250

                item.width = width

    def prepare_category(self, item, lang, site):
        if item.category is not None:
            #item.category = self.get_category(item.category, lang, site)
            item.articles = self.get_articles(item.category, lang, site)
            for item_art in item.articles:
                item_art.get_language(lang.id)

    def prepare_menu(self, item, lang):
        safemenuitems = []
        err = 0
        if item.menu is not None:
            item.menu.get_language(lang.id)
            item.menu.menuitems = self.get_menu_items(item.menu)
            err = 0
            for it in item.menu.menuitems:
                err = 0
                it.get_language(lang.id)

                it.module_model = get_module_options_model(
                    it.registered_module.id)
                try:
                    options = it.module_model.__class__.objects.filter(
                        menuitem=it)
                    if len(options) > 0:
                        options = options[0]
                    else:
                        options = None
                except Exception, e:
                    err = 1
                    options = None
                    self.debugger.catch_error('prepare_menu: ', e)

                if options is not None:
                    try:
                        it.options = options
                        it.slug = it.options.get_slug(lang.id)
                        it.url_prefix = it.options.get_url_prefix()
                        it.object_id = it.options.get_object_id()
                        it.registered_module_id = it.options.registered_module.id
                    except Exception, e:
                        self.debugger.catch_error('prepare_menu: ', e)
                        err = 1
                else:
                    err = 1
                if err == 0:
                    safemenuitems.append(it)
            item.menu.menuitems = safemenuitems
예제 #36
0
class ModuleManager(ModuleBaseManager):
    def __init__(self, *args, **kwargs):
        super(ModuleBaseManager, self).__init__(*args, **kwargs)
        self.registered_module = None
        self.menu = None
        self.menuitems = []
        self.treemenuitems = None
        self.options = None
        self.language = None
        self.debugger = Debugger(__MNAME__, __FNAME__)
        self.permissions = None

    def get_data(self, lang, site):
        self.language = lang
        self.fetch_options()
        self.fetch_menu()
        self.fetch_menu_items()

        self.treemenuitems = self.get_items_as_tree()

        newitems = []
        for item in self.menuitems:
            if item.parent is not None:
                newitems.append(item)
        self.menuitems = newitems

        safemenuitems = []
        if self.menuitems is not None:
            for item in self.menuitems:
                if self.permissions is not None:
                    self.permissions.permissions = None
                err = 0
                if item is not None:

                    item.get_language(lang.id)
                    item.module_model = get_module_options_model(
                        item.registered_module.id)

                    if self.permissions is not None:
                        self.permissions.prepare_permissions(item.permissions)
                        self.permissions.compare_permissions(
                            item, item.__class__.__name__, False)

                    options = None
                    try:
                        options = item.module_model.__class__.objects.filter(
                            menuitem=item)
                        if len(options) > 0:
                            options = options[0]
                        else:
                            options = None
                    except Exception, e:
                        err = 1
                        options = None
                        self.debugger.catch_error('get_data: ', e)

                    if options is not None:
                        item.options = options
                        try:
                            item.slug = item.options.get_slug(lang.id)
                            item.url_prefix = item.options.get_url_prefix()
                            item.object_id = item.options.get_object_id()
                            item.registered_module = item.options.registered_module
                        except Exception, e:
                            err = 1
                            self.debugger.catch_error('get_data: ', e)
                    else:
                        err = 1
                if err == 0:
                    if self.permissions is not None:
                        if self.permissions.permissions['public'] is True:
                            safemenuitems.append(item)
                    # chwilowo!!! usunac
                    #else:
                    #    safemenuitems.append(item)
            self.menuitems = safemenuitems
예제 #37
0
class SystemManager(object):

    def __init__(self, request, *args, **kwargs):
        self.portal = PortalManager(request)
        self.manager = None
        self.extramanager = None
        self.requester = Requester(request)
        self.sheet = SheetManager()
        self.sheet.request = request
        self.sheet.admin_site = settings.DEFAULT_SITE_ID
        self.language = LanguageManager(request)
        self.data = dict()
        self.items = None
        self.urls = UrlContener()
        self.template = None
        self.activerootmenu = None
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.portal.fetch_data()
        self.language.fetch_active_languages()
        self.language.fetch_current_language(request)
        self.requester.get_messages(request)
        self.sheet.reqsite = settings.DEFAULT_SITE_ID
        self.portal.reqsite = settings.DEFAULT_SITE_ID
        self.portal.fetch_active_site(self.requester.rData['activesite'])
        self.portal.fetchOptions = { 'site': self.portal.activeSite.id, 'active': '1', 'activesite': self.portal.activeSite.id }
        self.portal.fetch_modules()
        self.permission = PermissionManager()

        #self.get_active_root_menu()
        self.permission.check_logged_user(request)


    """ Dont need
    def get_active_root_menu(self):
        try:
            self.activerootmenu = Menu.objects.get(id=self.requester.rData['rm'])
        except Exception, e:
            self.debugger.catch_error('get_active_root_menu: ', e)
    """

    def get_context(self, block=False):
        self.data.update(self.sheet.get_context())
        if self.manager is not None:
            self.data.update(self.manager.get_context())
        self.data.update(self.language.get_context())
        self.data.update(self.requester.get_context())
        self.data.update(self.portal.get_context())
        self.data.update(self.permission.get_context())
        self.data.update({ 'activerootmenu': self.activerootmenu })
        self.data.update({ 'urls': self.urls })
        self.data.update({ 'data': self.items })
        if block is True:
            self.data.update({ 'nochanges': True })

        if self.manager is not None:
            if self.manager.model is not None:
                self.data.update({ 'model': self.manager.model.__class__.__name__ })
            else:
                self.data.update({ 'model': None })
        else:
            self.data.update({ 'model': None })
        #key = str(self.manager.moduleName)
        #self.requester.pages(key)

        return self.data

    def show_item(self, request, itemId, admin=False):
        if itemId is not None:
            if itemId != -1:
                self.manager.fetch_item(itemId)
                self.manager.set_language(self.language.currentLanguage)
                self.items = self.manager.item
                self.permission.compare_permissions(self.manager.item, self.manager.model.__class__.__name__, admin)

    def show_item_by_slug(self, request, slug, lang, admin=False):
        if slug is not None:
            if slug != -1:
                self.manager.fetch_item_by_slug(slug, lang)
                self.manager.set_language(self.language.currentLanguage)
                self.items = self.manager.item
                self.permission.compare_permissions(self.manager.item, self.manager.model.__class__.__name__, admin)

    def show_items(self, request, default_filter=False, allow_tree=False, has_language=True, admin=False):
        key = self.manager.moduleName
        self.requester.pages(key, request)

        if default_filter is False:
            count = self.manager.count_items(default_filter=False)
        else:
            count = self.manager.count_items(default_filter=True)

        pages = map(lambda x:x,range(1,((count/int(self.requester.rData[key+'pni'])) + 1)))
        rangedPages = ranged_pages(pages, int(self.requester.rData[key+'page']), 3, 2)
        self.requester.rData[key+'pages'] = rangedPages
        self.requester.rData['pages'] = rangedPages

        self.manager.rangeItemsStart = self.requester.rData['pni'] * self.requester.rData['page']
        if self.manager.rangeItemsStart != 0:
            self.manager.rangeItemsEnd = self.manager.rangeItemsStart + self.requester.rData['pni']
        else:
            self.manager.rangeItemsEnd = self.requester.rData['pni']

        #print self.manager.rangeItemsStart, self.manager.rangeItemsEnd

        if allow_tree == True:
            if int(self.requester.rData['selectedactivity']) == -1:
                self.manager.rangeItemsStart = None
                self.manager.rangeItemsEnd = None

        if self.requester.rData['selectedmenu'] is None:
            if self.requester.rData['selectedmenu'] == -1:
                self.manager.rangeItemsStart = None
                self.manager.rangeItemsEnd = None

        if default_filter is False:
            self.manager.fetch_items(default_filter=False)
        else:
            self.manager.fetch_items(default_filter=True)

        if has_language is True:
            self.manager.set_language(self.language.currentLanguage)

        #self.template = loader.get_template(self.sheet.get_sheet_file('admin_list'))

        if allow_tree is True:
            if int(self.requester.rData['selectedactivity']) == -1:
                if self.requester.rData['selectedmenu'] is None:
                    self.items = self.manager.get_items_as_tree(request)
                else:
                    if self.requester.rData['selectedmenu'] == -1:
                        self.items = self.manager.get_items_as_tree(request)
                    else:
                        self.items = self.manager.get_items()
            else:
                self.items = self.manager.get_items()
        else:
            self.items = self.manager.get_items()

        self.permission.compare_permissions(None, self.manager.model.__class__.__name__, admin)


    def edit_item(self, request, itemId, set_owner=True, new_item=False):
        self.manager.fetch_item(itemId)
        self.manager.fetch_items()
        self.items = self.manager.item

        if self.manager.modelLanguage is not None:
            self.language.set_non_existent_language_items(self.manager.item, self.manager.modelLanguage.__class__)
            self.manager.set_language(self.language.currentLanguage)

        #t = loader.get_template(self.sheet.get_sheet_file('admin_edit'))

        if self.manager.edit_item(request):

            self.portal.fetch_active_site(self.requester.rData['activesite'])
            if set_owner is True:
                self.manager.item.owner = self.permission.user
            try:
                self.manager.item.sites.add(self.portal.get_active_site())
            except Exception,e:
                self.debugger.catch_error('edit_item', e)
            try:
                #sites = self.manager.item.sites.all()
                #actives = self.manager.item.active.all()
                self.manager.item.active.add(self.portal.get_active_site())
            except Exception,e:
                self.debugger.catch_error('edit_item', e)

            if request.POST['sn'] == '1':
                return HttpResponseRedirect(reverse(self.urls.add)) # wracamy do nowego elementu
            else:
                return HttpResponseRedirect(reverse(self.urls.show_items)) # wracamy do listy
예제 #38
0
파일: megamenu.py 프로젝트: MobyDevel/Rtm
class ModuleManager(object):
    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.megamenu_items = []
        self.options = None
        self.debugger = Debugger(__MNAME__, __FNAME__)
        self.permissions = None

    def get_data(self, lang, site):
        self.language = lang
        self.fetch_megamenu()
        if self.megamenu_items:
            for item in self.megamenu_items:
                item.get_language(lang.id)
                self.prepare_menu(item, lang)
                self.prepare_category(item, lang, site)

                width = 3
                if item.category is not None:
                    width = width + 310
                if item.menu is not None:
                    width = width + 200
                width = width + 250

                item.width = width

    def prepare_category(self, item, lang, site):
        if item.category is not None:
            # item.category = self.get_category(item.category, lang, site)
            item.articles = self.get_articles(item.category, lang, site)
            for item_art in item.articles:
                item_art.get_language(lang.id)

    def prepare_menu(self, item, lang):
        safemenuitems = []
        err = 0
        if item.menu is not None:
            item.menu.get_language(lang.id)
            item.menu.menuitems = self.get_menu_items(item.menu)
            err = 0
            for it in item.menu.menuitems:
                err = 0
                it.get_language(lang.id)

                it.module_model = get_module_options_model(it.registered_module.id)
                try:
                    options = it.module_model.__class__.objects.filter(menuitem=it)
                    if len(options) > 0:
                        options = options[0]
                    else:
                        options = None
                except Exception, e:
                    err = 1
                    options = None
                    self.debugger.catch_error("prepare_menu: ", e)

                if options is not None:
                    try:
                        it.options = options
                        it.slug = it.options.get_slug(lang.id)
                        it.url_prefix = it.options.get_url_prefix()
                        it.object_id = it.options.get_object_id()
                        it.registered_module_id = it.options.registered_module.id
                    except Exception, e:
                        self.debugger.catch_error("prepare_menu: ", e)
                        err = 1
                else:
                    err = 1
                if err == 0:
                    safemenuitems.append(it)
            item.menu.menuitems = safemenuitems
예제 #39
0
class ModuleManager(object):
    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.options = None
        self.language = None
        self.adv = None
        self.advgroup = None
        self.debugger = Debugger(__MNAME__, __FNAME__)
        self.fetch_opt = dict()

    def get_data(self, lang, site):
        #date = ((datetime.date.today() + datetime.timedelta(days=1)) - datetime.timedelta(6 * 365 / 12))
        self.language = lang
        self.fetch_options()
        if self.options is not None:
            if self.options.advgroup is not None:
                self.fetch_adv_group(self.options.advgroup.id, lang, site)
            elif self.options.adv is not None:
                self.fetch_adv(self.options.adv.id)

            if self.advgroup is not None:
                if self.advs is not None:
                    filteradv = []
                    for adv in self.advs:
                        #print adv
                        to_filter = False
                        if adv.datestart is not None:
                            if adv.datestart <= datetime.today():
                                if adv.dateend is not None:
                                    if adv.dateend >= datetime.today():
                                        to_filter = True
                                else:
                                    to_filter = True
                        #print '1: ', to_filter
                        if adv.views is not None:
                            if adv.views != 0:
                                if adv.views > adv.visits:
                                    to_filter = False
                        #print '2: ', to_filter
                        if adv.clicks is not None:
                            if adv.clicks != 0:
                                if adv.clicks > adv.clickcount:
                                    to_filter = False
                        #print '3: ', to_filter
                        if adv.is_active is False:
                            to_filter = False
                        #print '4: ', to_filter
                        if to_filter is True:
                            size = str(adv.group.width) + "x" + str(
                                adv.group.height)
                            adv.size = size
                            filteradv.append(adv)
                        #print '5: ', to_filter

                    total = len(filteradv)  #self.advs.count()
                    if total > 1:
                        self.adv = filteradv[random.randrange(
                            len(filteradv)
                        )]  #Adv.objects.filter(group=self.advgroup).order_by('?')[0]
                    elif total == 1:
                        self.adv = filteradv[0]

                    one_adv = False
                    if self.options.ammount is not None:
                        if self.options.ammount > 0:
                            random_advs = []
                            for i in range(0, (self.options.ammount)):
                                random_advs.append(
                                    self.select_random(filteradv))
                            self.advs = random_advs  #filteradv[:self.options.ammount]
                            for adv in self.advs:
                                self.adv.visits = self.adv.visits + 1
                                self.adv.save()
                        else:
                            one_adv = True
                    else:
                        one_adv = True

                    if one_adv is True:
                        self.adv.visits = self.adv.visits + 1
                    self.adv.save()

    def select_random(self, data):
        if data != []:
            pos = random.randrange(len(data))
            elem = data[pos]
            data[pos] = data[-1]
            del data[-1]
            return elem
        else:
            return None

    def fetch_registered_module(self, rid):
        try:
            self.registered_module = RegisteredModule.objects.get(id=rid)
        except Exception, e:
            self.debugger.catch_error('fetch_registered_module: ', e)
예제 #40
0
class ModuleManager(object):
    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.menu = None
        self.menuitems = []
        self.treemenuitems = None
        self.options = None
        self.language = None
        self.debugger = Debugger(__MNAME__, __FNAME__)

    def get_data(self, lang, site):
        self.language = lang
        self.fetch_options()
        self.fetch_menu()
        self.fetch_menu_items()

        self.treemenuitems = self.get_items_as_tree()

        newitems = []
        for item in self.menuitems:
            if item.parent is not None:
                newitems.append(item)
        self.menuitems = newitems

        safemenuitems = []
        if self.menuitems is not None:
            for item in self.menuitems:
                err = 0
                if item is not None:
                    item.get_language(lang.id)
                    item.module_model = get_module_options_model(
                        item.registered_module.id)

                    options = None
                    try:
                        options = item.module_model.__class__.objects.filter(
                            menuitem=item)
                        if len(options) > 0:
                            options = options[0]
                        else:
                            options = None
                    except Exception, e:
                        err = 1
                        options = None
                        self.debugger.catch_error('get_data: ', e)

                    if options is not None:
                        item.options = options
                        try:
                            item.slug = item.options.get_slug(lang.id)
                            item.url_prefix = item.options.get_url_prefix()
                            item.object_id = item.options.get_object_id()
                            item.registered_module = item.options.registered_module
                        except Exception, e:
                            err = 1
                            self.debugger.catch_error('get_data: ', e)
                    else:
                        err = 1
                if err == 0:
                    safemenuitems.append(item)
            self.menuitems = safemenuitems
예제 #41
0
class Requester(object):


    def __init__(self, request, *args, **kwargs):

        self.selectedActivity = -1
        self.painateni = None
        self.numItemsOnPage = 25
        self.contextdata = dict()
        self.activeSite = None
        self.selectedCategory = None
        self.request = request
        self.rData = {
            'selectedactivity': -1,
            'activesite': None,
            'pni': 10,
            'pages': [],
            'page': 0,
            'pprev': None,
            'pnext': 1,
            'pagesinfo': {},
            #'paginateni': 10,
            'rm': None,
            'selectedmenu': -1,
            'selectedcategory': None,
            'selectedtest': None,
            'selectedcourse': None,
            'selectedquestion': None,
            'adminall': settings.ADMINALLSITES,
            'currentdate': datetime.now()
        }
        #print self.rData
        self.debugger = Debugger(__MNAME__,__FNAME__)
        super(Requester, self).__init__(*args, **kwargs)

    def pages(self, key, request):
        self.get_opt_pages(key, 'pni', request, 10, True)
        self.get_opt_pages(key, 'page', request, 0, True)
        self.get_opt_pages(key, 'pages', request, [], False)
        self.get_opt_pages(key, 'pprev', request, None, False)
        self.get_opt_pages(key, 'pnext', request, 2, True)
        if request.method == 'GET':
            if request.GET.has_key('pni'):
                self.rData[key+'page'] = 0
        self.set_session_values(request)


    def get_opt_pages(self, key1, key2, request, default, integer):
        if key1 is not None:
            if key2 is not None:
                if not self.rData.has_key(key1+key2):
                    if request.session.has_key(key1+key2):
                        self.rData[key1+key2] = request.session[key1+key2]
                    else:
                        self.rData.update({ key1+key2: default })

                if self.rData.has_key(key1+key2):
                    if request.method == 'GET':
                        if request.GET.has_key(key2):
                            self.rData[key1+key2] = request.GET[key2]
                        else:
                            if self.rData[key1+key2] == '':
                                self.rData[key1+key2] = default
                            self.rData[key2] = self.rData[key1+key2]

                if integer is True:
                    if self.rData.has_key(key2):
                        self.rData[key2] = int(self.rData[key2])


    def get_messages(self, request):
        if settings.ADMINALLSITES is False:
            self.activeSite = settings.SITE_ID
        else:
            #self.get_option('activesite', request, True)
            self.get_session_active_site(request)
        self.get_option('selectedcategory', request)
        self.get_option('pni', request)
        self.get_option('pages', request)
        self.get_option('page', request)
        self.get_option('pprev', request)
        self.get_option('pnext', request)
        self.get_option('selectedmenu', request, True)
        self.get_option('selectedactivity', request)
        self.get_option('selectedtest', request, True)
        self.get_option('selectedcourse', request, True)
        self.get_option('selectedquestion', request, True)
        self.get_session_active_site(request)
        self.set_session_values(request)
        self.get_option('rm', request)

    def get_page(self, request):
        if self.rData['page'] == 1:
                self.rData['pprev'] = None
        else:
                self.rData['pprev'] = int(self.rData['page']) - 1

        self.rData['pnext'] = int(self.rData['page']) + 1

        #data.update({ 'page': page, 'prevpage': prevpage, 'nextpage': nextpage })

    def get_option(self, key, request, integer=False):
        if not self.rData.has_key(key):
            self.rData.update({ key: '' })

        data = ''
        try:
            data = request.session[key]
        except Exception,e:
            self.debugger.catch_error('get_option: ', e)

        try:
            data = request.GET[key]
        except Exception,e:
            self.debugger.catch_error('get_option: ', e)
예제 #42
0
 def __init__(self, *args, **kwargs):
     self.registered_module = None
     self.megamenu_items = []
     self.options = None
     self.debugger = Debugger(__MNAME__, __FNAME__)
     self.permissions = None
예제 #43
0
파일: adv_module.py 프로젝트: MobyDevel/Rtm
class ModuleManager(object):

    def __init__(self, *args, **kwargs):
        self.registered_module = None
        self.options = None
        self.language = None
        self.adv = None
        self.advgroup = None
        self.debugger = Debugger(__MNAME__,__FNAME__)
        self.fetch_opt = dict()

    def get_data(self, lang, site):
        #date = ((datetime.date.today() + datetime.timedelta(days=1)) - datetime.timedelta(6 * 365 / 12))
        self.language = lang
        self.fetch_options()
        if self.options is not None:
            if self.options.advgroup is not None:
                self.fetch_adv_group(self.options.advgroup.id, lang, site)
            elif self.options.adv is not None:
                self.fetch_adv(self.options.adv.id)

            if self.advgroup is not None:
                if self.advs is not None:
                    filteradv = []
                    for adv in self.advs:
                        #print adv
                        to_filter = False
                        if adv.datestart is not None:
                            if adv.datestart <= datetime.today():
                                if adv.dateend is not None:
                                    if adv.dateend >= datetime.today():
                                        to_filter = True
                                else:
                                    to_filter = True
                        #print '1: ', to_filter
                        if adv.views is not None:
                            if adv.views != 0:
                                if adv.views > adv.visits:
                                    to_filter = False
                        #print '2: ', to_filter
                        if adv.clicks is not None:
                            if adv.clicks != 0:
                                if adv.clicks > adv.clickcount:
                                    to_filter = False
                        #print '3: ', to_filter
                        if adv.is_active is False:
                            to_filter = False
                        #print '4: ', to_filter
                        if to_filter is True:
                            size = str(adv.group.width) + "x" + str(adv.group.height)
                            adv.size = size
                            filteradv.append(adv)
                        #print '5: ', to_filter

                    total = len(filteradv) #self.advs.count()
                    if total > 1:
                        self.adv = filteradv[random.randrange(len(filteradv))] #Adv.objects.filter(group=self.advgroup).order_by('?')[0]
                    elif total == 1:
                        self.adv = filteradv[0]

                    one_adv = False
                    if self.options.ammount is not None:
                        if self.options.ammount > 0:
                            random_advs = []
                            for i in range(0, (self.options.ammount)):
                                random_advs.append(self.select_random(filteradv))
                            self.advs = random_advs #filteradv[:self.options.ammount]
                            for adv in self.advs:
                                self.adv.visits = self.adv.visits + 1
                                self.adv.save()
                        else:
                            one_adv = True
                    else:
                        one_adv = True

                    if one_adv is True:
                        self.adv.visits = self.adv.visits + 1
                    self.adv.save()

    def select_random(self, data):
        if data != []:
            pos = random.randrange( len(data) )
            elem = data[pos]
            data[pos] = data[-1]
            del data[-1]
            return elem
        else:
            return None

    def fetch_registered_module(self, rid):
        try:
            self.registered_module = RegisteredModule.objects.get(id=rid)
        except Exception, e:
            self.debugger.catch_error('fetch_registered_module: ', e)
예제 #44
0
 def __init__(self, *args, **kwargs):
     self.options = None
     self.debugger = Debugger(__MNAME__,__FNAME__)