Python django.conf.settings.STATICFILES_DIRS Examples

The following are 30 code examples for showing how to use django.conf.settings.STATICFILES_DIRS(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.conf.settings , or try the search function .

Example 1
Project: GTDWeb   Author: lanbing510   File: finders.py    License: GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, app_names=None, *args, **kwargs):
        # List of locations with static files
        self.locations = []
        # Maps dir paths to an appropriate storage instance
        self.storages = OrderedDict()
        if not isinstance(settings.STATICFILES_DIRS, (list, tuple)):
            raise ImproperlyConfigured(
                "Your STATICFILES_DIRS setting is not a tuple or list; "
                "perhaps you forgot a trailing comma?")
        for root in settings.STATICFILES_DIRS:
            if isinstance(root, (list, tuple)):
                prefix, root = root
            else:
                prefix = ''
            if settings.STATIC_ROOT and os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
                raise ImproperlyConfigured(
                    "The STATICFILES_DIRS setting should "
                    "not contain the STATIC_ROOT setting")
            if (prefix, root) not in self.locations:
                self.locations.append((prefix, root))
        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage
        super(FileSystemFinder, self).__init__(*args, **kwargs) 
Example 2
Project: bioforum   Author: reBiocoder   File: finders.py    License: MIT License 6 votes vote down vote up
def __init__(self, app_names=None, *args, **kwargs):
        # List of locations with static files
        self.locations = []
        # Maps dir paths to an appropriate storage instance
        self.storages = OrderedDict()
        for root in settings.STATICFILES_DIRS:
            if isinstance(root, (list, tuple)):
                prefix, root = root
            else:
                prefix = ''
            if (prefix, root) not in self.locations:
                self.locations.append((prefix, root))
        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage
        super().__init__(*args, **kwargs) 
Example 3
Project: bioforum   Author: reBiocoder   File: finders.py    License: MIT License 6 votes vote down vote up
def check(self, **kwargs):
        errors = []
        if not isinstance(settings.STATICFILES_DIRS, (list, tuple)):
            errors.append(Error(
                'The STATICFILES_DIRS setting is not a tuple or list.',
                hint='Perhaps you forgot a trailing comma?',
                id='staticfiles.E001',
            ))
        for root in settings.STATICFILES_DIRS:
            if isinstance(root, (list, tuple)):
                _, root = root
            if settings.STATIC_ROOT and os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
                errors.append(Error(
                    'The STATICFILES_DIRS setting should not contain the '
                    'STATIC_ROOT setting.',
                    id='staticfiles.E002',
                ))
        return errors 
Example 4
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: finders.py    License: MIT License 6 votes vote down vote up
def __init__(self, app_names=None, *args, **kwargs):
        # List of locations with static files
        self.locations = []
        # Maps dir paths to an appropriate storage instance
        self.storages = OrderedDict()
        for root in settings.STATICFILES_DIRS:
            if isinstance(root, (list, tuple)):
                prefix, root = root
            else:
                prefix = ''
            if (prefix, root) not in self.locations:
                self.locations.append((prefix, root))
        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage
        super().__init__(*args, **kwargs) 
Example 5
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: finders.py    License: MIT License 6 votes vote down vote up
def check(self, **kwargs):
        errors = []
        if not isinstance(settings.STATICFILES_DIRS, (list, tuple)):
            errors.append(Error(
                'The STATICFILES_DIRS setting is not a tuple or list.',
                hint='Perhaps you forgot a trailing comma?',
                id='staticfiles.E001',
            ))
        for root in settings.STATICFILES_DIRS:
            if isinstance(root, (list, tuple)):
                _, root = root
            if settings.STATIC_ROOT and os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
                errors.append(Error(
                    'The STATICFILES_DIRS setting should not contain the '
                    'STATIC_ROOT setting.',
                    id='staticfiles.E002',
                ))
        return errors 
Example 6
Project: exist   Author: nict-csl   File: views.py    License: MIT License 6 votes vote down vote up
def getImage(self, url):
        imagehash = hashlib.md5(url.encode('utf-8')).hexdigest()
        if settings.STATIC_ROOT is None:
            filepath = settings.STATICFILES_DIRS[0] + "webimg/" + imagehash + ".png"
        else:
            filepath = settings.STATIC_ROOT + "webimg/" + imagehash + ".png"
        path = "static/webimg/" + imagehash + ".png"
        options = {
            'quiet': '',
            'xvfb': '',
        }
        if not os.path.exists(filepath):
            try:
                imgkit.from_url(url, filepath, options=options)
            except Exception as e:
                logger.error(e)
                return
        return path 
