Exemple #1
0
	def get_context_data(self, *args, **kwargs):
		context = super(TaskList, self).get_context_data(*args, **kwargs)
		context['project'] = get_object_or_404(Project, pk=self.kwargs['project_pk'])
		context['breadcrumbs'] = [
			{
				'label': _("Projects"),
				'url': reverse('project_list')
			},
			{
				'label': _(u"%s" % context['project']),
			},
			{
				'label': _("Tasks"),
				'menu': [
					{
						'label': _("Detail"),
						'url': reverse('project_detail', kwargs={'pk': self.kwargs['project_pk']}),
					},
					{
						'label': _("Organisations"),
					},
					{
						'label': _("Locations"),
					},
					{
						'label': _("Activities"),
					},
					{
						'label': _("Documents"),
					},
					{
						'label': _("Staff"),
					},
					{
						'label': _("Volunteers"),
					},
				]
			}
		]
		context['module_menu'] = menu()

		context['table'] = table_from_list(
			context['serialized_data'],
			Task,
			self.fields,
		)
		return context
Exemple #2
0
	def get_context_data(self, *args, **kwargs):
		context = super(ListView, self).get_context_data(*args, **kwargs)

		context['path'] = self.request.path

		if hasattr(self, "serializer_class"):
			context['serialized_data'] = self.serializer_class(self.object_list).data

			context['json'] = json.dumps(
				context['serialized_data'],
				cls=JSONEncoder
			)

			context['table'] = table_from_list(
				context['serialized_data'],
				self.model,
				self.fields,
			)

		if hasattr(self, "filter_class"):
			context['filter'] = self.filter_class(self.request.GET)
			context['filter'].form.html_action = self.request.path

		return context
Exemple #3
0
	def test_table_from_list(self):
		serialized_data = [
			{
				'pk': 1,
				'url': '/organisations/2/',
				'name': u'Test Org',
				'orgtype': u'Test Org Type',
				'country': u'Afghanistan',
				'sectors': [
					u'Agriculture',
					u'Coordination and Support Services'
				],
				'offices': [],
				'lat': 33.677,
				'lon': 65.216,
				'acronym': u'ARCS',
				'website': u'http://www.arcs.org.af/'
			}
		]

		result = {
			'cols': [
				{
					'field': "name",
					'type': "CharField",
					'label': u"name",
				},
				{
					'field': "orgtype",
					'type': "ForeignKey",
					'label': u"type",
				},
				{
					'field': "sectors",
					'type': "ManyToManyField",
					'label': u"sectors",
				}
			],
			'rows': [
				{
					'pk': 1,
					'cells': [
						{
							'field': "name",
							'type': "CharField",
							'value': u"Test Org",
						},
						{
							'field': "orgtype",
							'type': "ForeignKey",
							'value': u"Test Org Type",
						},
						{
							'field': "sectors",
							'type': "ManyToManyField",
							'value': [
								u'Agriculture',
								u'Coordination and Support Services'
							],
						}
					]
				}
			]
		}

		self.assertEqual(
			table_from_list(
				serialized_data,
				Organisation,
				[
					"name",
					"orgtype",
					"sectors",
				]
			),
			result
		)