コード例 #1
0
ファイル: forms.py プロジェクト: ejaury/maitreya_van
    def save(self, commit=True):
        try:
            # so we can get form.save_m2m()
            page = super(BasePageAdminForm, self).save(commit=False)
            page.save()
            url = page.get_absolute_url()
            menu_kwargs = {
                'parent': self.cleaned_data['parent_menu_item'],
                'caption': self.cleaned_data['menu_caption'],
                'url': url,
            }
            if not self.instance.menu_item:
                menu_item = MenuItem(**menu_kwargs)
                menu_item.save()
                self.instance.menu_item = menu_item
                self.instance.save()
            else:
                for attr, val in menu_kwargs.items():
                    setattr(self.instance.menu_item, attr, val)
                self.instance.menu_item.save()

            menu_item_ext, created = MenuItemExtension.objects.get_or_create(
                menu_item=self.instance.menu_item)
            menu_item_ext.selected_patterns = '^%s$' % url
            menu_item_ext.save()
        except Exception:
            transaction.rollback()
            raise
        else:
            return page
コード例 #2
0
 def save(self, force_insert=False, **kwargs):
     if not self.root_item:
         root_item = MenuItem()
         root_item.caption = ugettext('root')
         if not self.pk:  # If creating a new object (i.e does not have a pk yet)
             super(Menu, self).save(force_insert, **kwargs)  # Save, so that it gets a pk
             force_insert = False
         root_item.menu = self
         root_item.save()  # Save, so that it gets a pk
         self.root_item = root_item
     super(Menu, self).save(force_insert, **kwargs)
コード例 #3
0
ファイル: models.py プロジェクト: KANU82/maitreya_van
 def save(self, *args, **kwargs):
     try:
         super(BasePage, self).save(*args, **kwargs)
         menu_kwargs = {
             'parent': self.parent_menu_item,
             'caption': self.title,
             'url': self.get_absolute_url(),
         }
         if self.menu_item is None:
             menu_item = MenuItem(**menu_kwargs)
             menu_item.save()
             self.menu_item = menu_item
             super(BasePage, self).save(*args, **kwargs)
         else:
             for attr, val in menu_kwargs.items():
                 setattr(self.menu_item, attr, val)
             self.menu_item.save()
         menu_item_ext, created = MenuItemExtension.objects.get_or_create(
             menu_item=self.menu_item)
         menu_item_ext.selected_patterns = '^%s$' % self.get_absolute_url()
         menu_item_ext.save()
     except Exception:
         transaction.rollback()
         raise
