From 1ce3fe5a96303ef77223871bd643cb70780d5c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uro=C5=A1=20Trebec?= Date: Sat, 15 Jul 2006 00:17:34 +0000 Subject: [PATCH] First code commit. Some of it works, some doesn't. Some of the changes are not included (soon). git-svn-id: http://code.djangoproject.com/svn/django/branches/full-history@3351 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/history/__init__.py | 0 django/contrib/history/__init__.pyc | Bin 0 -> 192 bytes django/contrib/history/api.py | 39 ++++++++ django/contrib/history/api.pyc | Bin 0 -> 1979 bytes django/contrib/history/models.py | 84 ++++++++++++++++++ django/contrib/history/models.pyc | Bin 0 -> 3809 bytes django/contrib/history/templates/base.html | 3 + .../history/changelogentry_list.html | 10 +++ .../history/templates/history/detail.html | 15 ++++ .../history/templates/history/list.html | 19 ++++ django/contrib/history/urls.py | 13 +++ django/contrib/history/urls.pyc | Bin 0 -> 1022 bytes django/contrib/history/views/__init__.py | 0 django/contrib/history/views/__init__.pyc | Bin 0 -> 198 bytes django/contrib/history/views/main.py | 62 +++++++++++++ django/contrib/history/views/main.pyc | Bin 0 -> 2436 bytes 16 files changed, 245 insertions(+) create mode 100644 django/contrib/history/__init__.py create mode 100644 django/contrib/history/__init__.pyc create mode 100644 django/contrib/history/api.py create mode 100644 django/contrib/history/api.pyc create mode 100644 django/contrib/history/models.py create mode 100644 django/contrib/history/models.pyc create mode 100644 django/contrib/history/templates/base.html create mode 100644 django/contrib/history/templates/history/changelogentry_list.html create mode 100644 django/contrib/history/templates/history/detail.html create mode 100644 django/contrib/history/templates/history/list.html create mode 100644 django/contrib/history/urls.py create mode 100644 django/contrib/history/urls.pyc create mode 100644 django/contrib/history/views/__init__.py create mode 100644 django/contrib/history/views/__init__.pyc create mode 100644 django/contrib/history/views/main.py create mode 100644 django/contrib/history/views/main.pyc diff --git a/django/contrib/history/__init__.py b/django/contrib/history/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/django/contrib/history/__init__.pyc b/django/contrib/history/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3fbf68948ad91578544c8b1b18bfa98c116227e2 GIT binary patch literal 192 zcmd1(#LE>EInO1T0SXv_v;zTW=#Z6h4zn)3i;yH^g!igLoi9+KE8>#se#{f<;<|$}91ZmuNC}6YosNqp{Pf zQhDnB9Qbqm0XW}rnpCA?B0I;&_VIVVb2`~RHS)UhOD)*=w&}_hq9+mqv85_d$`h?6O-6S2n`ELA( z0gn?vhY#mYo65)a07|>8^IOFME41}Z9*UJ|H zy(kNTAY!~CNEA$udBiDjRA}V$#S7th^28MUxk0zBGQK-?Qs(Qn)&_d~9WXaBMqoY{pkW*wTb~gaoQQ++a?U zEjQptxB=Z@WlPCRR%|H=E0g~EdeWK;3uI}%K3|wNb!X|8{nRjsD{uw3#rFWo>W9cs zLg-W82f|ys^JsU(>K#;G$hU=xtC~1;&`fs(@1$t`h_~-rf6QwSNbEoUFuFX%|4&$m z{@V`SNP2MXTqi6iF-fN4PE(E%`ylwQ8WTWVWY`B-%d1Kf;mlUSv;nj?dCTO?nF&0p z5EpgK(?ftOj^TV0$Y*?J1K9q<-+!a_5EWoWkT99|UjW#Pm|Y+5j2FO-RfoSMrt7G3Juw$7$w z5G`zPGg3&X+)`}V+K0R@jDnxSzG4CXa5AmW8?QiugcTOYI3{uQrq-raA8pstljLCD zE@S4{n#CP$s;$-yos|2NTh83cs)Uju@<)O>4~ zmV4)>_`hcTCX*C0T|LKT@d>=eK9cE$cpSTMK)2j(WEeb@(o8xRLwY$B~}s>8>uQr}?WK?*#|!}p0t%znh=5!+G1zs`t5 SJL(L3{Ob<8N8RCY*!vePp>>)7 literal 0 HcmV?d00001 diff --git a/django/contrib/history/models.py b/django/contrib/history/models.py new file mode 100644 index 0000000000..7ffa4144c6 --- /dev/null +++ b/django/contrib/history/models.py @@ -0,0 +1,84 @@ +from django.db import models +from django.db.models import signals +from django.dispatch import dispatcher +from django.contrib.auth.models import User +from tut1.polls.models import Poll #Temp import of used models +# Misc stuff +import cPickle as Pickle +from datetime import datetime +#from django.contrib.history.api import get_object, save_new_revision + +class ChangeLog(models.Model): + change_time = models.DateTimeField(_('time of change'), auto_now=True) + parent = models.ForeignKey(Poll) + user = models.ForeignKey(User, default="1") + object = models.TextField() + #object_type = models.CharField(maxlength=50) + #pub_date = models.DateTimeField('date published') + + class Meta: + verbose_name = _('changelog entry') + verbose_name_plural = _('changelog entries') + db_table = _('history_changelog') + + class Admin: + fields = ( + ('Meta info', {'fields': ('change_time', 'parent', 'user',)}), + ('Object', {'fields': ('object',),}), + ) + + list_display = ('parent', 'user', 'change_time') + + def get_object(self): + """ Returns unpickled object. """ + return Pickle.loads(self.object) + + def get_revision_number(self): + """ Returns the ID/revision number of ChangeLog entry. """ + return self.id + +################ +# Other (API) methods +################ + +def get_version(object, offset=1): + """ Returns 'current-offset' revision of the 'object' """ + list = ChangeLog.objects.order_by('-id').filter(parent=object.id)[offset] + print list.get_object() + return list + +def list_history(parent_id, *args): + """ Returns a list of all revisions for that id. """ + if args: + return ChangeLog.objects.filter(parent=parent_id)[:args[0]] + #print "extra" + #return ChangeLog.objects.filter(parent=parent_id) + else: + return ChangeLog.objects.filter(parent=parent_id) + +def version(object, num=5): + """ Returns last 'num' revisions of the 'object'. """ + return ChangeLog.objects.order_by('-id').filter(parent=object.id)[:num] + +def version_by_date(object, date): + """ Returns a list of revisions made at 'date'. """ + return ChangeLog.objects.filter(parent=object.id).filter(change_time__exact=date) + + +def save_new_revision(sender, instance, signal, *args, **kwargs): + """ Saves a old copy of the record into the History table.""" + #modelname = instance.__class__.__name__ + #print modelname + old = Poll.objects.filter(pk=instance.id) + log = ChangeLog() + log.parent_id = instance.id + #log.user_id = .user_id + log.object = Pickle.dumps(old[0], protocol=0) + log.save() + print "New change saved." + +def _get_first_revision(object): + pass + + +dispatcher.connect( save_new_revision, signal=signals.pre_save, sender=Poll ) diff --git a/django/contrib/history/models.pyc b/django/contrib/history/models.pyc new file mode 100644 index 0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z*j;Aycd4Pp5L(2$$+xSoTPz@#pw;`UXa0fa2Ofjo>hbFqlk8gLb(?-e_^K`O z0hyK^%BvRfI03csgZm%nj<_Pz>m9GuPoL=>mWgVAg(f^pUK$%FVVS4lq?|9;1gOje zxsDUtm0BvE`D;?Bx0t@x@cB%0KK{&DHAe7h0%K`@G8soxT)yL0c3VHlXAdPo|PSD+ZFF1U|VX1Twlob~Cq1Vl> zTD$uy=0(hUH_a+sDAojh4zVTsC5U+QiWsCG&v7j#{&Lq(#}O|Ij;B>E>aWf}qOtl4 zairdQ!Rk9ikG{=EiR0n5TC%z`_HkLiSZRwwOzS<_E!?O5InGGCo?_i?@T$t9;8l-W=9P&xz69SZpx0i3s?xoT zPxJ>is!uhC94g&tQ}iVpzGF8E49^#A?0aaAgVq0DCpd1L{H)vVbh^z>tJCc?{|9Tx B%69+& literal 0 HcmV?d00001 diff --git a/django/contrib/history/templates/base.html b/django/contrib/history/templates/base.html new file mode 100644 index 0000000000..f03116e9ae --- /dev/null +++ b/django/contrib/history/templates/base.html @@ -0,0 +1,3 @@ + diff --git a/django/contrib/history/templates/history/changelogentry_list.html b/django/contrib/history/templates/history/changelogentry_list.html new file mode 100644 index 0000000000..529638c968 --- /dev/null +++ b/django/contrib/history/templates/history/changelogentry_list.html @@ -0,0 +1,10 @@ +{% for object in object_list %} +

