Beispiel #1
0
def license_view(request):

    license_id = request.matchdict['license_id']
    license = License.get_by_license_id(license_id)

    if license is None:
        msg = "This license was not found in our database"
        return HTTPFound(request.route_url('not_found'))

    #calculate for next/previous-navigation
    max_id = License.get_max_id()
    # previous
    if license.id == 1:           # if looking at first id
        prev_id = max_id          # --> choose highest id (wrap around)
    else:                         # if looking at any other
        prev_id = license.id - 1  # --> choose previous
    # next
    if license.id != max_id:      # if not on highest id
        next_id = license.id + 1  # --> choose next
    elif license.id == max_id:    # if highest id
        next_id = 1               # --> choose first id (wrap around)

    # show who is watching. maybe we should log this ;-)
    viewer_username = authenticated_userid(request)

    return {
        'license': license,
        'viewer_username': viewer_username,
        'prev_id': prev_id,
        'next_id': next_id
        }
Beispiel #2
0
 def test_get_by_license_id(self):
     instance = self._makeOne()
     self.session.add(instance)
     self.session.flush()  # to get the id from the db
     # print "--- type(instance): " + str(type(instance))
     # --> <class 'c3sar.models.License'>
     # print "--- dir(instance): " + str(dir(instance))
     # ... '_sa_instance_state', 'author', 'get_by_license_id',
     # 'id', 'license_listing', 'metadata', 'name', 'url'
     # print "--- instance.id: " + str(instance.id) # 1
     from c3sar.models import License
     result = License.get_by_license_id(1)
     # print "result: " + str(result)
     # --> <c3sar.models.License object at 0x949f74c>
     # print "result.id: " + str(result.id) # 1
     self.assertNotEqual(instance.id, None, "may not be None.")
     self.assertNotEqual(result.id, None, "may not be None.")
     self.assertEqual(instance.id, result.id, "license ids didn't match!")
Beispiel #3
0
 def test_license_listing(self):
     instance = self._makeOne()
     self.session.add(instance)
     self.session.flush()  # to get the id from the db
     # print "--- type(instance): " + str(type(instance))
     # <class 'c3sar.models.License'>
     # print "--- dir(instance): " + str(dir(instance))
     # ... '_sa_instance_state', 'author', 'get_by_license_id',
     # 'id', 'license_listing', 'metadata', 'name', 'url'
     #print "--- instance.id: " + str(instance.id) # 1
     from c3sar.models import License
     result = License.license_listing()
     # print "--- result: " + str(result)
     # [<c3sar.models.License object at 0x9fba10c>]
     # print "--- dir(result): " + str(dir(result)) #
     # print "--- license_listing: result.__len__(): "
     #       + str(result.__len__()) # 1
     self.assertEqual(
         result.__len__(), 1, "we expect the result list to have one entry")
Beispiel #4
0
def license_list(request):
    licenses = License.license_listing(License.id.desc())
    return {
        'licenses': licenses,
        }