Example 7
Project: exist   Author: nict-csl   File: views.py    License: MIT License 6 votes vote down vote up
def getSrc(self, url):
        imagehash = hashlib.md5(url.encode('utf-8')).hexdigest()
        if settings.STATIC_ROOT is None:
            filepath = settings.STATICFILES_DIRS[0] + "websrc/" + imagehash
        else:
            filepath = settings.STATIC_ROOT + "websrc/" + imagehash

        if not os.path.exists(filepath):
            ua = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko"
            headers = {
                'User-Agent': ua
            }
            try:
                res = requests.get(url, headers=headers, verify=False)
            except Exception as e:
                logger.error(e)
                return
            if "content-type" in res.headers:
                if 'text/html' in res.headers['content-type']:
                    with open(filepath, 'w') as fp:
                        fp.write(res.text)
            else:
                with open(filepath, 'wb') as fp:
                    fp.write(res.content)
        return imagehash 
Example 8
Project: openhgsenti   Author: drexly   File: finders.py    License: Apache License 2.0 6 votes vote down vote up
def __init__(self, app_names=None, *args, **kwargs):
        # List of locations with static files
        self.locations = []
        # Maps dir paths to an appropriate storage instance
        self.storages = OrderedDict()
        if not isinstance(settings.STATICFILES_DIRS, (list, tuple)):
            raise ImproperlyConfigured(
                "Your STATICFILES_DIRS setting is not a tuple or list; "
                "perhaps you forgot a trailing comma?")
        for root in settings.STATICFILES_DIRS:
            if isinstance(root, (list, tuple)):
                prefix, root = root
            else:
                prefix = ''
            if settings.STATIC_ROOT and os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
                raise ImproperlyConfigured(
                    "The STATICFILES_DIRS setting should "
                    "not contain the STATIC_ROOT setting")
            if (prefix, root) not in self.locations:
                self.locations.append((prefix, root))
        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage
        super(FileSystemFinder, self).__init__(*args, **kwargs) 
Example 9
Project: python2017   Author: bpgc-cte   File: finders.py    License: MIT License 6 votes vote down vote up
def __init__(self, app_names=None, *args, **kwargs):
        # List of locations with static files
        self.locations = []
        # Maps dir paths to an appropriate storage instance
        self.storages = OrderedDict()
        if not isinstance(settings.STATICFILES_DIRS, (list, tuple)):
            raise ImproperlyConfigured(
                "Your STATICFILES_DIRS setting is not a tuple or list; "
                "perhaps you forgot a trailing comma?")
        for root in settings.STATICFILES_DIRS:
            if isinstance(root, (list, tuple)):
                prefix, root = root
            else:
                prefix = ''
            if settings.STATIC_ROOT and os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
                raise ImproperlyConfigured(
                    "The STATICFILES_DIRS setting should "
                    "not contain the STATIC_ROOT setting")
            if (prefix, root) not in self.locations:
                self.locations.append((prefix, root))
        for prefix, root in self.locations:
            filesystem_storage = FileSystemStorage(location=root)
            filesystem_storage.prefix = prefix
            self.storages[root] = filesystem_storage
        super(FileSystemFinder, self).__init__(*args, **kwargs) 
Example 10
Project: pets   Author: jllorencetti   File: tests.py    License: MIT License 6 votes vote down vote up
def test_upload_second_photo(self):
        # pre register pet
        pet = self.create_pet()

        # login
        self.login()

        # go to own pet
        self.browser.get(self.live_server_url + "/pets/{}/".format(pet.slug))

        # upload some new photo
        img_path = os.path.abspath("{}/img/{}.png".format(settings.STATICFILES_DIRS[0], "logo"))
        profile_picture = self.browser.find_element_by_name("another_picture")
        profile_picture.send_keys(img_path)

        img_before = len(self.browser.find_elements_by_tag_name("img"))

        submit = self.browser.find_element_by_name("submit")
        submit.click()

        img_after = len(self.browser.find_elements_by_tag_name("img"))

        # verify new photo is showing
        self.assertIn("More photos", self.browser.page_source)
        self.assertEquals(img_after, img_before + 1) 
