Beispiel #1
0
	def add_book(self, user_num, book):
		for item in self.items:
			if item.book.id == book.id and item.user_num == user_num:
				collection_list = CollectionItem.objects.filter(user_num=user_num, book_id__exact=book.id)
				collection_list.update(dis_collect=False)
				collection_list.update(add_date = datetime.now())
				return
		collection_item = CollectionItem(user_num=user_num, book=book, dis_collect=False)
		collection_item.save() 
		self.items.append(collection_item)
Beispiel #2
0
def register_menu(subitem_url, subitem_text, parent_path = "/", permmited_group = None):
    """
    If subitem_test contains dynamic, subitem_url is not used.
    Otherwise, subitem_url is the content of this menu item.
    Register a menu item in the left tree in object manager, the info is stored in obj_sys.models.Collection.
    :param subitem_url: menu item's URL. When the item is clicked, the URL will be loaded to the content pane
    :param subitem_text: menu item's text. It is stored in to id_in_col field for Collection and if it is
                            "dynamic://xxxx", the parent item's children will be dynamically generated by opening
                            URL: xxxx. xxxx should return a collection of items as in tags.tag_list. The format is
                            described in tags.tag_list as well.
    :param parent_path: the parent for this menu item. Root item is "/", sub menus should start with "/" as well.
    :param permmited_group:
    :return: N/A
    """
    try:
        root_uuid = get_item_id(parent_path)
        url = u"view://%s"%(subitem_url)
        qs = UfsObj.objects.filter(ufs_url = url)
        if 0 == qs.count():
            print 'creating new ufs obj'
            o = UfsObj(ufs_url = url, uuid = unicode(uuid.uuid4()), timestamp=timezone.now(), user=User.objects.filter(username="******")[0])
            o.save()
        else:
            #print 'use existing item'
            o = qs[0]
        
    except django.db.utils.DatabaseError:
        #Database is not created yet, just return, items will be created after syncdb is executed
        return
    #print 'creating collection item for root: ', root_uuid
    if permmited_group is None:
        #If no permission requested, set anonymous user accessable.
        permitted_user_or_group = User.objects.filter(pk=settings.ANONYMOUS_USER_ID)[0]
    else:
        try:
            permitted_user_or_group = Group.objects.filter(name = permmited_group)[0]
        except:
            #Group not exist, create it
            permitted_user_or_group = Group.objects.create(name = permmited_group)
    collqs = CollectionItem.objects.filter(uuid = root_uuid, id_in_col = subitem_text)
    if 0 == collqs.count():
        c = CollectionItem(obj = o, uuid = root_uuid, id_in_col = subitem_text, 
                            timestamp=timezone.now(), user=User.objects.filter(username="******")[0])
        c.save()
    else:
        c = collqs[0]
    #Assign group permission

    assign_perm('view_collection_item', permitted_user_or_group, c)
Beispiel #3
0
def register(objectClass, group_name = "scheduling"):
    module_name = objectClass.__module__.split(".")[0].lower()
    class_name = objectClass.__name__.lower()
    url = u"view://admin/%s/%s/add"%(module_name, class_name)
    try:
        for i in UfsObj.objects.filter(ufs_url = url):
            return
    except django.db.utils.DatabaseError:
        #Database is not created yet, just return, items will be created after syncdb is executed
        return
    o = UfsObj(ufs_url = url, uuid = unicode(uuid.uuid4()), timestamp=timezone.now(), user=User.objects.filter(username="******")[0])
    o.save()
    c = CollectionItem(obj = o, uuid = gRootUuid, id_in_col="%s_%s_add"%(module_name, class_name), 
                        timestamp=timezone.now(), user=User.objects.filter(username="******")[0])
    c.save()
    #Add to group
    try:
        group = Group.objects.filter(name=group_name)[0]
    except:
        #Group not exist, create it
        group = Group.objects.create(name=group_name)
    #print 'assigning: ', group, c
    assign_perm('view_collection_item', group, c)