Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage assigned webpage #12

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
Binary file added Templates/.assigned.html.swp
Binary file not shown.
99 changes: 64 additions & 35 deletions Templates/assigned.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
$def with (assigneds, names, browsers, sites)
$def with (assigneds, names, names_orderN, browsers, sites, message)

<head>
<title>Liste des sites</title>
<link rel="icon" type="image/png" href="https://wiki.epfl.ch/sdf/documents/logo_sdf.png" />

<style>
table {
Expand Down Expand Up @@ -51,37 +52,61 @@
overflow:auto;
}


.message{
font-family: helvetica, sans-serif;
font-size:20px;
text-align:center;
border: 2px solid #888888;
width: 33%; /*can be in percentage also.*/
height: auto;
margin: 0 auto;
position: relative;
}

</style>
</head>
<body>
<!--
<div>
<table>
<tbody>
<tr>
<th>
<select name ="select-user">
<option value=0>Choisissez l'utilisateur</option>
</select>
</th>
<th>
<select name ="select-browser">
<option value=0>Choisissez le navigateur</option>
</select>
</th>
<th>
<select name ="select-websites">
<option value=0>Choisissez le site</option>
</select>
</th>
<th>
<input type="submit" value="Ajouter ! ">
</th>
</tr>
<form method="post" action="assigned">
<tr>
<th>
<select name = "select_user">
<option value=0>N'importe quel utilisateur</option>
$for user in names_orderN:
<option value="$user.id">$user.first_name $user.last_name ($user.id)</option>
</select>
</th>
<th>
<select name = "select_browser">
<option value=-1>Choisissez le navigateur</option>
$for browser in browsers:
<option value="$browser.id">$browser.name — $browser.os</option>
</select>
</th>
<th>
<select name ="select_website">
<option value=-1>Choisissez le site</option>
$for site in sites:
<option value="$site.id">$site.name ($site.id)</option>
</select>
</th>
<th>
<input type="submit" value="Ajouter ! ">
</th>
</tr>
</form>
</tbody>
</table>
</div>
//-->
<div id="container">
$if message:
<div class="message">
<p>$message</p>
</div>
</div>
<div id="table-wrapper">
<table>
<thead>
Expand All @@ -94,25 +119,29 @@
<th>ID du site</th>
<th>Jahia</th>
<th>Wordpress</th>
<th>Suppression</th>
</tr>
</thead>
<tbody>
$for assigned in assigneds:
<tr>
<td class="user">
$for assigned in assigneds:
<tr>
<td class="user">
$if assigned.user_id:
$assigned.user_id - $names[assigned.user_id-1].first_name $names[assigned.user_id-1].last_name
$else:
Tous
N'importe quel utilisateur
</td>
<td class="browser">$assigned.browser_id</td>
<td class="browser">$browsers[assigned.browser_id].name</td>
<td class="browser">$browsers[assigned.browser_id].version</td>
<td class="browser">$browsers[assigned.browser_id].os</td>
<td class="website">$assigned.website_id </td>
<td class="website"><a href="$sites[assigned.website_id].jahia">$sites[assigned.website_id].jahia</a></td>
<td class="website"><a href="$sites[assigned.website_id].wordpress">$sites[assigned.website_id].wordpress</a></td>
</tr>
<td class="browser">$assigned.browser_id</td>
<td class="browser">$browsers[assigned.browser_id].name</td>
<td class="browser">$browsers[assigned.browser_id].version</td>
<td class="browser">$browsers[assigned.browser_id].os</td>
<td class="website">$assigned.website_id </td>
<td class="website"><a href="$sites[assigned.website_id].jahia">$sites[assigned.website_id].jahia</a></td>
<td class="website"><a href="$sites[assigned.website_id].wordpress">$sites[assigned.website_id].wordpress</a></td>
<form method="post" name="" action="delete">
<td class="website"><input type="submit" name="$assigned.user_id,$assigned.browser_id,$assigned.website_id" value="supprimer"><td>
</form>
</tr>
</tbody>
</table>
</div>
Expand Down
1 change: 1 addition & 0 deletions Templates/compare.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
$def with (names, user_id, status, url1, url2)
<head>
<link rel="icon" type="image/png" href="https://wiki.epfl.ch/sdf/documents/logo_sdf.png" />
<meta charset="UTF-8">
<title> Comparateur de pages</title>

Expand Down
2 changes: 2 additions & 0 deletions Templates/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
$def with (users, version)
<head>
<link rel="icon" type="image/png" href="https://wiki.epfl.ch/sdf/documents/logo_sdf.png" />
<title>Comparateur de pages</title>
<style>
@import url('https://fonts.googleapis.com/css?family=Convergence');
Expand Down Expand Up @@ -38,6 +39,7 @@
padding:13px;
text-align: center;
font-family: "Convergence", sans-serif;
font-size: 27px;
}
#logs-footer {
position: absolute;
Expand Down
1 change: 1 addition & 0 deletions Templates/logs.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$def with (logs)

<head>
<link rel="icon" type="image/png" href="https://wiki.epfl.ch/sdf/documents/logo_sdf.png" />
<title>Liste des sites</title>

