Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoravcik committed May 23, 2014
1 parent fbd96a7 commit f9a5a6b
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .gitignore
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 added my_css/__init__.py
Empty file.
42 changes: 42 additions & 0 deletions my_css/abstract_models.py
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)
7 changes: 7 additions & 0 deletions my_css/admin.py
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)
9 changes: 9 additions & 0 deletions my_css/models.py
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 added my_css/templatetags/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions my_css/templatetags/my_css.py
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
33 changes: 33 additions & 0 deletions setup.py
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']
)

0 comments on commit f9a5a6b

Please sign in to comment.