{{ object.question }}

+
    +
  • ID: {{ object.id }}
  • +
  • PID: {{ object.parent_id }}
  • +
  • Change time: {{ object.change_time }}
  • +
  • Question: {{ object.object }}
  • +
  • Pub date: {{ object.pub_date }}
  • +
+{% endfor %} diff --git a/django/contrib/history/templates/history/detail.html b/django/contrib/history/templates/history/detail.html new file mode 100644 index 0000000000..747457499f --- /dev/null +++ b/django/contrib/history/templates/history/detail.html @@ -0,0 +1,15 @@ +{% if change %} +
    +
  • ID: {{ change.id }}
  • +
  • PID: {{ change.parent_id }}
  • +
  • UID: {{ change.user_id }}
  • +
  • Change time: {{ change.change_time }}
  • + +
  • ID: {{ object.id }} +
  • Question: {{ object.question }}
  • +
  • Pub date: {{ object.pub_date }}
  • + +
+{% else %} +

No changes are available.

+{% endif %} diff --git a/django/contrib/history/templates/history/list.html b/django/contrib/history/templates/history/list.html new file mode 100644 index 0000000000..4d6f5a6d51 --- /dev/null +++ b/django/contrib/history/templates/history/list.html @@ -0,0 +1,19 @@ +{% if changes_list %} + + + + + + + +{% for change in changes_list %} + + + + + + +{% endfor %} +{% else %} +