Example 11
Project: silver   Author: silverapp   File: pdf.py    License: Apache License 2.0 6 votes vote down vote up
def fetch_resources(uri, rel):
    """
    Callback to allow xhtml2pdf/reportlab to retrieve Images,Stylesheets, etc.
    `uri` is the href attribute from the html link element.
    `rel` gives a relative path, but it's not used here.
    """
    if settings.MEDIA_URL and uri.startswith(settings.MEDIA_URL):
        path = os.path.join(settings.MEDIA_ROOT,
                            uri.replace(settings.MEDIA_URL, ""))
    elif settings.STATIC_URL and uri.startswith(settings.STATIC_URL):
        path = os.path.join(settings.STATIC_ROOT,
                            uri.replace(settings.STATIC_URL, ""))
        if not os.path.exists(path):
            for d in settings.STATICFILES_DIRS:
                path = os.path.join(d, uri.replace(settings.STATIC_URL, ""))
                if os.path.exists(path):
                    break
    elif uri.startswith("http://") or uri.startswith("https://"):
        path = uri
    else:
        raise UnsupportedMediaPathException('media urls must start with %s or %s' % (
            settings.MEDIA_URL, settings.STATIC_URL))

    return path 
Example 12
Project: tethys   Author: tethysplatform   File: site_settings.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def load_custom_css(var):
    if var.startswith('/'):
        var = var.lstrip('/')

    is_file = os.path.isfile(os.path.join(settings.STATIC_ROOT, var))

    if is_file:
        return '<link href="' + os.path.join('/static', var) + '" rel="stylesheet" />'

    else:
        for path in settings.STATICFILES_DIRS:
            is_file = os.path.isfile(os.path.join(path, var))
            if is_file:
                return '<link href="' + os.path.join('/static', var) + '" rel="stylesheet" />'

    return '<style>' + var + '</style>' 
Example 13
Project: GTDWeb   Author: lanbing510   File: finders.py    License: GNU General Public License v2.0 5 votes vote down vote up
def find(self, path, all=False):
        """
        Looks for files in the extra locations
        as defined in ``STATICFILES_DIRS``.
        """
        matches = []
        for prefix, root in self.locations:
            if root not in searched_locations:
                searched_locations.append(root)
            matched_path = self.find_location(root, path, prefix)
            if matched_path:
                if not all:
                    return matched_path
                matches.append(matched_path)
        return matches 
Example 14
Project: bioforum   Author: reBiocoder   File: finders.py    License: MIT License 5 votes vote down vote up
def find(self, path, all=False):
        """
        Look for files in the extra locations as defined in STATICFILES_DIRS.
        """
        matches = []
        for prefix, root in self.locations:
            if root not in searched_locations:
                searched_locations.append(root)
            matched_path = self.find_location(root, path, prefix)
            if matched_path:
                if not all:
                    return matched_path
                matches.append(matched_path)
        return matches 
Example 15
Project: django-tenants   Author: django-tenants   File: finders.py    License: MIT License 5 votes vote down vote up
def __init__(self, app_names=None, *args, **kwargs):
        # Don't call parent's init method as settings.STATICFILES_DIRS will be loaded
        # by the standard FileSystemFinder already.

        # Instead of initializing the locations and storages now, we'll do so lazily
        # the first time they are needed.
        self._locations = {}
        self._storages = {} 
Example 16
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: finders.py    License: MIT License 5 votes vote down vote up
def find(self, path, all=False):
        """
        Look for files in the extra locations as defined in STATICFILES_DIRS.
        """
        matches = []
        for prefix, root in self.locations:
            if root not in searched_locations:
                searched_locations.append(root)
            matched_path = self.find_location(root, path, prefix)
            if matched_path:
                if not all:
                    return matched_path
                matches.append(matched_path)
        return matches 
Example 17
Project: exist   Author: nict-csl   File: views.py    License: MIT License 5 votes vote down vote up
def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        if not re.compile(r'\w{32}').match(self.kwargs['pk']):
            return context
        if settings.STATIC_ROOT is None:
            srcpath = settings.STATICFILES_DIRS[0] + 'websrc/' + self.kwargs['pk']
        else:
            srcpath = settings.STATIC_ROOT + 'websrc/' + self.kwargs['pk']
        f = open(srcpath, 'r')
        context['websrc'] = f.read()
        f.close()
        return context 
Example 18
Project: exist   Author: nict-csl   File: views.py    License: MIT License 5 votes vote down vote up
def getContents(request, pk):
    if not re.compile(r'(?=(\b[a-fA-F0-9]{32}\b))').match(pk):
        return redirect('index')
    if settings.STATIC_ROOT is None:
        filepath = settings.STATICFILES_DIRS[0] + 'websrc/' + pk
    else:
        filepath = settings.STATIC_ROOT + 'websrc/' + pk
    f = open(filepath, 'rb')
    contents = f.read()
    f.close()
    response = HttpResponse(contents)
    response["Content-Disposition"] = "filename=%s" % pk
    return response 
