def show(request): """View all tags""" data = support.default_answer_data(request) if not data['auth']: return support.auth_error() database = DataBase() if request.method == 'POST': if request.POST['do'] == 'delete': id_tag = request.POST['id_tag'] if request.user.has_perm('main.delete_tag'): database.del_tag(database.tag.get(id = id_tag)) if request.POST['do'] == 'add': name = request.POST['name'] desc = request.POST['description'] if request.user.has_perm('main.add_tag'): database.add_tag(name, desc) all_db_tags = database.tag.all() all_tags = [] for db_tag in all_db_tags: if not parse_docs.check_cycle(db_tag.name): all_tags.append(db_tag) out = [] for tag in all_tags: numbers = database.numbers_from_tag(tag) out.append( {'tag': tag, 'numbers': numbers} ) data['out'] = out data['content'] = 'tags/show.html' return render_to_response('index.html', data)
def testBasic(self): database = DataBase() doc1 = database.add_doc('jopa.odt', 'JOPA', 'odt', 0, True) doc1 = database.add_doc('jopa.odt', 'JOPA1', 'odt', 0, True) self.assertEqual(doc1.id, 1) self.assertEqual(doc1.title, 'JOPA1') doc2 = database.add_doc('jopa2.odt', 'JOPA2', 'odt', 0, False) self.assertEqual(doc2.id, 2) doc3 = database.add_doc('jopa3.odt', 'JOPA3', 'odt', 0, False) self.assertEqual(doc3.id, 3) tag1 = database.add_tag('FIO', 'Name and Surname') tag1 = database.add_tag('FIO', 'Name and Surname 2') self.assertEqual(tag1.id, 1) self.assertEqual(tag1.description, 'Name and Surname 2') tag2 = database.add_tag('date', u'Date') self.assertEqual(tag2.id, 2) tag3 = database.add_tag('tag3', u'Tag3') self.assertEqual(database.del_tag(tag3), True) link1 = database.add_link(doc1, tag1) link1 = database.add_link(doc1, tag1) self.assertEqual(link1.id, 1) link2 = database.add_link(doc1, tag2) link3 = database.add_link(doc2, tag2) link4 = database.add_link(doc3, tag1) database.del_link_id(link4.id) self.assertEqual((link2.id, link3.id), (2, 3)) chain1 = database.add_chain(doc1, doc2) self.assertEqual(chain1.id, 1) chain1 = database.add_chain(doc1, doc2) self.assertEqual(chain1.id, 1) chain2 = database.add_chain(doc3, doc1) self.assertEqual(chain2.id, 2) self.assertEqual(database.check_add_chain(doc1.id, doc2.id), False) self.assertEqual(database.check_add_chain(doc2.id, doc1.id), True) num1 = database.add_number(doc1, self.user) self.assertEqual(num1.id, 1) num2 = database.add_number(doc1, self.user, num1) self.assertEqual(num2.id, 2) num3 = database.add_number(doc3, self.user) self.assertEqual(database.del_number(num3), True) num3 = database.add_number(doc3, self.user) database.change_number(num3, True) self.assertEqual(database.del_number(num3), False) data1 = database.add_data(num1, tag1.name, 'gggg') self.assertEqual(data1, True) data2 = database.add_data(num1, tag1.name, 'hhhh') self.assertEqual(data2, False) data2 = database.add_data(num2, tag1.name, 'hhhh') self.assertEqual(data2, True) database.add_data(num2, tag1.name, 'tag1') self.assertEqual(database.del_tag_from_datadoc(num2, tag1.name), True) database.numbers_from_doc(doc1) data1 = database.change_data(num1, tag1.name, 'lololo') self.assertEqual(data1.tag_value, 'lololo') r = database.change_number(num1, False) self.assertEqual(r, True) r = database.change_number(num1, True) self.assertEqual(r, True) docs = database.get_slave_docs(num1) self.assertEqual(docs[0].id, 2) slaves = database.get_all_need_slave(self.user) self.assertEqual(slaves[0][0].id, 2) numbers = database.numbers_from_doc(doc1) self.assertEqual((numbers[0].id, numbers[1].id), (1, 2)) # Test doc permissions self.user1 = auth.models.User.objects.create_user('user1', '*****@*****.**', 'user1') self.group1 = auth.models.Group.objects.create() self.group1.name = 'group1' self.group1.save() self.assertEqual(database.check_user_perm(self.user1, doc1, False), False) database.add_user_perm(self.user1, doc1, False) self.assertEqual(database.check_user_perm(self.user1, doc1, False), True) self.assertEqual(database.check_user_perm(self.user1, doc1, True), False) database.add_user_perm(self.user1, doc2, True) self.assertEqual(database.check_user_perm(self.user1, doc2, True), True) self.user1.groups.add(self.group1) database.add_group_perm(self.group1, doc1, True) self.assertEqual(database.check_group_perm(self.group1, doc1, True), True) docs = database.doc.all() database.add_group_perm(self.group1, doc3, False) self.user.groups.add(self.group1) docs_f = database.perm_doc_filter(self.user1, docs, False) self.assertEqual(docs_f, [doc1, doc2, doc3]) docs_f = database.perm_doc_filter(self.user1, docs, True) self.assertEqual(docs_f, [doc2, doc1]) self.assertEqual(database.check_doc_id('1'), True) self.assertEqual(database.check_doc_id('100'), False) # False - in number self.assertEqual(database.del_tag(tag1), False)