def add(self, card_id): card = ReportCard.find_by_id(int(card_id)) if card.is_authorized(): signature_id = Signature.create(self.request.get('name'), int(card_id)).id() signature = Signature.find_by_id(signature_id) template = JinjaEnv.get().get_template('templates/signature/edit_row.html') self.response.out.write(template.render({'signature': signature}))
def test_move_up(self): signature1_id = Signature.create('Move Up Test Name 1', self.card_id).id() signature2_id = Signature.create('Move Up Test Name 2', self.card_id).id() self.assertRaises(Exception, self.testapp.post, '/signature/%d/move_up' % signature1_id) response = self.testapp.post('/signature/%d/move_up' % signature2_id) self.assertSuccess(response) card = ReportCard.find_by_id(self.card_id) signatures = card.signatures() self.assertEqual(2, len(signatures)) self.assertEqual(signature2_id, signatures[0].key().id()) self.assertEqual(signature1_id, signatures[1].key().id())
def test_edit(self): signature_id = Signature.create('Edit Test Name', self.card_id).id() response = self.testapp.post('/signature/%d/edit' % signature_id, {'name': 'Edit Test New Name'}) self.assertSuccess(response) card = ReportCard.find_by_id(self.card_id) self.assertEqual(1, len(card.signatures())) self.assertEqual('Edit Test New Name', card.signatures()[0].name)
def edit(self, signature_id): sig = Signature.find_by_id(int(signature_id)) if sig.card.is_authorized(): sig.name = self.request.get('name') sig.save() template = JinjaEnv.get().get_template('templates/signature/edit_row.html') self.response.out.write(template.render({'signature': sig}))
def move_up(self, signature_id): sig = Signature.find_by_id(int(signature_id)) if sig.card.is_authorized(): all_sigs = sig.card.signatures() id_list = map(lambda x: x.key().id(), all_sigs) index = id_list.index(sig.key().id()) if index >= 1: temp = sig.position sig.position = all_sigs[index-1].position all_sigs[index-1].position = temp sig.save() all_sigs[index-1].save() else: return webapp2.abort(403)
def setUp(self): self.controller = Controller() self.address = self.controller.connection.create_address('Controller Test address', True) coll_address = str(uuid.uuid1()) doc_hash_1 = str(uuid.uuid1()) doc_hash_2 = str(uuid.uuid1()) doc_hash_3 = str(uuid.uuid1()) self.test_collection = Collection( title="Test", description="This is a collection!", address=self.address, btc="123456789", keywords=[ Keyword(name="Keyword A"), Keyword(name="Keyword B"), ], documents=[ Document( description="Test document A", hash=doc_hash_1, title="Test A", accesses=0, filename="joe.txt", collection_address="afgagahhsgh" ), Document( description="Test document B", hash=doc_hash_2, title="Test B", accesses=3, filename="gile.txt", collection_address="afgagasghhhss" ), ], creation_date=datetime.datetime.now(), oldest_date=datetime.datetime.now(), latest_broadcast_date=datetime.datetime.now(), latest_btc_tx="btctx1", oldest_btc_tx="btctx12", accesses=2, votes=3, votes_last_checked=datetime.datetime.now() ) self.test_signature = Signature(pubkey='itsakey',address=self.address)
def test_delete(self): signature_id = Signature.create('Delete Test Name', self.card_id).id() response = self.testapp.post('/signature/%d/delete' % signature_id) self.assertSuccess(response) card = ReportCard.find_by_id(self.card_id) self.assertEqual(0, len(card.signatures()))
def test_delete_form(self): signature_id = Signature.create('Delete Form Test Name', self.card_id).id() response = self.testapp.get('/signature/%d/delete_form' % signature_id) self.assertSuccess(response)
def signatures(self): from models.signature import Signature items = Signature.gql("WHERE card = :1 ORDER BY position ASC", self).fetch(100) return items
def delete(self, signature_id): sig = Signature.find_by_id(int(signature_id)) if sig.card.is_authorized(): card_id = sig.card.key().id() sig.delete()
def delete_form(self, signature_id): sig = Signature.find_by_id(int(signature_id)) if sig.card.is_authorized(): template = JinjaEnv.get().get_template('templates/signature/delete_form.html') self.response.out.write(template.render({'signature_id': signature_id, 'signature': sig}))
def _cache_collection(self, payload, message): """ Checks to see if this collection is already in the cache. If it is we update the collection with the new data. Otherwise a new collection is made and cached. :param message: the Bitmessage message containing an FJ_message :param payload: the contents of the FJ_message """ # Grabbing the text representations of the documents and keywords and rebuilding them #docs, keywords = self._build_docs_keywords(payload) cached_collection = self.cache.get_collection_with_address( payload["address"]) if cached_collection is None: collection_model = Collection( title=payload["title"], description=payload["description"], address=payload["address"], btc=payload["btc"], creation_date=datetime.datetime.strptime( payload["creation_date"], "%A, %d. %B %Y %I:%M%p"), oldest_date=datetime.datetime.strptime( payload["oldest_date"], "%A, %d. %B %Y %I:%M%p"), latest_broadcast_date=datetime.datetime.strptime( payload["latest_broadcast_date"], "%A, %d. %B %Y %I:%M%p"), votes=payload['votes'], votes_last_checked=datetime.datetime.strptime( payload["votes_last_checked"], "%A, %d. %B %Y %I:%M%p"), ) self._build_docs_keywords(payload, collection_model) signature = Signature(pubkey=message["pubkey"], signature=message["signature"], address=payload["address"]) try: self.cache.insert_new_collection(collection_model) self.cache.insert_new_collection(signature) self._hash_document_filenames(collection_model.documents, collection_model) self.download_threads.add( self._download_documents(collection_model.title, collection_model.documents)) print "Cached New Collection" return True except IntegrityError as m: print m.message return False else: cached_collection.keywords = [] cached_sig = self.cache.get_signature_by_address( payload["address"]) cached_sig.pubkey = message["pubkey"] cached_sig.signature = message["signature"] cached_collection.title = payload["title"] cached_collection.description = payload["description"] cached_collection.address = payload["address"] cached_collection.btc = payload["btc"] cached_collection.documents = [] cached_collection.creation_date = datetime.datetime.strptime( payload["creation_date"], "%A, %d. %B %Y %I:%M%p") cached_collection.oldest_date = datetime.datetime.strptime( payload["oldest_date"], "%A, %d. %B %Y %I:%M%p") cached_collection.latest_broadcast_date = datetime.datetime.strptime( payload["latest_broadcast_date"], "%A, %d. %B %Y %I:%M%p") cached_collection.votes = payload['votes'] cached_collection.votes_last_checked = datetime.datetime.strptime( payload["votes_last_checked"], "%A, %d. %B %Y %I:%M%p") self._build_docs_keywords(payload, cached_collection) try: self.cache.insert_new_collection(cached_collection) self.cache.insert_new_collection(cached_sig) self._hash_document_filenames(cached_collection.documents, cached_collection) self.download_threads.add( self._download_documents(cached_collection.title, cached_collection.documents)) print "Cached Updated Collection" return True except IntegrityError as m: print m.message return False