forked from expo/troggle
add git commit to file saving in 3 places
This commit is contained in:
parent
26454bf6c6
commit
d1e6125d15
@ -37,6 +37,28 @@ todo='''- Move utility function into utils.py
|
|||||||
- Restore constraint: unique_together = (("area", "kataster_number"), ("area", "unofficial_number"))
|
- Restore constraint: unique_together = (("area", "kataster_number"), ("area", "unofficial_number"))
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
def writetrogglefile(filepath, filecontent):
|
||||||
|
'''Set permissions to rw-rw-r-- and commit the new saved file to git'''
|
||||||
|
filepath = Path(filepath)
|
||||||
|
cwd = filepath.parent
|
||||||
|
filename = filepath.name
|
||||||
|
git = settings.GIT
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(filepath, "w") as f:
|
||||||
|
os.chmod(filepath, 0o664) # set file permissions to rw-rw-r--
|
||||||
|
f.write(filecontent)
|
||||||
|
print(f'WRITING{cwd}---{filename} ')
|
||||||
|
call([git, "add", filename], cwd=cwd)
|
||||||
|
call([git, "commit", "-m", 'Online cave or entrance edit'], cwd=cwd)
|
||||||
|
except PermissionError:
|
||||||
|
message = f'CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {filename}. Ask a nerd to fix this.'
|
||||||
|
return render(request,'errors/generic.html', {'message': message})
|
||||||
|
except:
|
||||||
|
message = f'CANNOT git on server for this file {filename}. Edits not saved.\nAsk a nerd to fix this.'
|
||||||
|
return render(request,'errors/generic.html', {'message': message})
|
||||||
|
|
||||||
|
|
||||||
class Area(TroggleModel):
|
class Area(TroggleModel):
|
||||||
short_name = models.CharField(max_length=100)
|
short_name = models.CharField(max_length=100)
|
||||||
name = models.CharField(max_length=200, blank=True, null=True)
|
name = models.CharField(max_length=200, blank=True, null=True)
|
||||||
@ -202,19 +224,15 @@ class Cave(TroggleModel):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
def writeDataFile(self):
|
def writeDataFile(self):
|
||||||
try:
|
filepath = os.path.join(settings.CAVEDESCRIPTIONS, self.filename)
|
||||||
f = open(os.path.join(settings.CAVEDESCRIPTIONS, self.filename), "w")
|
|
||||||
except:
|
|
||||||
subprocess.call(settings.FIX_PERMISSIONS)
|
|
||||||
f = open(os.path.join(settings.CAVEDESCRIPTIONS, self.filename), "w")
|
|
||||||
t = loader.get_template('dataformat/cave.xml')
|
t = loader.get_template('dataformat/cave.xml')
|
||||||
#c = Context({'cave': self})
|
#c = Context({'cave': self})
|
||||||
c = dict({'cave': self})
|
c = dict({'cave': self})
|
||||||
u = t.render(c)
|
u = t.render(c)
|
||||||
# u8 = u.encode("utf-8")
|
writetrogglefile(filepath, u)
|
||||||
# f.write(u8)
|
return
|
||||||
f.write(u)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def getArea(self):
|
def getArea(self):
|
||||||
areas = self.area.all()
|
areas = self.area.all()
|
||||||
@ -382,18 +400,14 @@ class Entrance(TroggleModel):
|
|||||||
return Path(settings.ENTRANCEDESCRIPTIONS, self.filename)
|
return Path(settings.ENTRANCEDESCRIPTIONS, self.filename)
|
||||||
|
|
||||||
def writeDataFile(self):
|
def writeDataFile(self):
|
||||||
try:
|
filepath = os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename)
|
||||||
f = open(os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename), "w")
|
|
||||||
except:
|
|
||||||
subprocess.call(settings.FIX_PERMISSIONS)
|
|
||||||
f = open(os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename), "w")
|
|
||||||
t = loader.get_template('dataformat/entrance.xml')
|
t = loader.get_template('dataformat/entrance.xml')
|
||||||
c = dict({'entrance': self})
|
c = dict({'entrance': self})
|
||||||
u = t.render(c)
|
u = t.render(c)
|
||||||
# u8 = u.encode("utf-8")
|
writetrogglefile(filepath, u)
|
||||||
# f.write(u8)
|
return
|
||||||
f.write(u)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
class LogbookEntry(TroggleModel):
|
class LogbookEntry(TroggleModel):
|
||||||
"""Single parsed entry from Logbook
|
"""Single parsed entry from Logbook
|
||||||
|
@ -312,8 +312,9 @@ def editexpopage(request, path):
|
|||||||
git = settings.GIT
|
git = settings.GIT
|
||||||
try:
|
try:
|
||||||
with open(filepath, "w") as f:
|
with open(filepath, "w") as f:
|
||||||
|
os.chmod(filepath, 0o664) # set file permissions to rw-rw-r--
|
||||||
f.write(result)
|
f.write(result)
|
||||||
#print(f'WROTE {cwd}---{filename} ')
|
print(f'WRITING{cwd}---{filename} ')
|
||||||
subprocess.call([git, "add", filename], cwd=cwd)
|
subprocess.call([git, "add", filename], cwd=cwd)
|
||||||
subprocess.call([git, "commit", "-m", 'Edit this page'], cwd=cwd)
|
subprocess.call([git, "commit", "-m", 'Edit this page'], cwd=cwd)
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user