def display_coalition(request): party_list = list(Party.objects.all()) party_json = [] term = Term.objects.latest() gov_list = request.session.get('coalition_parties', None) if gov_list == None: # six-pack default DEFAULT_PARTIES = ('kok', 'sd', 'vas', 'kd', 'vihr', 'r') gov_list = [] for pn in DEFAULT_PARTIES: for p in party_list: if p.name == pn: gov_list.append(p) break for party in party_list: tn = DjangoThumbnail(party.logo, (38, 38)) d = {'id': party.name, 'name': party.full_name} d['logo'] = tn.absolute_url d['logo_dim'] = dict(x=tn.width(), y=tn.height()) mp_list = Member.objects.active_in_term(term) seats = mp_list.filter(party=party).count() d['nr_seats'] = seats for gp in gov_list: if party.pk == gp.pk: d['gov'] = True break else: d['gov'] = False party_json.append(d) q_models = Question.objects.filter(pk__in=stats_cache.questions) q_models = q_models.select_related('source') question_json = [] for idx, q in enumerate(q_models): name = '%s/%d' % (q.source.url_name, q.order) d = {'id': name, 'text': q.text} d['order'] = idx d['selected'] = True question_json.append(d) args = {'party_json': simplejson.dumps(party_json)} args['content'] = Item.objects.retrieve_content('coalition') args['question_json'] = simplejson.dumps(question_json) args['active_page'] = 'opinions' return render_to_response('opinions/coalition.html', args, context_instance=RequestContext(request))
def thumbnail(image_path, size=(50, 50), options=["crop"]): """ Поле в админке с уменьшенным изображением """ if image_path: try: thumbnail = DjangoThumbnail(image_path, size, options) except ValueError: return "" return '<img src="%s" width="%s" height="%s" />' % ( str(thumbnail.absolute_url), thumbnail.width(), thumbnail.height(), ) else: return ""
def thumbnail(self): thumb = DjangoThumbnail(self.file, (75,75)) thumb.generate() return '<img src="%s" width="%s" height="%s"/>' % (thumb.absolute_url, thumb.width(), thumb.height())
def thumbnail(self, obj): thumbnail = DjangoThumbnail(obj.image, (150, 150)) return u'<img src="%s" border="0" alt="" width="%s" height="%s" />' % \ (thumbnail.absolute_url, thumbnail.width(), thumbnail.height())