Kaydet (Commit) eb75f115 authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya

Ace code editor for snippets

üst 204a37b8
...@@ -8,6 +8,7 @@ verify_ssl = true ...@@ -8,6 +8,7 @@ verify_ssl = true
[packages] [packages]
django = "*" django = "*"
django-bootstrap4 = "*" django-bootstrap4 = "*"
django-ace = "*"
[requires] [requires]
python_version = "3.7" python_version = "3.7"
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "2d89fabddb89aa5f1cb3a06bf1fa034476becb0882f11225d5d37564b3cf94eb" "sha256": "52896a42e739f955a7fd50d6862a302027daa0487f341972373c0935e0a0b2aa"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
...@@ -24,6 +24,14 @@ ...@@ -24,6 +24,14 @@
"index": "pypi", "index": "pypi",
"version": "==2.2.1" "version": "==2.2.1"
}, },
"django-ace": {
"hashes": [
"sha256:1334f08b4c5548e8ab13b25787e6a3f49dfe5fc92bb3a3d845b5b42fa0e1aff6",
"sha256:a2616b0265bdc1f839cc905c77243f779d82c00f3fddf58d23c08eb07e91e189"
],
"index": "pypi",
"version": "==1.0.5"
},
"django-bootstrap4": { "django-bootstrap4": {
"hashes": [ "hashes": [
"sha256:9f115534ae8d052d397201f3d716c10d7c9832b422e44dd7382418c6f274df18" "sha256:9f115534ae8d052d397201f3d716c10d7c9832b422e44dd7382418c6f274df18"
......
...@@ -38,7 +38,8 @@ INSTALLED_APPS = [ ...@@ -38,7 +38,8 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'social', 'social',
'bootstrap4' 'bootstrap4',
'django_ace'
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
from django import forms from django import forms
from django.contrib.auth.forms import UserChangeForm, UserCreationForm from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django_ace import AceWidget
from social.models import Post, Link, Snippet from social.models import Post, Link, Snippet
...@@ -24,6 +25,9 @@ class SnippetCreationForm(forms.ModelForm): ...@@ -24,6 +25,9 @@ class SnippetCreationForm(forms.ModelForm):
class Meta: class Meta:
model = Snippet model = Snippet
fields = ("text",) fields = ("text",)
widgets = {
"text": AceWidget(mode='python', theme='monokai'),
}
class LinkCreationForm(forms.ModelForm): class LinkCreationForm(forms.ModelForm):
class Meta: class Meta:
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<body> <body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top"> <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="#">Aspava</a> <a class="navbar-brand" href="{% url 'home' %}">Aspava</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
......
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %}Post snippet{% endblock %} {% block title %}Post snippet{% endblock %}
{% block css %}{{ form.media }}{% endblock %}
{% block content %} {% block content %}
{% load bootstrap4 %} {% load bootstrap4 %}
......
...@@ -7,6 +7,7 @@ from purima.views import ExtendedListView ...@@ -7,6 +7,7 @@ from purima.views import ExtendedListView
from social import forms from social import forms
from social.models import Link, Post, Snippet from social.models import Link, Post, Snippet
class Home(ExtendedListView): class Home(ExtendedListView):
models = Post, Snippet, Link models = Post, Snippet, Link
template_name = "home.html" template_name = "home.html"
...@@ -14,8 +15,8 @@ class Home(ExtendedListView): ...@@ -14,8 +15,8 @@ class Home(ExtendedListView):
def get_queryset(self): def get_queryset(self):
qs = list(super().get_queryset()) qs = list(super().get_queryset())
qs.sort(key=(lambda item: item.pub_date)) qs.sort(key=(lambda item: item.id))
return qs return reversed(qs)
class Register(CreateView): class Register(CreateView):
...@@ -34,6 +35,17 @@ class SharableCreate(CreateView): ...@@ -34,6 +35,17 @@ class SharableCreate(CreateView):
form.instance.author = self.request.user form.instance.author = self.request.user
return super().form_valid(form) return super().form_valid(form)
class SharableCreate(CreateView):
def __init_subclass__(cls):
cls.form_class = getattr(forms, f"{cls.__name__}CreationForm")
cls.success_url = reverse_lazy("home")
cls.template_name = f"forms/{cls.__name__.lower()}.html"
super().__init_subclass__()
def form_valid(self, form):
form.instance.author = self.request.user
return super().form_valid(form)
class Post(SharableCreate): class Post(SharableCreate):
pass pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment