Permalink
Browse files

Add search for example and example on admin anyway

  • Loading branch information...
1 parent 8c3b564 commit 22b0aaf25ce389e01cc4d88f12e3477834562a44 @pydanny pydanny committed Nov 4, 2012
Showing with 44 additions and 35 deletions.
  1. +7 −0 package/admin.py
  2. +8 −5 profiles/admin.py
  3. +2 −2 profiles/context_processors.py
  4. +2 −4 profiles/forms.py
  5. +10 −11 profiles/models.py
  6. +3 −5 profiles/urls.py
  7. +12 −8 profiles/views.py
View
@@ -35,8 +35,15 @@ class CommitAdmin(admin.ModelAdmin):
class VersionLocalAdmin(admin.ModelAdmin):
search_fields = ("package__title",)
+
+class PackageExampleAdmin(admin.ModelAdmin):
+
+ list_display = ("title", )
+ search_fields = ("title",)
+
admin.site.register(Category, VersionAdmin)
admin.site.register(Package, PackageAdmin)
admin.site.register(Commit, CommitAdmin)
admin.site.register(Version, VersionLocalAdmin)
+admin.site.register(PackageExample, PackageExampleAdmin)
View
@@ -4,17 +4,20 @@
from profiles.models import Profile
+
def username(obj):
return (obj.user.username)
-username.short_description="User username"
+username.short_description = "User username"
+
def user_email(obj):
return (obj.user.email)
-username.short_description="User email"
+username.short_description = "User email"
+
class ProfileAdmin(VersionAdmin):
-
- search_fields = ("user__username","github_account", "user__email", "email")
+
+ search_fields = ("user__username", "github_account", "user__email", "email")
list_display = ("github_account", "email", username, user_email)
-admin.site.register(Profile, ProfileAdmin)
+admin.site.register(Profile, ProfileAdmin)
@@ -1,14 +1,14 @@
-from django.conf import settings
from django.utils.functional import lazy, memoize, SimpleLazyObject
+
def lazy_profile(request):
"""
Returns context variables required by templates that assume a profile
on each request
"""
def get_user_profile():
- if hasattr(request,'profile'):
+ if hasattr(request, 'profile'):
return request.profile
else:
return request.user.get_profile()
View
@@ -1,17 +1,15 @@
from django import forms
-from django.contrib.auth.models import User
-from django.utils.translation import ugettext_lazy as _
from profiles.models import Profile
class ProfileForm(forms.ModelForm):
-
+
def __init__(self, *args, **kwargs):
super(ProfileForm, self).__init__(*args, **kwargs)
class Meta:
-
+
fields = (
'bitbucket_url',
'google_code_url',
View
@@ -5,53 +5,52 @@
from core.models import BaseModel
-from package.models import Package
class Profile(BaseModel):
- user = models.OneToOneField(User)
-
+ user = models.OneToOneField(User)
+
# Note to coders: The '_url' fields below need to JUST be the name of the account.
# Examples:
# github_url = 'pydanny'
# bitbucket_url = 'pydanny'
- # google_code_url = 'pydanny'
+ # google_code_url = 'pydanny'
github_account = models.CharField(_("Github account"), null=True, blank=True, max_length=40)
github_url = models.CharField(_("Github account"), null=True, blank=True, max_length=100, editable=False)
bitbucket_url = models.CharField(_("Bitbucket account"), null=True, blank=True, max_length=100)
google_code_url = models.CharField(_("Google Code account"), null=True, blank=True, max_length=100)
email = models.EmailField(_("Email"), null=True, blank=True)
-
+
def __unicode__(self):
if not self.github_account:
return self.user.username
return self.github_account
-
+
def save(self, **kwargs):
""" Override save to always populate email changes to auth.user model
"""
if self.email is not None:
-
+
email = self.email.strip()
user_obj = User.objects.get(username=self.user.username)
user_obj.email = email
user_obj.save()
- super(Profile,self).save(**kwargs)
+ super(Profile, self).save(**kwargs)
def url_for_repo(self, repo):
"""Return the profile's URL for a given repo.
-
+
If url doesn't exist return None.
"""
url_mapping = {
'Github': self.github_account,
'BitBucket': self.bitbucket_url,
'Google Code': self.google_code_url}
return url_mapping.get(repo.title)
-
+
def my_packages(self):
"""Return a list of all packages the user contributes to.
-
+
List is sorted by package name.
"""
from package.repos import get_repo, supported_repos
View
@@ -1,11 +1,9 @@
from django.conf.urls.defaults import patterns, url
-from django.db.models import Count
from profiles import views
urlpatterns = patterns("",
- url(r"^edit/$", views.profile_edit, name="profile_edit"),
- url(r"^$", views.profile_list, name="profile_list"),
- url(r"^(?P<github_account>[-\w]+)$", views.profile_detail, name="profile_detail"),
-
+ url(r"^edit/$", views.profile_edit, name="profile_edit"),
+ url(r"^$", views.profile_list, name="profile_list"),
+ url(r"^(?P<github_account>[-\w]+)$", views.profile_detail, name="profile_detail"),
)
View
@@ -14,12 +14,14 @@
from profiles.forms import ProfileForm
from profiles.models import Profile
+
def profile_detail(request, github_account, template_name="profiles/profile.html"):
profile = get_object_or_404(Profile, github_account=github_account)
return render(request, template_name,
- {"local_profile": profile, "user":profile.user},)
+ {"local_profile": profile, "user": profile.user},)
+
def profile_list(request, template_name="profiles/profiles.html"):
@@ -33,6 +35,7 @@ def profile_list(request, template_name="profiles/profiles.html"):
"users": users
})
+
@login_required
def profile_edit(request, template_name="profiles/profile_edit.html"):
@@ -43,15 +46,15 @@ def profile_edit(request, template_name="profiles/profile_edit.html"):
form.save()
msg = 'Profile edited'
messages.add_message(request, messages.INFO, msg)
- return HttpResponseRedirect(reverse("profile_detail", kwargs={"github_account":profile.github_account }))
-
+ return HttpResponseRedirect(reverse("profile_detail", kwargs={"github_account": profile.github_account}))
+
# TODO - move this to a template
github_account = """
- <div
- id="div_id_github_account"
+ <div
+ id="div_id_github_account"
class="ctrlHolder"><label for="id_github_account" >Github account</label><strong>{0}</strong></div>
""".format(profile.github_account)
-
+
helper = FormHelper()
helper.form_class = "profile-edit-form"
helper.layout = Layout(
@@ -64,15 +67,16 @@ def profile_edit(request, template_name="profiles/profile_edit.html"):
ButtonHolder(
Submit('edit', 'Edit', css_class="awesome forestgreen"),
)
- )
+ )
return render(request, template_name,
{
"profile": profile,
"form": form,
- "helper":helper,
+ "helper": helper,
})
+
def github_user_update(sender, user, response, details, **kwargs):
profile_instance, created = Profile.objects.get_or_create(user=user)
profile_instance.github_account = details['username']

0 comments on commit 22b0aaf

Please sign in to comment.