예제 #1
0
def show_community_view(request):
    presses = PressModel.objects.order_by('-medium_published_at')[0:4]
    language = translation.get_language()
    language_code = codes.EntryLanguage.ENGLISH.value
    for language_item in settings.LANGUAGE_LIST:
        if language.startswith(language_item[0]):
            language_code = language_item[1]
            break
    entry = EntryDetail()
    # select activity entry object
    activity_entries = entry.get_queryset().filter(language=language_code, status=PUBLISHED,
                                                   entry_type=TYPE_ANNOUNCEMENT, entry_sub_type=0).order_by(
        '-creation_date')[0:4]
    if len(activity_entries) < 4:
        activity_entries = entry.get_queryset().filter(language=codes.EntryLanguage.ENGLISH.value, status=PUBLISHED,
                                                       entry_type=TYPE_ANNOUNCEMENT, entry_sub_type=0).order_by(
            '-creation_date')[0:4]
    # select operation entry object
    operation_entries = entry.get_queryset().filter(language=language_code, status=PUBLISHED,
                                                    entry_type=TYPE_ANNOUNCEMENT, entry_sub_type__in=[1, 2]).order_by(
        '-creation_date')[0:4]
    if len(operation_entries) < 4:
        operation_entries = entry.get_queryset().filter(language=codes.EntryLanguage.ENGLISH.value, status=PUBLISHED,
                                                        entry_type=TYPE_ANNOUNCEMENT,
                                                        entry_sub_type__in=[1, 2]).order_by('-creation_date')[0:4]
    # select blog entry object
    blog_entries = entry.get_queryset().filter(language=language_code, status=PUBLISHED, entry_type=TYPE_BLOG).order_by(
        '-creation_date')[0:4]
    if len(blog_entries) < 4:
        blog_entries = entry.get_queryset().filter(language=codes.EntryLanguage.ENGLISH.value, status=PUBLISHED,
                                                   entry_type=TYPE_BLOG).order_by('-creation_date')[0:4]
    # select community voice entry object
    if language_code == codes.EntryLanguage.CHINESE.value:
        voice_entries = entry.get_queryset().filter(language=codes.EntryLanguage.CHINESE.value, status=PUBLISHED,
                                                    entry_type=TYPE_COMMUNITY_VOICE).order_by('-creation_date')[0:4]
    else:
        voice_entries = entry.get_queryset().filter(language=codes.EntryLanguage.ENGLISH.value, status=PUBLISHED,
                                                    entry_type=TYPE_COMMUNITY_VOICE).order_by('-creation_date')[0:4]
    for activity_entry in activity_entries:
        activity_entry.urls = activity_entry.get_absolute_url().replace('/blog/', '/announcement/')
    for operation_entry in operation_entries:
        operation_entry.urls = operation_entry.get_absolute_url().replace('/blog/', '/announcement/')
    for blog_entry in blog_entries:
        blog_entry.urls = blog_entry.get_absolute_url()
    for voice_entry in voice_entries:
        voice_entry.urls = voice_entry.get_absolute_url().replace('/blog/', '/community-voice/')
    return render(request, 'welcome/community.html', locals())
예제 #2
0
def feed_latest(request):
    entry = EntryDetail()
    entries = entry.get_queryset().filter(
        status=PUBLISHED).order_by('-creation_date')[:50]
    for entry in entries:
        if entry.entry_type == TYPE_ANNOUNCEMENT:
            url = entry.get_absolute_url().replace('/blog/', '/announcement/')
            entry.urls = url
        else:
            entry.urls = entry.get_absolute_url()
    items = []
    for entry in entries:
        link = "%s%s" % (settings.BASE_URL, entry.urls)
        enclosure = None
        if entry.image:
            enclosure = PyRSS2Gen.Enclosure(entry.image.url, 1024,
                                            'image/jpeg')
        item = PyRSS2Gen.RSSItem(title=entry.title,
                                 link=link,
                                 guid=PyRSS2Gen.Guid(link),
                                 enclosure=enclosure,
                                 pubDate=entry.creation_date)
        items.append(item)
    rss = PyRSS2Gen.RSS2(title='newtonproject.org',
                         link="%s/feed/" % settings.BASE_URL,
                         description="newtonproject",
                         lastBuildDate=datetime.datetime.now(),
                         docs='%s/about/' % settings.BASE_URL,
                         items=items)
    rss.rss_attrs['xmlns:atom'] = 'http://www.w3.org/2005/Atom'
    xml = rss.to_xml(encoding='UTF-8')
    return HttpResponse(xml, mimetype='application/rss+xml;charset=utf-8')
예제 #3
0
 def get_queryset(self):
     language = translation.get_language()
     language_code = codes.EntryLanguage.ENGLISH.value
     for language_item in settings.LANGUAGE_LIST:
         if language.startswith(language_item[0]):
             language_code = language_item[1]
             break
     entry = EntryDetail()
     entries = entry.get_queryset().filter(entry_type=TYPE_ANNOUNCEMENT, language=language_code, status=PUBLISHED)
     if not entries:
         entries = entry.get_queryset().filter(entry_type=TYPE_ANNOUNCEMENT,
                                               language=codes.EntryLanguage.ENGLISH.value, status=PUBLISHED)
     for entry in entries:
         url = entry.get_absolute_url().replace('/blog/', '/announcement/')
         entry.urls = url
     return entries