コード例 #4
0
def run():

    from treemenus.models import Menu

    treemenus_menu_1 = Menu()
    treemenus_menu_1.name = u'root'
    treemenus_menu_1.save()

    treemenus_menu_2 = Menu()
    treemenus_menu_2.name = u'persona'
    treemenus_menu_2.save()

    treemenus_menu_3 = Menu()
    treemenus_menu_3.name = u'enfermeria'
    treemenus_menu_3.save()

    from treemenus.models import MenuItem

    treemenus_menuitem_1 = MenuItem()
    treemenus_menuitem_1.parent = None
    treemenus_menuitem_1.caption = u'root'
    treemenus_menuitem_1.url = u''
    treemenus_menuitem_1.named_url = u''
    treemenus_menuitem_1.level = 0
    treemenus_menuitem_1.rank = 0
    treemenus_menuitem_1.menu = treemenus_menu_1
    treemenus_menuitem_1.save()

    treemenus_menuitem_2 = MenuItem()
    treemenus_menuitem_2.parent = None
    treemenus_menuitem_2.caption = u'root'
    treemenus_menuitem_2.url = u''
    treemenus_menuitem_2.named_url = u''
    treemenus_menuitem_2.level = 0
    treemenus_menuitem_2.rank = 0
    treemenus_menuitem_2.menu = treemenus_menu_2
    treemenus_menuitem_2.save()

    treemenus_menuitem_3 = MenuItem()
    treemenus_menuitem_3.parent = treemenus_menuitem_1
    treemenus_menuitem_3.caption = u'Enfermer\xeda'
    treemenus_menuitem_3.url = u''
    treemenus_menuitem_3.named_url = u'nightingale-index'
    treemenus_menuitem_3.level = 1
    treemenus_menuitem_3.rank = 4
    treemenus_menuitem_3.menu = treemenus_menu_1
    treemenus_menuitem_3.save()

    treemenus_menuitem_4 = MenuItem()
    treemenus_menuitem_4.parent = treemenus_menuitem_1
    treemenus_menuitem_4.caption = u'Admisiones'
    treemenus_menuitem_4.url = u''
    treemenus_menuitem_4.named_url = u'admision-index '
    treemenus_menuitem_4.level = 1
    treemenus_menuitem_4.rank = 3
    treemenus_menuitem_4.menu = treemenus_menu_1
    treemenus_menuitem_4.save()

    treemenus_menuitem_5 = MenuItem()
    treemenus_menuitem_5.parent = treemenus_menuitem_1
    treemenus_menuitem_5.caption = u'Examenes'
    treemenus_menuitem_5.url = u''
    treemenus_menuitem_5.named_url = u'examen-index '
    treemenus_menuitem_5.level = 1
    treemenus_menuitem_5.rank = 2
    treemenus_menuitem_5.menu = treemenus_menu_1
    treemenus_menuitem_5.save()

    treemenus_menuitem_6 = MenuItem()
    treemenus_menuitem_6.parent = treemenus_menuitem_1
    treemenus_menuitem_6.caption = u'Inicio'
    treemenus_menuitem_6.url = u''
    treemenus_menuitem_6.named_url = u'home'
    treemenus_menuitem_6.level = 1
    treemenus_menuitem_6.rank = 0
    treemenus_menuitem_6.menu = treemenus_menu_1
    treemenus_menuitem_6.save()

    treemenus_menuitem_7 = MenuItem()
    treemenus_menuitem_7.parent = treemenus_menuitem_1
    treemenus_menuitem_7.caption = u'Pacientes'
    treemenus_menuitem_7.url = u''
    treemenus_menuitem_7.named_url = u'persona-index'
    treemenus_menuitem_7.level = 1
    treemenus_menuitem_7.rank = 1
    treemenus_menuitem_7.menu = treemenus_menu_1
    treemenus_menuitem_7.save()

    treemenus_menuitem_8 = MenuItem()
    treemenus_menuitem_8.parent = treemenus_menuitem_1
    treemenus_menuitem_8.caption = u'B\xfasqueda'
    treemenus_menuitem_8.url = u''
    treemenus_menuitem_8.named_url = u'haystack_search'
    treemenus_menuitem_8.level = 1
    treemenus_menuitem_8.rank = 5
    treemenus_menuitem_8.menu = treemenus_menu_1
    treemenus_menuitem_8.save()

    treemenus_menuitem_9 = MenuItem()
    treemenus_menuitem_9.parent = treemenus_menuitem_2
    treemenus_menuitem_9.caption = u'Agregar Examen'
    treemenus_menuitem_9.url = u''
    treemenus_menuitem_9.named_url = u'examen-agregar persona.id'
    treemenus_menuitem_9.level = 1
    treemenus_menuitem_9.rank = 0
    treemenus_menuitem_9.menu = treemenus_menu_2
    treemenus_menuitem_9.save()

    treemenus_menuitem_10 = MenuItem()
    treemenus_menuitem_10.parent = treemenus_menuitem_2
    treemenus_menuitem_10.caption = u'Ver Datos Personales'
    treemenus_menuitem_10.url = u''
    treemenus_menuitem_10.named_url = u'persona-view-id persona.id'
    treemenus_menuitem_10.level = 1
    treemenus_menuitem_10.rank = 1
    treemenus_menuitem_10.menu = treemenus_menu_2
    treemenus_menuitem_10.save()

    treemenus_menuitem_11 = MenuItem()
    treemenus_menuitem_11.parent = treemenus_menuitem_2
    treemenus_menuitem_11.caption = u'Examenes'
    treemenus_menuitem_11.url = u''
    treemenus_menuitem_11.named_url = u'examen-persona-lista persona.id'
    treemenus_menuitem_11.level = 1
    treemenus_menuitem_11.rank = 2
    treemenus_menuitem_11.menu = treemenus_menu_2
    treemenus_menuitem_11.save()

    treemenus_menuitem_12 = MenuItem()
    treemenus_menuitem_12.parent = treemenus_menuitem_2
    treemenus_menuitem_12.caption = u'Admitir Paciente'
    treemenus_menuitem_12.url = u''
    treemenus_menuitem_12.named_url = u'admision-persona-agregar persona.id'
    treemenus_menuitem_12.level = 1
    treemenus_menuitem_12.rank = 3
    treemenus_menuitem_12.menu = treemenus_menu_2
    treemenus_menuitem_12.save()

    treemenus_menu_1.root_item = treemenus_menuitem_1
    treemenus_menu_1.save()

    treemenus_menu_2.root_item = treemenus_menuitem_2
    treemenus_menu_2.save()
