def __get__(self, instance, owner=None): """ Tag getter. Returns an instance's tags if accessed on an instance, and all of a model's tags if called on a class. That is, this model:: class Link(models.Model): ... tags = TagField() Lets you do both of these:: >>> l = Link.objects.get(...) >>> l.tags 'tag1 tag2 tag3' >>> Link.tags 'tag1 tag2 tag3 tag4' """ # Handle access on the model (i.e. Link.tags) if instance is None: return edit_string_for_tags(Tag.objects.usage_for_model(owner)) tags = self._get_instance_tag_cache(instance) if tags is None: if instance.pk is None: self._set_instance_tag_cache(instance, '') else: self._set_instance_tag_cache( instance, edit_string_for_tags( Tag.objects.get_for_object(instance))) return self._get_instance_tag_cache(instance)
def post(self, request, msg_id=None): msg = save_submitted_msg_data(request.POST, msg_id) msg['post_target'] = 'posts:edit_msg' if msg_id else 'posts:new_msg' try: post_date = parse_date(request.POST['msg_date']) if request.POST['message']: if msg_id is None: m = TeamPost(author=request.user.userprofile, message=request.POST['message'], post_date=post_date) m.save() print("User", request.user.username, "Tags", edit_string_for_tags(request.user.userprofile.tags)) Tag.objects.update_tags(m, edit_string_for_tags(request.user.userprofile.tags)) else: m = TeamPost.objects.get(pk=msg_id) m.message = request.POST['message'] m.post_date = post_date m.save() return redirect("home") else: return render(request, self.template_name, dict(error="Message is required.", msg=msg)) except ValueError: return render(request, self.template_name, dict(error="Date format must be 01-01-2017 (leading zeroes required)", msg=msg))
def test_recreation_of_tag_list_string_representations(self): plain = Tag.objects.create(name='plain') spaces = Tag.objects.create(name='spa ces') comma = Tag.objects.create(name='com,ma') self.assertEquals(edit_string_for_tags([plain]), u'plain') self.assertEquals(edit_string_for_tags([plain, spaces]), u'plain, spa ces') self.assertEquals(edit_string_for_tags([plain, spaces, comma]), u'plain, spa ces, "com,ma"') self.assertEquals(edit_string_for_tags([plain, comma]), u'plain "com,ma"') self.assertEquals(edit_string_for_tags([comma, spaces]), u'"com,ma", spa ces')
def testRecreatingStringRepresentaionsOfTagLists(self): plain = Tag.objects.create(name='plain') spaces = Tag.objects.create(name='spa ces') comma = Tag.objects.create(name='com,ma') from tagging.utils import edit_string_for_tags self.assertEqual(u'plain', edit_string_for_tags([plain])) self.assertEqual(u'plain, spa ces', edit_string_for_tags([plain, spaces])) self.assertEqual(u'plain, spa ces, "com,ma"', edit_string_for_tags([plain, spaces, comma])) self.assertEqual(u'plain "com,ma"', edit_string_for_tags([plain, comma])) self.assertEqual(u'"com,ma", spa ces', edit_string_for_tags([comma, spaces]))
def get(self, request, team_name): print("RENDERING Team Summary for", team_name) # Get all the runs for the team, group by user to show a total # for each user for the season order by most miles to least # May have to get all team posts an reduce to just runs to query by # tag t = Tag.objects.get(name=team_name) print("Loaded team tag", t) tags = edit_string_for_tags([t]) print("Querying team members with", tags) team_members = UserProfile.tagged.with_any(tags) print("Found", len(team_members), "members") season_totals = [] for athlete in team_members: print("Getting totals for", athlete.user.username) user_runs = RunPost.objects.filter( author=athlete, post_date__gte=athlete.season_start).aggregate( season_total=Sum('distance')) print("Totals", user_runs) season_totals.append( dict(user=athlete, season_total=user_runs['season_total'] if user_runs['season_total'] else 0)) print("Sorting totals") sorted_totals = sorted(season_totals, key=lambda st: st['season_total'], reverse=True) print("Sorted totals", sorted_totals) return render(request, self.template_name, dict(user_totals=sorted_totals))
def __init__(self, cache_for_form_optimization=None, *args, **kwargs): # The cache_for_form_optimization is an object that is # optionally created by the request that calls # BulkEditForm. One difficulty with BulkEditForms is that the # forms generate similar data over and over again; we can # avoid some database hits by running some queries just once # (at BulkEditForm instantiation time), rather than once per # sub-form. # # However, it is unsafe to cache data in the BulkEditForm # class because that persists for as long as the Python # process does (meaning that subsequent requests will use the # same cache). EditVideoForm.__init__(self, *args, **kwargs) # We have to initialize tags manually because the model form # (django.forms.models.model_to_dict) only collects fields and # relations, and not descriptors like Video.tags self.initial['tags'] = edit_string_for_tags(self.instance.tags) # cache the querysets so that we don't hit the DB for each form cache_for_form_optimization = self.fill_cache(cache_for_form_optimization) self.fields['categories'].queryset = cache_for_form_optimization[ 'categories_qs'] self.fields['authors'].queryset = cache_for_form_optimization[ 'authors_qs']
def edit_post(request, idee): entry = get_object_or_404(BlogEntry, pk=idee) form = BlogEntryForm( dict(entry_id=entry.id, title=entry.title, content=entry.content, tags=edit_string_for_tags(Tag.objects.get_for_object(entry))) ) return render_to_response('edit_post.html', {'form': form, 'entry': entry})
def __get__(self, instance, owner=None): """ Tag getter. Returns an instance's tags if accessed on an instance, and all of a model's tags if called on a class. That is, this model:: class Link(models.Model): ... tags = TagField() Lets you do both of these:: >>> l = Link.objects.get(...) >>> l.tags 'tag1 tag2 tag3' >>> Link.tags 'tag1 tag2 tag3 tag4' """ # Handle access on the model (i.e. Link.tags) if instance is None: try: return edit_string_for_tags(Tag.objects.usage_for_model(owner)) except DatabaseError: # handle error when this is accessed before database schema exists return '' return self._get_instance_tag_cache(instance)
def __init__(self, user, *args, **kwargs): super(EditCheckForm, self).__init__(*args, **kwargs) if 'instance' in kwargs: self.fields['tags'].initial = edit_string_for_tags( kwargs['instance'].tags) self.fields['notifications'] = ModelMultipleChoiceField( queryset=NotificationReceiver.objects.filter(owner=user), widget=CheckboxSelectMultiple)
def _update_instance_tag_cache(self, instance): """ Helper: update an instance's tag cache from actual Tags. """ # for an unsaved object, leave the default value alone if instance.pk is not None: tags = edit_string_for_tags(Tag.objects.get_for_object(instance)) self._set_instance_tag_cache(instance, tags)
def test_delete_skill(self): """ test deleting skills """ url_edit_skills = reverse("edit_skills", args=["daveb"]) p = DjangoPerson.objects.get(user__username="******") self.assertEqual(len(p.skilltags), 3) self.assertTrue("jazz" in edit_string_for_tags(p.skilltags)) self.assertTrue("linux" in edit_string_for_tags(p.skilltags)) self.assertTrue("python" in edit_string_for_tags(p.skilltags)) # delete jazz skill skills = "linux python" self.client.post(url_edit_skills, {"skills": skills}) p = DjangoPerson.objects.get(user__username="******") self.assertEqual(len(p.skilltags), 2) self.assertTrue("linux" in edit_string_for_tags(p.skilltags)) self.assertTrue("python" in edit_string_for_tags(p.skilltags)) self.assertFalse("jazz" in edit_string_for_tags(p.skilltags)) # delete all skills self.client.post(url_edit_skills, {"skills": ""}) p = DjangoPerson.objects.get(user__username="******") self.assertEqual(len(p.skilltags), 0) self.assertEqual(edit_string_for_tags(p.skilltags), "")
def test_delete_skill(self): ''' test deleting skills ''' url_edit_skills = reverse('edit_skills', args=['daveb']) p = DjangoPerson.objects.get(user__username='******') self.assertEqual(len(p.skilltags), 3) self.assertTrue('jazz' in edit_string_for_tags(p.skilltags)) self.assertTrue('linux' in edit_string_for_tags(p.skilltags)) self.assertTrue('python' in edit_string_for_tags(p.skilltags)) # delete jazz skill skills = 'linux python' self.client.post(url_edit_skills, {'skills': skills}) p = DjangoPerson.objects.get(user__username='******') self.assertEqual(len(p.skilltags), 2) self.assertTrue('linux' in edit_string_for_tags(p.skilltags)) self.assertTrue('python' in edit_string_for_tags(p.skilltags)) self.assertFalse('jazz' in edit_string_for_tags(p.skilltags)) # delete all skills self.client.post(url_edit_skills, {'skills': ''}) p = DjangoPerson.objects.get(user__username='******') self.assertEqual(len(p.skilltags), 0) self.assertEqual(edit_string_for_tags(p.skilltags), '')
def __set__(self, instance, value): kwargs = {'default_namespace': self.namespace} q = None if self.namespace is not None: q = models.Q(namespace=self.namespace) kwargs['filter_namespaces'] = (self.namespace,) value = edit_string_for_tags(value or (), **kwargs) Tag.objects.update_tags(instance, value, q=q, default_namespace=self.namespace)
def post(self, request, post_id=None): ''' Handle creates and edits of runs If there is an error in the date, time, or distance we need to render the correct ''' print("Saving run with id", post_id) run = save_submitted_run_data(request.POST, post_id) run['post_target'] = 'posts:edit_run' if post_id else 'posts:new_run' try: post_date = parse_date(request.POST['run_date']) if request.POST['run_distance'] and request.POST['run_time']: if not post_id: new_run = RunPost(author=request.user.userprofile, duration=parse_duration(request.POST['run_time']), distance=float(request.POST['run_distance']), message=request.POST['run_description'], route=request.POST['run_route'], details=request.POST['run_details'], post_date=post_date) new_run.save() print("User", request.user.username, "Tags", edit_string_for_tags(request.user.userprofile.tags)) Tag.objects.update_tags(new_run.teampost_ptr, edit_string_for_tags(request.user.userprofile.tags)) else: r = RunPost.objects.get(pk=post_id) r.duration = parse_duration(request.POST['run_time']) r.distance = float(request.POST['run_distance']) r.message = request.POST['run_description'] r.route = request.POST['run_route'] r.details = request.POST['run_details'] r.post_date = post_date r.save() return redirect("home") else: print("Rending template with run", run) return render(request, self.template_name, dict(error="Run requires at least time and distance.", run=run)) except ValueError: return render(request, self.template_name, dict(error="Date format must be 01-01-2017 (leading zeroes required)", run=run))
def edit_skills(request, username): person = get_object_or_404(DjangoPerson, user__username = username) if not request.POST.get('skills'): return render(request, 'edit_skills.html', { 'form': SkillsForm(initial={ 'skills': edit_string_for_tags(person.skilltags) }), }) person.skilltags = request.POST.get('skills', '') return redirect(reverse('user_profile', args=[username]))
def _pre_save(self, **kwargs): #signal, sender, instance): """ Save tags back to the database """ tags = self._get_instance_tag_cache(kwargs['instance']) tags = parse_tag_input(tags) #print 'Tags before: %s' % tags instance = kwargs['instance'] self._set_instance_tag_cache(instance, edit_string_for_tags(tags))
def edit_skills(request, username): person = get_object_or_404(DjangoPerson, user__username=username) if not request.POST.get("skills"): return render( request, "edit_skills.html", {"form": SkillsForm(initial={"skills": edit_string_for_tags(person.skilltags)})}, ) person.skilltags = request.POST.get("skills", "") return HttpResponseRedirect("/%s/" % username)
def edit_skills(request, username): person = get_object_or_404(DjangoPerson, user__username = username) if not request.POST.get('skills'): return render(request, 'edit_skills.html', { 'form': SkillsForm(initial={ 'skills': edit_string_for_tags(person.skilltags) }), }) person.skilltags = request.POST.get('skills', '') return HttpResponseRedirect('/%s/' % username)
def get(self, request, username): print("User View", username) now = date.today() auth_user = User.objects.get(username=username) user = auth_user.userprofile tags = edit_string_for_tags(user.tags) # filter the posts to just this user posts = TeamPost.tagged.with_any(tags).filter( author=user).order_by("post_date") run_stats = dict() run_stats['calendar'] = build_calendar( user.season_start, [r for r in posts if r.is_run()]) # now that calendar is build, re-sort the runs to most recent first #posts = TeamPost.tagged.with_any(tags).filter(author=user) posts = sorted(posts, key=lambda k: k.post_date, reverse=True) # get the total miles temp = RunPost.objects.filter(author=user).aggregate( total=Sum('distance')) run_stats['total'] = total_or_zero(temp['total']) # total for the season season_start = user.season_start temp = RunPost.objects.filter( author=user, post_date__gte=season_start).aggregate(total=Sum('distance')) run_stats['season'] = total_or_zero(temp['total']) run_stats['achievements'] = _get_achievements(run_stats['season']) # total for the week week_start = _get_first_sunday(now) print("Start of week", week_start) temp = RunPost.objects.filter( author=user, post_date__range=get_query_date_range( week_start, now)).aggregate(total=Sum('distance')) run_stats['week'] = total_or_zero(temp['total']) # get the teams so they can be shown teams = user.tags today = now.strftime(settings.DATE_FORMAT) return render( request, self.template_name, dict(user=auth_user, posts=posts, today=today, teams=teams, run_stats=run_stats))
def _pre_save(self, **kwargs): #signal, sender, instance): """ Save tags back to the database """ tags = self._get_instance_tag_cache(kwargs['instance']) tags = parse_tag_input(tags) #print 'Tags before: %s' % tags instance = kwargs['instance'] self._set_instance_tag_cache( instance, edit_string_for_tags(tags))
def sync_tags_with_object(Tag, query_object): # add_tag() doesn't sync the field of the event model # see bug: http://code.google.com/p/django-tagging/issues/detail?id=235 # therefore we manually retrieve the tags and set them explicitly again. tags = Tag.objects.get_for_object(query_object) new_tags = edit_string_for_tags(tags) query_object.tags = new_tags # the save method will change the tags in the Tag model! query_object.save()
def __set__(self, instance, value): kwargs = {'default_namespace': self.namespace} q = None if self.namespace is not None: q = models.Q(namespace=self.namespace) kwargs['filter_namespaces'] = (self.namespace, ) value = edit_string_for_tags(value or (), **kwargs) Tag.objects.update_tags(instance, value, q=q, default_namespace=self.namespace)
def update_objects_tags(object): if object is None: return object_tags = Tag.objects.get_for_object(object) tags_as_string = edit_string_for_tags(object_tags) for field in object._meta.fields: if isinstance(field, TagField): setattr(object, field.attname, tags_as_string) object.save() break
def profile(request, username): person = get_object_or_404(DjangoPerson, user__username=username) person.profile_views += 1 # Not bothering with transactions; only a stat person.save() mtags = tagdict(person.machinetags.all()) # Set up convenient iterables for IM and services ims = [] for key, value in mtags.get("im", {}).items(): shortname, name, icon = IMPROVIDERS_DICT.get(key, ("", "", "")) if not shortname: continue # Bad machinetag ims.append({"shortname": shortname, "name": name, "value": value}) ims.sort(lambda x, y: cmp(x["shortname"], y["shortname"])) services = [] for key, value in mtags.get("services", {}).items(): shortname, name, icon = SERVICES_DICT.get(key, ("", "", "")) if not shortname: continue # Bad machinetag services.append({"shortname": shortname, "name": name, "value": value}) services.sort(lambda x, y: cmp(x["shortname"], y["shortname"])) # Set up vars that control privacy stuff privacy = { "show_im": (mtags["privacy"]["im"] == "public" or not request.user.is_anonymous()), "show_email": ( mtags["privacy"]["email"] == "public" or (not request.user.is_anonymous() and mtags["privacy"]["email"] == "private") ), "hide_from_search": mtags["privacy"]["search"] != "public", "show_last_irc_activity": bool(person.last_active_on_irc and person.irc_tracking_allowed()), } # Should we show the 'Finding X' section at all? show_finding = services or privacy["show_email"] or (privacy["show_im"] and ims) return render( request, "profile.html", { "person": person, "api_key": settings.GOOGLE_MAPS_API_KEY, "is_owner": request.user.username == username, "skills_form": SkillsForm(initial={"skills": edit_string_for_tags(person.skilltags)}), "mtags": mtags, "ims": ims, "services": services, "privacy": privacy, "show_finding": show_finding, }, )
def edit(request, favorite_id): favorite = get_object_or_404(Favorite, pk=favorite_id, user=request.user) if request.method == 'POST': form = EditFavoriteForm(request.POST) if form.is_valid(): form.save(favorite) request.user.message_set.create(message='Your favorite was updated') return HttpResponseRedirect(reverse('tick_favorite_list')) form = EditFavoriteForm({'notes': favorite.notes, 'tags': edit_string_for_tags(favorite.tags)}) return render_to_response('tick/favorite/edit.haml', {'form': form, 'resource': favorite.resource, 'favorite': favorite}, context_instance=RequestContext(request))
def _set_instance_tag_cache(self, instance, tags): """ Helper: set an instance's tag cache. """ self._init(instance) # If there is a tag field with a namespace, make sure that this field # only gets the tags that are allowed. if tags and (self._has_instance_multiple_tag_fields or self.namespace is not None): kwargs = {'default_namespace': self.namespace} if self.namespace is None: kwargs['exclude_namespaces'] = self._foreign_namespaces else: kwargs['filter_namespaces'] = (self.namespace, ) tags = edit_string_for_tags(tags, **kwargs) setattr(instance, '_%s_cache' % self.attname, tags)
def _get_edit_string_for_tags(self, owner=None, instance=None): kwargs = {'default_namespace': self.namespace} # if there are more than one tag field on this model, # skip the tags with namespaces of athor fields. # Thats their domain. if self.namespace is not None: kwargs['filter_namespaces'] = (self.namespace, ) elif self._has_instance_multiple_tag_fields: kwargs['exclude_namespaces'] = self._foreign_namespaces # Handle access on the model (i.e. Link.tags) if instance is None: queryset = Tag.objects.usage_for_model(owner) # Handle access on the model instance else: queryset = Tag.objects.get_for_object(instance) return edit_string_for_tags(queryset, **kwargs)
def _get_edit_string_for_tags(self, owner=None, instance=None): kwargs = {'default_namespace': self.namespace} # if there are more than one tag field on this model, # skip the tags with namespaces of athor fields. # Thats their domain. if self.namespace is not None: kwargs['filter_namespaces'] = (self.namespace,) elif self._has_instance_multiple_tag_fields: kwargs['exclude_namespaces'] = self._foreign_namespaces # Handle access on the model (i.e. Link.tags) if instance is None: queryset = Tag.objects.usage_for_model(owner) # Handle access on the model instance else: queryset = Tag.objects.get_for_object(instance) return edit_string_for_tags(queryset, **kwargs)
def _set_instance_tag_cache(self, instance, tags): """ Helper: set an instance's tag cache. """ self._init(instance) # If there is a tag field with a namespace, make sure that this field # only gets the tags that are allowed. if tags and ( self._has_instance_multiple_tag_fields or self.namespace is not None ): kwargs = {'default_namespace': self.namespace} if self.namespace is None: kwargs['exclude_namespaces'] = self._foreign_namespaces else: kwargs['filter_namespaces'] = (self.namespace,) tags = edit_string_for_tags(tags, **kwargs) setattr(instance, '_%s_cache' % self.attname, tags)
def test_add_skills(self): """ test adding skills """ url_edit_skills = reverse("edit_skills", args=["daveb"]) p = DjangoPerson.objects.get(user__username="******") self.assertEqual(len(p.skilltags), 3) self.assertTrue("jazz" in edit_string_for_tags(p.skilltags)) self.assertTrue("linux" in edit_string_for_tags(p.skilltags)) self.assertTrue("python" in edit_string_for_tags(p.skilltags)) skills = "%s django" % (edit_string_for_tags(p.skilltags)) self.client.post(url_edit_skills, {"skills": skills}) p = DjangoPerson.objects.get(user__username="******") self.assertEqual(len(p.skilltags), 4) self.assertTrue("jazz" in edit_string_for_tags(p.skilltags)) self.assertTrue("linux" in edit_string_for_tags(p.skilltags)) self.assertTrue("python" in edit_string_for_tags(p.skilltags)) self.assertTrue("django" in edit_string_for_tags(p.skilltags))
def test_add_skills(self): ''' test adding skills ''' url_edit_skills = reverse('edit_skills', args=['daveb']) p = DjangoPerson.objects.get(user__username='******') self.assertEqual(len(p.skilltags), 3) self.assertTrue('jazz' in edit_string_for_tags(p.skilltags)) self.assertTrue('linux' in edit_string_for_tags(p.skilltags)) self.assertTrue('python' in edit_string_for_tags(p.skilltags)) skills = '%s django' % (edit_string_for_tags(p.skilltags)) self.client.post(url_edit_skills, {'skills': skills}) p = DjangoPerson.objects.get(user__username='******') self.assertEqual(len(p.skilltags), 4) self.assertTrue('jazz' in edit_string_for_tags(p.skilltags)) self.assertTrue('linux' in edit_string_for_tags(p.skilltags)) self.assertTrue('python' in edit_string_for_tags(p.skilltags)) self.assertTrue('django' in edit_string_for_tags(p.skilltags))
def get(self, request): now = date.today() print("RENDERING HOME for DATE", now) tags = edit_string_for_tags(request.user.userprofile.tags) posts = TeamPost.tagged.with_any(tags) run_stats = dict() # get the total miles temp = RunPost.objects.filter( author=request.user.userprofile).aggregate(total=Sum('distance')) run_stats['total'] = total_or_zero(temp['total']) # total for the season season_start = request.user.userprofile.season_start temp = RunPost.objects.filter( author=request.user.userprofile, post_date__gte=season_start).aggregate(total=Sum('distance')) run_stats['season'] = total_or_zero(temp['total']) run_stats['achievements'] = _get_achievements(run_stats['season']) # total for the week week_start = _get_first_sunday(now) temp = RunPost.objects.filter( author=request.user.userprofile, post_date__range=get_query_date_range( week_start, now)).aggregate(total=Sum('distance')) run_stats['week'] = total_or_zero(temp['total']) # get the teams so they can be shown teams = request.user.userprofile.tags today = now.strftime(settings.DATE_FORMAT) return render( request, self.template_name, dict(user=request.user, posts=posts, today=today, teams=teams, run_stats=run_stats))
def test_recreation_of_tag_list_string_representations(self): plain = Tag.objects.create(name='plain') spaces = Tag.objects.create(name='spa ces') comma = Tag.objects.create(name='com,ma') comma_and_space = Tag.objects.create(name='a b, c d e') self.assertEquals(edit_string_for_tags([plain]), u'plain') self.assertEquals(edit_string_for_tags([plain, spaces]), u'plain, spa ces') self.assertEquals(edit_string_for_tags([plain, spaces, comma]), u'plain, spa ces, "com,ma"') self.assertEquals(edit_string_for_tags([plain, comma]), u'plain "com,ma"') self.assertEquals(edit_string_for_tags([comma, spaces]), u'"com,ma", spa ces') self.assertEquals(edit_string_for_tags([comma_and_space]), u'"a b, c d e"') # Regression test for #184 self.assertEquals(edit_string_for_tags([spaces]), u'"spa ces"')
def document_properties(request, id): document = get_object_or_404(Document, user=request.user, id=id) if request.method == 'POST': form = DocumentPropertiesForm(request.POST) if form.is_valid(): if form.cleaned_data['title'] != '': document.title = form.cleaned_data['title'] else: document.title = None document.creation_time = form.cleaned_data['creation_time'] document.save() Tag.objects.update_tags(document, form.cleaned_data['tags']) request.user.message_set.create(message='Updated properties.') return redirect(reverse(document_properties, args=[id])) else: tag_string = edit_string_for_tags(Tag.objects.get_for_object(document)) form = DocumentPropertiesForm(dict(title=document.title, tags=tag_string, creation_time=document.creation_time)) return render_to_response('properties.html', dict(document=document, form=form), context_instance=RequestContext(request))
def __init__(self, *args, **kwargs): forms.ModelForm.__init__(self, *args, **kwargs) tags = list(self.instance.tags) for tag in tags: tag.name = force_unicode(tag.name) self.initial['tags'] = edit_string_for_tags(tags)
def tags_edit_string(self): return edit_string_for_tags(self.tags.exclude(name__in=self.get_auto_tags()))
def profile(request, username): person = get_object_or_404(DjangoPerson, user__username = username) person.profile_views += 1 # Not bothering with transactions; only a stat person.save() mtags = tagdict(person.machinetags.all()) # Set up convenient iterables for IM and services ims = [] for key, value in mtags.get('im', {}).items(): shortname, name, icon = IMPROVIDERS_DICT.get(key, ('', '', '')) if not shortname: continue # Bad machinetag ims.append({ 'shortname': shortname, 'name': name, 'value': value, }) ims.sort(lambda x, y: cmp(x['shortname'], y['shortname'])) services = [] for key, value in mtags.get('services', {}).items(): shortname, name, icon = SERVICES_DICT.get(key, ('', '', '')) if not shortname: continue # Bad machinetag services.append({ 'shortname': shortname, 'name': name, 'value': value, }) services.sort(lambda x, y: cmp(x['shortname'], y['shortname'])) # Set up vars that control privacy stuff privacy = { 'show_im': ( mtags['privacy']['im'] == 'public' or not request.user.is_anonymous() ), 'show_email': ( mtags['privacy']['email'] == 'public' or (not request.user.is_anonymous() and mtags['privacy']['email'] == 'private') ), 'hide_from_search': mtags['privacy']['search'] != 'public', 'show_last_irc_activity': bool(person.last_active_on_irc and person.irc_tracking_allowed()), } # Should we show the 'Finding X' section at all? show_finding = services or privacy['show_email'] or \ (privacy['show_im'] and ims) return render(request, 'profile.html', { 'person': person, 'is_owner': request.user.username == username, 'skills_form': SkillsForm(initial={ 'skills': edit_string_for_tags(person.skilltags) }), 'mtags': mtags, 'ims': ims, 'services': services, 'privacy': privacy, 'show_finding': show_finding, })
def picture_detail(request, username, picture): p = get_object_or_404(Picture, slug = picture) return render_to_response("freamware/picture.html", {'picture': p, 'tags': edit_string_for_tags(p.tags)}, context_instance = RequestContext(request))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.initial = { 'skills': edit_string_for_tags(self.instance.skilltags), }
def __init__(self, *args, **kwargs): super(SkillsForm, self).__init__(*args, **kwargs) self.initial = {"skills": edit_string_for_tags(self.instance.skilltags)}
def __init__(self, *args, **kwargs): super(SkillsForm, self).__init__(*args, **kwargs) self.initial = { 'skills': edit_string_for_tags(self.instance.skilltags), }
def __init__(self, *args, **kwargs): super(TaggingFormMixin, self).__init__(*args, **kwargs) self.initial['tags'] = edit_string_for_tags(self.instance.tags.all())