示例#1
0
 def test_model_chart(self):
     "Test Chart Model"
     report = Report(name='test')
     report.save()
     obj = Chart(name='test', report=report)
     obj.save()
     self.assertEquals('test', obj.name)
     self.assertNotEquals(obj.id, None)
     obj.delete()
示例#2
0
文件: forms.py 项目: tovmeod/anaf
 def save(self):
     if hasattr(self, 'chart_id'):
         chart = get_object_or_404(Chart, pk=self.chart_id)
     else:
         chart = Chart()
         report = get_object_or_404(Report, pk=self.report_id)
         chart.report = report
     chart.name = self.data['title']
     chart.options = dumps(self.data)
     chart.save()
     return chart
示例#3
0
def piechart_add(request, layer_id):
    if request.method == 'POST':
        layer = Layer.objects.get(id=int(layer_id))

        title = request.POST.get('title')
        description = request.POST.get('description')
        chart_conf = request.POST.get('chart_conf')

        chart = Chart(layer=layer,
                      type='piechart',
                      title=title,
                      description=description,
                      conf=chart_conf)
        chart.save()

        return HttpResponse(json.dumps({'success': True}, indent=4),
                            content_type='application/json')

    else:
        layer = Layer.objects.get(id=int(layer_id))

        layer = Layer.objects.get(id=int(layer_id))
        datastore = Datastore.objects.get(id=layer.datastore_id)
        workspace = Workspace.objects.get(id=datastore.workspace_id)
        gs = geographic_servers.get_instance().get_server_by_id(
            workspace.server.id)

        (ds_type, resource) = gs.getResourceInfo(workspace.name, datastore,
                                                 layer.name, "json")
        fields = utils.get_fields(resource)
        numeric_fields = utils.get_numeric_fields(fields)
        alpha_numeric_fields = utils.get_alphanumeric_fields(fields)
        geom_fields = utils.get_geometry_fields(fields)

        conf = {
            'layer_id': layer_id,
            'fields': json.dumps(fields),
            'numeric_fields': json.dumps(numeric_fields),
            'alpha_numeric_fields': json.dumps(alpha_numeric_fields),
            'geom_fields': json.dumps(geom_fields)
        }

        return render(request, 'piechart_add.html', conf)
示例#4
0
def api_create_chart(request, *, type, description, project_id, option):
    Option = json.dumps(option, ensure_ascii=False).encode('utf-8')
    chart = Chart(user_id=request.__user__.id,
                  user_name=request.__user__.name,
                  user_image=request.__user__.image,
                  project_id=project_id.strip(),
                  type=type.strip(),
                  description=description.strip(),
                  status=False,
                  option=Option)
    yield from chart.save()
    chart.option = markdown2.markdown(chart.option)
    return chart
示例#5
0
class ReportsViewsTest(TestCase):
    username = "******"
    password = "******"

    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(name='default')
        perspective.set_default_user()
        perspective.save()
        ModuleSetting.set('default_perspective', perspective.id)

        self.report = Report(name='test')
        self.report.set_default_user()
        self.report.save()

        self.chart = Chart(name='test_chart', report=self.report)
        self.chart.set_default_user()
        self.chart.save()

    ######################################
    # Testing views when user is logged in
    ######################################
    def test_reports_login(self):
        """Testing /reports/"""
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports'))
        self.assertEquals(response.status_code, 200)

    def test_index_login(self):
        "Testing /reports/index/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_index'))
        self.assertEquals(response.status_code, 200)

    def test_index_owned(self):
        "Testing /reports/owned/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_index'))
        self.assertEquals(response.status_code, 200)

    # Charts
    def test_chart_add(self):
        "Testing /reports/chart/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_chart_add'))
        self.assertEquals(response.status_code, 200)

    def test_chart_delete_login(self):
        "Testing /reports/chart/delete/<chart_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('reports_chart_delete', args=[self.chart.id]))
        self.assertEquals(response.status_code, 200)

    # Reports
    def test_report_add(self):
        "Testing /reports/report/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_report_add'))
        self.assertEquals(response.status_code, 200)

    def test_report_delete_login(self):
        "Testing /reports/report/delete/<report_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('reports_report_delete', args=[self.report.id]))
        self.assertEquals(response.status_code, 200)

    ######################################
    # Testing views when user is not logged in
    ######################################
    def test_reports_out(self):
        "Testing /reports/"
        response = self.client.get(reverse('reports'))
        self.assertRedirects(response, reverse('user_login'))

    def test_index_out(self):
        "Testing /reports/index/"
        response = self.client.get(reverse('reports_index'))
        self.assertRedirects(response, reverse('user_login'))

    def test_index_owned_out(self):
        "Testing /reports/owned/"
        response = self.client.get(reverse('reports_index'))
        self.assertRedirects(response, reverse('user_login'))

    # Charts
    def test_chart_add_out(self):
        "Testing /reports/chart/add/"
        response = self.client.get(reverse('reports_chart_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_chart_add_typed_out(self):
        "Testing /reports/chart/add/<report_id>"
        response = self.client.get(
            reverse('reports_chart_add', args=[self.report.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_chart_edit_out(self):
        "Testing /reports/chart/edit/<chart_id>"
        response = self.client.get(
            reverse('reports_chart_edit', args=[self.chart.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_chart_delete_out(self):
        "Testing /reports/chart/delete/<chart_id>"
        response = self.client.get(
            reverse('reports_chart_delete', args=[self.chart.id]))
        self.assertRedirects(response, reverse('user_login'))

    # Reports
    def test_report_add_out(self):
        "Testing /reports/report/add/"
        response = self.client.get(reverse('reports_report_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_report_view_out(self):
        "Testing /reports/report/view/<report_id>"
        response = self.client.get(
            reverse('reports_report_view', args=[self.report.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_report_edit_out(self):
        "Testing /reports/report/edit/<report_id>"
        response = self.client.get(
            reverse('reports_report_edit', args=[self.report.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_report_delete_out(self):
        "Testing /reports/report/delete/<report_id>"
        response = self.client.get(
            reverse('reports_report_delete', args=[self.report.id]))
        self.assertRedirects(response, reverse('user_login'))
示例#6
0
def api_create_chart(request , *, type, description, project_id, option):
    Option = json.dumps(option, ensure_ascii=False).encode('utf-8')
    chart = Chart(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, project_id=project_id.strip(), type=type.strip(), description=description.strip(), status=False, option = Option)
    yield from chart.save()
    chart.option = markdown2.markdown(chart.option)
    return chart