-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finalized app. Missing create-user script
- Loading branch information
Showing
12 changed files
with
231 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ __pycache__ | |
*.sqlite3 | ||
django4 | ||
venv | ||
.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
import django | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "home.settings") | ||
django.setup() | ||
|
||
from django.contrib.auth.models import User | ||
from your_app.models import Professor, Student, Course | ||
|
||
# Function to create user and assign role-specific profile | ||
def create_user(username, email, password, role, name, courses): | ||
# Create User | ||
user = User.objects.create_user(username=username, email=email, password=password) | ||
|
||
# Create role-specific profile and assign courses | ||
if role.lower() == 'professor': | ||
professor = Professor.objects.create(user=user, name=name) | ||
for course_name in courses: | ||
course, created = Course.objects.get_or_create(course_name=course_name) | ||
professor.courses.add(course) | ||
elif role.lower() == 'student': | ||
student = Student.objects.create(user=user, name=name) | ||
for course_name in courses: | ||
course, _ = Course.objects.get_or_create(course_name=course_name) | ||
student.courses.add(course) | ||
|
||
courses = ['Designing and Using Databases', 'Programming 1', 'Algorithms & Data Structures', 'Cloud Computing', 'Technology', 'Calculus for Computer Science'] | ||
|
||
students = [('ricardo', '[email protected]', 'password123', 'student', 'Ricardo Mendez', courses), | ||
] | ||
professors = [('antonio', '[email protected]', 'password123', 'professor', 'Antonio Momblan', [courses[2]]), | ||
] | ||
|
||
# Create users | ||
for student in students: | ||
create_user(*student) | ||
|
||
for professor in professors: | ||
create_user(*professor) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,37 @@ | ||
{% load static %} | ||
|
||
{% block content %} | ||
<html> | ||
<head> | ||
<title>Login</title> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> | ||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css"> | ||
<head> | ||
<body> | ||
<div class="container mt-5"> | ||
<div class="jumbotron bg-light text-center"> | ||
<h1 class="display-4 text-primary">Login</h1> | ||
<p class="lead">Please enter your credentials to login.</p> | ||
|
||
{% if form.errors %} | ||
<p>Your username and password didn't match. Please try again.</p> | ||
{% endif %} | ||
{% if form.errors %} | ||
<div class="alert alert-danger" role="alert"> | ||
Your username and password didn't match. Please try again. | ||
</div> | ||
{% endif %} | ||
|
||
<form method="post" action="{% url 'login' %}" class="mt-4"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<input type="submit" class="btn btn-primary" value="Login" /> | ||
<input type="hidden" name="next" value="{{ next }}" /> | ||
</form> | ||
</div> | ||
</div> | ||
</body> | ||
|
||
<form method="post" action="{% url 'login' %}"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<input type="submit" class="btn btn-primary" value="Login" /> | ||
<input type="hidden" name="next" value="{{ next }}" /> | ||
</form> | ||
{% endblock %} | ||
|
||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script> | ||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.