---------- Forwarded message ----------
From: Lucy Fletcher-Jones <[email protected]>
Date: Tue, Nov 15, 2016 at 11:33 AM
Subject: Re: [Arches] Compiling .py programs
To: Adam Cox <[email protected]>


Hi Adam,

Thank you for your help. I tried adding the print lines to resource.py and
forms.py but I wasn't sure what the development server print output file
was! But it didn't matter because I could see that a .pyc was not being
created for either program, as I had removed the previous versions. So I
googled and found the interactive python compiler command and used that to
manually compile the files on the server and found I had indentation errors
in forms.py! It seems that when a python file is 'imported' if there are
errors in it, no error report is issued but that file is ignored and the
first .pyc file that is encountered will be used, or the first error free
.py file will be compiled and used if a .pyc file does not exist. If anyone
else is interested in this, I used the python command to compile all python
files in a directory :

 python -m compileall .

Unfortunately, it still does not explain why the resource.py file failed to
compile when accessing the web site. There were no errors in it.  I presume
when you say 'watch for it to be recreated when you restart the dev
server.', you mean simply call the web site? Or do you mean we should
explicitly use the command:

python manage.py runserver  (server name).?

I have also come across an indentation error in forms.py which I cannot
solve. It is not even in the line of code that I have altered! Here is the
section of code with the erroneous line highlighted. The indentation error
is the new line at the end of ....append({

 for entity in classification_entities:
           ''' to_date_nodes = datetime_nodes_to_dates(self.get_nodes(entity,
'TO_DATE.E49'))
            from_date_nodes = datetime_nodes_to_dates(self.get_nodes(entity,
'FROM_DATE.E49'))'''
            ##Removed date nodes and added dynasty and ruler below

            self.data['data'].append({
                'HERITAGE_RESOURCE_TYPE.E55': {
                    'branch_lists': self.get_nodes(entity,
'HERITAGE_RESOURCE_TYPE.E55')
                },
                'HERITAGE_RESOURCE_USE_TYPE.E55': {
                    'branch_lists': self.get_nodes(entity,
'HERITAGE_RESOURCE_USE_TYPE.E55')
                },
                'CULTURAL_PERIOD.E55': {
                    'branch_lists': self.get_nodes(entity,
'CULTURAL_PERIOD.E55')
                },
                'STYLE.E55': {
                    'branch_lists': self.get_nodes(entity, 'STYLE.E55')
                },
                'ANCILLARY_FEATURE_TYPE.E55': {
                    'branch_lists': self.get_nodes(entity,
'ANCILLARY_FEATURE_TYPE.E55')
                },
                'PHASE_TYPE_ASSIGNMENT.E17': {
                    'branch_lists': self.get_nodes(entity,
'PHASE_TYPE_ASSIGNMENT.E17')
                },
                'DYNASTY.E55': {
                    'branch_lists': self.get_nodes(entity, 'DYNASTY.E55')
                },
                'RULER.E55': {
                    'branch_lists': self.get_nodes(entity, 'RULER.E55')
                }
            })

Any ideas on why this is incorrect will be gratefully received!

Thank you,
Lucy









Lucy Fletcher-Jones
Egypt Database Project
TMP Room 2181, HUSS Building AUC New Campus
Tel: 02 2615 1760
Mobile: 010 1633 8367


On Tue, Nov 8, 2016 at 10:06 PM, Adam Cox <[email protected]> wrote:

> Hi Lucy, the .pyc files are automatically created every time a .py file is
> imported by a different .py file. So, to test your system, you could just
> delete *any* .pyc file and watch for it to be recreated when you restart
> the dev server. Try this with settings.pyc. If the file is not created and
> things don't work, then you could have an issue with python, but I would be
> surprised if that is the real problem.
>
> Another way to test that the correct files are being used is to add a
> print statement to the top of each. For example, in resource.py, under import
> forms write
> print "------USING LOCAL RESOURCE.PY------"
> and in forms.py add
> print "------USING LOCAL FORMS.PY------"
> right underneath the import statements. Then run the dev server and
> navigate to any resource data entry form. If those print statements don't
> show up, in the dev server print output you know that the files are not
> being referenced.
>
> What's strange is that it sounds like you have everything set up correctly:
>
> 1. In models/ you should have two files, resource.py and forms.py.
> 2. In resource.py you have changed the import statement to use the
> adjacent forms.py file (by using import forms), instead of the arches_hip
> forms.py file.
> 3. In your settings.py file you have redefined the RESOURCE_MODEL variable
> to point to your version of resource.py, instead of the one in the
> arches-hip package. One thing to check, is there a resource.pyc file? If
> not, you may want to change RESOURCE_MODEL to the syntax I had, even though
> what you had should work fine.
>
> As for the difference between models/resource.py and views/resource*s*.py,
> the one in views defines functions that are used to create all of the data
> necessary for a specific webpage (i.e. a view). For example, in
> resources.py you'll find functions that collect all of the geometry from
> the database and returns a set of features, which are then passed to the
> map view. If you look in urls.py, you'll see that urls are mapped to
> specific "views", meaning that different view functions are called based on
> the urls.
>
> Hopefully some of this helps :)
>
> Adam
>
> On Tuesday, November 8, 2016 at 6:57:18 AM UTC-6, Lucy FJ wrote:
>>
>> Hi again,
>> I have just read through some notes you put on the forum last may and
>> wonder if we have confused two files. Are you referring to the resource.py
>> file that resides in the ....arches_hip/models directory and therefore
>> should be moved to our apps/models directory? There is another file called
>> resource*s*.py (note the s at the end) which resides in the
>> .....arches_hip/views directory and is different. We have changed the
>> former, not the latter. What is the latter used for by the way?
>>
>>
>>
>>
>> On Tuesday, November 8, 2016 at 9:29:00 AM UTC+2, Lucy FJ wrote:
>>>
>>> Hi Adam,
>>>
>>> Thank you for your help.
>>>
>>> Yes, we have copied the resource.py file into our app - it is in the
>>> same directory as forms.py, ../our app/our app/models. However, the
>>> settings.py file (and compiled version) has been modified slightly
>>> differently from what you suggest and is located in ...../our app/our app.
>>> As I do not know python, I do not know if this is effectively the same:
>>>
>>> RESOURCE_MODEL = {'default': 'ead.models.resource.Resource'} where
>>> 'ead' is our app.
>>>
>>> (In the past we have managed to compile python programs but the
>>> technician involved cannot now be contacted and I do not know what has
>>> changed.)
>>>
>>> Thanks, Lucy
>>>
>>>
>>> On Sunday, November 6, 2016 at 4:29:39 PM UTC+2, Adam Cox wrote:
>>>>
>>>> Hi Lucy, regarding the resource.py file, have you already copied that
>>>> from Arches-HIP to your app? You must do this if you wish to use your own
>>>> forms.py file, and you need to update the RESOURCE_MODEL variable in your
>>>> settings.py file. Mine is set like this:
>>>>
>>>> RESOURCE_MODEL = {'default': '{}.models.resource.Resource'.
>>>> format(PACKAGE_NAME)}
>>>>
>>>> For example
>>>> <https://github.com/mradamcox/afrh/blob/master/afrh/settings.py#L36>
>>>>
>>>> Hope that's all you need. In general, you are right to look for a .pyc
>>>> file as an indication that the .py file is being used.
>>>>
>>>> Adam
>>>>
>>>> On Sun, Nov 6, 2016 at 4:29 AM, 'Lucy FJ' via Arches Project <
>>>> [email protected]> wrote:
>>>>
>>>>> Hi everyone,
>>>>>
>>>>> This is a basic technical question which I am asking as a not
>>>>> particularly technical person.
>>>>>
>>>>> We are customising Arches and are changing forms.py because we have
>>>>> added new nodes to the Heritage Resource graph.
>>>>> I have copied forms.py from the Arches HIP directory, changed it and
>>>>> put it into our custom directory. I opened Arches and found that the
>>>>> changes had not taken effect and noticed that a .pyc file had not been
>>>>> created in the custom directory. I assume that the .pyc file in the HIP
>>>>> directory is being read instead? (It is still there). I have tried 
>>>>> stopping
>>>>> and restarting our server and still the .pyc file fails to be created. The
>>>>> file resource.py has been changed as suggested by the Arches documentation
>>>>> to pick up the correct version of 'forms' (*from arches_hip.models
>>>>> import forms *has been changed to *import forms*) and is also located
>>>>> in the custom directory. What is the mechanism that causes the .pyc file 
>>>>> to
>>>>> be created? I was wondering if it was a permission/ownership problem. All
>>>>> our Arches programs are owned by Root. is this normal in an Arches
>>>>> installation?
>>>>>
>>>>> Thank you very much for your help.
>>>>>
>>>>>
>>>>> --
>>>>> -- To post, send email to [email protected]. To unsubscribe,
>>>>> send email to [email protected]. For more information,
>>>>> visit https://groups.google.com/d/forum/archesproject?hl=en
>>>>> ---
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Arches Project" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>> --
> -- To post, send email to [email protected]. To unsubscribe,
> send email to [email protected]. For more
> information, visit https://groups.google.com/d/forum/archesproject?hl=en
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Arches Project" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/to
> pic/archesproject/pi3aJKAbayk/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- To post, send email to [email protected]. To unsubscribe, send 
email to [email protected]. For more information, 
visit https://groups.google.com/d/forum/archesproject?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Arches Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to