예제 #4
0
 def get_queryset(self):
     language = translation.get_language()
     language_code = codes.EntryLanguage.ENGLISH.value
     for language_item in settings.LANGUAGE_LIST:
         if language.startswith(language_item[0]):
             language_code = language_item[1]
             break
     entry = EntryDetail()
     if language_code == codes.EntryLanguage.CHINESE.value:
         entries = entry.get_queryset().filter(entry_type=TYPE_COMMUNITY_VOICE,
                                               language=codes.EntryLanguage.CHINESE.value, status=PUBLISHED)
     else:
         entries = entry.get_queryset().filter(entry_type=TYPE_COMMUNITY_VOICE,
                                               language=codes.EntryLanguage.ENGLISH.value, status=PUBLISHED)
     for entry in entries:
         url = entry.get_absolute_url().replace('/blog/', '/community-voice/')
         entry.urls = url
     return entries
예제 #5
0
"""Urls for the Zinnia entries"""
from django.conf.urls import url
from django.conf.urls import patterns

from zinnia.views.entries import EntryDetail

urlpatterns = patterns(
    '',
    url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',
        EntryDetail.as_view(),
        name='zinnia_entry_detail'),
)
예제 #6
0
"""Urls for the Zinnia entries"""
from django.conf.urls import url
from django.conf.urls import patterns

from zinnia.views.entries import EntryDetail


urlpatterns = patterns(
    '',
    url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',
        EntryDetail.as_view(),
        name='zinnia_entry_detail'),
)
예제 #7
0
def show_home_view(request):
    language = translation.get_language()
    language_code = codes.EntryLanguage.ENGLISH.value
    for language_item in settings.LANGUAGE_LIST:
        if language.startswith(language_item[0]):
            language_code = language_item[1]
            break
    presses = PressModel.objects.order_by('-medium_published_at')[0:3]
    entry = EntryDetail()
    activity_entry = entry.get_queryset().filter(language=language_code, status=PUBLISHED,
                                                 entry_type=TYPE_ANNOUNCEMENT, entry_sub_type=0).order_by(
        '-creation_date').first()
    # select operation entry object
    operation_entry = entry.get_queryset().filter(language=language_code, status=PUBLISHED,
                                                  entry_type=TYPE_ANNOUNCEMENT, entry_sub_type__in=[1, 2]).order_by(
        '-creation_date').first()
    # select blog entry object
    blog_entry = entry.get_queryset().filter(language=language_code, status=PUBLISHED,
                                             entry_type=TYPE_BLOG).order_by('-creation_date').first()
    if activity_entry:
        activity_entry.urls = activity_entry.get_absolute_url().replace('/blog/', '/announcement/')
    if operation_entry:
        operation_entry.urls = operation_entry.get_absolute_url().replace('/blog/', '/announcement/')
    if blog_entry:
        blog_entry.urls = blog_entry.get_absolute_url()
    banner_press = PressModel.objects.order_by('-medium_published_at').first()
    webpush_settings = getattr(settings, 'WEBPUSH_SETTINGS', {})
    vapid_key = webpush_settings.get('VAPID_PUBLIC_KEY')
    user = request.user
    is_index = True
    # events
    event_items = []
    month_range_list = []
    current_month = datetime.date.today()
    events_entries = EventsEntryDetail()
    events_by_language = events_entries.get_queryset().filter(language=language_code).order_by("event_date")
    past_events_list = events_entries.get_queryset().filter(
        language=language_code, event_date__lt=datetime.date.today()).order_by("-event_date")[:6]
    if not events_by_language:
        events_by_language = events_entries.get_queryset().filter(language=codes.EntryLanguage.ENGLISH.value).order_by(
            "event_date")
        past_events_list = events_entries.get_queryset().filter(
            language=codes.EntryLanguage.ENGLISH.value, event_date__lt=datetime.date.today()).order_by("-event_date")[
                           :6]
    coming_events_list = events_by_language.filter(event_date__gte=datetime.date.today())[:6]
    month_list = events_by_language.dates("event_date", "month")
    for each_month in month_list:
        last_day = calendar.monthrange(each_month.year, each_month.month)[-1]
        last_day_month = each_month.replace(day=last_day)
        month_range_list.append((each_month, last_day_month))
    for month_range in month_range_list:
        event_items.append(
            (
                month_range[0],
                events_by_language.filter(event_date__gte=month_range[0], event_date__lte=month_range[1])
            )
        )
    # newpay 1.0 related
    d = datetime.datetime.now()
    is_newpay_release = False
    if d > datetime.datetime(2019,3,15):
        is_newpay_release = True
    return render(request, 'welcome/index.html', {user: user, 'vapid_key': vapid_key, 'presses': presses,
                                                  'activity_entry': activity_entry, 'operation_entry': operation_entry,
                                                  'blog_entry': blog_entry, 'banner_press': banner_press,
                                                  "current_month": current_month, "event_items": event_items,
                                                  "month_list": month_list,
                                                  "past_events_list": past_events_list,
                                                  "coming_events_list": coming_events_list,
                                                  "is_index": is_index, "language": language, "is_newpay_release": is_newpay_release})
예제 #8
0
 def get_queryset(self):
     entry = EntryDetail()
     entries = entry.get_queryset().filter(entry_type=TYPE_COMMUNITY_VOICE)
     self.get_object(entries)
     return entries
예제 #9
0
 def get_queryset(self):
     entry = EntryDetail()
     entries = entry.get_queryset().filter(entry_type=TYPE_ANNOUNCEMENT)
     self.get_object(entries)
     return entries