desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Testing /messaging/settings/view/'
| def test_messaging_settings_view_out(self):
| response = self.client.get(reverse('messaging_settings_view'))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /messaging/settings/edit/'
| def test_finance_settings_edit_out(self):
| response = self.client.get(reverse('messaging_settings_edit'))
self.assertRedirects(response, reverse('user_login'))
|
'Sets choices and initial value'
| def __init__(self, user, *args, **kwargs):
| super(SettingsForm, self).__init__(*args, **kwargs)
self.user = user
self.fields['default_contact_type'].label = _('Default Contact Type')
self.fields['default_contact_type'].queryset = Object.filter_permitted(user, ContactType.objects, mode='x')
try:
conf = ModuleSetting.get_for_modul... |
'Form processor'
| def save(self):
| try:
ModuleSetting.set_for_module('default_contact_type', self.cleaned_data['default_contact_type'].id, 'treeio.messaging')
except:
pass
try:
ModuleSetting.set_for_module('default_imap_folder', self.cleaned_data['default_imap_folder'], 'treeio.messaging')
except:
pass
... |
'Save override to omit empty fields'
| def save(self, *args, **kwargs):
| if self.instance:
if self.is_valid():
if self.cleaned_data['stream']:
self.instance.stream = self.cleaned_data['stream']
if (self.user and self.cleaned_data['mark']):
if (self.cleaned_data['mark'] == 'read'):
try:
... |
'Initial Setup'
| def setUp(self):
| if (not self.prepared):
Object.objects.all().delete()
try:
self.group = Group.objects.get(name='test')
except Group.DoesNotExist:
Group.objects.all().delete()
self.group = Group(name='test')
self.group.save()
try:
self.user ... |
'Test index page at /api/infrastructure/types'
| def test_unauthenticated_access(self):
| response = self.client.get('/api/infrastructure/types')
self.assertEquals(response.status_code, 401)
|
'Test index page api/infrastructure/types'
| def test_get_fields_list(self):
| response = self.client.get(path=reverse('api_infrastructure_fields'), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
|
'Test index page api/infrastructure/types'
| def test_get_types_list(self):
| response = self.client.get(path=reverse('api_infrastructure_types'), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
|
'Test index page api/infrastructure/types'
| def test_get_statuses_list(self):
| response = self.client.get(path=reverse('api_infrastructure_statuses'), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
|
'Test index page api/infrastructure/service_records'
| def test_get_services(self):
| response = self.client.get(path=reverse('api_infrastructure_service_records'), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
|
'Test index page api/infrastructure/items'
| def test_get_items_list(self):
| response = self.client.get(path=reverse('api_infrastructure_items'), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
|
'Returns absolute URL of the object'
| def get_absolute_url(self):
| try:
return reverse('infrastructure_item_view', args=[self.id])
except Exception:
return ''
|
'Returns a QuerySet of all ItemServicing records'
| def get_servicing(self):
| return self.itemservicing_set.filter()
|
'Returns a QuerySet of active ItemServicing records with expiry date in the future'
| def get_active_servicing(self):
| now = datetime.datetime.now()
return self.itemservicing_set.filter(expiry_date__gte=now.date())
|
'Returns absolute URL of the object'
| def get_absolute_url(self):
| try:
return reverse('infrastructure_service_record_view', args=[self.id])
except Exception:
return ''
|
'Test item field model'
| def test_model_item_field(self):
| obj = ItemField(name='test', label='test', field_type='text')
obj.save()
self.assertEquals('test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
|
'Test item type model'
| def test_model_item_type(self):
| obj = ItemType(name='test')
obj.save()
self.assertEquals('test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
|
'Test item status model'
| def test_model_item_status(self):
| obj = ItemStatus(name='test')
obj.save()
self.assertEquals('test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
|
'Test item model'
| def test_model_item(self):
| type = ItemType(name='test')
type.save()
status = ItemStatus(name='test')
status.save()
obj = Item(name='test', item_type=type, status=status)
obj.save()
self.assertEquals('test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
|
'Test item value model'
| def test_model_item_value(self):
| status = ItemStatus(name='test')
status.save()
type = ItemType(name='test')
type.save()
item = Item(name='test', item_type=type, status=status)
item.save()
field = ItemField(name='test', label='test', field_type='text')
field.save()
obj = ItemValue(value='test', field=field, item=ite... |
'Test item servicing model'
| def test_model_item_servicing(self):
| obj = ItemServicing(name='test')
obj.save()
self.assertEquals('test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
|
'Initial Setup'
| def setUp(self):
| if (not self.prepared):
(self.group, created) = Group.objects.get_or_create(name='test')
(duser, created) = DjangoUser.objects.get_or_create(username=self.username)
duser.set_password(self.password)
duser.save()
(self.user, created) = User.objects.get_or_create(user=duser)
... |
'Test index page with login at /infrastructure/'
| def test_index_login(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure'))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/index/'
| def test_index_infrastructure_login(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_index'))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/owned/'
| def test_infrastructure_index_owned(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_index_owned'))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/type/add/'
| def test_infrastructure_type_add(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_type_add'))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/type/view/<type_id>'
| def test_infrastructure_type_view(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_type_view', args=[self.type.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/type/edit/<type_id>'
| def test_infrastructure_type_edit(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_type_edit', args=[self.type.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/type/delete/<type_id>'
| def test_infrastructure_type_delete(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_type_delete', args=[self.type.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/field/add/'
| def test_infrastructure_field_add(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_field_add'))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/field/view/<field_id>'
| def test_infrastructure_field_view(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_field_view', args=[self.field.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/field/edit/<field_id>'
| def test_infrastructure_field_edit(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_field_edit', args=[self.field.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/field/delete/<field_id>'
| def test_infrastructure_field_del(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_field_delete', args=[self.field.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/status/add/'
| def test_infrastructure_status_add(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_status_add'))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/status/view/<status_id>'
| def test_infrastructure_status_view(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_status_view', args=[self.status.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/status/edit/<status_id>'
| def test_infrastructure_status_edit(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_status_edit', args=[self.status.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/status/delete/<status_id>'
| def test_infrastructure_status_del(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_status_delete', args=[self.status.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/item/add/'
| def test_infrastructure_item_add(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_item_add'))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/item/add/<type_id>'
| def test_infr_item_add_typed(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_item_add_typed', args=[self.type.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/item/view/<item_id>'
| def test_infrastructure_item_view(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_item_view', args=[self.item.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/item/edit/<item_id>'
| def test_infrastructure_item_edit(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_item_edit', args=[self.item.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/item/delete/<item_id>'
| def test_infrastructure_item_del(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_item_delete', args=[self.item.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/service_record/index/'
| def test_infr_service_record_index(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_service_record_index'))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/service_record/add/'
| def test_infr_service_record_add(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_service_record_add'))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/service_record/view/<service_record_id>'
| def test_infr_service_record_view(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_service_record_view', args=[self.servicing.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/service_record/edit/<service_record_id>'
| def test_infr_service_record_edit(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_service_record_edit', args=[self.servicing.id]))
self.assertEquals(response.status_code, 200)
|
'Test index page with login at /infrastructure/service_record/delete/<service_record_id>'
| def test_infr_service_record_delete(self):
| response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('infrastructure_service_record_delete', args=[self.servicing.id]))
self.assertEquals(response.status_code, 200)
|
'Testing /infrastructure/'
| def test_index(self):
| response = self.client.get('/infrastructure/')
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/index/'
| def test_index_infrastructure_out(self):
| response = self.client.get(reverse('infrastructure_index'))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/owned/'
| def test_infrastructure_index_owned_out(self):
| response = self.client.get(reverse('infrastructure_index_owned'))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/type/add/'
| def test_infrastructure_type_add_out(self):
| response = self.client.get(reverse('infrastructure_type_add'))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/type/view/<type_id>'
| def test_infrastructure_type_view_out(self):
| response = self.client.get(reverse('infrastructure_type_view', args=[self.type.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/type/edit/<type_id>'
| def test_infrastructure_type_edit_out(self):
| response = self.client.get(reverse('infrastructure_type_edit', args=[self.type.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/type/delete/<type_id>'
| def test_infrastructure_type_delete_out(self):
| response = self.client.get(reverse('infrastructure_type_delete', args=[self.type.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/field/add/'
| def test_infrastructure_field_add_out(self):
| response = self.client.get(reverse('infrastructure_field_add'))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/field/view/<field_id>'
| def test_infrastructure_field_view_out(self):
| response = self.client.get(reverse('infrastructure_field_view', args=[self.field.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/field/edit/<field_id>'
| def test_infrastructure_field_edit_out(self):
| response = self.client.get(reverse('infrastructure_field_edit', args=[self.field.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/field/delete/<field_id>'
| def test_infrastructure_field_del_out(self):
| response = self.client.get(reverse('infrastructure_field_delete', args=[self.field.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/status/add/'
| def test_infrastructure_status_add_out(self):
| response = self.client.get(reverse('infrastructure_status_add'))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/status/view/<status_id>'
| def test_infrastructure_status_view_out(self):
| response = self.client.get(reverse('infrastructure_status_view', args=[self.status.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/status/edit/<status_id>'
| def test_infrastructure_status_edit_out(self):
| response = self.client.get(reverse('infrastructure_status_edit', args=[self.status.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/status/delete/<status_id>'
| def test_infrastructure_status_del_out(self):
| response = self.client.get(reverse('infrastructure_status_delete', args=[self.status.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/item/add/'
| def test_infrastructure_item_add_out(self):
| response = self.client.get(reverse('infrastructure_item_add'))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/item/add/<type_id>'
| def test_infr_item_add_typed_out(self):
| response = self.client.get(reverse('infrastructure_item_add_typed', args=[self.type.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/item/view/<item_id>'
| def test_infrastructure_item_view_out(self):
| response = self.client.get(reverse('infrastructure_item_view', args=[self.item.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/item/edit/<item_id>'
| def test_infrastructure_item_edit_out(self):
| response = self.client.get(reverse('infrastructure_item_edit', args=[self.item.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/item/delete/<item_id>'
| def test_infrastructure_item_del_out(self):
| response = self.client.get(reverse('infrastructure_item_delete', args=[self.item.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/service_record/index/'
| def test_infr_service_record_index_out(self):
| response = self.client.get(reverse('infrastructure_service_record_index'))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/service_record/add/'
| def test_infr_service_record_add_out(self):
| response = self.client.get(reverse('infrastructure_service_record_add'))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/service_record/view/<service_record_id>'
| def test_infr_service_record_view_out(self):
| response = self.client.get(reverse('infrastructure_service_record_view', args=[self.servicing.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/service_record/edit/<service_record_id>'
| def test_infr_service_record_edit_out(self):
| response = self.client.get(reverse('infrastructure_service_record_edit', args=[self.servicing.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Testing /infrastructure/service_record/delete/<service_record_id>'
| def test_infr_service_record_delete_out(self):
| response = self.client.get(reverse('infrastructure_service_record_delete', args=[self.servicing.id]))
self.assertRedirects(response, reverse('user_login'))
|
'Generate a Django-friendly field from Hardtree spec in DB'
| def _get_form_field(self, field, value=None):
| form_field = None
if (field.field_type == 'text'):
form_field = forms.CharField(label=field.label, max_length=512, widget=forms.TextInput(attrs={'size': '30'}))
elif (field.field_type == 'details'):
form_field = forms.CharField(label=field.label, widget=forms.Textarea())
elif (field.fiel... |
'Generate an available name for a field'
| def _get_free_field_name(self, field):
| num = 0
field_name = ((unicode(field.name) + u'___') + unicode(num))
while (field_name in self.fields):
num += 1
field_name = ((unicode(field.name) + u'___') + unicode(num))
return field_name
|
'Returns an upload_to path to a new file'
| def _get_upload_name(self, filename):
| import hashlib
import random
while True:
hasher = hashlib.md5()
hasher.update(str(random.random()))
filepath = (((u'infrastructure/' + hasher.hexdigest()) + u'__') + filename)
fullpath = (settings.MEDIA_ROOT + filepath)
if (not default_storage.exists(fullpath)):
... |
'Process an uploaded file'
| def _handle_uploaded_file(self, field_name):
| try:
file = self.files[field_name]
filepath = self._get_upload_name(file.name)
except KeyError:
return ''
destination = open((settings.MEDIA_ROOT + filepath), 'wb+')
for chunk in file.chunks():
destination.write(chunk)
destination.close()
return (settings.MEDI... |
'Resizes Image if it\'s over the maximum dimension'
| def _image_resize(self, filepath):
| filepath = filepath.replace(settings.MEDIA_URL, '')
filepath = (settings.MEDIA_ROOT + filepath)
try:
img = Image.open(filepath)
expected_size = getattr(settings, 'HARDTREE_IMAGE_MAX_SIZE', [400, 300])
if ((img.size[0] > expected_size[0]) or (img.size[1] > expected_size[1])):
... |
'Populates form with fields from given AssetType'
| def __init__(self, user, item_type, *args, **kwargs):
| self.item_type = item_type
if ('instance' in kwargs):
self.instance = kwargs['instance']
values = self.instance.itemvalue_set.all()
del kwargs['instance']
super(ItemForm, self).__init__(*args, **kwargs)
if ('files' in kwargs):
self.files = kwargs['files']
self.fields[... |
'Process form and create DB objects as required'
| def save(self, request):
| if self.instance:
item = self.instance
else:
item = Item()
item.item_type = self.item_type
item.name = unicode(self.cleaned_data['name'])
item.parent = self.cleaned_data['parent']
item.status = self.cleaned_data['status']
item.manufacturer = self.cleaned_data['manufacture... |
'Ensure the name of the field only contains alphanumeric'
| def clean_name(self):
| name = self.cleaned_data['name']
if (not re.match('^[a-zA-Z0-9-_]+$', name)):
raise forms.ValidationError(_('Sorry, field names can only contain letters, numbers, hyphens (-) and underscores (_)'))
return name
|
'Process form'
| def save(self, *args, **kwargs):
| if self.instance:
if self.is_valid():
if self.cleaned_data['location']:
self.instance.location = self.cleaned_data['location']
if self.cleaned_data['status']:
self.instance.status = self.cleaned_data['status']
self.instance.save()
... |
'Sets choices and initial value'
| def __init__(self, user, *args, **kwargs):
| super(SettingsForm, self).__init__(*args, **kwargs)
self.fields['default_item_status'].queryset = ItemStatus.objects.filter(trash=False)
try:
conf = ModuleSetting.get_for_module('treeio.infrastructure', 'default_item_status')[0]
default_item_status = ItemStatus.objects.get(pk=long(conf.value... |
'Form processor'
| def save(self):
| try:
ModuleSetting.set_for_module('default_item_status', self.cleaned_data['default_item_status'].id, 'treeio.infrastructure')
except Exception:
return False
|
'Initial Setup'
| def setUp(self):
| if (not self.prepared):
Object.objects.all().delete()
try:
self.group = Group.objects.get(name='test')
except Group.DoesNotExist:
Group.objects.all().delete()
self.group = Group(name='test')
self.group.save()
try:
self.user ... |
'Test index page at /api/knowledge/folders'
| def test_unauthenticated_access(self):
| response = self.client.get('/api/knowledge/folders')
self.assertEquals(response.status_code, 401)
|
'Test index page api/knowledge/folders'
| def test_get_folders_list(self):
| response = self.client.get(path=reverse('api_knowledge_folders'), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
|
'Test index page api/knowledge/categories'
| def test_get_categories_list(self):
| response = self.client.get(path=reverse('api_knowledge_categories'), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
|
'Test index page api/knowledge/items'
| def test_get_items_list(self):
| response = self.client.get(path=reverse('api_knowledge_items'), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
|
'Returns absolute URL of the object'
| def get_absolute_url(self):
| try:
return reverse('knowledge_folder_view', args=[self.treepath])
except Exception:
return ''
|
'Walks up the tree to construct Type treepath'
| def treewalk(self, save=True):
| treepath = ''
for folder in self.get_tree_path():
slug = unicode(folder.name).replace(' ', '-')
slug = defaultfilters.slugify(unidecode(slug))
treepath += (slug + '/')
self.treepath = treepath
if save:
self.save()
return self
|
'Returns a KnowledgeFolder instance matching the given treepath'
| def by_path(treePath):
| folder = KnowledgeFolder.objects.filter(treepath=unicode(treePath))
if folder:
folder = folder[0]
else:
folder = None
return folder
|
'Overridden save() method to compute treepath and full names'
| def save(self, *args, **kwargs):
| self.treewalk(save=False)
super(KnowledgeFolder, self).save(*args, **kwargs)
|
'Returns absolute URL of the object'
| def get_absolute_url(self):
| try:
return reverse('knowledge_category_view', args=[self.treepath])
except Exception:
return ''
|
'Walks up the tree to construct Category'
| def treewalk(self, save=True):
| slug = unicode(self.name).replace(' ', '-')
slug = defaultfilters.slugify(unidecode(slug))
treepath = (slug + '/')
self.treepath = treepath
if save:
self.save()
return self
|
'Returns a Knowledge Category instance matching the given treepath'
| def by_path(path):
| category = KnowledgeCategory.objects.filter(treepath=unidecode(path))
if category:
category = category[0]
else:
category = None
return category
|
'Overridden save() method to compute treepath and full names'
| def save(self, *args, **kwargs):
| self.treewalk(save=False)
super(KnowledgeCategory, self).save(*args, **kwargs)
|
'Returns absolute URL of the object'
| def get_absolute_url(self):
| try:
return reverse('knowledge_item_view', args=[self.folder.treepath, self.treepath])
except Exception:
return ''
|
'Walks up the tree to construct both Item treepath and item.name from database'
| def treewalk(self, save=True):
| slug = unicode(self.name).replace(' ', '-')
slug = defaultfilters.slugify(unidecode(slug))
treepath = (slug + '/')
self.treepath = treepath
if save:
self.save()
return self
|
'Returns a Knowledge Item instance matching the given treepath'
| def by_path(treePath, itemPath):
| folder = KnowledgeFolder.by_path(unidecode(treePath))
item = KnowledgeItem.objects.filter(treepath=unidecode(itemPath), folder=folder)
if item:
item = item[0]
else:
item = None
return item
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.