def test_get_aristotle_url(self): user = get_user_model().objects.create( email='*****@*****.**', password='******' ) item = models.ObjectClass.objects.create(name="tname",definition="my definition",submitter=None) ra = models.RegistrationAuthority.objects.create(name="tname",definition="my definition") org = models.Organization.objects.create(name="tname",definition="my definition") wg = models.Workgroup.objects.create(name="tname",definition="my definition") url = utils.get_aristotle_url(item._meta.label_lower, item.pk, item.name) self.assertEqual(url, reverse('aristotle:item', args=[item.pk])) url = utils.get_aristotle_url(ra._meta.label_lower, ra.pk, ra.name) self.assertEqual(url, reverse('aristotle:registrationAuthority', args=[ra.pk, ra.name])) url = utils.get_aristotle_url(org._meta.label_lower, org.pk, org.name) self.assertEqual(url, reverse('aristotle:organization', args=[org.pk, org.name])) url = utils.get_aristotle_url(wg._meta.label_lower, wg.pk, wg.name) self.assertEqual(url, reverse('aristotle:workgroup', args=[wg.pk, wg.name])) url = utils.get_aristotle_url('aristotle_mdr.fake_model', 7, 'fake_name') self.assertTrue(url is None)
def test_get_aristotle_url_item(self): item = models.ObjectClass.objects.create(name="tname", definition="my definition", submitter=None) url = utils.get_aristotle_url(item._meta.label_lower, item.pk, item.name) self.assertEqual(url, reverse('aristotle:item', args=[item.pk]))
def test_get_aristotle_url_wg(self): wg = models.Workgroup.objects.create( name="tname", definition="my definition", stewardship_organisation=self.steward_org_1) url = utils.get_aristotle_url(wg._meta.label_lower, wg.pk, wg.name) self.assertEqual(url, reverse('aristotle:workgroup', args=[wg.pk, wg.name]))
def test_get_aristotle_url_ra(self): ra = models.RegistrationAuthority.objects.create( name="tname", definition="my definition", stewardship_organisation=self.steward_org_1) url = utils.get_aristotle_url(ra._meta.label_lower, ra.pk, ra.name) self.assertEqual( url, reverse('aristotle:registrationAuthority', args=[ra.pk, ra.name]))
def test_get_aristotle_url_rr(self): user = get_user_model().objects.create(email='*****@*****.**', password='******') ra = models.RegistrationAuthority.objects.create( name="tname", definition="my definition", stewardship_organisation=self.steward_org_1) rr = ReviewRequest.objects.create(registration_authority=ra, requester=user) url = utils.get_aristotle_url(rr._meta.label_lower, rr.pk) self.assertEqual( url, reverse('aristotle_reviews:review_details', args=[rr.pk]))
def home(request): from reversion.models import Revision recent = Revision.objects.filter(user=request.user).order_by('-date_created')[0:10] recentdata = [] for rev in recent: revdata = {'revision': rev, 'versions': []} seen_ver_ids = [] for ver in rev.version_set.all(): seen = ver.object_id in seen_ver_ids add_version = None url = None if ver.format == 'json': object_data = json.loads(ver.serialized_data) try: model = object_data[0]['model'] except KeyError: model = None if model: add_version = (model != 'aristotle_mdr.status' and not seen) try: name = object_data[0]['fields']['name'] except KeyError: name = None url = get_aristotle_url(object_data[0]['model'], object_data[0]['pk'], name) if add_version is None: # Fallback for if add_version could not be set, results in db query add_version = (not isinstance(ver.object, MDR.Status) and not seen) if add_version: if url: revdata['versions'].append({'id': ver.object_id, 'text': str(ver), 'url': url}) else: # Fallback, results in db query # print(ver) obj = ver.object if hasattr(obj, 'get_absolute_url'): revdata['versions'].append({'id': ver.object_id, 'text': str(ver), 'url': obj.get_absolute_url}) seen_ver_ids.append(ver.object_id) recentdata.append(revdata) recently_viewed = [] for viewed in ( request.user.recently_viewed_metadata.all() .order_by("-view_date") .prefetch_related('concept')[:5] ): recently_viewed.append(viewed) page = render( request, "aristotle_mdr/user/userHome.html", { "item": request.user, 'recentdata': recentdata, "recently_viewed": recently_viewed, } ) return page
def test_get_aristotle_url_fake(self): url = utils.get_aristotle_url('aristotle_mdr.fake_model', 7, 'fake_name') self.assertTrue(url is None)
def test_get_aristotle_url_org(self): org = models.Organization.objects.create(name="tname", definition="my definition") url = utils.get_aristotle_url(org._meta.label_lower, org.pk, org.name) self.assertEqual( url, reverse('aristotle:organization', args=[org.pk, org.name]))