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
Empty file added planteer/accounts/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions planteer/accounts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions planteer/accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
name = 'accounts'
26 changes: 26 additions & 0 deletions planteer/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 6.0.3 on 2026-04-27 06:39

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Profile',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('about', models.TextField(blank=True)),
('avatar', models.ImageField(blank=True, default='images/avatars/default.png', upload_to='images/avatars/')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file.
12 changes: 12 additions & 0 deletions planteer/accounts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import models
from django.contrib.auth.models import User
# Create your models here.

class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
about = models.TextField(blank=True)
avatar = models.ImageField(upload_to='images/avatars/',default="images/avatars/default.png", blank=True)
#TODO: make a fav list of plants

def __str__(self) -> str:
return f"Profile {self.user.username}"
31 changes: 31 additions & 0 deletions planteer/accounts/templates/accounts/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends 'main/base.html'%}


{% block title %} Sign In{% endblock %}

{% block content %}
<div class="container d-flex flex-column justify-content-center align-items-center">

<h2>Sign In</h2>

<form class="d-flex flex-column gap-3 w-50" action="{% url 'accounts:log_in' %}{% if 'next' in request.GET %}?next={{request.GET.next}}{% endif %}" method="POST">
{% csrf_token %}


<div class="form-floating">
<input type="text" class="form-control" id="floatingInput" placeholder="username" name="username">
<label for="floatingInput">User name</label>
</div>


<div class="form-floating">
<input type="password" class="form-control" id="floatingPassword" placeholder="Password" name="password">
<label for="floatingPassword">Password</label>
</div>


<button class="btn btn-primary w-100 py-2" type="submit">Sign In</button>
</form>
</div>

{% endblock %}
40 changes: 40 additions & 0 deletions planteer/accounts/templates/accounts/profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends 'main/base.html'%}


{% block title %} profile for {{user.username}} {% endblock %}

{% block content %}


<div class="row">

<div class="col-2">

<img src="{{user.profile.avatar.url}}" class="w-100 rounded-circle" />
{% if request.user == user %}
<a href="#"><i class="bi bi-pencil-square"></i></a>
{% endif %}
</div>

<div class="col">

<div class="d-flex flex-column gap-3">
<p>{{user.profile.about}}</p>


<hr />
<h5>Comments added by {{user.username}}</h5>
{% for comment in user.comments_set.all %}
<div class="p-3 rounded shadow">
<div class="d-flex justify-content-between align-items-center">
<h6>{{comment.plant.name}}</h6>
<p class="text-muted">{{comment.created_at}}</p>
</div>
<p>{{comment.comment}}</p>
</div>
{% endfor %}
</div>
</div>
</div>

{% endblock %}
49 changes: 49 additions & 0 deletions planteer/accounts/templates/accounts/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% extends 'main/base.html'%}


{% block title %} Sign Up new user {% endblock %}

{% block content %}
<div class="container d-flex flex-column justify-content-center align-items-center">

<h2>Sign Up</h2>
<form class="d-flex flex-column gap-3 w-50" action="{% url 'accounts:sign_up' %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}


<div class="form-floating">
<input type="email" class="form-control" id="floatingInput" placeholder="name@example.com" name="email" required>
<label for="floatingInput">Email address</label>
</div>

<div class="form-floating">
<input type="text" class="form-control" id="floatingInput" placeholder="username" name="username" required>
<label for="floatingInput">User name</label>
</div>

<div class="form-floating">
<input type="text" class="form-control" id="floatingInput" placeholder="First name" name="first_name" required>
<label for="floatingInput">First name</label>
</div>

<div class="form-floating">
<input type="text" class="form-control" id="floatingInput" placeholder="Last name" name="last_name" required>
<label for="floatingInput">Last name</label>
</div>

<div class="form-floating">
<input type="password" class="form-control" id="floatingPassword" placeholder="Password" name="password" required>
<label for="floatingPassword">Password</label>
</div>

<textarea class="form-control" placeholder="About" name="about"></textarea>

<h5>Choose Avatar:</h5>
<input type="file" name="avatar" accept="images/*" class="form-control" />

<button class="btn btn-primary w-100 py-2" type="submit">Sign up</button>

</form>
</div>

{% endblock %}
3 changes: 3 additions & 0 deletions planteer/accounts/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
12 changes: 12 additions & 0 deletions planteer/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.urls import path
from . import views

app_name = "accounts"

