Skip to content

Instantly share code, notes, and snippets.

View todatasudata's full-sized avatar
🏠
Working from home

Vitalik Esipov todatasudata

🏠
Working from home
View GitHub Profile
@Toshinaki
Toshinaki / Wagtail FormBuilder + drf.md
Last active January 8, 2025 04:35
create submissions to wagtail forms created with formbuilder, with django rest framework

Thanks to the friendly and detailed advice of @LB from Wagtail community (https://wagtail.io/slack/)

views.py

class FormSubmissionViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet):
    """
    A viewset for viewing and editing contact form submissions.
    """

    serializer_class = FormSubmissionSerializer
# Code from https://python.plainenglish.io/telegram-channel-listener-with-python-8176ebe3c89b
import configparser
import json
import re
from telethon.errors import SessionPasswordNeededError
from telethon import TelegramClient, events, sync
from telethon.tl.functions.messages import (GetHistoryRequest)
from telethon.tl.types import (
PeerChannel
@vinodpandey
vinodpandey / MySql-5.6-installation guide.md
Last active April 29, 2025 08:20
Install MySQL 5.6.xx on Ubuntu 18.04 & Ubuntu 20.04

MySQL Download URL

https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

Open the terminal and follow along:

  • Uninstall any existing version of MySQL
sudo rm /var/lib/mysql/ -R

Restricting some fields in a model

We would like to be able to add images to events - or tag them with display locations such as "Home Page". But we do not want oridinary Event Planners to be able to do either of those things. Wagtail's admin interface is defined at the class level, so omitting those fields for just a subset of users would be hard to do in the panel definition. Instead we hide those fields during panel instantiation.

First, in the EventPage model, we create a MultiFieldPanel with a specific CSS class name:

@briggleman
briggleman / gitlab-ci.yml
Last active August 6, 2024 20:48
Example of semantic versioning w/ gitlab ci/cd and semrel
# example ci/cd file for gitlab ci/cd w/ poetry
# this file will run tests on merge and will bump
# the version on commit to master using go-semrel
# go-semrel commits will trigger a final test for
# the code coverage pipeline. this file ensures
# both the pipeline badge and coverage badge are
# populated and that the pyproject.toml file is
# bumped as well
stages:
- test
@mihow
mihow / elasticsearch6_fuzzy.py
Last active April 7, 2021 10:56
Enable fuzziness for all Elasticsearch plaintext queries in Wagtail
"""Elasticsearch backend that enables fuzzy search to all plaintext queries."""
from wagtail.search.backends.elasticsearch6 import (Elasticsearch6SearchBackend,
Elasticsearch6SearchQueryCompiler)
class ElasticsearchQueryCompilerWithFuzziness(Elasticsearch6SearchQueryCompiler):
"""
Copy of Elasticsearch6SearchQueryCompiler class with a modified default query.
Adds the "fuzziness" parameter to all queries so that we can return inexact
matches for misspellings, etc.
@lb-
lb- / final_models.py
Last active March 28, 2023 17:20
Django + Wagtail - custom taxonomy model
"""Node model and Node admin interaction."""
from django import forms
from django.conf.urls import url
from django.contrib.admin.utils import quote, unquote
from django.core.exceptions import PermissionDenied
from django.core.validators import MinLengthValidator, RegexValidator
from django.db import models
from django.shortcuts import get_object_or_404
from django.template.loader import render_to_string
@veuncent
veuncent / create_wagtail_pages_through_migration
Last active June 26, 2024 03:14
Set wagtail (home)pages programmatically during Django Migrations
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from wagtail.wagtailcore.models import Page, Site
def forwards_func(apps, schema_editor):
HomePage = apps.get_model('website', 'HomePage')
@Jamp
Jamp / gunicorn.service
Created June 24, 2017 23:29
Gunicorn Systemd Config
[Unit]
Description=gunicorn daemon
After=network.target
After=syslog.target
[Service]
User=nginx
Group=nginx
EnvironmentFile=/etc/api.gunicorn
WorkingDirectory=/var/webapps/api
@nickoala
nickoala / 0_python_email.md
Last active February 11, 2025 20:23
Use Python to send and receive emails

Use Python to:

  • send a plain text email
  • send an email with attachment
  • receive and filter emails according to some criteria