datahuborg/datahub

View on GitHub
src/api/views.py

Summary

Maintainability
F
1 wk
Test Coverage

File views.py has 769 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import ast
import json

from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
Severity: Major
Found in src/api/views.py - About 1 day to fix

    Function patch has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def patch(self, request, repo_base, repo_name, card_name, format=None):
    Severity: Minor
    Found in src/api/views.py - About 35 mins to fix

      Function delete has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def delete(self, request, repo_base, repo_name, collaborator, format=None):
      Severity: Minor
      Found in src/api/views.py - About 35 mins to fix

        Function delete has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def delete(self, request, repo_base, repo_name, table, format=None):
        Severity: Minor
        Found in src/api/views.py - About 35 mins to fix

          Function delete has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def delete(self, request, repo_base, repo_name, card_name, format=None):
          Severity: Minor
          Found in src/api/views.py - About 35 mins to fix

            Function get has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def get(self, request, repo_base, repo_name, view, format=None):
            Severity: Minor
            Found in src/api/views.py - About 35 mins to fix

              Function get has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def get(self, request, repo_base, repo_name, card_name, format=None):
              Severity: Minor
              Found in src/api/views.py - About 35 mins to fix

                Function delete has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def delete(self, request, repo_base, repo_name, view, format=None):
                Severity: Minor
                Found in src/api/views.py - About 35 mins to fix

                  Function get has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def get(self, request, repo_base, repo_name, file_name, format=None):
                  Severity: Minor
                  Found in src/api/views.py - About 35 mins to fix

                    Function delete has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def delete(self, request, repo_base, repo_name, file_name, format=None):
                    Severity: Minor
                    Found in src/api/views.py - About 35 mins to fix

                      Function get has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          def get(self, request, repo_base, repo_name, collaborator, format=None):
                      Severity: Minor
                      Found in src/api/views.py - About 35 mins to fix

                        Function get has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            def get(self, request, repo_base, repo_name, table, format=None):
                        Severity: Minor
                        Found in src/api/views.py - About 35 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return Response(
                          Severity: Major
                          Found in src/api/views.py - About 30 mins to fix

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                    elif table:
                                        serializer = TableSerializer(username, repo_base, request)
                                        serializer.export_table(repo_name, table, file_name, file_format,
                                                                delimiter, header)
                            
                            
                            Severity: Major
                            Found in src/api/views.py and 1 other location - About 4 hrs to fix
                            src/api/views.py on lines 476..483

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 79.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                    elif view:
                                        serializer = ViewSerializer(username, repo_base, request)
                                        serializer.export_view(repo_name, view, file_name, file_format,
                                                               delimiter, header)
                                        filename = file_name + "." + file_format
                            Severity: Major
                            Found in src/api/views.py and 1 other location - About 4 hrs to fix
                            src/api/views.py on lines 466..474

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 79.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                def get(self, request, repo_base, repo_name, table, format=None):
                                    """
                                    See the schema of a single table
                            
                                    This endpoint does not throw an error if the table does not exist.
                            Severity: Major
                            Found in src/api/views.py and 1 other location - About 3 hrs to fix
                            src/api/views.py on lines 571..582

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 70.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                def get(self, request, repo_base, repo_name, view, format=None):
                                    """
                                    See the schema of a single view
                            
                                    This endpoint does not throw an error if the table does not exist.
                            Severity: Major
                            Found in src/api/views.py and 1 other location - About 3 hrs to fix
                            src/api/views.py on lines 364..375

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 70.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 4 locations. Consider refactoring.
                            Open

                                def get(self, request, repo_base, repo_name, format=None):
                                    """
                                    Collaborators in a repo
                                    """
                                    username = request.user.get_username()
                            Severity: Major
                            Found in src/api/views.py and 3 other locations - About 3 hrs to fix
                            src/api/views.py on lines 291..300
                            src/api/views.py on lines 396..404
                            src/api/views.py on lines 527..536

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 67.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 4 locations. Consider refactoring.
                            Open

                                def get(self, request, repo_base, repo_name, format=None):
                                    """
                                    Tables in a repo
                                    """
                                    username = request.user.get_username()
                            Severity: Major
                            Found in src/api/views.py and 3 other locations - About 3 hrs to fix
                            src/api/views.py on lines 204..214
                            src/api/views.py on lines 396..404
                            src/api/views.py on lines 527..536

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 67.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 4 locations. Consider refactoring.
                            Open

                                def get(self, request, repo_base, repo_name, format=None):
                                    """
                                    Views in a repo
                                    """
                                    username = request.user.get_username()
                            Severity: Major
                            Found in src/api/views.py and 3 other locations - About 3 hrs to fix
                            src/api/views.py on lines 204..214
                            src/api/views.py on lines 291..300
                            src/api/views.py on lines 396..404

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 67.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 4 locations. Consider refactoring.
                            Open

                                def get(self, request, repo_base, repo_name, format=None):
                                    """
                                    Files in a repo
                                    """
                                    username = request.user.get_username()
                            Severity: Major
                            Found in src/api/views.py and 3 other locations - About 3 hrs to fix
                            src/api/views.py on lines 204..214
                            src/api/views.py on lines 291..300
                            src/api/views.py on lines 527..536

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 67.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                def delete(self, request, repo_base, repo_name, collaborator, format=None):
                                    """
                                    Remove a collaborator from a given repo
                                    """
                                    username = request.user.get_username()
                            Severity: Major
                            Found in src/api/views.py and 2 other locations - About 3 hrs to fix
                            src/api/views.py on lines 514..522
                            src/api/views.py on lines 714..722

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 64.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                def delete(self, request, repo_base, repo_name, file_name, format=None):
                                    """
                                    Delete a file
                                    """
                                    username = request.user.get_username()
                            Severity: Major
                            Found in src/api/views.py and 2 other locations - About 3 hrs to fix
                            src/api/views.py on lines 278..286
                            src/api/views.py on lines 714..722

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 64.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                def delete(self, request, repo_base, repo_name, card_name, format=None):
                                    """
                                    Delete a single card
                                    """
                                    username = request.user.get_username()
                            Severity: Major
                            Found in src/api/views.py and 2 other locations - About 3 hrs to fix
                            src/api/views.py on lines 278..286
                            src/api/views.py on lines 514..522

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 64.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                for drf_status, exceptions in exceptions_by_status.iteritems():
                                    if next((e for e in exceptions if issubclass(type(exc), e)), None):
                                        status_code = drf_status
                                        break
                            Severity: Major
                            Found in src/api/views.py and 1 other location - About 1 hr to fix
                            src/browser/middleware.py on lines 37..41

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 47.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                if issubclass(type(exc), PGError):
                                    result['pgcode'] = exc.pgcode
                                    result['severity'] = exc.diag.severity
                            Severity: Major
                            Found in src/api/views.py and 1 other location - About 1 hr to fix
                            src/browser/middleware.py on lines 50..52

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 41.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            There are no issues that match your filters.

                            Category
                            Status