-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.project | ||
.pydevproject | ||
*.py[co] | ||
.idea | ||
# Packages | ||
*.egg | ||
*.egg-info | ||
dist | ||
build | ||
eggs | ||
parts | ||
bin | ||
var | ||
sdist | ||
develop-eggs | ||
.installed.cfg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.coverage | ||
.tox | ||
|
||
#Translations | ||
*.mo | ||
|
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from django.db import models | ||
from django.conf import settings | ||
from django.core.files.storage import default_storage | ||
from django.core.files.base import ContentFile | ||
|
||
|
||
class AbstractMyCSS(models.Model): | ||
css = models.TextField(default="", blank=True) | ||
date_created = models.DateTimeField(auto_created=True) | ||
date_modified = models.DateTimeField(auto_now_add=True) | ||
|
||
class Meta: | ||
abstract = True | ||
|
||
def save(self): | ||
super(AbstractMyCSS, self).save() | ||
path = settings.MY_CSS_ROOT + settings.MY_CSS_FILENAME | ||
|
||
if default_storage.exists(path): | ||
default_storage.delete(path) | ||
default_storage.save(path, ContentFile(self.css)) | ||
|
||
self.archive() | ||
self.clean_archive() | ||
|
||
def archive(self): | ||
MyCSSArchive = models.get_model('my_css', 'MyCSSArchive') | ||
MyCSSArchive.objects.create(css=self.css) | ||
|
||
def clean_archive(self): | ||
MyCSSArchive = models.get_model('my_css', 'MyCSSArchive') | ||
MyCSSArchive.objects.delete( | ||
date_created__gte=datetime.now()-timedelta(days=30) | ||
) | ||
|
||
|
||
|
||
class AbstractMyCSSArchive(models.Model): | ||
css = models.TextField(default="", blank=True) | ||
date_created = models.DateTimeField(auto_created=True) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.db.models import get_model | ||
from django.contrib import admin | ||
|
||
MyCSS = get_model('my_css', 'MyCSS') | ||
|
||
|
||
admin.site.register(MyCSS) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from abstract_models import AbstractMyCSS, AbstractMyCSSArchive | ||
|
||
|
||
class MyCSS(AbstractMyCSS): | ||
pass | ||
|
||
|
||
class MyCSSArchive(AbstractMyCSSArchive): | ||
pass |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import uuid | ||
|
||
from django.conf import settings | ||
from django import template | ||
|
||
register = template.Library() | ||
|
||
|
||
@register.simple_tag() | ||
def my_css(cache=1): | ||
css = settings.MY_CSS_URL + settings.MY_CSS_FILENAME | ||
if not cache: | ||
css = "%s?u=%s" % (css, str(uuid.uuid4())) | ||
return css |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Installation script: | ||
""" | ||
|
||
from setuptools import setup, find_packages | ||
|
||
|
||
setup( | ||
name='django-my-css', | ||
version='0.0.1', | ||
url='https://github.com/mmoravcik/django-my-css', | ||
author="Matus Moravcik", | ||
author_email="[email protected]", | ||
description="Simple app that allows user to change " | ||
"CSS of Django app in admin", | ||
long_description=open('README.rst').read(), | ||
keywords="css", | ||
license='BSD', | ||
platforms=['linux'], | ||
packages=find_packages(exclude=["sandbox*", "tests*"]), | ||
include_package_data=True, | ||
install_requires=[ | ||
'django=>1.2', | ||
], | ||
# See http://pypi.python.org/pypi?%3Aaction=list_classifiers | ||
classifiers=['Environment :: Web Environment', | ||
'Framework :: Django', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: BSD License', | ||
'Operating System :: Unix', | ||
'Programming Language :: Python'] | ||
) |