No changes are available.

+{% endif %} diff --git a/django/contrib/history/urls.py b/django/contrib/history/urls.py new file mode 100644 index 0000000000..5b04a8bdac --- /dev/null +++ b/django/contrib/history/urls.py @@ -0,0 +1,13 @@ +from django.conf.urls.defaults import * +from django.contrib.history.models import ChangeLog + +info_dict = { + 'queryset': ChangeLog.objects.all(), +} + +urlpatterns = patterns('', + (r'^$', 'django.contrib.history.views.main.index'), + (r'^list/$', 'django.contrib.history.views.main.list'), + (r'^detail/(?P\d+)/$', 'django.contrib.history.views.main.detail'), + (r'^changes/(?P\d+)/$', 'django.contrib.history.views.main.changes'), +) diff --git a/django/contrib/history/urls.pyc b/django/contrib/history/urls.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1c6c78fdf77f6d7a5577bf39f4ace1046101a283 GIT binary patch literal 1022 zcmb_b!A=`75S`skNJ|^q-dd^LP`k9MEukI}R4S@^KotVSA*w*m+DS|tJM~PUIdg1( zg`evebi5lRI3PucUG4MC?!0I3)6C>wclFQT>%9sVSBKXx{NQ&64KM~c))|a5a5?mH z$VLDyorB527GPU&1yF4F+F({d7ofYK*Fe7j{SvO)(CdJH4oBrH7ArFbO7Ni$@hOL2 zN6HV)ei+gd&VJ2IoTDM)7%*oz-N5&}=yNU$q6(g(?Te8`3UMwjthq!nQPvCVwfT+d z^rw!$$_;$C6fYIy+eFibly$P)J=m`5Q=M78^HYD^WUX>3twsUYlUgHzwcJ!i% z=2CJCi63P$;sI_nyoXuRa39r|M)Hx(DO20fn>&6E#4I`#+6>gp5mMUno(7r(Z5-0w zPE3x4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