8000 Merge master into Prod by arjunnn · Pull Request #13 · arjunnn/linkinbio · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
8000
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

A simple "link in bio" service.

Live at [http://b2l.ink](http://b2l.ink)

See [http://b2l.ink/arjun](http://b2l.ink/arjun) for a sample profile

🚧 **Very much a work in progress. I'm building this in public and learning as I go** 🚧

# How to setup
Expand Down
18 changes: 18 additions & 0 deletions linkinbio/app/links/migrations/0019_auto_20210815_0202.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.5 on 2021-08-14 20:32

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("links", "0018_alter_profiletheme_name"),
]

operations = [
migrations.AddField(
model_name="link",
name="created",
field=models.DateTimeField(auto_now=True),
),
]
43 changes: 43 additions & 0 deletions linkinbio/app/links/migrations/0020_alter_profiletheme_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 3.2.5 on 2021-08-14 20:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("links", "0019_auto_20210815_0202"),
]

operations = [
migrations.AlterField(
model_name="profiletheme",
name="name",
field=models.CharField(
choices=[
("light", "🌞 light"),
("dark", "🌚 dark"),
("cupcake", "🧁 cupcake"),
("bumblebee", "🐝 bumblebee"),
("emerald", "❇ emerald"),
("corporate", "🏢 corporate"),
("synthwave", "🌃 synthwave"),
("retro", "👴 retro"),
("cyberpunk", "🤖 cyberpunk"),
("valentine", "🌸 valentine"),
("halloween", "🎃 halloween"),
("garden", "🌷 8000 garden"),
("forest", "🌲 forest"),
("aqua", "🐟 aqua"),
("lofi", "👓 lofi"),
("pastel", "🖍 pastel"),
("fantasy", "🧚\u200d♀️ fantasy"),
("wireframe", "📝 wireframe"),
("black", "🏴 black"),
("luxury", "💎 luxury"),
("dracula", "🧛\u200d♂️ dracula"),
],
max_length=20,
),
),
]
5 changes: 3 additions & 2 deletions linkinbio/app/links/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
("aqua", "🐟 aqua"),
("lofi", "👓 lofi"),
("pastel", "🖍 pastel"),
("‍fantasy", "🧚‍♀️ fantasy"),
("fantasy", "🧚‍♀️ fantasy"),
("wireframe", "📝 wireframe"),
("black", "🏴 black"),
("luxury", "💎 luxury"),
("‍dracula", "🧛‍♂️ dracula"),
("dracula", "🧛‍♂️ dracula"),
)


Expand Down Expand Up @@ -65,3 +65,4 @@ class Link(models.Model):
active = models.BooleanField(default=True)
uuid = models.UUIDField(default=uuid4, db_index=True, verbose_name="UUID")
hits = models.IntegerField(default=0)
created = models.DateTimeField(auto_now=True)
60 changes: 38 additions & 22 deletions linkinbio/app/links/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
HttpResponseBadRequest,
HttpResponse,
)
from django.db.models import Sum
from django.shortcuts import redirect
from django.shortcuts import reverse
from django.template.response import TemplateResponse, SimpleTemplateResponse
Expand Down Expand Up @@ -148,28 +149,30 @@ def get(self, request, *args, **kwargs):
return response

def post(self, request, *args, **kwargs):
link_formset = self.LinkFormSet(request.POST, request.FILES)
edit_profile_form = EditProfileForm(
request.POST, instance=self.profile, files=request.FILES
)
if edit_profile_form.is_valid():
edit_profile_form.save()
else:
print(edit_profile_form.errors)
if link_formset.is_valid():
link_formset.save()
for form in link_formset:
instance = form.save(commit=False)
if not (instance.name and instance.link):
continue
if form.cleaned_data.get("DELETE"):
instance.delete()
else:
instance.profile = request.user.profile
instance.save()
messages.success(request, "Profile updated successfully ✨")
else:
print(link_formset.errors)
if "edit_profile_form" in request.POST:
edit_profile_form = EditProfileForm(
request.POST, instance=self.profile, files=request.FILES
)
if edit_profile_form.is_valid():
edit_profile_form.save()
else:
print(edit_profile_form.errors)
if "link_formset" in request.POST:
link_formset = self.LinkFormSet(request.POST, request.FILES)
if link_formset.is_valid():
link_formset.save()
for form in link_formset:
instance = form.save(commit=False)
if not (instance.name and instance.link):
continue
if form.cleaned_data.get("DELETE"):
instance.delete()
else:
instance.profile = request.user.profile
instance.save()
messages.success(request, "Profile updated successfully ✨")
else:
print(link_formset.errors)
return redirect("edit-profile", username=request.user.username)


Expand All @@ -178,3 +181,16 @@ def get(self, request, *args, **kwargs):
if request.user.is_authenticated:
logout(request)
return redirect(reverse("login"))


class StatsView(View):
def get(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return redirect(reverse("login"))
context = {
"profile": request.user.profile,
"total_link_hits": request.user.profile.links.all().aggregate(
total_link_hits=Sum("hits")
)["total_link_hits"],
}
return TemplateResponse(request, "stats.html", context)
5 changes: 2 additions & 3 deletions linkinbio/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['13.59.253.78', 'localhost', 'b2l.ink']
ALLOWED_HOSTS = ["13.59.253.78", "localhost", "b2l.ink", "127.0.0.1"]

# Application definition

Expand Down Expand Up @@ -81,7 +81,6 @@
},
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

