Skip to content

Commit 341ad39

Browse files
author
Elías Rodríguez Martín
committed
Initial commit
0 parents  commit 341ad39

23 files changed

+948
-0
lines changed

APImpServ/__init__.py

Whitespace-only changes.

APImpServ/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

APImpServ/migrations/0001_initial.py

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import migrations, models
5+
from django.conf import settings
6+
import django.contrib.auth.models
7+
import uuid
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
dependencies = [
13+
('auth', '0006_require_contenttypes_0002'),
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name='BasicUser',
19+
fields=[
20+
('user_ptr', models.OneToOneField(primary_key=True, parent_link=True, to=settings.AUTH_USER_MODEL, serialize=False, auto_created=True)),
21+
],
22+
options={
23+
'abstract': False,
24+
'verbose_name': 'user',
25+
'verbose_name_plural': 'users',
26+
},
27+
bases=('auth.user',),
28+
managers=[
29+
('objects', django.contrib.auth.models.UserManager()),
30+
],
31+
),
32+
migrations.CreateModel(
33+
name='Logs',
34+
fields=[
35+
('id', models.UUIDField(editable=False, default=uuid.uuid4, serialize=False, primary_key=True)),
36+
('creation_date', models.DateTimeField(auto_now=True)),
37+
('n_pages', models.CharField(max_length=3)),
38+
],
39+
),
40+
migrations.CreateModel(
41+
name='Printer',
42+
fields=[
43+
('id', models.UUIDField(editable=False, default=uuid.uuid4, serialize=False, primary_key=True)),
44+
('name', models.CharField(max_length=50)),
45+
('uri', models.URLField()),
46+
('color', models.BooleanField(default=False)),
47+
('paper_size', models.CharField(max_length=5)),
48+
('description', models.TextField()),
49+
],
50+
),
51+
migrations.CreateModel(
52+
name='Quota',
53+
fields=[
54+
('id', models.UUIDField(editable=False, default=uuid.uuid4, serialize=False, primary_key=True)),
55+
('quota', models.CharField(max_length=4)),
56+
('printer', models.OneToOneField(to='APImpServ.Printer')),
57+
],
58+
),
59+
migrations.CreateModel(
60+
name='UserQuota',
61+
fields=[
62+
('id', models.UUIDField(editable=False, default=uuid.uuid4, serialize=False, primary_key=True)),
63+
('quota', models.CharField(max_length=4)),
64+
('mes', models.CharField(default=12, max_length=2)),
65+
('año', models.CharField(default=2015, max_length=4)),
66+
('printer', models.ForeignKey(to='APImpServ.Printer', related_name='printers')),
67+
('user', models.OneToOneField(to='APImpServ.BasicUser')),
68+
],
69+
),
70+
migrations.CreateModel(
71+
name='UserType',
72+
fields=[
73+
('id', models.UUIDField(editable=False, default=uuid.uuid4, serialize=False, primary_key=True)),
74+
('type_name', models.CharField(max_length=50)),
75+
('default', models.BooleanField(default=False)),
76+
],
77+
),
78+
migrations.AddField(
79+
model_name='quota',
80+
name='user_type',
81+
field=models.ForeignKey(to='APImpServ.UserType', related_name='Quotas'),
82+
),
83+
migrations.AddField(
84+
model_name='logs',
85+
name='printer',
86+
field=models.ForeignKey(to='APImpServ.Printer'),
87+
),
88+
migrations.AddField(
89+
model_name='logs',
90+
name='user',
91+
field=models.ForeignKey(to='APImpServ.BasicUser'),
92+
),
93+
migrations.AddField(
94+
model_name='basicuser',
95+
name='user_type',
96+
field=models.ForeignKey(to='APImpServ.UserType', related_name='users'),
97+
),
98+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('APImpServ', '0001_initial'),
11+
]
12+
13+
operations = [
14+
migrations.RenameField(
15+
model_name='userquota',
16+
old_name='mes',
17+
new_name='month',
18+
),
19+
migrations.RenameField(
20+
model_name='userquota',
21+
old_name='año',
22+
new_name='year',
23+
),
24+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import migrations, models
5+
from django.conf import settings
6+
import uuid
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('admin', '0001_initial'),
13+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
14+
('APImpServ', '0002_auto_20151201_1746'),
15+
]
16+
17+
operations = [
18+
migrations.CreateModel(
19+
name='UserProfile',
20+
fields=[
21+
('id', models.UUIDField(primary_key=True, editable=False, serialize=False, default=uuid.uuid4)),
22+
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
23+
('user_type', models.ForeignKey(to='APImpServ.UserType', related_name='users')),
24+
],
25+
),
26+
migrations.RemoveField(
27+
model_name='basicuser',
28+
name='user_ptr',
29+
),
30+
migrations.RemoveField(
31+
model_name='basicuser',
32+
name='user_type',
33+
),
34+
migrations.AlterField(
35+
model_name='logs',
36+
name='user',
37+
field=models.ForeignKey(to='APImpServ.UserProfile'),
38+
),
39+
migrations.AlterField(
40+
model_name='userquota',
41+
name='user',
42+
field=models.OneToOneField(to='APImpServ.UserProfile'),
43+
),
44+
migrations.DeleteModel(
45+
name='BasicUser',
46+
),
47+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('APImpServ', '0003_auto_20151202_1659'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='userquota',
16+
name='user',
17+
field=models.ForeignKey(to='APImpServ.UserProfile'),
18+
),
19+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import migrations, models
5+
import uuid
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('APImpServ', '0004_auto_20151202_1800'),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='PrintSession',
17+
fields=[
18+
('id', models.UUIDField(editable=False, default=uuid.uuid4, primary_key=True, serialize=False)),
19+
('session', models.UUIDField(editable=False, default=uuid.uuid4)),
20+
('date', models.DateTimeField(auto_now=True)),
21+
('user', models.ForeignKey(to='APImpServ.UserProfile')),
22+
],
23+
),
24+
migrations.AddField(
25+
model_name='printer',
26+
name='network',
27+
field=models.CharField(default='0.0.0.0/24', max_length=20),
28+
),
29+
]

