parent
7fcfafffdc
commit
d348025865
File diff suppressed because one or more lines are too long
@ -0,0 +1,214 @@
|
||||
-- phpMyAdmin SQL Dump
|
||||
-- version 5.2.1
|
||||
-- https://www.phpmyadmin.net/
|
||||
--
|
||||
-- Host: 172.20.0.2
|
||||
-- Generation Time: Jul 20, 2023 at 03:01 PM
|
||||
-- Server version: 10.4.28-MariaDB-1:10.4.28+maria~ubu2004
|
||||
-- PHP Version: 8.1.15
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
START TRANSACTION;
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
|
||||
--
|
||||
-- Database: `minibase_projects`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `market`
|
||||
--
|
||||
|
||||
CREATE TABLE `market` (
|
||||
`id` int(11) NOT NULL COMMENT 'primary key for thsi market',
|
||||
`name` varchar(50) NOT NULL COMMENT 'Name of the market',
|
||||
`upload_date` date NOT NULL DEFAULT current_timestamp(),
|
||||
`last_update_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp()
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `market`
|
||||
--
|
||||
|
||||
INSERT INTO `market` (`id`, `name`, `upload_date`, `last_update_date`) VALUES
|
||||
(1, 'Industrial', '2022-11-14', '2022-11-14 16:29:05'),
|
||||
(2, 'Medical', '2022-11-14', '2022-11-14 16:29:05');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `project`
|
||||
--
|
||||
|
||||
CREATE TABLE `project` (
|
||||
`id` int(11) NOT NULL,
|
||||
`name` varchar(150) NOT NULL,
|
||||
`description` varchar(500) NOT NULL,
|
||||
`upload_date` date NOT NULL DEFAULT current_timestamp(),
|
||||
`last_update_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp(),
|
||||
`project_owner_id` int(11) NOT NULL,
|
||||
`project_buyer_id` int(11) DEFAULT NULL,
|
||||
`date_prototype` date NOT NULL,
|
||||
`qte_prototype` int(11) NOT NULL,
|
||||
`date_production` date NOT NULL,
|
||||
`qte_production` int(11) NOT NULL,
|
||||
`qte_start` int(11) NOT NULL,
|
||||
`client_id` int(11) NOT NULL,
|
||||
`market_id` int(11) NOT NULL,
|
||||
`segment_id` int(11) NOT NULL,
|
||||
`internal_owner_id` int(11) NOT NULL,
|
||||
`inernal_sales_id` int(11) NOT NULL,
|
||||
`hierarchic_level` int(11) DEFAULT NULL,
|
||||
`part_of` int(11) DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `project`
|
||||
--
|
||||
|
||||
INSERT INTO `project` (`id`, `name`, `description`, `upload_date`, `last_update_date`, `project_owner_id`, `project_buyer_id`, `date_prototype`, `qte_prototype`, `date_production`, `qte_production`, `qte_start`, `client_id`, `market_id`, `segment_id`, `internal_owner_id`, `inernal_sales_id`, `hierarchic_level`, `part_of`) VALUES
|
||||
(1, 'STWA-HS', 'Spraying unit', '2022-11-14', '2022-11-14 16:56:44', 1, NULL, '2023-03-14', 2, '2023-11-14', 200000, 200000, 1, 1, 2, 2, 3, NULL, NULL);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `project_element`
|
||||
--
|
||||
|
||||
CREATE TABLE `project_element` (
|
||||
`id` int(11) NOT NULL,
|
||||
`name` varchar(75) NOT NULL,
|
||||
`description` varchar(300) NOT NULL,
|
||||
`upload_date` date NOT NULL DEFAULT current_timestamp(),
|
||||
`last_update_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp(),
|
||||
`comment` varchar(300) DEFAULT NULL,
|
||||
`qte_per_project` int(11) NOT NULL,
|
||||
`parent_project` int(11) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `project_element`
|
||||
--
|
||||
|
||||
INSERT INTO `project_element` (`id`, `name`, `description`, `upload_date`, `last_update_date`, `comment`, `qte_per_project`, `parent_project`) VALUES
|
||||
(1, 'Power Board', 'Power board for battery operation', '2022-11-14', '2022-11-14 17:19:16', NULL, 1, 1);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `segment`
|
||||
--
|
||||
|
||||
CREATE TABLE `segment` (
|
||||
`id` int(11) NOT NULL,
|
||||
`name` varchar(50) NOT NULL,
|
||||
`upload_date` date NOT NULL DEFAULT current_timestamp(),
|
||||
`last_update_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp()
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `segment`
|
||||
--
|
||||
|
||||
INSERT INTO `segment` (`id`, `name`, `upload_date`, `last_update_date`) VALUES
|
||||
(1, 'Mesurement', '2022-11-14', '2022-11-14 16:29:57'),
|
||||
(2, 'Automation', '2022-11-14', '2022-11-14 16:29:57');
|
||||
|
||||
--
|
||||
-- Indexes for dumped tables
|
||||
--
|
||||
|
||||
--
|
||||
-- Indexes for table `market`
|
||||
--
|
||||
ALTER TABLE `market`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `project`
|
||||
--
|
||||
ALTER TABLE `project`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD KEY `fk_market` (`market_id`),
|
||||
ADD KEY `fk_segment` (`segment_id`),
|
||||
ADD KEY `fk_project_owner` (`project_owner_id`),
|
||||
ADD KEY `fk_project_buyer` (`project_buyer_id`) USING BTREE,
|
||||
ADD KEY `fk_client` (`client_id`),
|
||||
ADD KEY `fk_int_responsible` (`internal_owner_id`),
|
||||
ADD KEY `fk_ext_responsible` (`inernal_sales_id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `project_element`
|
||||
--
|
||||
ALTER TABLE `project_element`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD KEY `fk_parent_project` (`parent_project`);
|
||||
|
||||
--
|
||||
-- Indexes for table `segment`
|
||||
--
|
||||
ALTER TABLE `segment`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for dumped tables
|
||||
--
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `market`
|
||||
--
|
||||
ALTER TABLE `market`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key for thsi market', AUTO_INCREMENT=3;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `project`
|
||||
--
|
||||
ALTER TABLE `project`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `project_element`
|
||||
--
|
||||
ALTER TABLE `project_element`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `segment`
|
||||
--
|
||||
ALTER TABLE `segment`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
|
||||
|
||||
--
|
||||
-- Constraints for dumped tables
|
||||
--
|
||||
|
||||
--
|
||||
-- Constraints for table `project`
|
||||
--
|
||||
ALTER TABLE `project`
|
||||
ADD CONSTRAINT `fk_client` FOREIGN KEY (`client_id`) REFERENCES `minibase_relationships`.`person` (`company`),
|
||||
ADD CONSTRAINT `fk_ext_responsible` FOREIGN KEY (`inernal_sales_id`) REFERENCES `minibase_relationships`.`person` (`id`),
|
||||
ADD CONSTRAINT `fk_int_responsible` FOREIGN KEY (`internal_owner_id`) REFERENCES `minibase_relationships`.`person` (`id`),
|
||||
ADD CONSTRAINT `fk_market` FOREIGN KEY (`market_id`) REFERENCES `market` (`id`),
|
||||
ADD CONSTRAINT `fk_project_buyer` FOREIGN KEY (`project_buyer_id`) REFERENCES `minibase_relationships`.`person` (`id`),
|
||||
ADD CONSTRAINT `fk_project_owner` FOREIGN KEY (`project_owner_id`) REFERENCES `minibase_relationships`.`person` (`id`),
|
||||
ADD CONSTRAINT `fk_segment` FOREIGN KEY (`segment_id`) REFERENCES `segment` (`id`);
|
||||
|
||||
--
|
||||
-- Constraints for table `project_element`
|
||||
--
|
||||
ALTER TABLE `project_element`
|
||||
ADD CONSTRAINT `fk_parent_project` FOREIGN KEY (`parent_project`) REFERENCES `project` (`id`);
|
||||
COMMIT;
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
@ -0,0 +1,233 @@
|
||||
-- phpMyAdmin SQL Dump
|
||||
-- version 5.2.1
|
||||
-- https://www.phpmyadmin.net/
|
||||
--
|
||||
-- Host: 172.20.0.2
|
||||
-- Generation Time: Jul 20, 2023 at 03:02 PM
|
||||
-- Server version: 10.4.28-MariaDB-1:10.4.28+maria~ubu2004
|
||||
-- PHP Version: 8.1.15
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
START TRANSACTION;
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
|
||||
--
|
||||
-- Database: `minibase_relationships`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `company`
|
||||
--
|
||||
|
||||
CREATE TABLE `company` (
|
||||
`id` int(11) NOT NULL,
|
||||
`upload_date` date NOT NULL DEFAULT current_timestamp(),
|
||||
`last_update_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp(),
|
||||
`name` varchar(100) NOT NULL,
|
||||
`corporation_type` varchar(50) NOT NULL,
|
||||
`role` int(11) NOT NULL,
|
||||
`country_bill` varchar(100) NOT NULL,
|
||||
`state_bill` varchar(100) NOT NULL,
|
||||
`city_bill` varchar(100) NOT NULL,
|
||||
`postal_code_bill` int(11) NOT NULL,
|
||||
`street_bill` varchar(100) NOT NULL,
|
||||
`street_no_bill` int(11) NOT NULL,
|
||||
`country_ship` varchar(100) NOT NULL,
|
||||
`state_ship` varchar(100) NOT NULL,
|
||||
`city_ship` varchar(100) NOT NULL,
|
||||
`postal_code_ship` int(11) NOT NULL,
|
||||
`street_ship` varchar(100) NOT NULL,
|
||||
`street_no_ship` int(11) NOT NULL,
|
||||
`main_comapany` tinyint(1) NOT NULL DEFAULT 1,
|
||||
`subsidiary_of` int(11) DEFAULT NULL,
|
||||
`classification` int(11) NOT NULL,
|
||||
`comment` varchar(300) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `company`
|
||||
--
|
||||
|
||||
INSERT INTO `company` (`id`, `upload_date`, `last_update_date`, `name`, `corporation_type`, `role`, `country_bill`, `state_bill`, `city_bill`, `postal_code_bill`, `street_bill`, `street_no_bill`, `country_ship`, `state_ship`, `city_ship`, `postal_code_ship`, `street_ship`, `street_no_ship`, `main_comapany`, `subsidiary_of`, `classification`, `comment`) VALUES
|
||||
(1, '2022-08-17', '0000-00-00 00:00:00', 'Steinel Solutions', 'AG', 4, 'Switzerland', 'Schwyz', 'Einsiedeln', 8840, 'Allmeindstrasse', 10, 'Switzerland', 'Schwyz', 'Einsiedeln', 8840, 'Allmeindstrasse', 10, 1, 5, 0, 'Main STM Client'),
|
||||
(5, '2022-10-03', '0000-00-00 00:00:00', 'Steinel Vertrieb', 'GmbH', 3, 'Germany', '', 'Herzebrock-Clarholz', 33442, 'Dieselstrasse', 80, 'Germany', '', 'Herzebrock-Clarholz', 33442, 'Dieselstrasse', 80, 1, NULL, 0, 'OEM PArt of Steinel solutions'),
|
||||
(6, '2022-10-03', '0000-00-00 00:00:00', 'Steinel Technik', 's.r.o', 1, 'Czechia', '', 'Liberec', 46001, 'Rumunská', 655, 'Czechia', '', 'Liberec', 46001, 'Rumunská', 655, 1, 5, 0, 'Production site of Steinel in Czechia'),
|
||||
(7, '2022-11-14', '2022-11-14 16:49:15', 'Solutioneer', 'NU', 6, 'Schweiz', 'Zürich', 'Uster', 8610, 'Meirackerstrasse', 10, 'Switzerland', 'Zürich', 'Uster', 8610, 'Meirackerstrasse', 10, 1, NULL, 1, 'The main organisation');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `company_role`
|
||||
--
|
||||
|
||||
CREATE TABLE `company_role` (
|
||||
`id` int(11) NOT NULL,
|
||||
`name` varchar(50) NOT NULL,
|
||||
`description` varchar(300) NOT NULL,
|
||||
`reference` varchar(20) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `company_role`
|
||||
--
|
||||
|
||||
INSERT INTO `company_role` (`id`, `name`, `description`, `reference`) VALUES
|
||||
(1, 'EMS', 'Electronics manufacturing services', 'EMS'),
|
||||
(2, 'Desing Partner', 'Desing partner for other clients', 'DP'),
|
||||
(3, 'OEM', 'Original Equipment Manufacturer', 'OEM'),
|
||||
(4, 'Engineering', 'Engineering Partner for custommer', 'EP'),
|
||||
(6, 'Owner', 'We are the firm', 'OWNER');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `person`
|
||||
--
|
||||
|
||||
CREATE TABLE `person` (
|
||||
`id` int(11) NOT NULL,
|
||||
`name` varchar(50) NOT NULL,
|
||||
`last_name` varchar(50) NOT NULL,
|
||||
`date_of_birth` date NOT NULL,
|
||||
`role` int(11) NOT NULL,
|
||||
`company` int(11) DEFAULT NULL,
|
||||
`tel_prof_fix` varchar(30) DEFAULT NULL,
|
||||
`tel_prof_mobile` varchar(30) DEFAULT NULL,
|
||||
`tel_priv_fix` varchar(30) DEFAULT NULL,
|
||||
`tel_priv_mobile` varchar(30) DEFAULT NULL,
|
||||
`mail_prof` varchar(320) NOT NULL,
|
||||
`mail_priv` varchar(320) DEFAULT NULL,
|
||||
`country` varchar(75) NOT NULL,
|
||||
`state` varchar(75) DEFAULT NULL,
|
||||
`city` varchar(75) DEFAULT NULL,
|
||||
`post_code` varchar(10) DEFAULT NULL,
|
||||
`street_name` varchar(150) DEFAULT NULL,
|
||||
`street_no` int(11) DEFAULT NULL,
|
||||
`upload_date` date NOT NULL DEFAULT current_timestamp(),
|
||||
`last_update_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp()
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `person`
|
||||
--
|
||||
|
||||
INSERT INTO `person` (`id`, `name`, `last_name`, `date_of_birth`, `role`, `company`, `tel_prof_fix`, `tel_prof_mobile`, `tel_priv_fix`, `tel_priv_mobile`, `mail_prof`, `mail_priv`, `country`, `state`, `city`, `post_code`, `street_name`, `street_no`, `upload_date`, `last_update_date`) VALUES
|
||||
(1, 'Stefan', 'Walker', '1980-11-01', 1, 1, '+41 876 45 35', '+41 876 45 45', NULL, NULL, 'stefan.walker@steinel.ch', NULL, '', NULL, NULL, NULL, NULL, NULL, '2022-11-14', '2022-11-14 16:23:49'),
|
||||
(2, 'Kerem', 'Yollu', '1991-09-24', 2, 7, NULL, '+41 78 97 166 97', NULL, NULL, 'kerem.yollu@solutioneer.ch', 'Kerem.yollu@gmail.com', 'Switzerland', 'Zürich', 'Uster', '8610', 'Meirackerstrasse', 10, '2022-11-14', '2022-11-14 16:07:38'),
|
||||
(3, 'Martina', 'Landolt', '1985-12-30', 3, 7, '+41 555 45 56', NULL, NULL, NULL, 'martina.landolt@solutioneer.ch', NULL, '', NULL, NULL, NULL, NULL, NULL, '2022-11-14', '2022-11-14 16:04:13');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `person_role`
|
||||
--
|
||||
|
||||
CREATE TABLE `person_role` (
|
||||
`id` int(11) NOT NULL,
|
||||
`name` varchar(50) NOT NULL,
|
||||
`description` varchar(300) NOT NULL,
|
||||
`reference` varchar(20) NOT NULL,
|
||||
`upload_date` date NOT NULL DEFAULT current_timestamp(),
|
||||
`last_update_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp()
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `person_role`
|
||||
--
|
||||
|
||||
INSERT INTO `person_role` (`id`, `name`, `description`, `reference`, `upload_date`, `last_update_date`) VALUES
|
||||
(1, 'Egineering Manager', 'Manages the engineering team', 'Engineering', '2022-11-14', '2022-11-14 15:25:58'),
|
||||
(2, 'CEO', 'Chief Executif Officer', 'Management', '2022-11-14', '2022-11-14 17:01:28'),
|
||||
(3, 'FAE', 'Field Application Engineer', 'Engineering', '2022-11-14', '2022-11-14 17:01:28'),
|
||||
(4, 'FSE', 'Field Sales Engineer', 'Sales', '2022-11-14', '2022-11-14 17:02:50');
|
||||
|
||||
--
|
||||
-- Indexes for dumped tables
|
||||
--
|
||||
|
||||
--
|
||||
-- Indexes for table `company`
|
||||
--
|
||||
ALTER TABLE `company`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD KEY `fk_client_role` (`role`) USING BTREE,
|
||||
ADD KEY `fk_subsidiary` (`subsidiary_of`);
|
||||
|
||||
--
|
||||
-- Indexes for table `company_role`
|
||||
--
|
||||
ALTER TABLE `company_role`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `person`
|
||||
--
|
||||
ALTER TABLE `person`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD KEY `fk_role` (`role`),
|
||||
ADD KEY `fk_company` (`company`);
|
||||
|
||||
--
|
||||
-- Indexes for table `person_role`
|
||||
--
|
||||
ALTER TABLE `person_role`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for dumped tables
|
||||
--
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `company`
|
||||
--
|
||||
ALTER TABLE `company`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `company_role`
|
||||
--
|
||||
ALTER TABLE `company_role`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `person`
|
||||
--
|
||||
ALTER TABLE `person`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `person_role`
|
||||
--
|
||||
ALTER TABLE `person_role`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
|
||||
|
||||
--
|
||||
-- Constraints for dumped tables
|
||||
--
|
||||
|
||||
--
|
||||
-- Constraints for table `company`
|
||||
--
|
||||
ALTER TABLE `company`
|
||||
ADD CONSTRAINT `fk_client_role` FOREIGN KEY (`role`) REFERENCES `company_role` (`id`),
|
||||
ADD CONSTRAINT `fk_subsidiary` FOREIGN KEY (`subsidiary_of`) REFERENCES `company` (`id`);
|
||||
|
||||
--
|
||||
-- Constraints for table `person`
|
||||
--
|
||||
ALTER TABLE `person`
|
||||
ADD CONSTRAINT `fk_company` FOREIGN KEY (`company`) REFERENCES `company` (`id`),
|
||||
ADD CONSTRAINT `fk_role` FOREIGN KEY (`role`) REFERENCES `person_role` (`id`);
|
||||
COMMIT;
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
@ -1,78 +0,0 @@
|
||||
import dbCommands as db
|
||||
|
||||
#Connect to the database
|
||||
cursor = db.connect("minibase_projects")
|
||||
|
||||
# This list must represent what the database contains as tables.
|
||||
# Chnages in the databse structure must be reflected here
|
||||
tables = ["market", "project", "project_element", "segment"]
|
||||
|
||||
#Tables with the main element of database table.
|
||||
tablesColumnNames = [] #name of each column of the table
|
||||
tablesPrimaryKeys = [] #Primary key of each table
|
||||
tablesForeignKeys = [] #Foreign keys of the table (this is a relational database)
|
||||
|
||||
#Initialise tables wiht information on the server! This will drastically hep reduce server
|
||||
#Requests jus for table indformations
|
||||
for table in tables:
|
||||
buffer = db.getColumnNames(cursor, table)
|
||||
tablesColumnNames.append(buffer)
|
||||
|
||||
buffer = db.getPrimaryKey(cursor, table)
|
||||
tablesPrimaryKeys.append(buffer)
|
||||
|
||||
buffer = db.getForeignKeys(cursor, table)
|
||||
tablesForeignKeys.append(buffer)
|
||||
|
||||
|
||||
#Get the tables contained in this database
|
||||
def getTables():
|
||||
return tables
|
||||
|
||||
#Get the foreign keys list of the given table
|
||||
def getForeignKeys(table):
|
||||
return(tablesForeignKeys[tables.index(table)])
|
||||
|
||||
#Get the amount of foreign key of the given table
|
||||
def getForeignKeyCount(table):
|
||||
return(len(tablesForeignKeys[tables.index(table)]))
|
||||
|
||||
#Get the index of a foreign key's name contained in the given table
|
||||
def getForeignKeyIndex(table, keyName):
|
||||
return(tablesForeignKeys[tables.index(table)].index(keyName))
|
||||
|
||||
#Get the name of a foreign key's index contained in the given table
|
||||
def getForeignKeyName(table, keyIndex):
|
||||
return(tablesForeignKeys[tables.index(table)][keyIndex])
|
||||
|
||||
#Get the primary key's name of the given table
|
||||
def getPrimaryKey(table):
|
||||
return(tablesPrimaryKeys[tables.index(table)])
|
||||
|
||||
#Get the column Names list of the given table
|
||||
def getColumnNames(table):
|
||||
return(tablesColumnNames[tables.index(table)])
|
||||
|
||||
#Get the amount of column's of the given table
|
||||
def getColumnCount(table):
|
||||
return(len(tablesColumnNames[tables.index(table)]))
|
||||
|
||||
#Get the index of a column's name contained in the given table
|
||||
def getColumnNameIndex(table, columnName):
|
||||
return(tablesColumnNames[tables.index(table)].index(columnName))
|
||||
|
||||
#Get the name of a columns's index contained in the given table
|
||||
def getColumnName(table, columnIndex):
|
||||
return(tablesColumnNames[tables.index(table)][columnIndex])
|
||||
|
||||
def printTablesInfo():
|
||||
for table in getTables():
|
||||
print( "Table: " + table)
|
||||
print( " - Primary Key : " + getPrimaryKey(table))
|
||||
for column in getColumnNames(table):
|
||||
print( " - Colum: " + column)
|
||||
for key in getForeignKeys(table):
|
||||
print( " - Foreign Key : " + key)
|
||||
|
||||
printTablesInfo()
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,102 @@
|
||||
# Based on https://mariadb.com/resources/blog/how-to-connect-python-programs-to-mariadb/
|
||||
import mariadb
|
||||
import sys
|
||||
import datetime
|
||||
#stores current time
|
||||
currentTime = datetime.datetime.now()
|
||||
|
||||
#Connects to the databse
|
||||
def connect(dbName):
|
||||
# Connect to MariaDB Platform
|
||||
try:
|
||||
conn = mariadb.connect(
|
||||
user="root",
|
||||
password="KyKvMdRt586591!*",
|
||||
host="db.keydev.me",
|
||||
port=3306,
|
||||
database=dbName
|
||||
)
|
||||
print(type(conn))
|
||||
except mariadb.Error as e:
|
||||
print(f"Error connecting to MariaDB Platform: {e}")
|
||||
return e
|
||||
sys.exit(1)
|
||||
|
||||
conn.autocommit = False
|
||||
return conn
|
||||
|
||||
#Get all the column naes of the given table
|
||||
def getColumnNames(cursor, table):
|
||||
command = "SHOW COLUMNS FROM " + table
|
||||
cursor.execute(command)
|
||||
colName = []
|
||||
index = 0
|
||||
for row in cursor:
|
||||
colName.append(row[0])
|
||||
return colName
|
||||
|
||||
#Gets all the Foreign Keys of the given table
|
||||
def getForeignKeys(cursor, table):
|
||||
command = "SHOW INDEX FROM " + table
|
||||
cursor.execute(command)
|
||||
colName = []
|
||||
index = 0
|
||||
for row in cursor:
|
||||
if not row[2] == "PRIMARY":
|
||||
colName.append(row[4])
|
||||
return colName
|
||||
|
||||
#Gets all the Primary Keys of the given table
|
||||
def getPrimaryKey(cursor, table):
|
||||
command = "SHOW INDEX FROM " + table
|
||||
cursor.execute(command)
|
||||
index = 0
|
||||
for row in cursor:
|
||||
if row[2] == "PRIMARY":
|
||||
pk = row[4]
|
||||
return pk
|
||||
|
||||
#Returns all the raws of the desired columns from the selected table
|
||||
def select(cursor,table,columns):
|
||||
buffer=[]
|
||||
command = "SELECT "+columns+" FROM "+table
|
||||
|
||||
try:
|
||||
cursor.execute(command)
|
||||
except mariadb.Error as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
for row in cursor:
|
||||
buffer.append(row)
|
||||
return buffer
|
||||
|
||||
#Returns the rows coreponding to the WHERE condition and desired colums from the selected table
|
||||
#If no data is to be fount the function returns 0
|
||||
def selectWhere(cursor,table,columns,where,equals):
|
||||
buffer=[]
|
||||
command = "SELECT "+columns+" FROM "+table+" WHERE "+where+"='"+equals+"'"
|
||||
print(command)
|
||||
try:
|
||||
cursor.execute(command)
|
||||
except mariadb.Error as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
for row in cursor:
|
||||
buffer.append(row)
|
||||
if len(buffer) == 0:
|
||||
return 0
|
||||
else:
|
||||
return buffer
|
||||
|
||||
def insert(cursor,table,column,data):
|
||||
command = "INSERT INTO "+table+" ("+column+") VALUES ("+data+")"
|
||||
try:
|
||||
cursor.execute(command)
|
||||
except mariadb.Error as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
def update(cursor,table,data,where,equals):
|
||||
command = "INSERT INTO "+table+" ("+column+") VALUES ("+data+")"
|
||||
|
||||
def delete(cursor,table,column):
|
||||
command = "INSERT INTO "+table+" ("+column+") VALUES ("+data+")"
|
@ -0,0 +1,125 @@
|
||||
import dbCommands as db
|
||||
|
||||
###################################################################################################
|
||||
# VARIABLES
|
||||
####################################################################################################
|
||||
|
||||
# This list must represent what the database contains as tables.
|
||||
connection = db.mariadb.connections.Connection
|
||||
cursor = db.mariadb.cursors.Cursor
|
||||
|
||||
# Chnages in the databse structure must be reflected here
|
||||
tables = ["market", "project", "project_element", "segment"]
|
||||
|
||||
#Tables with the main element of database table.
|
||||
tablesColumnNames = [] #name of each column of the table
|
||||
tablesPrimaryKeys = [] #Primary key of each table
|
||||
tablesForeignKeys = [] #Foreign keys of the table (this is a relational database)
|
||||
|
||||
####################################################################################################
|
||||
# INTIALISATION
|
||||
####################################################################################################
|
||||
|
||||
####################################################################################################
|
||||
# COMMON FUNCTIONS
|
||||
####################################################################################################
|
||||
#Connect
|
||||
def connect():
|
||||
#Connect to the database
|
||||
connection = db.connect("minibase_projects")
|
||||
cursor = connection.cursor()
|
||||
#Initialise tables wiht information on the server! This will drastically hep reduce server
|
||||
#Requests jus for table indformations
|
||||
for table in tables:
|
||||
buffer = db.getColumnNames(cursor, table)
|
||||
tablesColumnNames.append(buffer)
|
||||
|
||||
buffer = db.getPrimaryKey(cursor, table)
|
||||
tablesPrimaryKeys.append(buffer)
|
||||
|
||||
buffer = db.getForeignKeys(cursor, table)
|
||||
tablesForeignKeys.append(buffer)
|
||||
|
||||
#Get the tables contained in this database
|
||||
def getTables():
|
||||
return tables
|
||||
|
||||
#Get the foreign keys list of the given table
|
||||
def getForeignKeys(table):
|
||||
return(tablesForeignKeys[tables.index(table)])
|
||||
|
||||
#Get the amount of foreign key of the given table
|
||||
def getForeignKeyCount(table):
|
||||
return(len(tablesForeignKeys[tables.index(table)]))
|
||||
|
||||
#Get the index of a foreign key's name contained in the given table
|
||||
def getForeignKeyIndex(table, keyName):
|
||||
return(tablesForeignKeys[tables.index(table)].index(keyName))
|
||||
|
||||
#Get the name of a foreign key's index contained in the given table
|
||||
def getForeignKeyName(table, keyIndex):
|
||||
return(tablesForeignKeys[tables.index(table)][keyIndex])
|
||||
|
||||
#Get the primary key's name of the given table
|
||||
def getPrimaryKey(table):
|
||||
return(tablesPrimaryKeys[tables.index(table)])
|
||||
|
||||
#Get the column Names list of the given table
|
||||
def getColumnNames(table):
|
||||
return(tablesColumnNames[tables.index(table)])
|
||||
|
||||
#Get the amount of column's of the given table
|
||||
def getColumnCount(table):
|
||||
return(len(tablesColumnNames[tables.index(table)]))
|
||||
|
||||
#Get the index of a column's name contained in the given table
|
||||
def getColumnNameIndex(table, columnName):
|
||||
return(tablesColumnNames[tables.index(table)].index(columnName))
|
||||
|
||||
#Get the name of a columns's index contained in the given table
|
||||
def getColumnName(table, columnIndex):
|
||||
return(tablesColumnNames[tables.index(table)][columnIndex])
|
||||
|
||||
def commit():
|
||||
connection.commit()
|
||||
|
||||
def close():
|
||||
connection.close()
|
||||
return 0
|
||||
|
||||
def getDataTable(table):
|
||||
tableData = db.select(cursor,table,"*")
|
||||
return tableData
|
||||
|
||||
def getDataTableRowsByName(table, rowName):
|
||||
tableData = db.selectWhere(cursor,table,"*","name",rowName)
|
||||
|
||||
def getDataTableRowsById(table, rowId):
|
||||
tableData = db.selectWhere(cursor,table,"*","id",str(rowId))
|
||||
|
||||
####################################################################################################
|
||||
# DEBUG FUNCTIONS
|
||||
####################################################################################################
|
||||
def printTablesInfo():
|
||||
for table in getTables():
|
||||
print( "Table: " + table)
|
||||
print( " - Primary Key : " + getPrimaryKey(table))
|
||||
for column in getColumnNames(table):
|
||||
print( " - Colum: " + column)
|
||||
for key in getForeignKeys(table):
|
||||
print( " - Foreign Key : " + key)
|
||||
|
||||
####################################################################################################
|
||||
# TABLE SPECIFIC FUNCTIONS
|
||||
####################################################################################################
|
||||
def insertMarket(name):
|
||||
command="'"+name+"', '"+str(db.currentTime)+"'"
|
||||
db.insert(cursor,"market", "name, upload_date",command)
|
||||
commit()
|
||||
|
||||
#getDataTable("market")
|
||||
#getDataTableRowsByName(tables[0],"Industrial")
|
||||
#getDataTableRowsById(tables[0],19)
|
||||
|
||||
#commit()
|
||||
#close()
|
@ -0,0 +1,15 @@
|
||||
from flask import Flask
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_bcrypt import Bcrypt
|
||||
from flask_login import LoginManager
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = '57636aef33666affr6'
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
|
||||
db = SQLAlchemy(app)
|
||||
bcrypt = Bcrypt(app)
|
||||
login_manager = LoginManager(app)
|
||||
login_manager.login_view = 'login'
|
||||
login_manager.login_message_category = 'info'
|
||||
|
||||
from minibase import route
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,55 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_wtf.file import FileField, FileAllowed
|
||||
from flask_login import current_user
|
||||
from wtforms import StringField, PasswordField, SubmitField, BooleanField, TextAreaField
|
||||
from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError
|
||||
from minibase.models import User
|
||||
|
||||
class registrationForm(FlaskForm):
|
||||
username = StringField('User Name', validators=[DataRequired(),Length(min = 3, max = 20)])
|
||||
email = StringField('Email', validators=[DataRequired(),Email()])
|
||||
password = PasswordField('Password', validators=[DataRequired()])
|
||||
password_confirm = PasswordField('Confirm Password', validators=[DataRequired(), EqualTo('password')])
|
||||
submit = SubmitField('Sing Up')
|
||||
|
||||
def validate_username(self, username):
|
||||
user = User.query.filter_by(username=username.data).first()
|
||||
if user:
|
||||
raise ValidationError('That username is taken please choose another one')
|
||||
|
||||
def validate_email(self, email):
|
||||
email = User.query.filter_by(email=email.data).first()
|
||||
if email:
|
||||
raise ValidationError('That email is taken do you have an acocunt ?')
|
||||
|
||||
class loginForm(FlaskForm):
|
||||
email = StringField('Email',validators=[DataRequired(),Email()])
|
||||
password = PasswordField('Password',validators=[DataRequired()])
|
||||
remember = BooleanField('Remember Me')
|
||||
submit = SubmitField('Log In')
|
||||
|
||||
class updateAccountForm(FlaskForm):
|
||||
username = StringField('User Name',
|
||||
validators=[DataRequired(),Length(min = 3, max = 20)])
|
||||
email = StringField('Email',
|
||||
validators=[DataRequired(),Email()])
|
||||
picture = FileField('Update Profile Picture',
|
||||
validators=[FileAllowed(['jpg','png'])])
|
||||
submit = SubmitField('Update')
|
||||
|
||||
def validate_username(self, username):
|
||||
if username.data != current_user.username:
|
||||
user = User.query.filter_by(username=username.data).first()
|
||||
if user:
|
||||
raise ValidationError('That username is taken please choose another one')
|
||||
|
||||
def validate_email(self, email):
|
||||
if email.data != current_user.email:
|
||||
email = User.query.filter_by(email=email.data).first()
|
||||
if email:
|
||||
raise ValidationError('That email is taken do you have an acocunt ?')
|
||||
|
||||
class postForm(FlaskForm):
|
||||
title = StringField('Title', validators=[DataRequired(),Length(min = 3, max = 100)])
|
||||
content = TextAreaField('Content', validators=[DataRequired()])
|
||||
submit = SubmitField('Post')
|
@ -0,0 +1,28 @@
|
||||
from datetime import datetime
|
||||
from minibase import db, login_manager
|
||||
from flask_login import UserMixin
|
||||
|
||||
@login_manager.user_loader
|
||||
def load_user(user_id):
|
||||
return User.query.get(int(user_id))
|
||||
|
||||
class User(db.Model, UserMixin):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
username = db.Column(db.String(20), unique=True, nullable=False)
|
||||
email = db.Column(db.String(120), unique=True, nullable=False)
|
||||
image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
|
||||
password = db.Column(db.String(60), nullable=False)
|
||||
posts = db.relationship('Post', backref='author', lazy=True)
|
||||
|
||||
def __repr__(self):
|
||||
return f"User('{self.username}', '{self.email}', '{self.image_file}')"
|
||||
|
||||
class Post(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
title = db.Column(db.String(100), nullable=False)
|
||||
date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
||||
content = db.Column(db.Text, nullable=False)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
|
||||
|
||||
def __repr__(self):
|
||||
return f"User('{self.title}', '{self.date_posted}')"
|
@ -0,0 +1,143 @@
|
||||
import os
|
||||
import secrets
|
||||
from PIL import Image
|
||||
from flask import render_template, url_for, flash, redirect, request, abort
|
||||
from minibase import app, db, bcrypt
|
||||
from minibase.forms import registrationForm, loginForm, updateAccountForm, postForm
|
||||
from minibase.models import User, Post
|
||||
from flask_login import login_user, current_user, logout_user, login_required
|
||||
|
||||
|
||||
#Redirect from / and also /home routes to the /
|
||||
@app.route("/")
|
||||
@app.route("/home")
|
||||
def home():
|
||||
page = request.args.get('page', 1, type=int)
|
||||
posts = Post.query.order_by(Post.date_posted.asc()).paginate(per_page=2)
|
||||
return render_template('home.html', posts=posts)
|
||||
|
||||
|
||||
@app.route("/about")
|
||||
def about():
|
||||
return render_template('about.html', title='About')
|
||||
|
||||
@app.route("/register", methods=['GET', 'POST'])
|
||||
def register():
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for('home'))
|
||||
|
||||
form = registrationForm()
|
||||
if form.validate_on_submit():
|
||||
hashed_pw = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
|
||||
user = User(username=form.username.data, email=form.email.data, password=hashed_pw)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
flash(f'Your account has benn created you can now log in!','success')
|
||||
return redirect(url_for('home'))
|
||||
|
||||
return render_template('register.html', title='Register', form=form)
|
||||
|
||||
@app.route("/login", methods=['GET', 'POST'])
|
||||
def login():
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for('home'))
|
||||
form = loginForm()
|
||||
if form.validate_on_submit():
|
||||
user = User.query.filter_by(email=form.email.data).first()
|
||||
if user and bcrypt.check_password_hash(user.password, form.password.data):
|
||||
login_user(user,remember=form.remember.data)
|
||||
next_page = request.args.get('next')
|
||||
return redirect(next_page) if next_page else redirect(url_for('home'))
|
||||
else:
|
||||
flash('Login unsuccessful. Please chek your Email and Password!','danger')
|
||||
return render_template('login.html', title='Login', form=form)
|
||||
|
||||
@app.route("/logout")
|
||||
def logout():
|
||||
logout_user()
|
||||
return redirect(url_for('home'))
|
||||
|
||||
def save_picture(form_picture):
|
||||
random_hex = secrets.token_hex(8)
|
||||
_, f_ext =os.path.splitext(form_picture.filename)
|
||||
picture_fn = random_hex + f_ext
|
||||
picture_path = os.path.join(app.root_path, 'static/pics', picture_fn)
|
||||
output_size = (125,125)
|
||||
i = Image.open(form_picture)
|
||||
i.thumbnail(output_size)
|
||||
i.save(picture_path)
|
||||
return picture_fn
|
||||
|
||||
@app.route("/account", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def account():
|
||||
form = updateAccountForm()
|
||||
if form.validate_on_submit():
|
||||
if form.picture.data:
|
||||
picture_file = save_picture(form.picture.data)
|
||||
current_user.image_file = picture_file
|
||||
current_user.username = form.username.data
|
||||
current_user.email = form.email.data
|
||||
db.session.commit()
|
||||
flash('Your account has been updated!', 'success')
|
||||
return redirect(url_for('account'))
|
||||
elif request.method == 'GET':
|
||||
form.username.data = current_user.username
|
||||
form.email.data = current_user.email
|
||||
image_file = url_for('static', filename='pics/'+ current_user.image_file)
|
||||
return render_template('account.html', title='Account', image_file = image_file, form=form)
|
||||
|
||||
@app.route("/post/new", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def new_post():
|
||||
form = postForm()
|
||||
if form.validate_on_submit():
|
||||
post = Post(title=form.title.data, content=form.content.data, author=current_user)
|
||||
db.session.add(post)
|
||||
db.session.commit()
|
||||
flash('Your post has been created', 'success')
|
||||
return redirect(url_for('home'))
|
||||
return render_template('create_post.html', title='Create Post', legend='Create Post', form=form)
|
||||
|
||||
@app.route("/post/<int:post_id>")
|
||||
def post(post_id):
|
||||
post = Post.query.get_or_404(post_id)
|
||||
return render_template('post.html', title=post.title, post=post)
|
||||
|
||||
@app.route("/post/<int:post_id>/update", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def post_update(post_id):
|
||||
post = Post.query.get_or_404(post_id)
|
||||
if post.author != current_user:
|
||||
abort(403)
|
||||
form = postForm()
|
||||
if form.validate_on_submit():
|
||||
post.title = form.title.data
|
||||
post.content = form.content.data
|
||||
db.session.commit()
|
||||
flash('Your post has been updated', 'success')
|
||||
return redirect(url_for('post', post_id=post.id))
|
||||
elif request.method == 'GET':
|
||||
form.title.data = post.title
|
||||
form.content.data = post.content
|
||||
return render_template('create_post.html', title='Update Post', legend='Update Post', form=form)
|
||||
|
||||
@app.route("/post/<int:post_id>/delete", methods=['POST'])
|
||||
@login_required
|
||||
def post_delete(post_id):
|
||||
post = Post.query.get_or_404(post_id)
|
||||
if post.author != current_user:
|
||||
abort(403)
|
||||
db.session.delete(post)
|
||||
db.session.commit()
|
||||
flash('Your post has been deleted', 'success')
|
||||
return redirect(url_for('home'))
|
||||
|
||||
@app.route("/user/<string:username>")
|
||||
def user_posts(username):
|
||||
user = User.query.filter_by(username=username).first_or_404()
|
||||
page = request.args.get('page', 1, type=int)
|
||||
posts = Post.query.filter_by(author=user)\
|
||||
.order_by(Post.date_posted.asc())\
|
||||
.paginate(page=page, per_page=2)
|
||||
return render_template('user_posts.html', posts=posts, user=user)
|
Binary file not shown.
@ -0,0 +1,80 @@
|
||||
body {
|
||||
background: #fafafa;
|
||||
color: #333333;
|
||||
margin-top: 5rem;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
color: #444444;
|
||||
}
|
||||
|
||||
.bg-steel {
|
||||
background-color: #5f788a;
|
||||
}
|
||||
|
||||
.site-header .navbar-nav .nav-link {
|
||||
color: #cbd5db;
|
||||
}
|
||||
|
||||
.site-header .navbar-nav .nav-link:hover {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.site-header .navbar-nav .nav-link.active {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.content-section {
|
||||
background: #ffffff;
|
||||
padding: 10px 20px;
|
||||
border: 1px solid #dddddd;
|
||||
border-radius: 3px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.article-title {
|
||||
color: #444444;
|
||||
}
|
||||
|
||||
a.article-title:hover {
|
||||
color: #428bca;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.article-content {
|
||||
white-space: pre-line;
|
||||
}
|
||||
|
||||
.article-img {
|
||||
height: 65px;
|
||||
width: 65px;
|
||||
margin-right: 16px;
|
||||
}
|
||||
|
||||
.article-metadata {
|
||||
padding-bottom: 1px;
|
||||
margin-bottom: 4px;
|
||||
border-bottom: 1px solid #e3e3e3
|
||||
}
|
||||
|
||||
.article-metadata a:hover {
|
||||
color: #333;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.article-svg {
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.account-img {
|
||||
height: 125px;
|
||||
width: 125px;
|
||||
margin-right: 20px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.account-heading {
|
||||
font-size: 2.5rem;
|
||||
}
|
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 364 KiB |
After Width: | Height: | Size: 11 KiB |
@ -0,0 +1,5 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>About Page</h1>
|
||||
{% endblock content %}
|
@ -0,0 +1,60 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<div class="content-section">
|
||||
<div class="media">
|
||||
<img class="rounded-circle account-img" src="{{ image_file }}">
|
||||
<div class="media-body">
|
||||
<h2 class="account-heading">{{ current_user.username }}</h2>
|
||||
<p class="text-secondary">{{ current_user.email }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<form method="POST" action="" enctype="multipart/form-data">
|
||||
{{ form.hidden_tag() }}
|
||||
<fieldset class="form-group">
|
||||
<legend class="border-bottom mb-4"> Account Info </legend>
|
||||
<div class="form-group">
|
||||
{{ form.username.label(class="form-control-label") }}
|
||||
|
||||
{% if form.username.errors %}
|
||||
{{ form.username(class="form-control form-control-lg is-invalid") }}
|
||||
<div class="invalid-feedback">
|
||||
{% for error in form.username.errors %}
|
||||
<span>{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form.username(class="form-control form-control-lg") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</br>
|
||||
<div class="form-group">
|
||||
{{ form.email.label(class="form-control-label") }}
|
||||
{% if form.email.errors %}
|
||||
{{ form.email(class="form-control form-control-lg is-invalid") }}
|
||||
<div class="invalid-feedback">
|
||||
{% for error in form.email.errors %}
|
||||
<span>{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form.email(class="form-control form-control-lg") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</br>
|
||||
<div class="form-group">
|
||||
{{ form.picture.label() }} </br>
|
||||
{{ form.picture(class="form-control-file") }}</br>
|
||||
{% if form.picture.errors %}
|
||||
{% for error in form.picture.errors %}
|
||||
<span class="text-danger">{{ error }}</span></br>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</br>
|
||||
</fieldset>
|
||||
<div class="form-group">
|
||||
{{ form.submit(class="btn btn-outline-info") }}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock content %}
|
@ -0,0 +1,40 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<div class="content-section">
|
||||
<form method="POST" action="">
|
||||
{{ form.hidden_tag() }}
|
||||
<fieldset class="form-group">
|
||||
<legend class="border-bottom mb-4">{{ legend }}</legend>
|
||||
<div class="form-group">
|
||||
{{ form.title.label(class="form-control-label") }}
|
||||
{% if form.title.errors %}
|
||||
{{ form.title(class="form-control form-control-lg is-invalid") }}
|
||||
<div class="invalid-feedback">
|
||||
{% for error in form.title.errors %}
|
||||
<span>{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form.title(class="form-control form-control-lg") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.content.label(class="form-control-label") }}
|
||||
{% if form.content.errors %}
|
||||
{{ form.content(class="form-control form-control-lg is-invalid") }}
|
||||
<div class="invalid-feedback">
|
||||
{% for error in form.content.errors %}
|
||||
<span>{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form.content(class="form-control form-control-lg") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="form-group">
|
||||
{{ form.submit(class="btn btn-outline-info") }}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock content %}
|
@ -0,0 +1,28 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% for post in posts.items %}
|
||||
<article class="media content-section">
|
||||
<img class="rounded-circle article-img" src="{{ url_for('static', filename='pics/' + post.author.image_file) }}">
|
||||
<div class="media-body">
|
||||
<div class="article-metadata">
|
||||
<a class="mr-2" href="{{ url_for('user_posts', username=post.author.username) }} ">{{ post.author.username }}</a>
|
||||
<small class="text-muted">{{ post.date_posted.strftime('%Y-%m-%d') }}</small>
|
||||
</div>
|
||||
<h2><a class="article-title" href="{{ url_for('post', post_id=post.id) }}">{{ post.title }}</a></h2>
|
||||
<p class="article-content">{{ post.content }}</p>
|
||||
</div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
{% for page_num in posts.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %}
|
||||
{% if page_num %}
|
||||
{% if posts.page == page_num %}
|
||||
<a class="btn btn-info mb-4" href="{{ url_for('home', page=page_num) }}">{{ page_num }}</a>
|
||||
{% else %}
|
||||
<a class="btn btn-outline-info mb-4" href="{{ url_for('home', page=page_num) }}">{{ page_num }}</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
...
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endblock content %}
|
@ -0,0 +1,75 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}">
|
||||
|
||||
{% if title %}
|
||||
<title> MiniBase - {{ title }} </title>
|
||||
{% else %}
|
||||
<title> MiniBase </title>
|
||||
{% endif %}
|
||||
</head>
|
||||
<body>
|
||||
<header class="site-header">
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
|
||||
<div class="container">
|
||||
<a class="navbar-brand mr-4" href="{{ url_for('home') }}">MiniBase</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle" aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarToggle">
|
||||
<div class="navbar-nav mr-auto">
|
||||
<a class="nav-item nav-link" href="{{ url_for('home') }}">Home</a>
|
||||
<a class="nav-item nav-link" href="{{ url_for('about') }}">About</a>
|
||||
</div>
|
||||
<!-- Navbar Right Side -->
|
||||
<div class="navbar-nav">
|
||||
{% if current_user.is_authenticated %}
|
||||
<a class="nav-item nav-link" href="{{ url_for('new_post') }}">New Post</a>
|
||||
<a class="nav-item nav-link" href="{{ url_for('logout') }}">Logout</a>
|
||||
<a class="nav-item nav-link" href="{{ url_for('account') }}">Account</a>
|
||||
{% else %}
|
||||
<a class="nav-item nav-link" href="{{ url_for('login') }}">Login</a>
|
||||
<a class="nav-item nav-link" href="{{ url_for('register') }}">Register</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<main role="main" class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }}">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="content-section">
|
||||
<h3>Our Sidebar</h3>
|
||||
<p class='text-muted'>You can put any information here you'd like.
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item list-group-item-light">Latest Posts</li>
|
||||
<li class="list-group-item list-group-item-light">Announcements</li>
|
||||
<li class="list-group-item list-group-item-light">Calendars</li>
|
||||
<li class="list-group-item list-group-item-light">etc</li>
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,52 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<div class="content-section">
|
||||
<form method="POST" action="">
|
||||
{{ form.hidden_tag() }}
|
||||
<fieldset class="form-group">
|
||||
<legend class="border-bottom mb-4">Log In</legend>
|
||||
<div class="form-group">
|
||||
{{ form.email.label(class="form-control-label") }}
|
||||
{% if form.email.errors %}
|
||||
{{ form.email(class="form-control form-control-lg is-invalid") }}
|
||||
<div class="invalid-feedback">
|
||||
{% for error in form.email.errors %}
|
||||
<span>{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form.email(class="form-control form-control-lg") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.password.label(class="form-control-label") }}
|
||||
{% if form.password.errors %}
|
||||
{{ form.password(class="form-control form-control-lg is-invalid") }}
|
||||
<div class="invalid-feedback">
|
||||
{% for error in form.password.errors %}
|
||||
<span>{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form.password(class="form-control form-control-lg") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="form-check">
|
||||
{{ form.remember(class="form-check-input") }}
|
||||
{{ form.remember.label(class="form-check-label") }}
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="form-group">
|
||||
{{ form.submit(class="btn btn-outline-info") }}
|
||||
</div>
|
||||
<small class="text-muted ml-2">
|
||||
<a href="#">Forgot Password?</a>
|
||||
</small>
|
||||
</form>
|
||||
</div>
|
||||
<div class="border-top pt-3">
|
||||
<small class="text-muted">
|
||||
Need An Account? <a class="ml-2" href="{{ url_for('register') }}">Sign Up Now</a>
|
||||
</small>
|
||||
</div>
|
||||
{% endblock content %}
|
@ -0,0 +1,40 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
{% block content %}
|
||||
<article class="media content-section">
|
||||
<img class="rounded-circle article-img" src="{{ url_for('static', filename='pics/' + post.author.image_file) }}">
|
||||
<div class="media-body">
|
||||
<div class="article-metadata">
|
||||
<a class="mr-2" href="{{ url_for('user_posts', username=post.author.username) }}" >{{ post.author.username }}</a>
|
||||
<small class="text-muted">{{ post.date_posted.strftime('%Y-%m-%d') }}</small>
|
||||
{% if post.author == current_user %}
|
||||
<div>
|
||||
<a class="btn btn-secondary btn-sm m-1" href="{{ url_for('post_update', post_id=post.id) }}">Update</a>
|
||||
<button type="button" class="btn btn-danger btn-sm m-1" data-bs-toggle="modal" data-bs-target="#staticBackdrop">Delete</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<h2 class="article-title">{{ post.title }}</h2>
|
||||
<p class="article-content">{{ post.content }}</p>
|
||||
</div>
|
||||
</article>
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="staticBackdropLabel">Modal title</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Your last chance, are you Sure?
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<form action="{{ url_for('post_delete', post_id=post.id) }}" method="POST">
|
||||
<input class="btn btn-danger" type="submit" value="Delete">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
@ -0,0 +1,72 @@
|
||||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
<div class="content-section">
|
||||
<form method="POST" action="">
|
||||
{{ form.hidden_tag() }}
|
||||
<fieldset class="form-group">
|
||||
<legend class="border-bottom mb-4">Join Today</legend>
|
||||
<div class="form-group">
|
||||
{{ form.username.label(class="form-control-label") }}
|
||||
|
||||
{% if form.username.errors %}
|
||||
{{ form.username(class="form-control form-control-lg is-invalid") }}
|
||||
<div class="invalid-feedback">
|
||||
{% for error in form.username.errors %}
|
||||
<span>{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form.username(class="form-control form-control-lg") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.email.label(class="form-control-label") }}
|
||||
{% if form.email.errors %}
|
||||
{{ form.email(class="form-control form-control-lg is-invalid") }}
|
||||
<div class="invalid-feedback">
|
||||
{% for error in form.email.errors %}
|
||||
<span>{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form.email(class="form-control form-control-lg") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.password.label(class="form-control-label") }}
|
||||
{% if form.password.errors %}
|
||||
{{ form.password(class="form-control form-control-lg is-invalid") }}
|
||||
<div class="invalid-feedback">
|
||||
{% for error in form.password.errors %}
|
||||
<span>{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form.password(class="form-control form-control-lg") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ form.password_confirm.label(class="form-control-label") }}
|
||||
{% if form.password_confirm.errors %}
|
||||
{{ form.password_confirm(class="form-control form-control-lg is-invalid") }}
|
||||
<div class="invalid-feedback">
|
||||
{% for error in form.password_confirm.errors %}
|
||||
<span>{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ form.password_confirm(class="form-control form-control-lg") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="form-group">
|
||||
{{ form.submit(class="btn btn-outline-info") }}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="border-top pt-3">
|
||||
<small class="text-muted">
|
||||
Already Have An Account? <a class="ml-2" href="{{ url_for('login') }}">Sign In</a>
|
||||
</small>
|
||||
</div>
|
||||
{% endblock content %}
|
@ -0,0 +1,29 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1 class="mb-3"> Posts By {{ user.username }} ({{ posts.total }}) </h1>
|
||||
{% for post in posts.items %}
|
||||
<article class="media content-section">
|
||||
<img class="rounded-circle article-img" src="{{ url_for('static', filename='pics/' + post.author.image_file) }}">
|
||||
<div class="media-body">
|
||||
<div class="article-metadata">
|
||||
<a class="mr-2" href="{{ url_for('user_posts', username=post.author.username) }} ">{{ post.author.username }}</a>
|
||||
<small class="text-muted">{{ post.date_posted.strftime('%Y-%m-%d') }}</small>
|
||||
</div>
|
||||
<h2><a class="article-title" href="{{ url_for('post', post_id=post.id) }}">{{ post.title }}</a></h2>
|
||||
<p class="article-content">{{ post.content }}</p>
|
||||
</div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
{% for page_num in posts.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %}
|
||||
{% if page_num %}
|
||||
{% if posts.page == page_num %}
|
||||
<a class="btn btn-info mb-4" href="{{ url_for('user_posts', username=user.username, page=page_num) }}">{{ page_num }}</a>
|
||||
{% else %}
|
||||
<a class="btn btn-outline-info mb-4" href="{{ url_for('user_posts', username=user.username, page=page_num) }}">{{ page_num }}</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
...
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endblock content %}
|
@ -0,0 +1,5 @@
|
||||
from minibase import app
|
||||
#Enable debug option even if run directly form Python3
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
|
Binary file not shown.
Loading…
Reference in new issue