コード例 #5
0
ファイル: menus.py プロジェクト: Exian/hospicloud
def run():

    from treemenus.models import Menu

    treemenus_menu_1 = Menu()
    treemenus_menu_1.name = u'root'
    treemenus_menu_1.save()

    treemenus_menu_2 = Menu()
    treemenus_menu_2.name = u'persona'
    treemenus_menu_2.save()

    treemenus_menu_3 = Menu()
    treemenus_menu_3.name = u'enfermeria'
    treemenus_menu_3.save()

    from treemenus.models import MenuItem

    treemenus_menuitem_1 = MenuItem()
    treemenus_menuitem_1.parent = None
    treemenus_menuitem_1.caption = u'root'
    treemenus_menuitem_1.url = u''
    treemenus_menuitem_1.named_url = u''
    treemenus_menuitem_1.level = 0
    treemenus_menuitem_1.rank = 0
    treemenus_menuitem_1.menu = treemenus_menu_1
    treemenus_menuitem_1.save()

    treemenus_menuitem_2 = MenuItem()
    treemenus_menuitem_2.parent = None
    treemenus_menuitem_2.caption = u'root'
    treemenus_menuitem_2.url = u''
    treemenus_menuitem_2.named_url = u''
    treemenus_menuitem_2.level = 0
    treemenus_menuitem_2.rank = 0
    treemenus_menuitem_2.menu = treemenus_menu_2
    treemenus_menuitem_2.save()

    treemenus_menuitem_3 = MenuItem()
    treemenus_menuitem_3.parent = treemenus_menuitem_1
    treemenus_menuitem_3.caption = u'Enfermer\xeda'
    treemenus_menuitem_3.url = u''
    treemenus_menuitem_3.named_url = u'nightingale-index'
    treemenus_menuitem_3.level = 1
    treemenus_menuitem_3.rank = 4
    treemenus_menuitem_3.menu = treemenus_menu_1
    treemenus_menuitem_3.save()

    treemenus_menuitem_4 = MenuItem()
    treemenus_menuitem_4.parent = treemenus_menuitem_1
    treemenus_menuitem_4.caption = u'Admisiones'
    treemenus_menuitem_4.url = u''
    treemenus_menuitem_4.named_url = u'admision-index '
    treemenus_menuitem_4.level = 1
    treemenus_menuitem_4.rank = 3
    treemenus_menuitem_4.menu = treemenus_menu_1
    treemenus_menuitem_4.save()

    treemenus_menuitem_5 = MenuItem()
    treemenus_menuitem_5.parent = treemenus_menuitem_1
    treemenus_menuitem_5.caption = u'Examenes'
    treemenus_menuitem_5.url = u''
    treemenus_menuitem_5.named_url = u'examen-index '
    treemenus_menuitem_5.level = 1
    treemenus_menuitem_5.rank = 2
    treemenus_menuitem_5.menu = treemenus_menu_1
    treemenus_menuitem_5.save()

    treemenus_menuitem_6 = MenuItem()
    treemenus_menuitem_6.parent = treemenus_menuitem_1
    treemenus_menuitem_6.caption = u'Inicio'
    treemenus_menuitem_6.url = u''
    treemenus_menuitem_6.named_url = u'home'
    treemenus_menuitem_6.level = 1
    treemenus_menuitem_6.rank = 0
    treemenus_menuitem_6.menu = treemenus_menu_1
    treemenus_menuitem_6.save()

    treemenus_menuitem_7 = MenuItem()
    treemenus_menuitem_7.parent = treemenus_menuitem_1
    treemenus_menuitem_7.caption = u'Pacientes'
    treemenus_menuitem_7.url = u''
    treemenus_menuitem_7.named_url = u'persona-index'
    treemenus_menuitem_7.level = 1
    treemenus_menuitem_7.rank = 1
    treemenus_menuitem_7.menu = treemenus_menu_1
    treemenus_menuitem_7.save()

    treemenus_menuitem_8 = MenuItem()
    treemenus_menuitem_8.parent = treemenus_menuitem_1
    treemenus_menuitem_8.caption = u'B\xfasqueda'
    treemenus_menuitem_8.url = u''
    treemenus_menuitem_8.named_url = u'haystack_search'
    treemenus_menuitem_8.level = 1
    treemenus_menuitem_8.rank = 5
    treemenus_menuitem_8.menu = treemenus_menu_1
    treemenus_menuitem_8.save()

    treemenus_menuitem_9 = MenuItem()
    treemenus_menuitem_9.parent = treemenus_menuitem_2
    treemenus_menuitem_9.caption = u'Agregar Examen'
    treemenus_menuitem_9.url = u''
    treemenus_menuitem_9.named_url = u'examen-agregar persona.id'
    treemenus_menuitem_9.level = 1
    treemenus_menuitem_9.rank = 0
    treemenus_menuitem_9.menu = treemenus_menu_2
    treemenus_menuitem_9.save()

    treemenus_menuitem_10 = MenuItem()
    treemenus_menuitem_10.parent = treemenus_menuitem_2
    treemenus_menuitem_10.caption = u'Ver Datos Personales'
    treemenus_menuitem_10.url = u''
    treemenus_menuitem_10.named_url = u'persona-view-id persona.id'
    treemenus_menuitem_10.level = 1
    treemenus_menuitem_10.rank = 1
    treemenus_menuitem_10.menu = treemenus_menu_2
    treemenus_menuitem_10.save()

    treemenus_menuitem_11 = MenuItem()
    treemenus_menuitem_11.parent = treemenus_menuitem_2
    treemenus_menuitem_11.caption = u'Examenes'
    treemenus_menuitem_11.url = u''
    treemenus_menuitem_11.named_url = u'examen-persona-lista persona.id'
    treemenus_menuitem_11.level = 1
    treemenus_menuitem_11.rank = 2
    treemenus_menuitem_11.menu = treemenus_menu_2
    treemenus_menuitem_11.save()

    treemenus_menuitem_12 = MenuItem()
    treemenus_menuitem_12.parent = treemenus_menuitem_2
    treemenus_menuitem_12.caption = u'Admitir Paciente'
    treemenus_menuitem_12.url = u''
    treemenus_menuitem_12.named_url = u'admision-persona-agregar persona.id'
    treemenus_menuitem_12.level = 1
    treemenus_menuitem_12.rank = 3
    treemenus_menuitem_12.menu = treemenus_menu_2
    treemenus_menuitem_12.save()

    treemenus_menu_1.root_item = treemenus_menuitem_1
    treemenus_menu_1.save()

    treemenus_menu_2.root_item = treemenus_menuitem_2
    treemenus_menu_2.save()