Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions lab2/GitLecture.pyproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>14b610c4-f1db-415c-ac1b-eaa7f13bb2c0</ProjectGuid>
<ProjectHome>.</ProjectHome>
<ProjectTypeGuids>{789894c7-04a9-4a11-a6b5-3f4435165112};{1b580a1a-fdb3-4b32-83e1-6407eb2722e6};{349c5851-65df-11da-9384-00065b846f21};{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids>
<StartupFile>runserver.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<LaunchProvider>Web launcher</LaunchProvider>
<WebBrowserUrl>http://localhost</WebBrowserUrl>
<OutputPath>.</OutputPath>
<SuppressCollectPythonCloudServiceFiles>true</SuppressCollectPythonCloudServiceFiles>
<Name>GitLecture</Name>
<RootNamespace>GitLecture</RootNamespace>
<InterpreterId>MSBuild|env|$(MSBuildProjectFullPath)</InterpreterId>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="GitLecture\dao\credentials.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="GitLecture\dao\db.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="GitLecture\dao\entities.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="GitLecture\forms\forms.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="runserver.py" />
<Compile Include="GitLecture\__init__.py" />
<Compile Include="GitLecture\views.py" />
</ItemGroup>
<ItemGroup>
<Folder Include="GitLecture\" />
<Folder Include="GitLecture\forms\" />
<Folder Include="GitLecture\dao\" />
<Folder Include="GitLecture\static\" />
<Folder Include="GitLecture\static\content\" />
<Folder Include="GitLecture\static\fonts\" />
<Folder Include="GitLecture\static\scripts\" />
<Folder Include="GitLecture\templates\" />
</ItemGroup>
<ItemGroup>
<Content Include="GitLecture\templates\create_lecture.html" />
<Content Include="GitLecture\templates\create_user.html" />
<Content Include="GitLecture\templates\dashboard.html" />
<Content Include="GitLecture\templates\edit_subject.html" />
<Content Include="GitLecture\templates\layout.html" />
<Content Include="GitLecture\templates\lectures.html" />
<Content Include="GitLecture\templates\read_lecture.html" />
<Content Include="GitLecture\templates\subjects.html" />
<Content Include="GitLecture\templates\users.html" />
<Content Include="Procfile" />
<Content Include="requirements.txt" />
<Content Include="GitLecture\static\content\bootstrap.css" />
<Content Include="GitLecture\static\content\bootstrap.min.css" />
<Content Include="GitLecture\static\content\site.css" />
<Content Include="GitLecture\static\fonts\glyphicons-halflings-regular.eot" />
<Content Include="GitLecture\static\fonts\glyphicons-halflings-regular.svg" />
<Content Include="GitLecture\static\fonts\glyphicons-halflings-regular.ttf" />
<Content Include="GitLecture\static\fonts\glyphicons-halflings-regular.woff" />
<Content Include="GitLecture\static\scripts\bootstrap.js" />
<Content Include="GitLecture\static\scripts\bootstrap.min.js" />
<Content Include="GitLecture\static\scripts\jquery-1.10.2.intellisense.js" />
<Content Include="GitLecture\static\scripts\jquery-1.10.2.js" />
<Content Include="GitLecture\static\scripts\jquery-1.10.2.min.js" />
<Content Include="GitLecture\static\scripts\jquery-1.10.2.min.map" />
<Content Include="GitLecture\static\scripts\jquery.validate-vsdoc.js" />
<Content Include="GitLecture\static\scripts\jquery.validate.js" />
<Content Include="GitLecture\static\scripts\jquery.validate.min.js" />
<Content Include="GitLecture\static\scripts\jquery.validate.unobtrusive.js" />
<Content Include="GitLecture\static\scripts\jquery.validate.unobtrusive.min.js" />
<Content Include="GitLecture\static\scripts\modernizr-2.6.2.js" />
<Content Include="GitLecture\static\scripts\respond.js" />
<Content Include="GitLecture\static\scripts\respond.min.js" />
<Content Include="GitLecture\static\scripts\_references.js" />
</ItemGroup>
<ItemGroup>
<Interpreter Include="env\">
<Id>env</Id>
<Version>3.6</Version>
<Description>env (Python 3.6 (64-bit))</Description>
<InterpreterPath>Scripts\python.exe</InterpreterPath>
<WindowsInterpreterPath>Scripts\pythonw.exe</WindowsInterpreterPath>
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
<Architecture>X64</Architecture>
</Interpreter>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.Web.targets" />
<!-- Specify pre- and post-build commands in the BeforeBuild and
AfterBuild targets below. -->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<AutoAssignPort>True</AutoAssignPort>
<UseCustomServer>True</UseCustomServer>
<CustomServerUrl>http://localhost</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}" User="">
<WebProjectProperties>
<StartPageUrl>
</StartPageUrl>
<StartAction>CurrentPage</StartAction>
<AspNetDebugging>True</AspNetDebugging>
<SilverlightDebugging>False</SilverlightDebugging>
<NativeDebugging>False</NativeDebugging>
<SQLDebugging>False</SQLDebugging>
<ExternalProgram>
</ExternalProgram>
<StartExternalURL>
</StartExternalURL>
<StartCmdLineArguments>
</StartCmdLineArguments>
<StartWorkingDirectory>
</StartWorkingDirectory>
<EnableENC>False</EnableENC>
<AlwaysStartWebServerOnDebug>False</AlwaysStartWebServerOnDebug>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
6 changes: 6 additions & 0 deletions lab2/GitLecture.pyproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
</PropertyGroup>
</Project>
25 changes: 25 additions & 0 deletions lab2/GitLecture.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29509.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "GitLecture", "GitLecture.pyproj", "{14B610C4-F1DB-415C-AC1B-EAA7F13BB2C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{14B610C4-F1DB-415C-AC1B-EAA7F13BB2C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{14B610C4-F1DB-415C-AC1B-EAA7F13BB2C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14B610C4-F1DB-415C-AC1B-EAA7F13BB2C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14B610C4-F1DB-415C-AC1B-EAA7F13BB2C0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2629643C-5C03-4D49-925C-B3788D063B2B}
EndGlobalSection
EndGlobal
20 changes: 20 additions & 0 deletions lab2/GitLecture/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
The flask application package.
"""

from flask import Flask
from GitLecture.dao.db import PostgresDb
from GitLecture.dao.entities import Base
from flask_wtf.csrf import CSRFProtect

app = Flask(__name__)
db = PostgresDb()

Base.metadata.create_all(db.sqlalchemy_engine)

csrf = CSRFProtect(app)
app.config['SECRET_KEY'] = "secretkey"
app.config['WTF_CSRF_SECRET_KEY'] = "secretkey"
csrf.init_app(app)

import GitLecture.views
Binary file added lab2/GitLecture/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added lab2/GitLecture/__pycache__/views.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions lab2/GitLecture/dao/credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os

username = 'cjugncikzjwmfm'
password = '36f987b32bd08ff043c348331507079b2b6015413146a2fb059a92a9ab52e5eb'
host = 'ec2-54-228-207-163.eu-west-1.compute.amazonaws.com'
port = '5432'
database = 'postgres'
DATABASE_URI = 'postgres://cjugncikzjwmfm:36f987b32bd08ff043c348331507079b2b6015413146a2fb059a92a9ab52e5eb@ec2-54-228-207-163.eu-west-1.compute.amazonaws.com:5432/d8l1jv07g7mi6m'
37 changes: 37 additions & 0 deletions lab2/GitLecture/dao/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from GitLecture.dao.credentials import *


class PostgresDb(object):
_instance = None

def __new__(cls):
if cls._instance is None:
cls._instance = object.__new__(cls)
try:
engine = create_engine(DATABASE_URI)

Session = sessionmaker(bind=engine)
session = Session()

PostgresDb._instance.sqlalchemy_session = session
PostgresDb._instance.sqlalchemy_engine = engine

except Exception as error:
print('Error: connection not established {}'.format(error))

return cls._instance

def __init__(self):
engine = create_engine(DATABASE_URI)

Session = sessionmaker(bind=engine)
session = Session()

self.sqlalchemy_session = session
self.sqlalchemy_engine = engine

def __del__(self):
self.sqlalchemy_session.close()

32 changes: 32 additions & 0 deletions lab2/GitLecture/dao/entities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Date, ForeignKey, Boolean, ForeignKeyConstraint, update, func
from sqlalchemy.orm import relationship

Base = declarative_base()

class User(Base):
__tablename__ = 'Users'

user_id = Column(Integer, primary_key=True, autoincrement=True)
user_login = Column(String(255), nullable=False)
user_url = Column(String(255), nullable=False)

user_lectures = relationship("Lecture")

class Subject(Base):
__tablename__ = 'Subjects'

subject_id = Column(Integer, primary_key=True, autoincrement=True)
subject_name = Column(String(255), nullable=False)
subject_description = Column(String(255), nullable=False)


class Lecture(Base):
__tablename__ = 'Lectures'

lecture_id = Column(Integer, primary_key = True, autoincrement=True)
lecture_name = Column(String(255), nullable=False)
gitgist_id = Column(String(255), nullable=False)
user_id_fk = Column(Integer, ForeignKey('Users.user_id'))
subject_id_fk = Column(Integer, ForeignKey('Subjects.subject_id'))

Binary file not shown.
60 changes: 60 additions & 0 deletions lab2/GitLecture/forms/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, DateField, HiddenField, PasswordField, SelectField, TextAreaField
from wtforms import validators
from datetime import date
from GitLecture.dao.entities import Subject
from GitLecture.dao.db import PostgresDb


class UserForm(FlaskForm):
user_id = HiddenField()

user_login = StringField("Login: ", [
validators.DataRequired("Please enter github login."),
validators.Length(3, 255, "Login should be from 3 to 255 symbols")
])

user_password = PasswordField("Password: ", [
validators.DataRequired("Please enter password."),
validators.Length(3, 255, "Should be from 3 to 255 symbols")
])

submit = SubmitField("Save")

class SubjectForm(FlaskForm):
subject_id = HiddenField()

subject_name = StringField("Subject name: ", [
validators.DataRequired("Please enter subject name."),
validators.Length(3, 255, "Login should be from 3 to 255 symbols")
])

subject_description = StringField("Subject description: ", [
validators.DataRequired("Please enter subject name."),
validators.Length(3, 255, "Login should be from 3 to 255 symbols")
])

class LectureForm(FlaskForm):
lecture_id = HiddenField()

lecture_name = StringField("Lecture name: ", [
validators.DataRequired("Please enter lecture name."),
validators.Length(3, 255, "Lecture name should be from 3 to 255 symbols")
])

user_name = StringField("Login: ", [
validators.DataRequired("Please enter user name."),
validators.Length(3, 255, "User name should be from 3 to 255 symbols")
])

user_password = PasswordField("Password: ", [
validators.DataRequired("Please enter password."),
validators.Length(3, 255, "Should be from 3 to 255 symbols")
])

subject = SelectField("Subject: ")

lecture_text = TextAreaField("Lecture text")

class DeleteForm(FlaskForm):
delete = HiddenField()
Loading