Example 19
Project: openhgsenti   Author: drexly   File: finders.py    License: Apache License 2.0 5 votes vote down vote up
def find(self, path, all=False):
        """
        Looks for files in the extra locations
        as defined in ``STATICFILES_DIRS``.
        """
        matches = []
        for prefix, root in self.locations:
            if root not in searched_locations:
                searched_locations.append(root)
            matched_path = self.find_location(root, path, prefix)
            if matched_path:
                if not all:
                    return matched_path
                matches.append(matched_path)
        return matches 
Example 20
Project: python2017   Author: bpgc-cte   File: finders.py    License: MIT License 5 votes vote down vote up
def find(self, path, all=False):
        """
        Looks for files in the extra locations
        as defined in ``STATICFILES_DIRS``.
        """
        matches = []
        for prefix, root in self.locations:
            if root not in searched_locations:
                searched_locations.append(root)
            matched_path = self.find_location(root, path, prefix)
            if matched_path:
                if not all:
                    return matched_path
                matches.append(matched_path)
        return matches 
Example 21
Project: protwis   Author: protwis   File: functions.py    License: Apache License 2.0 5 votes vote down vote up
def __init__ (self, blast_path='blastp',
        blastdb=os.sep.join([settings.STATICFILES_DIRS[0], 'blast', 'protwis_blastdb']), top_results=1):

        self.blast_path = blast_path
        self.blastdb = blastdb
        #typicaly top scored result is enough, but for sequences with missing
        #residues it is better to use more results to avoid getting sequence of
        #e.g.  different species
        self.top_results = top_results

    #takes Bio.Seq sequence as an input and returns a list of tuples with the
    #alignments 
Example 22
Project: protwis   Author: protwis   File: assign_generic_numbers_gpcr.py    License: Apache License 2.0 5 votes vote down vote up
def __init__ (self, pdb_file=None, pdb_filename=None, structure=None, pdb_code=None, blast_path='blastp',
        blastdb=os.sep.join([settings.STATICFILES_DIRS[0], 'blast', 'protwis_blastdb']),top_results=1, sequence_parser=False, signprot=False):
    
        # pdb_file can be either a name/path or a handle to an open file
        self.pdb_file = pdb_file
        self.pdb_filename = pdb_filename

        # if pdb 4 letter code is specified
        self.pdb_code = pdb_code
        
        # dictionary of 'MappedResidue' object storing information about alignments and bw numbers
        self.residues = {}
        self.pdb_seq = {} #Seq('')
        # list of uniprot ids returned from blast
        self.prot_id_list = []
        #setup for local blast search
        self.blast = BlastSearch(blast_path=blast_path, blastdb=blastdb,top_results=top_results)
        
        # calling sequence parser
        if sequence_parser:
            if pdb_code:
                struct = Structure.objects.get(pdb_code__index=self.pdb_code)
            if not signprot:
                if pdb_code:
                    s = SequenceParser(pdb_file=self.pdb_file, wt_protein_id=struct.protein_conformation.protein.parent.id)
                else:
                    s = SequenceParser(pdb_file=self.pdb_file)#, wt_protein_id=struct.protein_conformation.protein.parent.id)
            else:
                s = SequenceParser(pdb_file=self.pdb_file, wt_protein_id=signprot.id)
            self.pdb_structure = s.pdb_struct
            self.mapping = s.mapping
            self.wt = s.wt
        else:
            if self.pdb_file:
                self.pdb_structure = PDBParser(PERMISSIVE=True, QUIET=True).get_structure('ref', self.pdb_file)[0]
            elif self.pdb_filename:
                self.pdb_structure = PDBParser(PERMISSIVE=True, QUIET=True).get_structure('ref', self.pdb_filename)[0]
            else:
                self.pdb_structure = structure

            self.parse_structure(self.pdb_structure) 
Example 23
Project: protwis   Author: protwis   File: views.py    License: Apache License 2.0 5 votes vote down vote up
def RenderTrees(request):
	number = request.GET['number']
	tree = open(settings.STATICFILES_DIRS[0] +'/home/images/00'+number+'_tree.xml').read()
	legend = open(settings.STATICFILES_DIRS[0] +'/home/images/00'+number+'_legend.svg').read()
	context = {'tree':tree, 'leg':legend, 'num':number}
	return render(request, 'phylogenetic_trees.html', context) 
