Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
cleanup: removed unused models
  • Loading branch information
HermanMartinus committed May 27, 2022
1 parent 0cd35f7 commit a4db772
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 127 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Expand Up @@ -56,6 +56,8 @@ coverage.xml
local_settings.py
db.sqlite3
dev.db
dev.db.backup
db.json

# Flask stuff:
instance/
Expand Down Expand Up @@ -105,5 +107,3 @@ venv.bak/
# mypy
.mypy_cache/
.jsbeautifyrc

tasklist.txt
4 changes: 1 addition & 3 deletions blogs/admin.py
Expand Up @@ -5,7 +5,7 @@
from django.db.models import Count
from django.utils import timezone

from .models import Blog, Image, Post, Upvote, Hit, Subscriber, Emailer
from .models import Blog, Post, Upvote, Hit, Subscriber
from django.utils.html import escape, format_html
from blogs.helpers import check_records, root
from django.urls import reverse
Expand Down Expand Up @@ -138,9 +138,7 @@ def upvote_count(self, obj):
ordering = ('-published_date',)


admin.site.register(Image)
admin.site.register(Upvote)
admin.site.register(Emailer)


@admin.register(Hit)
Expand Down
18 changes: 2 additions & 16 deletions blogs/forms.py
Expand Up @@ -2,8 +2,8 @@
from django.core.validators import RegexValidator, ValidationError
from django.template.defaultfilters import slugify

from .helpers import check_dns_connection, is_protected, root
from .models import Blog, Post, Emailer
from .helpers import is_protected, root
from .models import Blog, Post

subdomain_validator = RegexValidator(
r"^(?![0-9]+$)(?!-)[a-zA-Z0-9-]{,63}(?<!-)$",
Expand Down Expand Up @@ -251,17 +251,3 @@ class Meta:
fields = ('fathom_site_id',)


class NotifyForm(forms.ModelForm):
notify = forms.BooleanField(
label="Notify subscribers about new posts?",
help_text="<br>This will send an email to subscribers letting them know you've just published a new post",
required=False)
notification_text = forms.CharField(
help_text="The link to your new post will be appended to this notification",
required=False,
widget=forms.Textarea(attrs={'rows': 5, 'cols': 40}),
)

class Meta:
model = Emailer
fields = ('notify', 'notification_text')
@@ -0,0 +1,23 @@
# Generated by Django 4.0.4 on 2022-05-27 08:00

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('blogs', '0047_auto_20220526_0738'),
]

operations = [
migrations.RemoveField(
model_name='image',
name='blog',
),
migrations.DeleteModel(
name='Emailer',
),
migrations.DeleteModel(
name='Image',
),
]
30 changes: 0 additions & 30 deletions blogs/models.py
@@ -1,10 +1,7 @@
from django.db import models
from django.db.models.signals import pre_delete
from django.dispatch import receiver
from django.contrib.auth.models import User
from django.contrib.sites.models import Site

from .helpers import delete_domain, add_new_domain
from taggit.managers import TaggableManager


Expand Down Expand Up @@ -79,18 +76,6 @@ def save(self, *args, **kwargs):
super(Post, self).save(*args, **kwargs)


class Image(models.Model):
blog = models.ForeignKey(Blog, on_delete=models.CASCADE)
title = models.CharField(max_length=200, blank=True)
optimised_url = models.CharField(max_length=200, blank=True)
large_url = models.CharField(max_length=200, blank=True)
icon_url = models.CharField(max_length=200, blank=True)
created_date = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.title


class Upvote(models.Model):
post = models.ForeignKey(Post, on_delete=models.CASCADE)
created_date = models.DateTimeField(auto_now_add=True)
Expand All @@ -109,21 +94,6 @@ def __str__(self):
return f"{self.created_date.strftime('%d %b %Y, %X')} - {self.ip_address} - {self.post}"


class Emailer(models.Model):
blog = models.OneToOneField(
Blog,
on_delete=models.CASCADE,
primary_key=True,
)
notify = models.BooleanField(default=False)
notification_text = models.TextField(
blank=True,
default="Hey, I've just published a new post! Check out the link below.")

def __str__(self):
return f"Emailer settings for {self.blog}"