<style>
Expand Down
1 change: 1 addition & 0 deletions Templates/stats.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$def with (stats, total_websites)

<head>
<link rel="icon" type="image/png" href="https://wiki.epfl.ch/sdf/documents/logo_sdf.png" />
<title>Liste des sites</title>

<style>
Expand Down
111 changes: 100 additions & 11 deletions code.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import web
import time
import datetime
Expand All @@ -10,6 +11,14 @@
from random import randint
from version import __version__

# Pour débuguer
DEBUG = True

def debug(string):
if DEBUG:
print(string)


print('\n')
print(' ---------------------------')
print(' | Distrib Version : ' +__version__+' |')
Expand All @@ -24,14 +33,15 @@
'/compare', 'compare',
'/assigned', 'assigned',
'/stats', 'stats',
'/next', 'next'
'/next', 'next',
'/delete', 'delete'
)


path = '../credentials/'
db = web.database(dbn='sqlite', db=path+'distrib.db')
names_orderN = db.query('SELECT id, first_name, last_name FROM users ORDER BY first_name').list()
names = db.query('SELECT id, first_name, last_name FROM users').list()
names_orderN = db.query('SELECT id, first_name, last_name FROM users WHERE NOT (id = 0) ORDER BY first_name').list()
names = db.query('SELECT id, first_name, last_name FROM users WHERE NOT (id = 0)').list()
status = ['DONE', 'STARTED', 'EMPTY', 'CONNECTION ERROR', None]

