def commit(request, department, number, page_type, term, year, slug, hash): course = get_object_or_404(Course, department=department.upper(), number=int(number)) course_sem = get_object_or_404(CourseSemester, course=course, term=term, year=year) page = get_object_or_404(Page, course_sem=course_sem, page_type=page_type, slug=slug) page_type_obj = page_types[page_type] repo = Git(page.get_filepath()) # make this an object on the page commit = repo.get_commit(hash) files = {} for blob in commit.tree: raw = blob.data_stream.read().split('\n') files[blob.name] = { 'raw': '\n'.join(raw), 'title': raw[0].strip(), 'data': page_type_obj.format(raw[3:]), } raw_file = files.items()[0][1]['raw'].decode('utf-8') data = { 'title': 'Commit information (%s)' % page, 'course': course, 'page': page, 'hash': hash, 'content': raw_file, 'commit': { 'date': datetime.fromtimestamp(commit.authored_date), # returns a unix timestamp in 0.3.2 'author': User.objects.get(username=commit.author.name), 'message': commit.message, 'stats': commit.stats.total, 'diff': repo.get_diff(commit) }, } return render(request, "pages/commit.html", data)
def save_content(self, content, message, username): path = self.get_filepath() repo = Git(path) filename = '%scontent.md' % path file = open(filename, 'wt') file.write(content) file.close() repo.add('content.md') message = 'Minor edit' if not message else message repo.commit(message, username, '*****@*****.**')
def save_content(self, content, message, username): self.content = wikinotes_markdown(content) self.save() path = self.get_filepath() repo = Git(path) filename = '%scontent.md' % path file = open(filename, 'wt') file.write(content.encode('utf-8')) file.close() repo.add('content.md') message = 'Minor edit' if not message else message repo.commit(message, username, '*****@*****.**')
def get_repo(self): return Git(self.get_filepath())