id
int64
0
843k
repository_name
stringlengths
7
55
file_path
stringlengths
9
332
class_name
stringlengths
3
290
human_written_code
stringlengths
12
4.36M
class_skeleton
stringlengths
19
2.2M
total_program_units
int64
1
9.57k
total_doc_str
int64
0
4.2k
AvgCountLine
float64
0
7.89k
AvgCountLineBlank
float64
0
300
AvgCountLineCode
float64
0
7.89k
AvgCountLineComment
float64
0
7.89k
AvgCyclomatic
float64
0
130
CommentToCodeRatio
float64
0
176
CountClassBase
float64
0
48
CountClassCoupled
float64
0
589
CountClassCoupledModified
float64
0
581
CountClassDerived
float64
0
5.37k
CountDeclInstanceMethod
float64
0
4.2k
CountDeclInstanceVariable
float64
0
299
CountDeclMethod
float64
0
4.2k
CountDeclMethodAll
float64
0
4.2k
CountLine
float64
1
115k
CountLineBlank
float64
0
9.01k
CountLineCode
float64
0
94.4k
CountLineCodeDecl
float64
0
46.1k
CountLineCodeExe
float64
0
91.3k
CountLineComment
float64
0
27k
CountStmt
float64
1
93.2k
CountStmtDecl
float64
0
46.1k
CountStmtExe
float64
0
90.2k
MaxCyclomatic
float64
0
759
MaxInheritanceTree
float64
0
16
MaxNesting
float64
0
34
SumCyclomatic
float64
0
6k
5,700
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNINDEXTYPE
class SpiceUNKNOWNINDEXTYPE(SpiceyPyError): pass
class SpiceUNKNOWNINDEXTYPE(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,701
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNKERNELTYPE
class SpiceUNKNOWNKERNELTYPE(SpiceyPyError): pass
class SpiceUNKNOWNKERNELTYPE(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,702
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNKEY
class SpiceUNKNOWNKEY(SpiceyPyError): pass
class SpiceUNKNOWNKEY(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,703
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNMETAITEM
class SpiceUNKNOWNMETAITEM(SpiceyPyError): pass
class SpiceUNKNOWNMETAITEM(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,704
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNMODE
class SpiceUNKNOWNMODE(SpiceyPyError): pass
class SpiceUNKNOWNMODE(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,705
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNOP
class SpiceUNKNOWNOP(SpiceyPyError): pass
class SpiceUNKNOWNOP(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,706
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNPACKETDIR
class SpiceUNKNOWNPACKETDIR(SpiceyPyError): pass
class SpiceUNKNOWNPACKETDIR(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,707
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNPCKTYPE
class SpiceUNKNOWNPCKTYPE(SpiceyPyError): pass
class SpiceUNKNOWNPCKTYPE(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,708
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNREFDIR
class SpiceUNKNOWNREFDIR(SpiceyPyError): pass
class SpiceUNKNOWNREFDIR(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,709
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNSPKTYPE
class SpiceUNKNOWNSPKTYPE(SpiceyPyIOError): pass
class SpiceUNKNOWNSPKTYPE(SpiceyPyIOError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
6
0
0
5,710
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceBADADDRESS
class SpiceBADADDRESS(SpiceyPyError): pass
class SpiceBADADDRESS(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,711
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceTARGIDCODENOTFOUND
class SpiceTARGIDCODENOTFOUND(SpiceyPyError): pass
class SpiceTARGIDCODENOTFOUND(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,712
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceBADACTION
class SpiceBADACTION(SpiceyPyValueError): pass
class SpiceBADACTION(SpiceyPyValueError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
13
2
0
2
1
1
0
2
1
1
0
6
0
0
5,713
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceAVALOUTOFRANGE
class SpiceAVALOUTOFRANGE(SpiceyPyError): pass
class SpiceAVALOUTOFRANGE(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,714
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNINITIALIZED
class SpiceUNINITIALIZED(SpiceyPyError): pass
class SpiceUNINITIALIZED(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,715
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNINITIALIZEDHASH
class SpiceUNINITIALIZEDHASH(SpiceyPyError): pass
class SpiceUNINITIALIZEDHASH(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,716
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceADDRESSOUTOFBOUNDS
class SpiceADDRESSOUTOFBOUNDS(SpiceyPyError): pass
class SpiceADDRESSOUTOFBOUNDS(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,717
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceAGENTLISTOVERFLOW
class SpiceAGENTLISTOVERFLOW(SpiceyPyError): pass
class SpiceAGENTLISTOVERFLOW(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,718
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceALLGONE
class SpiceALLGONE(SpiceyPyError): pass
class SpiceALLGONE(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,719
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceAMBIGTEMPL
class SpiceAMBIGTEMPL(SpiceyPyError): pass
class SpiceAMBIGTEMPL(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,720
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceARRAYSHAPEMISMATCH
class SpiceARRAYSHAPEMISMATCH(SpiceyPyValueError): pass
class SpiceARRAYSHAPEMISMATCH(SpiceyPyValueError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
13
2
0
2
1
1
0
2
1
1
0
6
0
0
5,721
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceARRAYSIZEMISMATCH
class SpiceARRAYSIZEMISMATCH(SpiceyPyError): pass
class SpiceARRAYSIZEMISMATCH(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,722
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceARRAYTOOSMALL
class SpiceARRAYTOOSMALL(SpiceyPyMemoryError): pass
class SpiceARRAYTOOSMALL(SpiceyPyMemoryError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
13
2
0
2
1
1
0
2
1
1
0
6
0
0
5,723
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNINITIALIZEDVALUE
class SpiceUNINITIALIZEDVALUE(SpiceyPyError): pass
class SpiceUNINITIALIZEDVALUE(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,724
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNITSMISSING
class SpiceUNITSMISSING(SpiceyPyValueError): pass
class SpiceUNITSMISSING(SpiceyPyValueError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
13
2
0
2
1
1
0
2
1
1
0
6
0
0
5,725
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNITSNOTREC
class SpiceUNITSNOTREC(SpiceyPyValueError): pass
class SpiceUNITSNOTREC(SpiceyPyValueError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
13
2
0
2
1
1
0
2
1
1
0
6
0
0
5,726
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNONWNTIMESYSTEM
class SpiceUNKNONWNTIMESYSTEM(SpiceyPyError): pass
class SpiceUNKNONWNTIMESYSTEM(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,727
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNBFF
class SpiceUNKNOWNBFF(SpiceyPyError): pass
class SpiceUNKNOWNBFF(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,728
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNCKMETA
class SpiceUNKNOWNCKMETA(SpiceyPyError): pass
class SpiceUNKNOWNCKMETA(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,729
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNCOMPARE
class SpiceUNKNOWNCOMPARE(SpiceyPyValueError): pass
class SpiceUNKNOWNCOMPARE(SpiceyPyValueError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
13
2
0
2
1
1
0
2
1
1
0
6
0
0
5,730
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceUNKNOWNDATATYPE
class SpiceUNKNOWNDATATYPE(SpiceyPyError): pass
class SpiceUNKNOWNDATATYPE(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,731
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceAXISUNDERFLOW
class SpiceAXISUNDERFLOW(SpiceyPyError): pass
class SpiceAXISUNDERFLOW(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,732
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceSTRINGCREATEFAIL
class SpiceSTRINGCREATEFAIL(SpiceyPyError): pass
class SpiceSTRINGCREATEFAIL(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,733
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceTARGETMISMATCH
class SpiceTARGETMISMATCH(SpiceyPyValueError): pass
class SpiceTARGETMISMATCH(SpiceyPyValueError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
13
2
0
2
1
1
0
2
1
1
0
6
0
0
5,734
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceSYSTEMCALLFAILED
class SpiceSYSTEMCALLFAILED(SpiceyPyError): pass
class SpiceSYSTEMCALLFAILED(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,735
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceSTRINGTOOSHORT
class SpiceSTRINGTOOSHORT(SpiceyPyValueError): pass
class SpiceSTRINGTOOSHORT(SpiceyPyValueError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
13
2
0
2
1
1
0
2
1
1
0
6
0
0
5,736
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceTABLENOTLOADED
class SpiceTABLENOTLOADED(SpiceyPyIOError): pass
class SpiceTABLENOTLOADED(SpiceyPyIOError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
6
0
0
5,737
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceSTRINGTOOSMALL
class SpiceSTRINGTOOSMALL(SpiceyPyError): pass
class SpiceSTRINGTOOSMALL(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,738
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/get_spice.py
get_spice.GetCSPICE
class GetCSPICE(object): """ Class that support the download from the NAIF FTP server of the required CSPICE package for the architecture used by the Python distribution that invokes this module. By default the CSPICE Toolkit version N0066 is downloaded and unpacked on the directory where this module is located. Arguments --------- :argument version: String indicating the required version of the CSPICE Toolkit. By default it is 'N0066'. :type: str """ # This class variable will be used to store the CSPICE package in memory. _local = None # Supported distributions _dists = { # system arch distribution name extension # -------- ---------- ------------------------- --------- ("Darwin", "x86_64", "64bit"): ("MacIntel_OSX_AppleC_64bit", "tar.Z"), ("Darwin", "arm64", "64bit"): ("MacM1_OSX_clang_64bit", "tar.Z"), ("cygwin", "x86_64", "64bit"): ("PC_Cygwin_GCC_64bit", "tar.Z"), ("FreeBSD", "x86_64", "64bit"): ("PC_Linux_GCC_64bit", "tar.Z"), ("Linux", "x86_64", "64bit"): ("PC_Linux_GCC_64bit", "tar.Z"), ("Linux", "aarch64", "64bit"): ("PC_Linux_GCC_64bit", "tar.Z"), ("Windows", "x86_64", "64bit"): ("PC_Windows_VisualC_64bit", "zip"), } def __init__(self, version=spice_version, dst=None): """Init method that uses either the default N0066 toolkit version token or a user provided one. """ try: # Get the remote file path for the Python architecture that # executes the script. distribution, self._ext = self._distribution_info() except KeyError: print("SpiceyPy currently does not support your system.") else: cspice = "cspice.{}".format(self._ext) self._rcspice = ( "https://naif.jpl.nasa.gov/pub/naif/misc" "/toolkit_{0}/C/{1}/packages" "/{2}" ).format(version, distribution, cspice) # Setup the local directory (where the package will be downloaded) if dst is None: dst = os.path.realpath(os.path.dirname(__file__)) self._root = dst # Download the file print("Downloading CSPICE for {0}...".format(distribution)) attempts = 10 # Let's try a maximum of attempts for getting SPICE while attempts: attempts -= 1 try: self._download() except RuntimeError as error: print( "Download failed with URLError: {0}, trying again after " "15 seconds!".format(error) ) time.sleep(15) else: # Unpack the file print("Unpacking... (this may take some time!)") self._unpack() # We are done. Let's return to the calling code. break def _distribution_info(self): """Creates the distribution name and the expected extension for the CSPICE package and returns it. :return (distribution, extension) tuple where distribution is the best guess from the strings available within the platform_urls list of strings, and extension is either "zip" or "tar.Z" depending on whether we are dealing with a Windows platform or else. :rtype: tuple (str, str) :raises: KeyError if the (system, machine) tuple does not correspond to any of the supported SpiceyPy environments. """ print("Gathering information...") system = platform.system() processor = platform.processor() machine = platform.machine() # Cygwin system is CYGWIN-NT-xxx. system = "cygwin" if "CYGWIN" in system else system cpu_bits = "64bit" if sys.maxsize > 2 ** 32 else "32bit" if machine in ("x86", "x86_64", "AMD64", "i686"): machine = "x86_64" if is_macos_arm: machine = "arm64" print("SYSTEM: ", system) print("PROCESSOR:", processor) print("MACHINE: ", cpu_bits, machine) if machine in ("i386", "x86_32") or cpu_bits == "32bit": raise RuntimeError("32bit bit builds are not supported") return self._dists[(system, machine, cpu_bits)] def _download(self): """Support function that encapsulates the OpenSSL transfer of the CSPICE package to the self._local io.ByteIO stream. :raises RuntimeError if there has been any issue with the HTTPS communication .. note:: Handling of CSPICE downloads from HTTPS --------------------------------------- Some Python distributions may be linked to an old version of OpenSSL which will not let you connect to NAIF server due to recent SSL cert upgrades on the JPL servers. Moreover, versions older than OpenSSL 1.0.1g are known to contain the 'the Heartbleed Bug'. Therefore this method provides two different implementations for the HTTPS GET call to the NAIF server to download the required CSPICE distribution package. * as of 3.0.1, we default back to use built in openssl, as we require python 3.6 or above * """ try: # Send the request to get the CSPICE package (proxy auto detected). response = urllib.request.urlopen(self._rcspice, timeout=10) except urllib.error.URLError as err: raise RuntimeError(err.reason) # Convert the response to io.BytesIO and store it in local memory. self._local = io.BytesIO(response.read()) def _unpack(self): """Unpacks the CSPICE package on the given root directory. Note that Package could either be the zipfile.ZipFile class for Windows platforms or tarfile.TarFile for other platforms. """ if self._ext == "zip": with ZipFile(self._local, "r") as archive: archive.extractall(self._root) else: cmd = ( f"gunzip | tar {'xfC -' if host_OS == 'FreeBSD' else 'xC'} {self._root}" ) proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE) proc.stdin.write(self._local.read()) self._local.close()
class GetCSPICE(object): ''' Class that support the download from the NAIF FTP server of the required CSPICE package for the architecture used by the Python distribution that invokes this module. By default the CSPICE Toolkit version N0066 is downloaded and unpacked on the directory where this module is located. Arguments --------- :argument version: String indicating the required version of the CSPICE Toolkit. By default it is 'N0066'. :type: str ''' def __init__(self, version=spice_version, dst=None): '''Init method that uses either the default N0066 toolkit version token or a user provided one. ''' pass def _distribution_info(self): '''Creates the distribution name and the expected extension for the CSPICE package and returns it. :return (distribution, extension) tuple where distribution is the best guess from the strings available within the platform_urls list of strings, and extension is either "zip" or "tar.Z" depending on whether we are dealing with a Windows platform or else. :rtype: tuple (str, str) :raises: KeyError if the (system, machine) tuple does not correspond to any of the supported SpiceyPy environments. ''' pass def _download(self): '''Support function that encapsulates the OpenSSL transfer of the CSPICE package to the self._local io.ByteIO stream. :raises RuntimeError if there has been any issue with the HTTPS communication .. note:: Handling of CSPICE downloads from HTTPS --------------------------------------- Some Python distributions may be linked to an old version of OpenSSL which will not let you connect to NAIF server due to recent SSL cert upgrades on the JPL servers. Moreover, versions older than OpenSSL 1.0.1g are known to contain the 'the Heartbleed Bug'. Therefore this method provides two different implementations for the HTTPS GET call to the NAIF server to download the required CSPICE distribution package. * as of 3.0.1, we default back to use built in openssl, as we require python 3.6 or above * ''' pass def _unpack(self): '''Unpacks the CSPICE package on the given root directory. Note that Package could either be the zipfile.ZipFile class for Windows platforms or tarfile.TarFile for other platforms. ''' pass
5
5
31
4
16
11
4
0.76
1
5
0
0
4
3
4
4
157
24
76
22
71
58
58
19
53
6
1
3
16
5,739
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/setup.py
setup.BuildPyCommand
class BuildPyCommand(build_py): """Custom build command to ensure cspice is built and packaged""" def run(self): try_get_spice() return super().run()
class BuildPyCommand(build_py): '''Custom build command to ensure cspice is built and packaged''' def run(self): pass
2
1
3
0
3
0
1
0.25
1
1
0
0
1
0
1
71
6
1
4
2
2
1
4
2
2
1
3
0
1
5,740
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/setup.py
setup.InstallSpiceyPy
class InstallSpiceyPy(install): """Class that extends the install command and encapsulates the process for installing the required CSPICE distribution at the right place. """ def finalize_options(self): super().finalize_options() self.install_lib = self.install_platlib def run(self): try_get_spice() return super().run()
class InstallSpiceyPy(install): '''Class that extends the install command and encapsulates the process for installing the required CSPICE distribution at the right place. ''' def finalize_options(self): pass def run(self): pass
3
1
3
0
3
0
1
0.57
1
1
0
0
2
1
2
59
13
2
7
4
4
4
7
4
4
1
3
0
2
5,741
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceBADLATUSRECTUM
class SpiceBADLATUSRECTUM(SpiceyPyValueError): pass
class SpiceBADLATUSRECTUM(SpiceyPyValueError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
13
2
0
2
1
1
0
2
1
1
0
6
0
0
5,742
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/tests/gettestkernels.py
spiceypy.tests.gettestkernels.CassiniKernels
class CassiniKernels(object): cassPck_url = "https://raw.githubusercontent.com/AndrewAnnex/SpiceyPyTestKernels/main/cpck05Mar2004.tpc" cassPck_md5 = "8c16afc3bd886326e852b54bd71cc751" satSpk_url = "https://raw.githubusercontent.com/AndrewAnnex/SpiceyPyTestKernels/main/130220AP_SE_13043_13073.bsp" satSpk_md5 = "056c65b8a8064f2958aa097db40160b2" cassTourSpk_url = "https://raw.githubusercontent.com/AndrewAnnex/SpiceyPyTestKernels/main/130212AP_SK_13043_13058.bsp" cassTourSpk_md5 = "41210b787e06c1b8bce7ded3d0b930ab" cassFk_url = "https://raw.githubusercontent.com/AndrewAnnex/SpiceyPyTestKernels/main/cas_v40.tf" cassFk_md5 = "99f1f5a1900afc536354306419dc119b" cassCk_url = "https://raw.githubusercontent.com/AndrewAnnex/SpiceyPyTestKernels/main/13056_13057ra.bc" cassCk_md5 = "d3acb29fd931b66e34120feb26f7efb7" cassSclk_url = "https://raw.githubusercontent.com/AndrewAnnex/SpiceyPyTestKernels/main/cas00167.tsc" cassSclk_md5 = "a30faec21039ba589d3c88db6b5fb536" cassIk_url = "https://raw.githubusercontent.com/AndrewAnnex/SpiceyPyTestKernels/main/cas_iss_v10.ti" cassIk_md5 = "101419660e4fe5856d30eb624da61a3f" cassPck = get_path_from_url(cassPck_url) satSpk = get_path_from_url(satSpk_url) cassTourSpk = get_path_from_url(cassTourSpk_url) cassFk = get_path_from_url(cassFk_url) cassCk = get_path_from_url(cassCk_url) cassSclk = get_path_from_url(cassSclk_url) cassIk = get_path_from_url(cassIk_url)
class CassiniKernels(object): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
22
0
22
22
21
0
22
22
21
0
1
0
0
5,743
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceSTRINGTRUNCATED
class SpiceSTRINGTRUNCATED(SpiceyPyError): pass
class SpiceSTRINGTRUNCATED(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,744
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceSYNTAXERROR
class SpiceSYNTAXERROR(SpiceyPyError): pass
class SpiceSYNTAXERROR(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,745
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceSUBPOINTNOTFOUND
class SpiceSUBPOINTNOTFOUND(SpiceyPyValueError): pass
class SpiceSUBPOINTNOTFOUND(SpiceyPyValueError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
13
2
0
2
1
1
0
2
1
1
0
6
0
0
5,746
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/src/spiceypy/utils/exceptions.py
spiceypy.utils.exceptions.SpiceSUBORBITAL
class SpiceSUBORBITAL(SpiceyPyError): pass
class SpiceSUBORBITAL(SpiceyPyError): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
12
2
0
2
1
1
0
2
1
1
0
5
0
0
5,747
AndrewAnnex/SpiceyPy
AndrewAnnex_SpiceyPy/setup.py
setup.SpiceyPyBinaryDistribution
class SpiceyPyBinaryDistribution(Distribution): def is_pure(self): return False def root_is_pure(self): return False
class SpiceyPyBinaryDistribution(Distribution): def is_pure(self): pass def root_is_pure(self): pass
3
0
2
0
2
0
1
0
1
0
0
0
2
0
2
68
6
1
5
3
2
0
5
3
2
1
2
0
2
5,748
AndrewAnnex/moody
AndrewAnnex_moody/moody/moody.py
moody.moody.ODE
class ODE(object): """ class to hold ode downloading commands """ def __init__(self, https=True, debug=False): self.https = https if https: self.ode_url = "https://oderest.rsl.wustl.edu/live2" self.gds_url = "https://oderest.rsl.wustl.edu/livegds" else: self.ode_url = "http://oderest.rsl.wustl.edu/live2" self.gds_url = "http://oderest.rsl.wustl.edu/livegds" def ctx_edr(self, pid, chunk_size=1024*1024): """ Download a CTX EDR .IMG file to the CWD. pid: product ID of the CTX EDR, partial IDs ok chunk_size: Chunk size in bytes to use in download """ productid = "{}*".format(pid) query = {"target" : "mars", "query" : "product", "results" : "f", "output" : "j", "pt" : "EDR", "iid" : "CTX", "ihid" : "MRO", "productid" : productid} # Query the ODE product = query_ode(self.ode_url, query) # Validate query results with conditions for this particular query if isinstance(product, list): print("Error: Too many products selected for in query, Make PID more specific") sys.exit(1) else: download_edr_img_files(product, https=self.https, chunk_size=chunk_size) def hirise_edr(self, pid, chunk_size=1024*1024): """ Download a HiRISE EDR set of .IMG files to the CWD You must know the full id to specifiy the filter to use, ie: PSP_XXXXXX_YYYY will download every EDR IMG file available PSP_XXXXXX_YYYY_R will download every EDR RED filter IMG file PSP_XXXXXX_YYYY_BG12_0 will download only the BG12_0 As a wild card is auto applied to the end of the provided pid pid: product ID of the HiRISE EDR, partial IDs ok chunk_size: Chunk size in bytes to use in download """ productid = "{}*".format(pid) query = {"target" : "mars", "query" : "product", "results" : "f", "output" : "j", "pt" : "EDR", "iid" : "HiRISE", "ihid" : "MRO", "productid" : productid} # Query the ODE products = query_ode(self.ode_url, query) # Validate query results with conditions for this particular query if len(products) > 30: print("Error: Too many products selected for in query, Make PID more specific") sys.exit(1) if not isinstance(products, list): print("Error: Too few responses from server to be a full HiRISE EDR, ") else: # proceed to download download_edr_img_files_par(products, self.https, chunk_size) def lrocnac_edr(self, pid, chunk_size=1024*1024): """ Download a LROC NAC EDR set of .IMG files to the CWD As a wild card is auto applied to the end of the provided pid pid: product ID of the LROC EDR, partial IDs ok chunk_size: Chunk size in bytes to use in download """ productid = "{}*".format(pid) query = {"target" : "moon", "query" : "product", "results" : "f", "output" : "j", "pt" : "EDRNAC4", "iid" : "LROC", "ihid" : "LRO", "productid" : productid} # Query the ODE products = query_ode(self.ode_url, query) # Validate query results with conditions for this particular query if len(products) > 30: print("Error: Too many products selected for in query, Make PID more specific") sys.exit(1) if not isinstance(products, list): print("Error: Too few responses from server to be a full HiRISE EDR, ") else: # proceed to download download_edr_img_files_par(products, self.https, chunk_size) def pedr(self, minlon: float, minlat: float, maxlon: float, maxlat: float, wkt_footprint: Optional[str] = None, ext: str = 'csv', **kwargs): """ Get the mola pedr csv/shp file for the query bounds :param ext: :param minlon: minimum longitude (western most longitude) :param minlat: minimum latitude (southern most latitude) :param maxlon: maximum longitude (eastern most longitude) :param maxlat: maximum latitude (northern most latitude) :param wkt_footprint: Optional WKT footprint to further filter out points :return: """ if minlon < 0 or maxlon < 0: # convert -180 to 180 to 0 to 360 minlon += 180.0 maxlon += 180.0 assert 0 <= minlon <= 360 assert 0 <= maxlon <= 360 assert minlon < maxlon and minlat < maxlat # default is csv rt = 's' if ext == 'shp' else 'v' query = { "query": "molapedr", "results": rt, "output": "J", "minlat": str(minlat), "maxlat": str(maxlat), "westernlon": str(minlon), "easternlon": str(maxlon), "zipclean": 't', **kwargs } if wkt_footprint: query['footprint'] = f'{wkt_footprint}' # Query the ODEq response = query_gds(self.gds_url, query) # get the ResultFile, it seems ResultFile has the same number of contents as Number Files resultfile = response['ResultFiles']['ResultFile'] if isinstance(resultfile, dict): resultfile = [resultfile] for f in resultfile: fname = str(f['URL'].split('/')[-1]) fname = fname.replace('-', '__neg__') download_file(f['URL'], fname, 1024) def get_meta(self, **kwargs): """ Perform a mostly arbitrary meta_data query and dump to std out :param kwargs: :return: """ query = kwargs # filters query = query_params(query, 'productid', None, short_hand='pid') query = query_params(query, 'query', 'product') query = query_params(query, 'results', 'm') query = query_params(query, 'output', 'j') return query_ode(self.ode_url, query=query) def get_meta_by_key(self, key, **kwargs): res = self.get_meta(**kwargs) return res[key] def get_ctx_meta(self, pid): productid = "{}*".format(pid) query = {"target" : "mars", "query" : "product", "results" : "m", "output" : "j", "pt" : "EDR", "iid" : "CTX", "ihid" : "MRO", "productid": productid} return query_ode(self.ode_url, query=query) def get_ctx_meta_by_key(self, pid, key): res = self.get_ctx_meta(pid) return res[key] def get_hirise_meta(self, pid): productid = "{}*".format(pid) query = {"target" : "mars", "query" : "product", "results" : "m", "output" : "j", "pt" : "RDRV11", "iid" : "HiRISE", "ihid" : "MRO", "productid": productid} return query_ode(self.ode_url, query=query) def get_hirise_meta_by_key(self, pid, key): res = self.get_hirise_meta(pid) return res[key]
class ODE(object): ''' class to hold ode downloading commands ''' def __init__(self, https=True, debug=False): pass def ctx_edr(self, pid, chunk_size=1024*1024): ''' Download a CTX EDR .IMG file to the CWD. pid: product ID of the CTX EDR, partial IDs ok chunk_size: Chunk size in bytes to use in download ''' pass def hirise_edr(self, pid, chunk_size=1024*1024): ''' Download a HiRISE EDR set of .IMG files to the CWD You must know the full id to specifiy the filter to use, ie: PSP_XXXXXX_YYYY will download every EDR IMG file available PSP_XXXXXX_YYYY_R will download every EDR RED filter IMG file PSP_XXXXXX_YYYY_BG12_0 will download only the BG12_0 As a wild card is auto applied to the end of the provided pid pid: product ID of the HiRISE EDR, partial IDs ok chunk_size: Chunk size in bytes to use in download ''' pass def lrocnac_edr(self, pid, chunk_size=1024*1024): ''' Download a LROC NAC EDR set of .IMG files to the CWD As a wild card is auto applied to the end of the provided pid pid: product ID of the LROC EDR, partial IDs ok chunk_size: Chunk size in bytes to use in download ''' pass def pedr(self, minlon: float, minlat: float, maxlon: float, maxlat: float, wkt_footprint: Optional[str] = None, ext: str = 'csv', **kwargs): ''' Get the mola pedr csv/shp file for the query bounds :param ext: :param minlon: minimum longitude (western most longitude) :param minlat: minimum latitude (southern most latitude) :param maxlon: maximum longitude (eastern most longitude) :param maxlat: maximum latitude (northern most latitude) :param wkt_footprint: Optional WKT footprint to further filter out points :return: ''' pass def get_meta(self, **kwargs): ''' Perform a mostly arbitrary meta_data query and dump to std out :param kwargs: :return: ''' pass def get_meta_by_key(self, key, **kwargs): pass def get_ctx_meta(self, pid): pass def get_ctx_meta_by_key(self, pid, key): pass def get_hirise_meta(self, pid): pass def get_hirise_meta_by_key(self, pid, key): pass
12
6
17
1
12
4
2
0.39
1
4
0
0
11
3
11
11
205
27
128
38
116
50
79
38
67
6
1
1
22
5,749
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/dates.py
extra_views.dates.CalendarMonthView
class CalendarMonthView(MultipleObjectTemplateResponseMixin, BaseCalendarMonthView): """ A view for displaying a calendar month, and rendering a template response """ template_name_suffix = "_calendar_month"
class CalendarMonthView(MultipleObjectTemplateResponseMixin, BaseCalendarMonthView): ''' A view for displaying a calendar month, and rendering a template response ''' pass
1
1
0
0
0
0
0
1.5
2
0
0
1
0
0
0
8
6
1
2
2
1
3
2
2
1
0
2
0
0
5,750
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/dates.py
extra_views.dates.BaseCalendarMonthView
class BaseCalendarMonthView(DateMixin, YearMixin, MonthMixin, BaseListView): """ A base view for displaying a calendar month """ first_of_week = 0 # 0 = Monday, 6 = Sunday paginate_by = None # We don't want to use this part of MultipleObjectMixin date_field = None end_date_field = None # For supporting events with duration def get_paginate_by(self, queryset): if self.paginate_by is not None: raise ImproperlyConfigured( "'%s' cannot be paginated, it is a calendar view" % self.__class__.__name__ ) return None def get_allow_future(self): return True def get_end_date_field(self): """ Returns the model field to use for end dates """ return self.end_date_field def get_start_date(self, obj): """ Returns the start date for a model instance """ obj_date = getattr(obj, self.get_date_field()) try: obj_date = obj_date.date() except AttributeError: # It's a date rather than datetime, so we use it as is pass return obj_date def get_end_date(self, obj): """ Returns the end date for a model instance """ obj_date = getattr(obj, self.get_end_date_field()) try: obj_date = obj_date.date() except AttributeError: # It's a date rather than datetime, so we use it as is pass return obj_date def get_first_of_week(self): """ Returns an integer representing the first day of the week. 0 represents Monday, 6 represents Sunday. """ if self.first_of_week is None: raise ImproperlyConfigured( "%s.first_of_week is required." % self.__class__.__name__ ) if self.first_of_week not in range(7): raise ImproperlyConfigured( "%s.first_of_week must be an integer between 0 and 6." % self.__class__.__name__ ) return self.first_of_week def get_queryset(self): """ Returns a queryset of models for the month requested """ qs = super().get_queryset() year = self.get_year() month = self.get_month() date_field = self.get_date_field() end_date_field = self.get_end_date_field() date = _date_from_string( year, self.get_year_format(), month, self.get_month_format() ) since = date until = self.get_next_month(date) # Adjust our start and end dates to allow for next and previous # month edges if since.weekday() != self.get_first_of_week(): diff = math.fabs(since.weekday() - self.get_first_of_week()) since = since - datetime.timedelta(days=diff) if until.weekday() != ((self.get_first_of_week() + 6) % 7): diff = math.fabs(((self.get_first_of_week() + 6) % 7) - until.weekday()) until = until + datetime.timedelta(days=diff) if end_date_field: # 5 possible conditions for showing an event: # 1) Single day event, starts after 'since' # 2) Multi-day event, starts after 'since' and ends before 'until' # 3) Starts before 'since' and ends after 'since' and before 'until' # 4) Starts after 'since' but before 'until' and ends after 'until' # 5) Starts before 'since' and ends after 'until' predicate1 = Q(**{"%s__gte" % date_field: since, end_date_field: None}) predicate2 = Q( **{"%s__gte" % date_field: since, "%s__lt" % end_date_field: until} ) predicate3 = Q( **{ "%s__lt" % date_field: since, "%s__gte" % end_date_field: since, "%s__lt" % end_date_field: until, } ) predicate4 = Q( **{ "%s__gte" % date_field: since, "%s__lt" % date_field: until, "%s__gte" % end_date_field: until, } ) predicate5 = Q( **{"%s__lt" % date_field: since, "%s__gte" % end_date_field: until} ) return qs.filter( predicate1 | predicate2 | predicate3 | predicate4 | predicate5 ) return qs.filter(**{"%s__gte" % date_field: since}) def get_context_data(self, **kwargs): """ Injects variables necessary for rendering the calendar into the context. Variables added are: `calendar`, `weekdays`, `month`, `next_month` and `previous_month`. """ data = super().get_context_data(**kwargs) year = self.get_year() month = self.get_month() date = _date_from_string( year, self.get_year_format(), month, self.get_month_format() ) cal = Calendar(self.get_first_of_week()) month_calendar = [] now = datetime.datetime.utcnow() date_lists = defaultdict(list) multidate_objs = [] for obj in data["object_list"]: obj_date = self.get_start_date(obj) end_date_field = self.get_end_date_field() if end_date_field: end_date = self.get_end_date(obj) if end_date and end_date != obj_date: multidate_objs.append( { "obj": obj, "range": [x for x in daterange(obj_date, end_date)], } ) continue # We don't put multi-day events in date_lists date_lists[obj_date].append(obj) for week in cal.monthdatescalendar(date.year, date.month): week_range = set(daterange(week[0], week[6])) week_events = [] for val in multidate_objs: intersect_length = len(week_range.intersection(val["range"])) if intersect_length: # Event happens during this week slot = 1 width = ( intersect_length # How many days is the event during this week? ) nowrap_previous = ( True # Does the event continue from the previous week? ) nowrap_next = True # Does the event continue to the next week? if val["range"][0] >= week[0]: slot = 1 + (val["range"][0] - week[0]).days else: nowrap_previous = False if val["range"][-1] > week[6]: nowrap_next = False week_events.append( { "event": val["obj"], "slot": slot, "width": width, "nowrap_previous": nowrap_previous, "nowrap_next": nowrap_next, } ) week_calendar = {"events": week_events, "date_list": []} for day in week: week_calendar["date_list"].append( { "day": day, "events": date_lists[day], "today": day == now.date(), "is_current_month": day.month == date.month, } ) month_calendar.append(week_calendar) data["calendar"] = month_calendar data["weekdays"] = [DAYS[x] for x in cal.iterweekdays()] data["month"] = date data["next_month"] = self.get_next_month(date) data["previous_month"] = self.get_previous_month(date) return data
class BaseCalendarMonthView(DateMixin, YearMixin, MonthMixin, BaseListView): ''' A base view for displaying a calendar month ''' def get_paginate_by(self, queryset): pass def get_allow_future(self): pass def get_end_date_field(self): ''' Returns the model field to use for end dates ''' pass def get_start_date(self, obj): ''' Returns the start date for a model instance ''' pass def get_end_date_field(self): ''' Returns the end date for a model instance ''' pass def get_first_of_week(self): ''' Returns an integer representing the first day of the week. 0 represents Monday, 6 represents Sunday. ''' pass def get_queryset(self): ''' Returns a queryset of models for the month requested ''' pass def get_context_data(self, **kwargs): ''' Injects variables necessary for rendering the calendar into the context. Variables added are: `calendar`, `weekdays`, `month`, `next_month` and `previous_month`. ''' pass
9
7
26
3
19
5
3
0.27
4
8
0
1
8
0
8
8
225
34
156
53
147
42
101
53
92
10
1
4
25
5,751
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/contrib/mixins.py
extra_views.contrib.mixins.SuccessMessageWithInlinesMixin
class SuccessMessageWithInlinesMixin(object): """ Adds a success message on successful form submission. """ success_message = "" def forms_valid(self, form, inlines): response = super(SuccessMessageWithInlinesMixin, self).forms_valid( form, inlines ) success_message = self.get_success_message(form.cleaned_data) if success_message: messages.success(self.request, success_message) return response def get_success_message(self, cleaned_data): return self.success_message % cleaned_data
class SuccessMessageWithInlinesMixin(object): ''' Adds a success message on successful form submission. ''' def forms_valid(self, form, inlines): pass def get_success_message(self, cleaned_data): pass
3
1
5
0
5
0
2
0.25
1
1
0
0
2
0
2
2
18
3
12
6
9
3
10
6
7
2
1
1
3
5,752
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/contrib/mixins.py
extra_views.contrib.mixins.SortableListMixin
class SortableListMixin(ContextMixin): """ You can provide either sort_fields as a plain list like ['id', 'some', 'foo__bar', ...] or, if you want to hide original field names you can provide list of tuples with alias that will be used: [('id', 'by_id'), ('some', 'show_this'), ('foo__bar', 'bar')] If sort_param_name exists in query but sort_type_param_name is omitted queryset will be sorted as 'asc' """ sort_fields = [] sort_fields_aliases = [] sort_param_name = "o" sort_type_param_name = "ot" def get_sort_fields(self): if self.sort_fields: return zip(self.sort_fields, self.sort_fields) return self.sort_fields_aliases def get_sort_helper(self): return SortHelper( self.request, self.get_sort_fields(), self.sort_param_name, self.sort_type_param_name, ) def _sort_queryset(self, queryset): self.sort_helper = self.get_sort_helper() sort = self.sort_helper.get_sort() if sort: queryset = queryset.order_by(sort) return queryset def get_queryset(self): qs = super(SortableListMixin, self).get_queryset() if self.sort_fields and self.sort_fields_aliases: raise ImproperlyConfigured( "You should provide sort_fields or sort_fields_aliaces but not both" ) return self._sort_queryset(qs) def get_context_data(self, **kwargs): context = {} if hasattr(self, "sort_helper"): context["sort_helper"] = self.sort_helper context.update(kwargs) return super(SortableListMixin, self).get_context_data(**context)
class SortableListMixin(ContextMixin): ''' You can provide either sort_fields as a plain list like ['id', 'some', 'foo__bar', ...] or, if you want to hide original field names you can provide list of tuples with alias that will be used: [('id', 'by_id'), ('some', 'show_this'), ('foo__bar', 'bar')] If sort_param_name exists in query but sort_type_param_name is omitted queryset will be sorted as 'asc' ''' def get_sort_fields(self): pass def get_sort_helper(self): pass def _sort_queryset(self, queryset): pass def get_queryset(self): pass def get_context_data(self, **kwargs): pass
6
1
6
0
6
0
2
0.26
1
3
1
1
5
1
5
5
51
7
35
14
29
9
28
14
22
2
1
1
9
5,753
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/contrib/mixins.py
extra_views.contrib.mixins.SortHelper
class SortHelper(object): def __init__( self, request, sort_fields_aliases, sort_param_name, sort_type_param_name ): # Create a list from sort_fields_aliases, in case it is a generator, # since we want to iterate through it multiple times. sort_fields_aliases = list(sort_fields_aliases) self.initial_params = request.GET.copy() self.sort_fields = dict(sort_fields_aliases) self.inv_sort_fields = dict((v, k) for k, v in sort_fields_aliases) self.initial_sort = self.inv_sort_fields.get( self.initial_params.get(sort_param_name), None ) self.initial_sort_type = self.initial_params.get(sort_type_param_name, "asc") self.sort_param_name = sort_param_name self.sort_type_param_name = sort_type_param_name for field, alias in self.sort_fields.items(): setattr( self, "get_sort_query_by_%s" % alias, functools.partial(self.get_params_for_field, field), ) setattr( self, "get_sort_query_by_%s_asc" % alias, functools.partial(self.get_params_for_field, field, "asc"), ) setattr( self, "get_sort_query_by_%s_desc" % alias, functools.partial(self.get_params_for_field, field, "desc"), ) setattr( self, "is_sorted_by_%s" % alias, functools.partial(self.is_sorted_by, field), ) def is_sorted_by(self, field_name): return field_name == self.initial_sort and self.initial_sort_type or False def get_params_for_field(self, field_name, sort_type=None): """ If sort_type is None - inverse current sort for field, if no sorted - use asc """ if not sort_type: if self.initial_sort == field_name: sort_type = "desc" if self.initial_sort_type == "asc" else "asc" else: sort_type = "asc" self.initial_params[self.sort_param_name] = self.sort_fields[field_name] self.initial_params[self.sort_type_param_name] = sort_type return "?%s" % self.initial_params.urlencode() def get_sort(self): if not self.initial_sort: return None sort = "%s" % self.initial_sort if self.initial_sort_type == "desc": sort = "-%s" % sort return sort
class SortHelper(object): def __init__( self, request, sort_fields_aliases, sort_param_name, sort_type_param_name ): pass def is_sorted_by(self, field_name): pass def get_params_for_field(self, field_name, sort_type=None): ''' If sort_type is None - inverse current sort for field, if no sorted - use asc ''' pass def get_sort(self): pass
5
1
15
1
13
1
3
0.09
1
3
0
0
4
7
4
4
63
5
53
16
46
5
32
14
27
4
1
2
10
5,754
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/advanced.py
extra_views.advanced.SuccessMessageMixin
class SuccessMessageMixin(object): """ Adds success message on views with inlines if django.contrib.messages framework is used. In order to use just add mixin in to inheritance before main class, e.g.: class MyCreateWithInlinesView (SuccessMessageMixin, CreateWithInlinesView): success_message='Something was created!' """ success_message = "" def forms_valid(self, form, inlines): response = super().forms_valid(form, inlines) success_message = self.get_success_message(form.cleaned_data, inlines) if success_message: messages.success(self.request, success_message) return response def get_success_message(self, cleaned_data, inlines): return self.success_message % cleaned_data
class SuccessMessageMixin(object): ''' Adds success message on views with inlines if django.contrib.messages framework is used. In order to use just add mixin in to inheritance before main class, e.g.: class MyCreateWithInlinesView (SuccessMessageMixin, CreateWithInlinesView): success_message='Something was created!' ''' def forms_valid(self, form, inlines): pass def get_success_message(self, cleaned_data, inlines): pass
3
1
4
0
4
0
2
0.7
1
1
0
1
2
0
2
2
20
3
10
6
7
7
10
6
7
2
1
1
3
5,755
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/advanced.py
extra_views.advanced.UpdateWithInlinesView
class UpdateWithInlinesView( SingleObjectTemplateResponseMixin, BaseUpdateWithInlinesView ): """ View for updating an object with related model instances, with a response rendered by template. """ template_name_suffix = "_form"
class UpdateWithInlinesView( SingleObjectTemplateResponseMixin, BaseUpdateWithInlinesView ): ''' View for updating an object with related model instances, with a response rendered by template. ''' pass
1
1
0
0
0
0
0
1
2
0
0
1
0
0
0
9
9
1
4
4
1
4
2
2
1
0
3
0
0
5,756
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/advanced.py
extra_views.advanced.ProcessFormWithInlinesView
class ProcessFormWithInlinesView(FormView): """ A mixin that renders a form and inline formsets on GET and processes it on POST. """ def get(self, request, *args, **kwargs): """ Handles GET requests and instantiates a blank version of the form and formsets. """ form_class = self.get_form_class() form = self.get_form(form_class) inlines = self.construct_inlines() return self.render_to_response( self.get_context_data(form=form, inlines=inlines, **kwargs) ) def post(self, request, *args, **kwargs): """ Handles POST requests, instantiating a form and formset instances with the passed POST variables and then checked for validity. """ form_class = self.get_form_class() form = self.get_form(form_class) initial_object = self.object if form.is_valid(): self.object = form.save(commit=False) form_validated = True else: form_validated = False inlines = self.construct_inlines() if all_valid(inlines) and form_validated: return self.forms_valid(form, inlines) self.object = initial_object return self.forms_invalid(form, inlines) # PUT is a valid HTTP verb for creating (with a known URL) or editing an # object, note that browsers only support POST for now. def put(self, *args, **kwargs): return self.post(*args, **kwargs)
class ProcessFormWithInlinesView(FormView): ''' A mixin that renders a form and inline formsets on GET and processes it on POST. ''' def get(self, request, *args, **kwargs): ''' Handles GET requests and instantiates a blank version of the form and formsets. ''' pass def post(self, request, *args, **kwargs): ''' Handles POST requests, instantiating a form and formset instances with the passed POST variables and then checked for validity. ''' pass def put(self, *args, **kwargs): pass
4
3
11
1
8
2
2
0.5
1
0
0
2
3
1
3
3
42
6
24
13
20
12
21
13
17
3
1
1
5
5,757
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/advanced.py
extra_views.advanced.NamedFormsetsMixin
class NamedFormsetsMixin(ContextMixin): """ A mixin for use with `CreateWithInlinesView` or `UpdateWithInlinesView` that lets you define the context variable for each inline. """ inlines_names = [] def get_inlines_names(self): """ Returns a list of names of context variables for each inline in `inlines`. """ return self.inlines_names[:] def get_context_data(self, **kwargs): """ If `inlines_names` has been defined, add each formset to the context under its corresponding entry in `inlines_names` """ context = {} inlines_names = self.get_inlines_names() if inlines_names: # We have formset or inlines in context, but never both context.update(zip(inlines_names, kwargs.get("inlines", []))) if "formset" in kwargs: context[inlines_names[0]] = kwargs["formset"] context.update(kwargs) return super().get_context_data(**context)
class NamedFormsetsMixin(ContextMixin): ''' A mixin for use with `CreateWithInlinesView` or `UpdateWithInlinesView` that lets you define the context variable for each inline. ''' def get_inlines_names(self): ''' Returns a list of names of context variables for each inline in `inlines`. ''' pass def get_context_data(self, **kwargs): ''' If `inlines_names` has been defined, add each formset to the context under its corresponding entry in `inlines_names` ''' pass
3
3
10
1
6
4
2
0.92
1
2
0
2
2
0
2
2
29
4
13
6
10
12
13
6
10
3
1
2
4
5,758
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/advanced.py
extra_views.advanced.ModelFormWithInlinesMixin
class ModelFormWithInlinesMixin(ModelFormMixin): """ A mixin that provides a way to show and handle a modelform and inline formsets in a request. The inlines should be subclasses of `InlineFormSetFactory`. """ inlines = [] def get_inlines(self): """ Returns the inline formset classes """ return self.inlines[:] def forms_valid(self, form, inlines): """ If the form and formsets are valid, save the associated models. """ response = self.form_valid(form) for formset in inlines: formset.save() return response def forms_invalid(self, form, inlines): """ If the form or formsets are invalid, re-render the context data with the data-filled form and formsets and errors. """ return self.render_to_response( self.get_context_data(form=form, inlines=inlines) ) def construct_inlines(self): """ Returns the inline formset instances """ inline_formsets = [] for inline_class in self.get_inlines(): inline_instance = inline_class( self.model, self.request, self.object, self.kwargs, self ) inline_formset = inline_instance.construct_formset() inline_formsets.append(inline_formset) return inline_formsets
class ModelFormWithInlinesMixin(ModelFormMixin): ''' A mixin that provides a way to show and handle a modelform and inline formsets in a request. The inlines should be subclasses of `InlineFormSetFactory`. ''' def get_inlines(self): ''' Returns the inline formset classes ''' pass def forms_valid(self, form, inlines): ''' If the form and formsets are valid, save the associated models. ''' pass def forms_invalid(self, form, inlines): ''' If the form or formsets are invalid, re-render the context data with the data-filled form and formsets and errors. ''' pass def construct_inlines(self): ''' Returns the inline formset instances ''' pass
5
5
8
0
5
3
2
0.82
1
0
0
2
4
0
4
4
46
6
22
12
17
18
18
12
13
2
1
1
6
5,759
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/forms.py
extra_views_tests.forms.OrderForm
class OrderForm(forms.ModelForm): class Meta: model = Order fields = ["name"] def save(self, commit=True): instance = super().save(commit=commit) if commit: instance.action_on_save = True instance.save() return instance
class OrderForm(forms.ModelForm): class Meta: def save(self, commit=True): pass
3
0
8
2
6
0
2
0
1
1
0
0
1
0
1
1
13
3
10
6
7
0
10
6
7
2
1
1
2
5,760
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/formsets.py
extra_views_tests.formsets.AddressFormSet
class AddressFormSet(BaseFormSet): def add_fields(self, form, index): super().add_fields(form, index) form.fields["county"] = forms.ChoiceField(choices=COUNTRY_CHOICES, initial="gb")
class AddressFormSet(BaseFormSet): def add_fields(self, form, index): pass
2
0
3
0
3
0
1
0
1
1
0
0
1
0
1
1
4
0
4
2
2
0
4
2
2
1
1
0
1
5,761
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/contrib/mixins.py
extra_views.contrib.mixins.SearchableListMixin
class SearchableListMixin(object): """ Filter queryset like a django admin search_fields does, but with little more intelligence: if self.search_split is set to True (by default) it will split query to words (by whitespace) Also tries to convert each word to date with self.search_date_formats and then search each word in separate field e.g. with query 'foo bar' you can find object with obj.field1__icontains='foo' and obj.field2__icontains=='bar' To provide custom lookup just set one of the search_fields to tuple, e.g. search_fields = [('field1', 'iexact'), 'field2', ('field3', 'startswith')] This class is designed to be used with django.generic.ListView You could specify query by overriding get_search_query method by default this method will try to get 'q' key from request.GET (this can be disabled with search_use_q=False) """ search_fields = ["id"] search_date_fields = None search_date_formats = ["%d.%m.%y", "%d.%m.%Y"] search_split = True search_use_q = True check_lookups = True def get_words(self, query): if self.search_split: return query.split() return [query] def get_search_fields_with_filters(self): fields = [] for sf in self.search_fields: if isinstance(sf, str): fields.append((sf, "icontains")) else: if self.check_lookups and sf[1] not in VALID_STRING_LOOKUPS: raise ValueError("Invalid string lookup - %s" % sf[1]) fields.append(sf) return fields def try_convert_to_date(self, word): """ Tries to convert word to date(datetime) using search_date_formats Return None if word fits no one format """ for frm in self.search_date_formats: try: return datetime.datetime.strptime(word, frm).date() except ValueError: pass return None def get_search_query(self): """ Get query from request.GET 'q' parameter when search_use_q is set to True Override this method to provide your own query to search """ return self.search_use_q and self.request.GET.get("q", "").strip() def get_queryset(self): qs = super(SearchableListMixin, self).get_queryset() query = self.get_search_query() if query: w_qs = [] search_pairs = self.get_search_fields_with_filters() for word in self.get_words(query): filters = [ Q(**{"%s__%s" % (pair[0], pair[1]): word}) for pair in search_pairs ] if self.search_date_fields: dt = self.try_convert_to_date(word) if dt: filters.extend( [ Q(**{field_name: dt}) for field_name in self.search_date_fields ] ) w_qs.append(functools.reduce(operator.or_, filters)) qs = qs.filter(functools.reduce(operator.and_, w_qs)) qs = qs.distinct() return qs
class SearchableListMixin(object): ''' Filter queryset like a django admin search_fields does, but with little more intelligence: if self.search_split is set to True (by default) it will split query to words (by whitespace) Also tries to convert each word to date with self.search_date_formats and then search each word in separate field e.g. with query 'foo bar' you can find object with obj.field1__icontains='foo' and obj.field2__icontains=='bar' To provide custom lookup just set one of the search_fields to tuple, e.g. search_fields = [('field1', 'iexact'), 'field2', ('field3', 'startswith')] This class is designed to be used with django.generic.ListView You could specify query by overriding get_search_query method by default this method will try to get 'q' key from request.GET (this can be disabled with search_use_q=False) ''' def get_words(self, query): pass def get_search_fields_with_filters(self): pass def try_convert_to_date(self, word): ''' Tries to convert word to date(datetime) using search_date_formats Return None if word fits no one format ''' pass def get_search_query(self): ''' Get query from request.GET 'q' parameter when search_use_q is set to True Override this method to provide your own query to search ''' pass def get_queryset(self): pass
6
3
11
0
9
2
3
0.45
1
4
0
1
5
0
5
5
86
9
53
22
47
24
45
22
39
5
1
4
15
5,762
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/formsets.py
extra_views.formsets.BaseFormSetFactory
class BaseFormSetFactory(object): """ Base class for constructing a FormSet from `formset_factory` in a view. Calling `construct_formset` calls all other methods. """ initial = [] form_class = None formset_class = None prefix = None formset_kwargs = {} factory_kwargs = {} form_kwargs = {} def construct_formset(self): """ Returns an instance of the formset """ formset_class = self.get_formset() return formset_class(**self.get_formset_kwargs()) def get_initial(self): """ Returns a copy of the initial data to use for formsets on this view. """ return self.initial[:] def get_prefix(self): """ Returns the prefix used for formsets on this view. """ return self.prefix def get_formset_class(self): """ Returns the formset class to use in the formset factory """ return self.formset_class def get_form_class(self): """ Returns the form class to use with the formset in this view """ return self.form_class def get_form_kwargs(self): """ Returns the kwargs to be passed to each form via formset_kwargs["form_kwargs"]. """ return self.form_kwargs.copy() def get_formset(self): """ Returns the formset class from the formset factory """ return formset_factory(self.get_form_class(), **self.get_factory_kwargs()) def get_formset_kwargs(self): """ Returns the keyword arguments for instantiating the formset. """ kwargs = self.formset_kwargs.copy() kwargs.update({"initial": self.get_initial(), "prefix": self.get_prefix()}) kwargs.setdefault("form_kwargs", {}).update(self.get_form_kwargs()) if self.request.method in ("POST", "PUT"): kwargs.update( {"data": self.request.POST.copy(), "files": self.request.FILES} ) return kwargs def get_factory_kwargs(self): """ Returns the keyword arguments for calling the formset factory """ kwargs = self.factory_kwargs.copy() if self.get_formset_class(): kwargs["formset"] = self.get_formset_class() return kwargs
class BaseFormSetFactory(object): ''' Base class for constructing a FormSet from `formset_factory` in a view. Calling `construct_formset` calls all other methods. ''' def construct_formset(self): ''' Returns an instance of the formset ''' pass def get_initial(self): ''' Returns a copy of the initial data to use for formsets on this view. ''' pass def get_prefix(self): ''' Returns the prefix used for formsets on this view. ''' pass def get_formset_class(self): ''' Returns the formset class to use in the formset factory ''' pass def get_form_class(self): ''' Returns the form class to use with the formset in this view ''' pass def get_form_kwargs(self): ''' Returns the kwargs to be passed to each form via formset_kwargs["form_kwargs"]. ''' pass def get_formset_class(self): ''' Returns the formset class from the formset factory ''' pass def get_formset_kwargs(self): ''' Returns the keyword arguments for instantiating the formset. ''' pass def get_factory_kwargs(self): ''' Returns the keyword arguments for calling the formset factory ''' pass
10
10
6
0
3
3
1
0.84
1
0
0
2
9
0
9
9
80
12
37
20
27
31
35
20
25
2
1
1
11
5,763
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/generic.py
extra_views.generic.GenericInlineFormSetView
class GenericInlineFormSetView(BaseGenericInlineFormSetView, InlineFormSetView): """ A view for displaying a generic inline formset for a queryset belonging to a parent model """
class GenericInlineFormSetView(BaseGenericInlineFormSetView, InlineFormSetView): ''' A view for displaying a generic inline formset for a queryset belonging to a parent model ''' pass
1
1
0
0
0
0
0
4
2
0
0
1
0
0
0
23
5
0
1
1
0
4
1
1
0
0
6
0
0
5,764
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/forms.py
extra_views_tests.forms.AddressForm
class AddressForm(forms.Form): name = forms.CharField(max_length=255, required=True) line1 = forms.CharField(max_length=255, required=False) line2 = forms.CharField(max_length=255, required=False) city = forms.CharField(max_length=255, required=False) postcode = forms.CharField(max_length=10, required=True) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)
class AddressForm(forms.Form): def __init__(self, *args, **kwargs): pass
2
0
2
0
2
0
1
0
1
1
0
0
1
0
1
1
9
1
8
7
6
0
8
7
6
1
1
0
1
5,765
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/formsets.py
extra_views.formsets.InlineFormSetMixin
class InlineFormSetMixin(BaseInlineFormSetFactory, SingleObjectMixin, FormSetMixin): """ A view mixin that provides a way to show and handle a single inline formset in a request. """ def formset_valid(self, formset): self.object_list = formset.save() return super().formset_valid(formset)
class InlineFormSetMixin(BaseInlineFormSetFactory, SingleObjectMixin, FormSetMixin): ''' A view mixin that provides a way to show and handle a single inline formset in a request. ''' def formset_valid(self, formset): pass
2
1
3
0
3
0
1
1
3
1
0
2
1
1
1
17
9
1
4
3
2
4
4
3
2
1
3
0
1
5,766
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/formsets.py
extra_views.formsets.FormSetView
class FormSetView(TemplateResponseMixin, BaseFormSetView): """ A view for displaying a formset, and rendering a template response """
class FormSetView(TemplateResponseMixin, BaseFormSetView): ''' A view for displaying a formset, and rendering a template response ''' pass
1
1
0
0
0
0
0
3
2
0
0
3
0
0
0
15
4
0
1
1
0
3
1
1
0
0
4
0
0
5,767
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/formsets.py
extra_views.formsets.FormSetMixin
class FormSetMixin(BaseFormSetFactory, ContextMixin): """ A view mixin that provides a way to show and handle a single formset in a request. """ success_url = None def get_success_url(self): """ Returns the supplied URL. """ if self.success_url: url = self.success_url else: # Default to returning to the same page url = self.request.get_full_path() return url def formset_valid(self, formset): """ If the formset is valid redirect to the supplied URL """ return HttpResponseRedirect(self.get_success_url()) def formset_invalid(self, formset): """ If the formset is invalid, re-render the context data with the data-filled formset and errors. """ return self.render_to_response(self.get_context_data(formset=formset))
class FormSetMixin(BaseFormSetFactory, ContextMixin): ''' A view mixin that provides a way to show and handle a single formset in a request. ''' def get_success_url(self): ''' Returns the supplied URL. ''' pass def formset_valid(self, formset): ''' If the formset is valid redirect to the supplied URL ''' pass def formset_invalid(self, formset): ''' If the formset is invalid, re-render the context data with the data-filled formset and errors. ''' pass
4
4
7
0
3
4
1
1.17
2
0
0
3
3
0
3
12
30
4
12
6
8
14
11
6
7
2
2
1
4
5,768
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/formsets.py
extra_views.formsets.BaseModelFormSetView
class BaseModelFormSetView(ModelFormSetMixin, ProcessFormSetView): """ A base view for displaying a model formset """ def get(self, request, *args, **kwargs): self.object_list = self.get_queryset() return super().get(request, *args, **kwargs) def post(self, request, *args, **kwargs): self.object_list = self.get_queryset() return super().post(request, *args, **kwargs)
class BaseModelFormSetView(ModelFormSetMixin, ProcessFormSetView): ''' A base view for displaying a model formset ''' def get(self, request, *args, **kwargs): pass def post(self, request, *args, **kwargs): pass
3
1
3
0
3
0
1
0.43
2
1
0
1
2
1
2
21
12
2
7
4
4
3
7
4
4
1
4
0
2
5,769
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/formsets.py
extra_views.formsets.BaseInlineFormSetView
class BaseInlineFormSetView(InlineFormSetMixin, ProcessFormSetView): """ A base view for displaying an inline formset for a queryset belonging to a parent model """ def get(self, request, *args, **kwargs): self.object = self.get_object() return super().get(request, *args, **kwargs) def post(self, request, *args, **kwargs): self.object = self.get_object() return super().post(request, *args, **kwargs)
class BaseInlineFormSetView(InlineFormSetMixin, ProcessFormSetView): ''' A base view for displaying an inline formset for a queryset belonging to a parent model ''' def get(self, request, *args, **kwargs): pass def post(self, request, *args, **kwargs): pass
3
1
3
0
3
0
1
0.57
2
1
0
2
2
1
2
22
13
2
7
4
4
4
7
4
4
1
4
0
2
5,770
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/formsets.py
extra_views.formsets.BaseInlineFormSetFactory
class BaseInlineFormSetFactory(BaseFormSetFactory): """ Base class for constructing a FormSet from `inlineformset_factory` in a view. Calling `construct_formset` calls all other methods. """ model = None inline_model = None exclude = None fields = None def get_inline_model(self): """ Returns the inline model to use with the inline formset """ return self.inline_model def get_formset_kwargs(self): """ Returns the keyword arguments for instantiating the formset. """ kwargs = super().get_formset_kwargs() kwargs["instance"] = self.object return kwargs def get_factory_kwargs(self): """ Returns the keyword arguments for calling the formset factory """ kwargs = super().get_factory_kwargs() kwargs.setdefault("fields", self.fields) kwargs.setdefault("exclude", self.exclude) if self.get_form_class(): kwargs["form"] = self.get_form_class() return kwargs def get_formset(self): """ Returns the formset class from the inline formset factory """ return inlineformset_factory( self.model, self.get_inline_model(), **self.get_factory_kwargs() )
class BaseInlineFormSetFactory(BaseFormSetFactory): ''' Base class for constructing a FormSet from `inlineformset_factory` in a view. Calling `construct_formset` calls all other methods. ''' def get_inline_model(self): ''' Returns the inline model to use with the inline formset ''' pass def get_formset_kwargs(self): ''' Returns the keyword arguments for instantiating the formset. ''' pass def get_factory_kwargs(self): ''' Returns the keyword arguments for calling the formset factory ''' pass def get_formset_kwargs(self): ''' Returns the formset class from the inline formset factory ''' pass
5
5
8
0
4
3
1
0.73
1
1
0
3
4
0
4
13
45
7
22
11
17
16
20
11
15
2
2
1
5
5,771
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/formsets.py
extra_views.formsets.BaseFormSetView
class BaseFormSetView(FormSetMixin, ProcessFormSetView): """ A base view for displaying a formset """
class BaseFormSetView(FormSetMixin, ProcessFormSetView): ''' A base view for displaying a formset ''' pass
1
1
0
0
0
0
0
3
2
0
0
1
0
0
0
15
4
0
1
1
0
3
1
1
0
0
3
0
0
5,772
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/formsets.py
extra_views.formsets.InlineFormSetView
class InlineFormSetView(SingleObjectTemplateResponseMixin, BaseInlineFormSetView): """ A view for displaying an inline formset for a queryset belonging to a parent model """
class InlineFormSetView(SingleObjectTemplateResponseMixin, BaseInlineFormSetView): ''' A view for displaying an inline formset for a queryset belonging to a parent model ''' pass
1
1
0
0
0
0
0
3
2
0
0
2
0
0
0
22
4
0
1
1
0
3
1
1
0
0
5
0
0
5,773
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/formsets.py
extra_views.formsets.ModelFormSetView
class ModelFormSetView(MultipleObjectTemplateResponseMixin, BaseModelFormSetView): """ A view for displaying a model formset, and rendering a template response """
class ModelFormSetView(MultipleObjectTemplateResponseMixin, BaseModelFormSetView): ''' A view for displaying a model formset, and rendering a template response ''' pass
1
1
0
0
0
0
0
3
2
0
0
4
0
0
0
21
4
0
1
1
0
3
1
1
0
0
5
0
0
5,774
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/formsets.py
extra_views.formsets.ProcessFormSetView
class ProcessFormSetView(View): """ A mixin that processes a formset on POST. """ def get(self, request, *args, **kwargs): """ Handles GET requests and instantiates a blank version of the formset. """ formset = self.construct_formset() return self.render_to_response(self.get_context_data(formset=formset)) def post(self, request, *args, **kwargs): """ Handles POST requests, instantiating a formset instance with the passed POST variables and then checked for validity. """ formset = self.construct_formset() if formset.is_valid(): return self.formset_valid(formset) else: return self.formset_invalid(formset) # PUT is a valid HTTP verb for creating (with a known URL) or editing an # object, note that browsers only support POST for now. def put(self, *args, **kwargs): return self.post(*args, **kwargs)
class ProcessFormSetView(View): ''' A mixin that processes a formset on POST. ''' def get(self, request, *args, **kwargs): ''' Handles GET requests and instantiates a blank version of the formset. ''' pass def post(self, request, *args, **kwargs): ''' Handles POST requests, instantiating a formset instance with the passed POST variables and then checked for validity. ''' pass def put(self, *args, **kwargs): pass
4
3
6
0
4
2
1
1
1
0
0
3
3
0
3
3
27
3
12
6
8
12
11
6
7
2
1
1
4
5,775
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/generic.py
extra_views.generic.BaseGenericInlineFormSetFactory
class BaseGenericInlineFormSetFactory(BaseInlineFormSetFactory): """ Base class for constructing a GenericInlineFormSet from `generic_inlineformset_factory` in a view. """ def get_formset(self): """ Returns the final formset class from generic_inlineformset_factory. """ result = generic_inlineformset_factory( self.inline_model, **self.get_factory_kwargs() ) return result
class BaseGenericInlineFormSetFactory(BaseInlineFormSetFactory): ''' Base class for constructing a GenericInlineFormSet from `generic_inlineformset_factory` in a view. ''' def get_formset(self): ''' Returns the final formset class from generic_inlineformset_factory. ''' pass
2
2
8
0
5
3
1
1.17
1
0
0
2
1
0
1
14
14
1
6
3
4
7
4
3
2
1
3
0
1
5,776
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/generic.py
extra_views.generic.BaseGenericInlineFormSetView
class BaseGenericInlineFormSetView(GenericInlineFormSetMixin, BaseInlineFormSetView): """ A base view for displaying a generic inline formset """
class BaseGenericInlineFormSetView(GenericInlineFormSetMixin, BaseInlineFormSetView): ''' A base view for displaying a generic inline formset ''' pass
1
1
0
0
0
0
0
3
2
0
0
1
0
0
0
23
4
0
1
1
0
3
1
1
0
0
5
0
0
5,777
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/generic.py
extra_views.generic.GenericInlineFormSetFactory
class GenericInlineFormSetFactory(BaseGenericInlineFormSetFactory): """ Class used to create a `GenericInlineFormSet` from `generic_inlineformset_factory` as one of multiple `GenericInlineFormSet`s within a single view. Subclasses `BaseGenericInlineFormSetFactory` and passes in the necessary view arguments. """ def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): self.inline_model = self.model self.model = parent_model self.request = request self.object = instance self.kwargs = view_kwargs self.view = view
class GenericInlineFormSetFactory(BaseGenericInlineFormSetFactory): ''' Class used to create a `GenericInlineFormSet` from `generic_inlineformset_factory` as one of multiple `GenericInlineFormSet`s within a single view. Subclasses `BaseGenericInlineFormSetFactory` and passes in the necessary view arguments. ''' def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): pass
2
1
7
0
7
0
1
0.75
1
0
0
1
1
6
1
15
16
2
8
8
6
6
8
8
6
1
4
0
1
5,778
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/generic.py
extra_views.generic.GenericInlineFormSetMixin
class GenericInlineFormSetMixin(BaseGenericInlineFormSetFactory, InlineFormSetMixin): """ A mixin that provides a way to show and handle a generic inline formset in a request. """
class GenericInlineFormSetMixin(BaseGenericInlineFormSetFactory, InlineFormSetMixin): ''' A mixin that provides a way to show and handle a generic inline formset in a request. ''' pass
1
1
0
0
0
0
0
4
2
0
0
1
0
0
0
18
5
0
1
1
0
4
1
1
0
0
4
0
0
5,779
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/formsets.py
extra_views.formsets.ModelFormSetMixin
class ModelFormSetMixin(FormSetMixin, MultipleObjectMixin): """ A view mixin that provides a way to show and handle a single model formset in a request. Uses `modelformset_factory`. """ exclude = None fields = None def get_formset_kwargs(self): """ Returns the keyword arguments for instantiating the formset. """ kwargs = super().get_formset_kwargs() kwargs["queryset"] = self.get_queryset() return kwargs def get_factory_kwargs(self): """ Returns the keyword arguments for calling the formset factory """ kwargs = super().get_factory_kwargs() kwargs.setdefault("fields", self.fields) kwargs.setdefault("exclude", self.exclude) if self.get_form_class(): kwargs["form"] = self.get_form_class() return kwargs def get_formset(self): """ Returns the formset class from the model formset factory """ return modelformset_factory(self.model, **self.get_factory_kwargs()) def formset_valid(self, formset): """ If the formset is valid, save the associated models. """ self.object_list = formset.save() return super().formset_valid(formset)
class ModelFormSetMixin(FormSetMixin, MultipleObjectMixin): ''' A view mixin that provides a way to show and handle a single model formset in a request. Uses `modelformset_factory`. ''' def get_formset_kwargs(self): ''' Returns the keyword arguments for instantiating the formset. ''' pass def get_factory_kwargs(self): ''' Returns the keyword arguments for calling the formset factory ''' pass def get_formset_kwargs(self): ''' Returns the formset class from the model formset factory ''' pass def formset_valid(self, formset): ''' If the formset is valid, save the associated models. ''' pass
5
5
7
0
4
3
1
0.89
2
1
0
1
4
1
4
16
43
7
19
10
14
17
19
10
14
2
3
1
5
5,780
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/advanced.py
extra_views.advanced.InlineFormSetFactory
class InlineFormSetFactory(BaseInlineFormSetFactory): """ Class used to create an `InlineFormSet` from `inlineformset_factory` as one of multiple `InlineFormSet`s within a single view. Subclasses `BaseInlineFormSetFactory` and passes in the necessary view arguments. """ def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): self.inline_model = self.model self.model = parent_model self.request = request self.object = instance self.kwargs = view_kwargs self.view = view def construct_formset(self): """ Overrides construct_formset to attach the model class as an attribute of the returned formset instance. """ formset = super().construct_formset() formset.model = self.inline_model return formset
class InlineFormSetFactory(BaseInlineFormSetFactory): ''' Class used to create an `InlineFormSet` from `inlineformset_factory` as one of multiple `InlineFormSet`s within a single view. Subclasses `BaseInlineFormSetFactory` and passes in the necessary view arguments. ''' def __init__(self, parent_model, request, instance, view_kwargs=None, view=None): pass def construct_formset(self): ''' Overrides construct_formset to attach the model class as an attribute of the returned formset instance. ''' pass
3
2
8
0
6
2
1
0.75
1
1
0
1
2
6
2
15
24
3
12
10
9
9
12
10
9
1
3
0
2
5,781
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/advanced.py
extra_views.advanced.BaseUpdateWithInlinesView
class BaseUpdateWithInlinesView(ModelFormWithInlinesMixin, ProcessFormWithInlinesView): """ Base view for updating an existing object with related model instances. Using this base class requires subclassing to provide a response mixin. """ def get(self, request, *args, **kwargs): self.object = self.get_object() return super().get(request, *args, **kwargs) def post(self, request, *args, **kwargs): self.object = self.get_object() return super().post(request, *args, **kwargs)
class BaseUpdateWithInlinesView(ModelFormWithInlinesMixin, ProcessFormWithInlinesView): ''' Base view for updating an existing object with related model instances. Using this base class requires subclassing to provide a response mixin. ''' def get(self, request, *args, **kwargs): pass def post(self, request, *args, **kwargs): pass
3
1
3
0
3
0
1
0.57
2
1
0
1
2
1
2
9
14
3
7
4
4
4
7
4
4
1
2
0
2
5,782
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views/advanced.py
extra_views.advanced.CreateWithInlinesView
class CreateWithInlinesView( SingleObjectTemplateResponseMixin, BaseCreateWithInlinesView ): """ View for creating a new object instance with related model instances, with a response rendered by template. """ template_name_suffix = "_form"
class CreateWithInlinesView( SingleObjectTemplateResponseMixin, BaseCreateWithInlinesView ): ''' View for creating a new object instance with related model instances, with a response rendered by template. ''' pass
1
1
0
0
0
0
0
1
2
0
0
1
0
0
0
9
9
1
4
4
1
4
2
2
1
0
3
0
0
5,783
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.EventCalendarView
class EventCalendarView(CalendarMonthView): template_name = "extra_views/event_calendar_month.html" model = Event month_format = "%b" date_field = "date"
class EventCalendarView(CalendarMonthView): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
8
5
0
5
5
4
0
5
5
4
0
3
0
0
5,784
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.FormAndFormSetOverrideView
class FormAndFormSetOverrideView(ModelFormSetView): model = Item form_class = ItemForm formset_class = BaseArticleFormSet template_name = "extra_views/item_formset.html"
class FormAndFormSetOverrideView(ModelFormSetView): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
21
5
0
5
5
4
0
5
5
4
0
6
0
0
5,785
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.ItemModelFormSetExcludeView
class ItemModelFormSetExcludeView(ModelFormSetView): model = Item exclude = ["sku", "price"] template_name = "extra_views/item_formset.html"
class ItemModelFormSetExcludeView(ModelFormSetView): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
21
4
0
4
4
3
0
4
4
3
0
6
0
0
5,786
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.ItemModelFormSetView
class ItemModelFormSetView(ModelFormSetView): model = Item fields = ["name", "sku", "price", "order", "status"] template_name = "extra_views/item_formset.html"
class ItemModelFormSetView(ModelFormSetView): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
21
4
0
4
4
3
0
4
4
3
0
6
0
0
5,787
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.ItemsInline
class ItemsInline(InlineFormSetFactory): model = Item fields = ["name", "sku", "price", "order", "status"]
class ItemsInline(InlineFormSetFactory): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
15
3
0
3
3
2
0
3
3
2
0
4
0
0
5,788
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.OrderCreateNamedView
class OrderCreateNamedView(NamedFormsetsMixin, OrderCreateView): inlines_names = ["Items", "Tags"]
class OrderCreateNamedView(NamedFormsetsMixin, OrderCreateView): pass
1
0
0
0
0
0
0
0
2
0
0
0
0
0
0
14
2
0
2
2
1
0
2
2
1
0
5
0
0
5,789
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.AddressFormSetViewNamed
class AddressFormSetViewNamed(NamedFormsetsMixin, AddressFormSetView): inlines_names = ["AddressFormset"]
class AddressFormSetViewNamed(NamedFormsetsMixin, AddressFormSetView): pass
1
0
0
0
0
0
0
0
2
0
0
0
0
0
0
19
2
0
2
2
1
0
2
2
1
0
6
0
0
5,790
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.OrderCreateView
class OrderCreateView(SuccessMessageMixin, CreateWithInlinesView): model = Order fields = ["name"] context_object_name = "order" inlines = [ItemsInline, TagsInline] template_name = "extra_views/order_and_items.html" success_message = "Order %(name)s was created successfully!" def form_valid(self, form): response = super().form_valid(form) # Update the response url to indicate that form_valid was called response["Location"] += "?form_valid_called=1" return response
class OrderCreateView(SuccessMessageMixin, CreateWithInlinesView): def form_valid(self, form): pass
2
0
5
0
4
1
1
0.09
2
1
0
1
1
0
1
12
13
1
11
9
9
1
11
9
9
1
4
0
1
5,791
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.OrderTagsView
class OrderTagsView(GenericInlineFormSetView): model = Order inline_model = Tag template_name = "extra_views/inline_formset.html" initial = [{"name": "test_tag_name"}]
class OrderTagsView(GenericInlineFormSetView): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
23
5
0
5
5
4
0
5
5
4
0
7
0
0
5,792
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.OrderUpdateView
class OrderUpdateView(UpdateWithInlinesView): model = Order form_class = OrderForm inlines = [ItemsInline, TagsInline] template_name = "extra_views/order_and_items.html"
class OrderUpdateView(UpdateWithInlinesView): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
9
5
0
5
5
4
0
5
5
4
0
4
0
0
5,793
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.PagedModelFormSetView
class PagedModelFormSetView(ModelFormSetView): paginate_by = 2 model = Item template_name = "extra_views/paged_formset.html"
class PagedModelFormSetView(ModelFormSetView): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
21
4
0
4
4
3
0
4
4
3
0
6
0
0
5,794
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.SearchableItemListView
class SearchableItemListView(SearchableListMixin, generic.ListView): template_name = "extra_views/item_list.html" search_fields = ["name", "sku"] search_date_fields = ["date_placed"] model = Item define_query = False exact_query = False wrong_lookup = False def get_search_query(self): if self.define_query: return "test B" else: return super().get_search_query() def get(self, request, *args, **kwargs): if self.exact_query: self.search_fields = [("name", "iexact"), "sku"] elif self.wrong_lookup: self.search_fields = [("name", "gte"), "sku"] return super().get(request, *args, **kwargs)
class SearchableItemListView(SearchableListMixin, generic.ListView): def get_search_query(self): pass def get_search_query(self): pass
3
0
6
0
6
0
3
0
2
1
0
0
2
0
2
7
21
2
19
10
16
0
17
10
14
3
2
1
5
5,795
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.SortableItemListView
class SortableItemListView(SortableListMixin, generic.ListView): template_name = "extra_views/sortable_item_list.html" sort_fields = ["name", "sku"] model = Item def get(self, request, *args, **kwargs): if kwargs["flag"] == "fields_and_aliases": self.sort_fields_aliases = [("name", "by_name"), ("sku", "by_sku")] elif kwargs["flag"] == "aliases": self.sort_fields_aliases = [("name", "by_name"), ("sku", "by_sku")] self.sort_fields = [] return super().get(request, *args, **kwargs)
class SortableItemListView(SortableListMixin, generic.ListView): def get(self, request, *args, **kwargs): pass
2
0
7
0
7
0
3
0
2
1
0
0
1
1
1
6
12
1
11
6
9
0
10
6
8
3
2
1
3
5,796
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.TagsInline
class TagsInline(GenericInlineFormSetFactory): model = Tag fields = ["name"]
class TagsInline(GenericInlineFormSetFactory): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
15
3
0
3
3
2
0
3
3
2
0
5
0
0
5,797
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.OrderItemFormSetView
class OrderItemFormSetView(InlineFormSetView): model = Order fields = ["name", "sku", "price", "order", "status"] inline_model = Item template_name = "extra_views/inline_formset.html"
class OrderItemFormSetView(InlineFormSetView): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
22
5
0
5
5
4
0
5
5
4
0
6
0
0
5,798
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.AddressFormSetViewKwargs
class AddressFormSetViewKwargs(FormSetView): # Used for testing class level kwargs form_class = AddressForm template_name = "extra_views/address_formset.html" formset_kwargs = {"auto_id": "id_test_%s", "form_kwargs": {"empty_permitted": True}} factory_kwargs = {"max_num": 27} prefix = "test_prefix" initial = [{"name": "address1"}]
class AddressFormSetViewKwargs(FormSetView): pass
1
0
0
0
0
0
0
0.14
1
0
0
0
0
0
0
15
8
0
7
7
6
1
7
7
6
0
5
0
0
5,799
AndrewIngram/django-extra-views
AndrewIngram_django-extra-views/extra_views_tests/views.py
extra_views_tests.views.AddressFormSetViewFormKwargs
class AddressFormSetViewFormKwargs(FormSetView): form_class = AddressForm template_name = "extra_views/address_formset.html" formset_kwargs = {"form_kwargs": {"empty_permitted": True}} factory_kwargs = {"max_num": 27} form_kwargs = {"label_suffix": ":"}
class AddressFormSetViewFormKwargs(FormSetView): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
15
6
0
6
6
5
0
6
6
5
0
5
0
0