class Subscriber(models.Model):
blog = models.ForeignKey(Blog, on_delete=models.CASCADE)
email_address = models.EmailField()
Expand Down
4 changes: 0 additions & 4 deletions blogs/urls.py
Expand Up @@ -9,9 +9,6 @@
path('review/', staff.review_flow, name='review_flow'),
path('review/approve/<pk>', staff.approve, name='review_approve'),
path('review/block/<pk>', staff.block, name='review_block'),
path('staff/bulk_mail_users/', staff.bulk_mail_users, name='bulk_mail_users'),
path('bulk_mail_unsubscribe/<email>/', staff.bulk_mail_unsubscribe, name='bulk_mail_unsubscribe'),
path('staff/export_emails/', staff.export_emails, name='export_emails'),

path('accounts/delete/', dashboard.delete_user, name='user_delete'),
path('dashboard/', dashboard.dashboard, name='dashboard'),
Expand All @@ -20,7 +17,6 @@
path('dashboard/account/', dashboard.account, name='account'),
path('dashboard/domain/', dashboard.domain_edit, name='domain'),
path('dashboard/email-list/', emailer.email_list, name='email_list'),
path('dashboard/email-list/settings/', emailer.notification_settings, name='notification_settings'),
path('dashboard/analytics/', analytics.analytics, name='analytics'),
path('dashboard/upgrade/', dashboard.upgrade, name='upgrade'),

Expand Down
26 changes: 1 addition & 25 deletions blogs/views/emailer.py
Expand Up @@ -8,8 +8,7 @@
from django.utils import timezone

from blogs.helpers import validate_subscriber_email
from blogs.models import Blog, Subscriber, Emailer
from blogs.forms import NotifyForm
from blogs.models import Blog, Subscriber
from blogs.views.blog import resolve_address, not_found
from blogs.views.dashboard import resolve_subdomain

Expand Down Expand Up @@ -50,29 +49,6 @@ def email_list(request):
})


@login_required
def notification_settings(request):
blog = get_object_or_404(Blog, user=request.user)
if not resolve_subdomain(request.META['HTTP_HOST'], blog):
return redirect(f"{blog.useful_domain()}/dashboard")

Emailer.objects.get_or_create(blog=blog)

if request.method == "POST":
form = NotifyForm(request.POST, instance=blog.emailer)
if form.is_valid():
emailer_info = form.save(commit=False)
emailer_info.save()
return redirect("/dashboard/subscribers/")
else:
form = NotifyForm(instance=blog.emailer)

return render(request, "dashboard/notification_settings.html", {
"blog": blog,
"form": form
})


def subscribe(request):
blog = resolve_address(request)
if not blog:
Expand Down
42 changes: 0 additions & 42 deletions blogs/views/staff.py
Expand Up @@ -65,45 +65,3 @@ def block(request, pk):
blog.blocked = True
blog.save()
return redirect('review_flow')


@staff_member_required
def export_emails(request):
users = Blog.objects.filter(reviewed=True, blocked=False).values('user__email')

return djqscsv.render_to_csv_response(users)


@staff_member_required
def bulk_mail_users(request):
if request.method == "POST":
if request.POST.get("subject", "") and request.POST.get("body", ""):
if request.POST.get("is_test", ""):
# Sends to first registered user (assuming that's the admin)
queryset = Blog.objects.filter(pk=1)
else:
queryset = Blog.objects.filter(blocked=False, reviewed=True)
bulk_email(
queryset,
request.POST.get("subject", ""),
markdown(request.POST.get("body", ""))
)
return HttpResponse(f"Your mail has been sent to {len(queryset)} users!")
return render(
request,
'staff/bulk_mail_users.html',
{'error': 'Missing message subject or body'}
)
else:
return render(
request,
'staff/bulk_mail_users.html',
{}
)


def bulk_mail_unsubscribe(request, email):
blog = get_object_or_404(Blog, user__email=email)
blog.subscribed = False
blog.save()
return HttpResponse('You have been successfully unsubscribed.')
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -10,7 +10,7 @@ distlib==0.3.0
dj-database-url==0.5.0
Django==3.1.14
django-allauth==0.41.0
django-debug-toolbar==2.2.1
django-debug-toolbar==3.4.0
django-ip==1.0.2
django-pg-utils==0.1.5
django-pygmentify==0.3.7
Expand Down
5 changes: 1 addition & 4 deletions textblog/urls.py
@@ -1,14 +1,11 @@
from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url
from django.conf import settings
from django.contrib.staticfiles.storage import staticfiles_storage
from django.views.generic import TemplateView
from django.views.generic.base import RedirectView

urlpatterns = [
path('mothership/', admin.site.urls),
url(r'^accounts/', include('allauth.urls')),
path('accounts/', include('allauth.urls')),
path('', include('blogs.urls')),
path(
"robots.txt",
Expand Down

0 comments on commit a4db772

Please sign in to comment.