This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EditProfileView(LoginRequiredMixin, SuccessMessageMixin, FormView): | |
model = User | |
template_name = 'accounts/settings/settings.html' | |
success_message = _('Your profile was successfully updated!') | |
form_class = UserForm | |
second_form_class = ProfileForm | |
def get_context_data(self, **kwargs): | |
context = super().get_context_data(**kwargs) | |
if 'user_form' not in context: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1st | |
import string | |
import random | |
def pw_gen(size = 8, chars=string.ascii_letters + string.digits + string.punctuation): | |
return ''.join(random.choice(chars) for _ in range(size)) | |
print(pw_gen(int(input('How many characters in your password?')))) | |
#2nd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gulp from 'gulp' | |
import * as stylus from './tasks/stylus' | |
import * as templates from './tasks/templates' | |
import * as pub from './tasks/public' | |
import * as images from './tasks/images' | |
gulp.task('images', images.dev) | |
gulp.task('public', pub.dev) | |
gulp.task('stylus', stylus.dev) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.forms import PasswordResetForm | |
class MailCheckPasswordResetForm(PasswordResetForm): | |
email = forms.EmailField(max_length=254) | |
error_messages = { | |
'unknown': _("That email address doesn't have an associated " | |
"user account. Are you sure you've registered?"), | |
'unusable': _("The user account associated with this email " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
// using jQuery | |
function getCookie(name) { | |
var cookieValue = null; | |
if (document.cookie && document.cookie !== '') { | |
var cookies = document.cookie.split(';'); | |
for (var i = 0; i < cookies.length; i++) { | |
var cookie = jQuery.trim(cookies[i]); | |
// Does this cookie string begin with the name we want? | |
if (cookie.substring(0, name.length + 1) === (name + '=')) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from .models import Like | |
admin.site.register(Like) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Include before main script file and after jquery (or after jquery if everything in one file) | |
$(document).ready(function(){ | |
... | |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Cross Site Request Forgery protection~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
function getCookie(name) { | |
var cookieValue = null; | |
if (document.cookie && document.cookie != '') { | |
var cookies = document.cookie.split(';'); | |
for (var i = 0; i < cookies.length; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'base.html' %} | |
{% load static %} | |
{% load widget_tweaks %} | |
{% load i18n %} | |
{% block content %} | |
<div class="row"> | |
<div class="col-md-10 col-md-offset-1"> | |
<h2> | |
{% if action == 'update' %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Article - your model | |
# Action, Like - Generic Relation models | |
# Deleting action and likes, associated with article, if we deleting article | |
def deleted_gfk_Action(sender, instance, using, **kwargs): | |
ctype = ContentType.objects.get_for_model(sender) | |
try: | |
action_objs = Action.objects.filter(target_ct=ctype, target_id=instance.id) | |
like_objs = Like.objects.filter(content_type=ctype, object_id=instance.id) | |
except Action.DoesNotExist: | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--Another jinja template for variant with cache categories--> | |
<ul class="categories"> | |
<li> | |
<form id="all_categories_form" action="{{ url('articles:home') }}" method="get"> | |
<input type="hidden" name="is_clear" value="True"> | |
<a href="#" onclick="document.getElementById('all_categories_form').submit();">All</a> | |
</form> | |
</li> |