Example 24
Project: protwis   Author: protwis   File: views.py    License: Apache License 2.0 5 votes vote down vote up
def post(self, request, *args, **kwargs):

        if 'human' in request.POST.keys():
            blast = BlastSearch(blastdb=os.sep.join([settings.STATICFILES_DIRS[0], 'blast', 'protwis_human_blastdb']), top_results=50)
            blast_out = blast.run(request.POST['input_seq'])
        else:
            blast = BlastSearch(top_results=50)
            blast_out = blast.run(request.POST['input_seq'])

        context = {}
        context['results'] = [(Protein.objects.get(pk=x[0]), x[1]) for x in blast_out]
        context["input"] = request.POST['input_seq']

        return render(request, self.template_name, context) 
Example 25
Project: pets   Author: jllorencetti   File: tests.py    License: MIT License 5 votes vote down vote up
def test_register_pet(self):
        self.login()
        self.assertIn("Register Pet", self.browser.page_source)

        self.browser.get(self.live_server_url + "/pets/novo/")

        name = self.browser.find_element_by_name("name")
        name.send_keys("Test")

        description = self.browser.find_element_by_name("description")
        description.send_keys("Testing Adoption")

        self.select_dropdown("status", 1)

        self.select_dropdown("kind", 1)

        self.select_dropdown("state", 1)
        self.select_dropdown("city", 1)

        img_path = os.path.abspath("{}/img/{}.png".format(settings.STATICFILES_DIRS[0], "logo"))
        profile_picture = self.browser.find_element_by_name("profile_picture")
        profile_picture.send_keys(img_path)

        submit = self.browser.find_element_by_name("submit")
        submit.click()

        self.assertIn("Obrigado", self.browser.page_source) 
Example 26
Project: dtp-stat   Author: tadata-ru   File: md5url.py    License: GNU General Public License v2.0 5 votes vote down vote up
def get_md5(cls, file):
        try:
            return cls._md5_sum[file]
        except KeyError:
            with cls._lock:
                try:
                    for root_url in settings.STATICFILES_DIRS:
                        md5 = cls.calc_md5(path.join(root_url, file))[:8]
                        value = '%s%s?v=%s' % (settings.STATIC_URL, file, md5)
                except IsADirectoryError:
                    value = settings.STATIC_URL + file
                cls._md5_sum[file] = value
                return value 
Example 27
Project: djongo   Author: nesdis   File: test_storage.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super().setUp()

        temp_dir = tempfile.mkdtemp()
        os.makedirs(os.path.join(temp_dir, 'test'))
        self._clear_filename = os.path.join(temp_dir, 'test', 'cleared.txt')
        with open(self._clear_filename, 'w') as f:
            f.write('to be deleted in one test')

        self.patched_settings = self.settings(
            STATICFILES_DIRS=settings.STATICFILES_DIRS + [temp_dir],
        )
        self.patched_settings.enable()
        self.addCleanup(shutil.rmtree, temp_dir)
        self._manifest_strict = storage.staticfiles_storage.manifest_strict 
Example 28
Project: djongo   Author: nesdis   File: test_storage.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def test_file_change_after_collectstatic(self):
        # Create initial static files.
        file_contents = (
            ('foo.png', 'foo'),
            ('bar.css', 'url("foo.png")\nurl("xyz.png")'),
            ('xyz.png', 'xyz'),
        )
        for filename, content in file_contents:
            with open(self._get_filename_path(filename), 'w') as f:
                f.write(content)

        with self.modify_settings(STATICFILES_DIRS={'append': self._temp_dir}):
            finders.get_finder.cache_clear()
            err = StringIO()
            # First collectstatic run.
            call_command('collectstatic', interactive=False, verbosity=0, stderr=err)
            relpath = self.hashed_file_path('test/bar.css')
            with storage.staticfiles_storage.open(relpath) as relfile:
                content = relfile.read()
                self.assertIn(b'foo.acbd18db4cc2.png', content)
                self.assertIn(b'xyz.d16fb36f0911.png', content)

            # Change the contents of the png files.
            for filename in ('foo.png', 'xyz.png'):
                with open(self._get_filename_path(filename), 'w+b') as f:
                    f.write(b"new content of file to change its hash")

            # The hashes of the png files in the CSS file are updated after
            # a second collectstatic.
            call_command('collectstatic', interactive=False, verbosity=0, stderr=err)
            relpath = self.hashed_file_path('test/bar.css')
            with storage.staticfiles_storage.open(relpath) as relfile:
                content = relfile.read()
                self.assertIn(b'foo.57a5cb9ba68d.png', content)
                self.assertIn(b'xyz.57a5cb9ba68d.png', content) 