urlpatterns = [
path('signup/', views.sign_up_view, name="sign_up"),
path('login/', views.sign_in_view, name="log_in"),
path('logout/', views.log_out, name="log_out"),
path('profile/<str:user_id>/', views.profile_view, name="profile_view"),
]
#accounts:log_in
74 changes: 74 additions & 0 deletions planteer/accounts/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from django.shortcuts import render
from django.shortcuts import redirect
from django.http import HttpRequest, HttpResponse
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login, logout
from django.contrib import messages
from django.db import IntegrityError, transaction

from .models import Profile


# Create your views here.
def sign_up_view(request):

if request.method == 'POST':
try:
# ============ making user ============
username = request.POST.get('username')
email = request.POST.get('email')
password = request.POST.get('password')
first_name = request.POST.get('first_name', '')
last_name = request.POST.get('last_name', '')
new_user = User.objects.create_user(username=username, email=email, password=password, first_name=first_name, last_name=last_name)
new_user.save()

# ============ making profile ============
profile = Profile(user=new_user,about=request.POST.get('about'), avatar=request.FILES.get('avatar'))
profile.save()

# ============ end ============
print(f"new user -> {new_user.username} has signed up")
#ts myby needs the views.name one but idk
return redirect('accounts:log_in')
except IntegrityError as e:
messages.error(request, "Please choose another username", "alert-danger")

except Exception as e:
print(e)
return render(request, 'accounts/signup.html', {})

def sign_in_view(request):
if request.method == "POST":

#checking user credentials
user = authenticate(request, username=request.POST["username"], password=request.POST["password"])
print(user)
if user:
#login the user
login(request, user)
messages.success(request, "Logged in successfully", "alert-success")
return redirect(request.GET.get("next", "/"))
else:
messages.error(request, "Please try again. You credentials are wrong", "alert-danger")


return render(request, 'accounts/login.html', {})

def log_out(request):
logout(request)
messages.success(request, "logged out successfully", "alert-warning")

return redirect(request.GET.get("next", "/"))

def profile_view(request, user_id):

try:
user = User.objects.get(username=user_id)
if not Profile.objects.filter(user=user).first():
new_profile = Profile(user=user)
new_profile.save()
except Exception as e:
print(e)
return redirect(request,'main:home')
return render(request, 'accounts/profile.html', {"user": user})
Binary file added planteer/db.sqlite3
Binary file not shown.
Empty file added planteer/main/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions planteer/main/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.contrib import admin
from .models import Contact
from plants.models import Plant, Comments, Country
from django.urls import path, include

# Register your models here.
class PlantAdmin(admin.ModelAdmin):
list_display = ["name","category","is_edible","created_at"]
list_filter = ("category", "is_edible")

class CommentsAdmin(admin.ModelAdmin):
list_display = ["name", "plant", "created_at"]
list_filter = ("plant","created_at")


class ContactAdmin(admin.ModelAdmin):
list_display = ["first_name", "last_name", "email", "created_at"]

admin.site.register(Contact, ContactAdmin)
admin.site.register(Comments, CommentsAdmin)
admin.site.register(Plant, PlantAdmin)
admin.site.register(Country)
5 changes: 5 additions & 0 deletions planteer/main/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class MainConfig(AppConfig):
name = 'main'
7 changes: 7 additions & 0 deletions planteer/main/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django import forms
from .models import Contact

class ContactForm(forms.ModelForm):
class Meta:
model = Contact
fields = ['first_name', 'last_name', 'email', 'message']
25 changes: 25 additions & 0 deletions planteer/main/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 6.0.3 on 2026-04-19 15:22

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Contact',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=1024)),
('last_name', models.CharField(max_length=1024)),
('email', models.EmailField(max_length=254)),
('message', models.TextField()),
('created_at', models.DateTimeField(auto_now_add=True)),
],
),
]
Empty file.
21 changes: 21 additions & 0 deletions planteer/main/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.db import models

# that wasnt meant to be here oops
# class Plant(models.Model):
# name = models.CharField(max_length=2048),
# about = models.TextField(),
# used_for = models.TextField(),
# image = models.ImageField( upload_to=None, height_field=None, width_field=None, max_length=None),
# is_edible = models.BooleanField(default= False),
# created_at = models.DateTimeField(auto_now_add=True),

class Contact(models.Model):
first_name = models.CharField(max_length=1024)
last_name = models.CharField(max_length=1024)
email = models.EmailField()
message = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self) -> str:
return self.first_name + " " + self.last_name

Binary file added planteer/main/static/images/home-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Loading