Expand Down Expand Up @@ -137,4 +136,4 @@

MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"
DEFAULT_CHARSET = 'utf-8'
DEFAULT_CHARSET = "utf-8"
2 changes: 2 additions & 0 deletions linkinbio/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
RedirectView,
DashboardView,
LogoutView,
StatsView,
)

urlpatterns = [
Expand All @@ -43,6 +44,7 @@
path("", SignUpView.as_view(), name="home"),
path("dashboard", DashboardView.as_view(), name="dashboard"),
path("r/<uuid>", RedirectView.as_view(), name="redirect"),
path("stats", StatsView.as_view(), name="stats"),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
48 changes: 31 additions & 17 deletions linkinbio/templates/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% load static %}
<html data-theme="{{request.user.profile.get_theme|default:"dark"}}">
<html data-theme="{{request.user.profile.get_theme|default:'dark'}}">
<head>
<title>Edit Profile | Bio2Link</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
Expand Down Expand Up @@ -33,7 +34,9 @@

<body>
<div class="">
<div class="navbar m-4 shadow-lg bg-neutral text-neutral-content rounded-box">
<div
class="navbar m-4 shadow-lg bg-neutral text-neutral-content rounded-box"
>
<div class="flex-1 hidden px-2 mx-2 lg:flex navbar-start">
<span class="text-lg font-bold"
><a href="{% url 'home' %}">Bio2Link</a></span
Expand All @@ -52,11 +55,20 @@
>
</div>
</div>

<div class="flex-none cursor-pointer account-button px-2 mx-2">
<div class="avatar">
<div class="rounded-full w-10 h-10 m-1 ring ring-secondary ring-offset-base-100 ring-offset-2">
<div
class="
rounded-full
w-10
h-10
m-1
ring ring-secondary ring-offset-base-100 ring-offset-2
"
>
<!-- <img src="https://i.pravatar.cc/500?img=32" /> -->
<img src="/media/{{user.profile.image}}" alt="">
<img src="/media/{{user.profile.image}}" alt="" />
</div>
</div>
</div>
Expand All @@ -83,19 +95,22 @@
<li>
<a href="mailto:arjunmunji@gmail.com">Need help?</a>
</li>
<li>
<!-- <li>
<a href="#"
>Changelog
<div class="badge ml-2 success">3</div></a
>
</li>
</li> -->
<li><a href="/">Home 🏡</a></li>
<li><a href="{% url 'stats' %}"> Stats 📈</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
<li>
<a href="#about">about ℹ</a>

</li>
</ul>
<div class="float-right overflow-hidden absolute messages-container fade-out">
<div
class="float-right overflow-hidden absolute messages-container fade-out"
>
{% if messages %}
<ul class="messages">
{% for message in messages %}
Expand All @@ -106,20 +121,20 @@
</div>
{% block content %} {% endblock %}
</div>

<div id="about" class="modal">
<div class="modal-box">
<p>
Bio2Link (<a href="http://b2l.ink" class="link">b2l.ink</a>) is
a free website to show your presence all over the web with just one
link. If you have any feedback, please let me know at
Bio2Link (<a href="http://b2l.ink" class="link">b2l.ink</a>) is a free
website to show your presence all over the web with just one link. If
you have any feedback, please let me know at
<a href="mailto:arjunmunji+bio2link@gmail.com" class="link"
>arjunmunji@gmail.com</a
>.
</p>
<p>
I hope you enjoy using this website as much as I had fun building
it. Please consider donating if you can. Thank you 🙏
I hope you enjoy using this website as much as I had fun building it.
Please consider donating if you can. Thank you 🙏
</p>
<div class="modal-action">
<a
Expand All @@ -138,7 +153,7 @@
let copyProfileLinkButton = document.querySelector('.copy-profile-link')
let fileUploadButton = document.querySelector('input#file-upload-button')

if(fileUploadButton) {
if (fileUploadButton) {
console.log(fileUploadButton)
fileUploadButton.classList.add('btn')
}
Expand All @@ -158,10 +173,9 @@
await navigator.clipboard.writeText(profileLink)
}
})
document.querySelectorAll('input[type="checkbox"]').forEach(el =>{
document.querySelectorAll('input[type="checkbox"]').forEach((el) => {
el.classList.add('checkbox')
})
</script>

</body>
</html>
14 changes: 12 additions & 2 deletions linkinbio/templates/edit_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ <h2 class="card-title">Edit Profile</h2>
</div>

<div class="card-actions">
<input type="submit" value="save" class="btn btn-primary" />
<input
type="submit"
value="save"
class="btn btn-primary"
name="edit_profile_form"
/>
<!-- <button class="btn btn-primary">Get Started</button>
<button class="btn btn-ghost">More info</button> -->
</div>
Expand Down Expand Up @@ -76,7 +81,12 @@ <h2 class="card-title">Your Links</h2>
</table>
</div>
<div class="card-actions">
<input type="submit" value="save" class="btn btn-primary" />
<input
type="submit"
value="save"
class="btn btn-primary"
name="link_formset"
/>
</div>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion linkinbio/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html data-theme={{ profile.get_theme|default:"light" }}>

<head>
<meta>
<title>{{ profile.user.username }} | Bio2Link</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
Expand Down
Loading
0