def detail(request, object_id, template_name='accounts/accounts_detail.html', next=None): account = get_one_or_404(Account, id=object_id) user = request.user pt_results = {} centres = None # if account.locations: # centres = [{'name': unicode(account.locations[0]), 'location': (account.locations[0].lat_lon) }] centres = [{'name': unicode(loc), 'location': (loc.lat_lon) } for loc in account.locations] # curations = Curation.objects(owner=account).order_by('-item_metadata__last_modified')[:40] curations = get_pages(request, Curation.objects(owner=account).order_by('-item_metadata__last_modified'), 20) # map has all curations for curation in Curation.objects(owner=account): for loc in curation.resource.locations: pt_results.setdefault(tuple(loc.lat_lon), []).append((curation.resource.id, curation.resource.title)) context = { 'curations': curations, 'curations_count': Curation.objects(owner=account).count(), 'pt_results': pt_results, 'centres': centres, 'google_key': settings.GOOGLE_KEY, 'show_map': centres or pt_results, 'next': next or '%s?page=%s' % (reverse('accounts_detail', args=[account.id]), curations.number) } return render_to_response( template_name, {'object': account}, RequestContext(request, context) )
def move_res_tags_to_owner_curation(): i = 0 r = [] # start = datetime.now() for res in Resource.objects.all(): curations = Curation.objects(owner=res.owner, resource=res) cur = None if curations.count() < 1: r.append('<a href="http://127.0.0.1:8080/depot/resource/%s">%s</a>' % (res._id, res.title)) cur = Curation(outcome=STATUS_OK, tags=res.tags, owner=res.owner) cur.item_metadata.author = res.owner cur.resource = res cur.save() res.curations = [cur] + list(res.curations) res.save(reindex=True) print i, res.curations i += 1 # else: # cur = curations[0] # cur.tags = list(set(cur.tags + res.tags)) # cur.save() # end = datetime.now() # print end - start return 'found %s resources: %s' % (i, ', '.join(r))
def render(self, context): owner = self.owner.resolve(context) # context[self.varname] = list(Resource.objects(curations__owner=owner)[:int(self.num)]) context[self.varname] = [ c.resource for c in Curation.objects(owner=owner).order_by("-item_metadata__last_modified")[: int(self.num)] ] return ""
def curations_for_group_html(request, object_id, template_name='depot/curations_for_group_embed.html'): object = get_one_or_404(Account, id=ObjectId(object_id)) curations = [c.resource for c in Curation.objects(owner=object).order_by('-item_metadata__last_modified')[:10]] template_context = {'object': object, 'curations': curations} return render_to_response( template_name, template_context, RequestContext(request) )
def curations_for_group_js(request, object_id, template_name='depot/curations_for_group_embed.js'): object = get_one_or_404(Account, id=ObjectId(object_id)) curations = [c.resource for c in Curation.objects(owner=object).order_by('-item_metadata__last_modified')[:10]] base_url = Site.objects.get_current().domain print base_url template_context = Context( {'object': object, 'curations': curations, 'base_url': 'http://%s' % base_url}) response = HttpResponse(mimetype='text/javascript') t = loader.get_template(template_name) response.write(t.render(template_context)) return response
def delete(self, *args, **kwargs): """docstring for delete""" from issues.models import Issue from resources.models import Resource, Curation res = Resource.objects(owner=self) curs = Curation.objects(owner=self) if curs.count() or res.count(): raise Exception('This account owns resources/curations.') Collection.objects(owner=self).delete() Issue.objects(reporter=self).delete() User.objects.get(pk=self.local_id).delete() self.reindex(remove=True) super(Account, self).delete(*args, **kwargs)
def curations_for_group_html( request, object_id, template_name='depot/curations_for_group_embed.html'): object = get_one_or_404(Account, id=ObjectId(object_id)) curations = [ c.resource for c in Curation.objects( owner=object).order_by('-item_metadata__last_modified')[:10] ] template_context = {'object': object, 'curations': curations} return render_to_response(template_name, template_context, RequestContext(request))
def resource_edit_complete(request, resource, template_info): """docstring for resource_edit_complete""" if resource: curations = Curation.objects(owner=resource.owner, resource=resource) if curations.count() != 1: raise Exception('Resource %s with %s owner Curations' % (resource.id, curations.count())) cur = curations[0] cur.tags = list(set(resource.tags)) cur.save() popup_url = reverse('resource_popup_close') url = reverse('resource', args=[resource.id]) else: # resource_add cancelled popup_url = reverse('resource_popup_cancel') url = reverse('resource_find') if template_info['popup']: return HttpResponseRedirect(popup_url) else: return HttpResponseRedirect(url)
def tags_process(request, options): results = [] if options['split'] or options['lower_case']: setting, _ = Setting.objects.get_or_create(key=UPPERCASE) exceptions = setting.value.get('data', []) for obj in Curation.objects(): tp = TagProcessor(obj.tags) new_tags = tp.split(options['split']).lower(options['lower_case'], exceptions).tags if new_tags != obj.tags: obj.tags = new_tags obj.save() for obj in Account.objects(): tp = TagProcessor(obj.tags) new_tags = tp.split(options['split']).lower(options['lower_case'], exceptions).tags if new_tags != obj.tags: obj.tags = new_tags obj.save() results.append('done') messages.success(request, '<br>'.join(results))
def curations_for_group_js(request, object_id, template_name='depot/curations_for_group_embed.js'): object = get_one_or_404(Account, id=ObjectId(object_id)) curations = [ c.resource for c in Curation.objects( owner=object).order_by('-item_metadata__last_modified')[:10] ] base_url = Site.objects.get_current().domain print base_url template_context = Context({ 'object': object, 'curations': curations, 'base_url': 'http://%s' % base_url }) response = HttpResponse(mimetype='text/javascript') t = loader.get_template(template_name) response.write(t.render(template_context)) return response
def curation_count(acct): result = cache.get('account_curations_count.%s' % acct.id, None) if result is None: result = Curation.objects(owner=acct).count() cache.set('account_curations_count.%s' % acct.id, result) return result
def curations(request, template_name='youraliss/curations.html'): object = get_one_or_404(Account, local_id=str(request.user.id)) curations = [c.resource for c in Curation.objects(owner=object).order_by('-item_metadata__last_modified')[:10]] template_context = {'object': object, 'curations': curations} return render_to_response(template_name, RequestContext(request, template_context))
def render(self, context): owner = self.owner.resolve(context) # context[self.varname] = list(Resource.objects(curations__owner=owner)[:int(self.num)]) context[self.varname] = [c.resource for c in Curation.objects(owner=owner).order_by('-item_metadata__last_modified')[:int(self.num)]] return ''
def get_stories(): objects = [get_story(obj, 'curation') for obj in Curation.objects(tags=settings.STORY_TAG)] objects.extend([get_story(obj, 'account') for obj in Account.objects(tags=settings.STORY_TAG)]) objects.extend([get_story(obj, 'flatpage') for obj in FlatPage.objects.filter(url__startswith='/story/')]) return objects