button = form.Form(
Expand Down Expand Up @@ -119,18 +129,38 @@ def get_browser_id(browser_info):

@staticmethod
def get_assigned_url(user_id, browser_id):
# regarde si site attribué à user_id et browser_id
url = db.query(('SELECT id, jahia, wordpress FROM '
+'(SELECT * FROM assigned_websites aw '
+'WHERE (aw.browser_id = ' + str(browser_id)
+ ' AND aw.user_id = ' + str(user_id) + ')) as aw '
+' AND aw.user_id = ' + str(user_id) + ')) as aw '
+'INNER JOIN websites w '
+'ON (w.id = aw.website_id) LIMIT 1;')).list()
if not url:
# si site attribué à user_id et browser_id=0
url = db.query(('SELECT id, jahia, wordpress FROM '
+'(SELECT * FROM assigned_websites aw '
+'WHERE (aw.user_id IS NULL AND aw.browser_id = ' + str(browser_id) + ')) as aw '
+'WHERE (aw.user_id = '+ str(user_id)
+' AND aw.browser_id = 0)) as aw '
+'INNER JOIN websites w '
+'ON (w.id = aw.website_id) LIMIT 1;')).list()
if not url:
# si site attribué à user_id=0 et browser_id
url = db.query(('SELECT id, jahia, wordpress FROM '
+'(SELECT * FROM assigned_websites aw '
+'WHERE (aw.user_id = 0'
+' AND aw.browser_id =' + str(browser_id) + ')) as aw '
+'INNER JOIN websites w '
+'ON (w.id = aw.website_id) LIMIT 1;')).list()
if not url:
# si site attribué à user_id=0 et browser_id=0
url = db.query(('SELECT id, jahia, wordpress FROM '
+'(SELECT * FROM assigned_websites aw '
+'WHERE (aw.user_id = 0'
+' AND aw.browser_id = 0)) as aw '
+'INNER JOIN websites w '
+'ON (w.id = aw.website_id) LIMIT 1;')).list()

if url:
url = url[0]
url.status = None
Expand All @@ -139,8 +169,29 @@ def get_assigned_url(user_id, browser_id):
return None

@staticmethod
def update_assigned_websites(website_id, browser_id):
db.delete('assigned_websites', where='browser_id=' + str(browser_id) + ' AND website_id=' + str(website_id) )
def update_assigned_websites(user_id, browser_id, website_id):
debug('usr_id: ' + str(user_id) + '\nbrw_id: ' + str(browser_id) + '\nweb_id: ' + str(website_id))
# Prend la liste des assigned ayant l'id de website_id
assigned_with_web_id = db.query(('SELECT * FROM assigned_websites '
+ 'WHERE website_id=' + str(website_id) + ';')).list()
for asweb in assigned_with_web_id:
debug(asweb)
# user fixed and browser fixed
if asweb.user_id == user_id and asweb.browser_id == browser_id:
db.delete('assigned_websites', where=('user_id=' + str(user_id)
+ ' AND browser_id=' + str(browser_id) + ' AND website_id=' + str(website_id)))
# user fixed and browser not fixed
elif asweb.user_id == user_id and asweb.browser_id == 0:
db.delete('assigned_websites',where=('user_id=' + str(user_id)
+ ' AND browser_id=0 AND website_id=' + str(website_id)))
# user not fixed and browser fixed
elif asweb.user_id == 0 and asweb.browser_id == browser_id:
db.delete('assigned_websites', where=('user_id=0 AND browser_id=' + str(browser_id)
+ ' AND website_id=' + str(website_id)))
# user not fixed and browser fixed
elif asweb.user_id == 0 and asweb.browser_id == 0:
db.delete('assigned_websites', where=('user_id=0 AND browser_id=0 AND website_id=' + str(website_id)))


@staticmethod
def add_browser(browser_info):
Expand Down Expand Up @@ -202,9 +253,45 @@ def POST(self):
class assigned:
def GET(self):
browsers = db.query('SELECT * FROM browsers;').list()
websites = db.query('SELECT id, jahia, wordpress FROM websites;').list()
websites = db.query('SELECT id, name, jahia, wordpress FROM websites;').list()
assigneds = db.query('SELECT * FROM assigned_websites;').list()
print(assigneds)
return render.assigned(assigneds, names, names_orderN, browsers, websites, '')

def POST(self):
message = ''
select_user = web.input(select = None).select_user
select_browser = web.input(select = None).select_browser
select_website = web.input(select = None).select_website
# Teste les valeurs
if (select_user == '-1'):
select_user = 'NULL'

try:
db.query(('INSERT INTO assigned_websites VALUES ('
+ str(select_user) + ','
+ str(select_browser) + ','
+ str(select_website) + ')'))
except sqlite3.IntegrityError as e:
print (e)
message = "L'entrée est déjà existante"


browsers = db.query('SELECT * FROM browsers;').list()
websites = db.query('SELECT id, name, jahia, wordpress FROM websites;').list()
assigneds = db.query('SELECT * FROM assigned_websites;').list()
return render.assigned(assigneds, names, browsers, websites)
return render.assigned(assigneds, names, names_orderN, browsers, websites, message)

class delete:
def POST(self):
values = web.input().keys()[0]
values = values.split(',')
db.delete('assigned_websites', where=('user_id=' + values[0]
+ ' AND browser_id=' + values[1]
+ ' AND website_id=' + values[2]))
print(values)
print('Hellllllo')
raise web.seeother('/assigned')

class stats:
def GET(self):
Expand All @@ -221,11 +308,13 @@ def POST(self):
url = web.input(url1=None).url1
user_id = web.input(user_id=None).user_id
if user_id != '0':
user_id = int(user_id)
browser_id = int(browser_id)
website_id = query.get_id_from_jahia_url(url)
query.update_assigned_websites(website_id, browser_id)
query.update_assigned_websites(user_id, browser_id, website_id)
query.add_log(user_id, browser_id, website_id, statu)
add_log_to_csv(user_id, browser_id, website_id, statu)
raise web.seeother('/compare?user_id=' + user_id)
raise web.seeother('/compare?user_id=' + str(user_id))
else:
raise web.seeother('/')

Expand Down
4 changes: 2 additions & 2 deletions create_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ CREATE TABLE "browsers"(
UNIQUE("id")
);
CREATE TABLE "assigned_websites"(
"user_id" INTEGER,
"user_id" INTEGER NOT NULL,
"browser_id" INTEGER NOT NULL,
"website_id" INTEGER NOT NULL,
PRIMARY KEY("browser_id", "website_id"),
PRIMARY KEY("user_id", "browser_id", "website_id"),
FOREIGN KEY("browser_id") REFERENCES "browsers"("id")
FOREIGN KEY("website_id") REFERENCES "websites"("id")
);
Expand Down
19 changes: 13 additions & 6 deletions fillDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
for row in reader:
# (id, name, Jahia, WP, userview, password, random)
cur.execute(('INSERT INTO websites VALUES('
+ str(i) + ', "'+ row[3] + '", "' + row[1]+ '", "' + row[2] + '", "' + row[5] + '", "' + row[6] + '", ' + row[0] + ');\n'))
+ str(i) + ', "'+ row[3] + '", "' + row[1]+ '", "' + row[2] + '", "'
+ row[5] + '", "' + row[6] + '", ' + row[0] + ');\n'))
i += 1
con.commit()
credentials.close()
Expand All @@ -31,11 +32,17 @@
users.close()
print('Users OK')

#cur.execute('INSERT INTO browsers VALUES (0, "Firefox", "0", "Windows");')
#cur.execute('INSERT INTO browsers VALUES (1, "Firefox", "0", "Linux");')
#cur.execute('INSERT INTO assigned_websites VALUES (NULL, 1, 1);')
#cur.execute('INSERT INTO assigned_websites VALUES (3, 0, 25);')
#con.commit()
# Insere l'utilisateur "Tous" et le browser "Tous"
cur.execute('INSERT INTO users VALUES (0, "N\'importe quel utilisateur", "N\'importe quel utilisateur")')
cur.execute('INSERT INTO browsers VALUES (0, "N\'importe quel navigateur", "0", "N\'importe quel OS");')

cur.execute('INSERT INTO browsers VALUES (1, "Firefox", "0", "Linux");')
cur.execute('INSERT INTO browsers VALUES (2, "Firefox", "0", "Windows");')
cur.execute('INSERT INTO assigned_websites VALUES (0, 1, 4);')
cur.execute('INSERT INTO assigned_websites VALUES (0, 0, 1);')
cur.execute('INSERT INTO assigned_websites VALUES (1, 0, 1);')
cur.execute('INSERT INTO assigned_websites VALUES (1, 1, 1);')
con.commit()

con.close()

Loading