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
[packages]
django = "*"
django-bootstrap4 = "*"
django-ace = "*"
[requires]
python_version = "3.7"
{
"_meta": {
"hash": {
"sha256": "2d89fabddb89aa5f1cb3a06bf1fa034476becb0882f11225d5d37564b3cf94eb"
"sha256": "52896a42e739f955a7fd50d6862a302027daa0487f341972373c0935e0a0b2aa"
},
"pipfile-spec": 6,
"requires": {
......@@ -24,6 +24,14 @@
"index": "pypi",
"version": "==2.2.1"
},
"django-ace": {
"hashes": [
"sha256:1334f08b4c5548e8ab13b25787e6a3f49dfe5fc92bb3a3d845b5b42fa0e1aff6",
"sha256:a2616b0265bdc1f839cc905c77243f779d82c00f3fddf58d23c08eb07e91e189"
],
"index": "pypi",
"version": "==1.0.5"
},
"django-bootstrap4": {
"hashes": [
"sha256:9f115534ae8d052d397201f3d716c10d7c9832b422e44dd7382418c6f274df18"
......
......@@ -38,7 +38,8 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'social',
'bootstrap4'
'bootstrap4',
'django_ace'
]
MIDDLEWARE = [
......
from django import forms
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.contrib.auth import get_user_model
from django_ace import AceWidget
from social.models import Post, Link, Snippet
......@@ -24,6 +25,9 @@ class SnippetCreationForm(forms.ModelForm):
class Meta:
model = Snippet
fields = ("text",)
widgets = {
"text": AceWidget(mode='python', theme='monokai'),
}
class LinkCreationForm(forms.ModelForm):
class Meta:
......
......@@ -16,7 +16,7 @@
<body>
<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">
<span class="navbar-toggler-icon"></span>
</button>
......
{% extends 'base.html' %}
{% block title %}Post snippet{% endblock %}
{% block css %}{{ form.media }}{% endblock %}
{% block content %}
{% load bootstrap4 %}
......
......@@ -7,6 +7,7 @@ from purima.views import ExtendedListView
from social import forms
from social.models import Link, Post, Snippet
class Home(ExtendedListView):
models = Post, Snippet, Link
template_name = "home.html"
......@@ -14,8 +15,8 @@ class Home(ExtendedListView):
def get_queryset(self):
qs = list(super().get_queryset())
qs.sort(key=(lambda item: item.pub_date))
return qs
qs.sort(key=(lambda item: item.id))
return reversed(qs)
class Register(CreateView):
......@@ -33,7 +34,18 @@ class SharableCreate(CreateView):
def form_valid(self, form):
form.instance.author = self.request.user
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):
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