Example 29
Project: protwis   Author: protwis   File: sequence_parser.py    License: Apache License 2.0 4 votes vote down vote up
def __init__(self, pdb_file=None, sequence=None, wt_protein_id=None):

        # dictionary of 'ParsedResidue' object storing information about alignments and bw numbers
        self.mapping = {}
        self.residues = {}
        self.segments = {}
        self.blast = BlastSearch(blastdb=os.sep.join([settings.STATICFILES_DIRS[0], 'blast', 'protwis_blastdb']))
        self.wt_protein_id = wt_protein_id
        
        if pdb_file is not None:
            self.pdb_struct = PDBParser(QUIET=True).get_structure('pdb', pdb_file)[0]
            # a list of SeqRecord objects retrived from the pdb SEQRES section
            try:
                self.seqres = list(SeqIO.parse(pdb_file, 'pdb-seqres'))
                self.struct_id = self.seqres[0].id.split(':')[0]
            except:
                self.seqres = None
                self.struct_id = None
            # SeqRecord id is a pdb_code:chain

        self.sequence = sequence
        if type(sequence) == "string":
            self.sequence = { x: y for x,y in enumerate(sequnece) }


        # If not specified, attempt to get wildtype from pdb.
        try:
            if not wt_protein_id and pdb_file is not None:
                self.wt = Structure.objects.get(pdb_code__index=self.struct_id).protein_conformation.protein.parent
            else:
                raise Exception()
        except:
            if not wt_protein_id:
                self.wt = None
                self.wt_seq = ''
            else:
                self.wt = Protein.objects.get(id=wt_protein_id)
                self.wt_seq = str(self.wt.sequence)
        self.fusions = []

        self.parse_pdb(self.pdb_struct)
        #if self.seqres:
        #    self.map_seqres()
        
        self.mark_deletions() 
Example 30
Project: pets   Author: jllorencetti   File: tests.py    License: MIT License 4 votes vote down vote up
def test_edit_own_pet(self):
        # user log in
        self.login()
        self.assertIn("Register Pet", self.browser.page_source)

        # user register a lost cat with wrong name
        self.browser.get(self.live_server_url + "/pets/novo/")
        self.browser.find_element_by_name("name").send_keys("Wrong Boots")
        self.browser.find_element_by_name("description").send_keys("My dear lovely cat")

        # select the city
        self.select_dropdown("state", 1)
        self.select_dropdown("city", 1)

        # select status
        self.select_dropdown("status", 1)

        # selects the kind as a Cat
        self.select_dropdown("kind", 1)

        # selects the size of the pet
        self.select_dropdown("size", 3)

        # selects the sex of the pet
        self.select_dropdown("sex", 1)

        # user select a picture of his cat
        img_path = os.path.abspath("{}/img/{}.png".format(settings.STATICFILES_DIRS[0], "logo"))
        profile_picture = self.browser.find_element_by_name("profile_picture")
        profile_picture.send_keys(img_path)

        # click on submit
        self.browser.find_element_by_name("submit").click()

        # assert pet was registered
        self.browser.find_element_by_link_text("aqui").click()
        self.assertIn("Wrong Boots - For Adoption", self.browser.page_source)

        # user is redirected for the page of his pet and see the wrong name
        # then click on 'Edit' and get redirected for the editing page
        self.browser.find_element_by_link_text("Edit").click()

        # user change the status to 'Missing'
        self.select_dropdown("status", 2)

        # user inform the correct name for the pet then save
        self.browser.find_element_by_name("name").clear()
        self.browser.find_element_by_name("name").send_keys("Fuzzy Boots")
        self.browser.find_element_by_name("submit").click()

        # user see that he is back at the pet page
        self.browser.find_element_by_link_text("Edit")

        # user see the correct name of the cat
        self.assertIn("Fuzzy Boots", self.browser.page_source)
        self.assertIn("Large", self.browser.page_source)
        self.assertIn("Female", self.browser.page_source)
        self.assertIn("Araras", self.browser.page_source)
        self.assertIn("Fuzzy Boots - Missing", self.browser.page_source)