APImpServ/migrations/0006_print.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('APImpServ', '0005_auto_20151202_1910'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Print',
16+
fields=[
17+
('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)),
18+
('printers', models.ForeignKey(to='APImpServ.Printer')),
19+
('quotas', models.ForeignKey(to='APImpServ.UserQuota')),
20+
('sessions', models.ForeignKey(to='APImpServ.PrintSession')),
21+
],
22+
),
23+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('APImpServ', '0006_print'),
11+
]
12+
13+
operations = [
14+
migrations.RemoveField(
15+
model_name='print',
16+
name='printers',
17+
),
18+
migrations.RemoveField(
19+
model_name='print',
20+
name='quotas',
21+
),
22+
migrations.RemoveField(
23+
model_name='print',
24+
name='sessions',
25+
),
26+
migrations.AlterModelOptions(
27+
name='printsession',
28+
options={'get_latest_by': 'date'},
29+
),
30+
migrations.AlterField(
31+
model_name='quota',
32+
name='printer',
33+
field=models.ForeignKey(to='APImpServ.Printer'),
34+
),
35+
migrations.DeleteModel(
36+
name='Print',
37+
),
38+
]

APImpServ/migrations/__init__.py

Whitespace-only changes.

APImpServ/models.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import uuid
2+
from django.db import models
3+
from django.db.models import Model, URLField, UUIDField, DateTimeField, CharField, BooleanField, TextField
4+
from django.contrib.auth.models import User
5+
from datetime import date
6+
from django.conf import settings as st
7+
8+
# Create your models here.
9+
class UserProfile(Model):
10+
id = UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
11+
user = models.OneToOneField(st.AUTH_USER_MODEL)
12+
user_type = models.ForeignKey('UserType', related_name="users")
13+
14+
def __str__(self):
15+
return '%s' % self.user.get_username()
16+
17+
class Printer(Model):
18+
id = UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
19+
name = CharField(max_length=50)
20+
uri = URLField()
21+
color = BooleanField(default=False)
22+
paper_size = CharField(max_length=5)
23+
description = TextField()
24+
network = CharField(max_length=20, default="0.0.0.0/24")
25+
26+
def __str__(self):
27+
return '%s' % self.name
28+
29+
class UserType(Model):
30+
id = UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
31+
type_name = CharField(max_length=50)
32+
default = BooleanField(default=False)
33+
34+
def __str__(self):
35+
return '%s' % self.type_name
36+
37+
class Quota(Model):
38+
id = UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
39+
printer = models.ForeignKey('Printer')
40+
user_type = models.ForeignKey('UserType', related_name="Quotas")
41+
#La cuota será un número, que será el número de paǵina a imprimir por mes y usuario.
42+
quota = CharField(max_length=4)
43+
44+
class UserQuota(Model):
45+
id = UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
46+
user = models.ForeignKey('UserProfile')
47+
printer = models.ForeignKey('Printer', related_name="printers")
48+
quota = CharField(max_length=4)
49+
month = CharField(max_length=2, default=date.today().month)
50+
year = CharField(max_length=4, default=date.today().year)
51+
52+
def __str__(self):
53+
return '%s' % self.quota
54+
55+
class Logs(Model):
56+
id = UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
57+
user = models.ForeignKey('UserProfile')
58+
printer = models.ForeignKey('Printer')
59+
creation_date = DateTimeField(auto_now=True)
60+
n_pages = CharField(max_length=3)
61+
62+
class PrintSession(Model):
63+
id = UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
64+
user = models.ForeignKey('UserProfile')
65+
session = UUIDField(default=uuid.uuid4, editable=False)
66+
date = DateTimeField(auto_now=True)
67+
68+
class Meta:
69+
get_latest_by = "date"

APImpServ/permissions.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from rest_framework import permissions
2+
3+
class IsOwnerOrReadOnly(permissions.BasePermission):
4+
def has_object_permission(self, request, view, obj):
5+
if request.method in permissions.SAFE_METHODS:
6+
return True
7+
return obj.user == request.user

APImpServ/scripts/auth.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
s1="user1"
4+
s2="contrasena"
5+
6+
if [ "$1" == "$s1" ] && [ "$2" == "$s2" ]; then
7+
exit 0
8+
else
9+
exit 1
10+
fi
11+

0 commit comments

Comments
 (0)