示例#1
0
def subscribe_drawing(request, drawing_name, go_to):
    ''' toggle drawing subscriptions '''
    user = request.user
    drawing = Drawing.objects.get(name=drawing_name)
    sub = DrawingSubscription.objects.filter(drawing=drawing, user=user)
    if not sub.exists():
        newsub = DrawingSubscription(drawing=drawing, user=user)
        newsub.save()
    elif sub.count() == 1:
        sub.first().delete()

    if go_to == 'drawing':
        return httprespred(reverse('tracking:drawing_detail', args=[drawing_name]))
    elif go_to == 'list':
        return httprespred(reverse('tracking:subscriptions'))
示例#2
0
def subscribe_drawing(request, drawing_name, go_to):
    """ toggle drawing subscriptions """
    user = request.user
    drawing = Drawing.objects.get(name=drawing_name)
    sub = DrawingSubscription.objects.filter(drawing=drawing, user=user)
    if not sub.exists():
        newsub = DrawingSubscription(drawing=drawing, user=user)
        newsub.save()
    elif sub.count() == 1:
        sub.first().delete()

    if go_to == "drawing":
        return httprespred(reverse("tracking:drawing_detail", args=[drawing_name]))
    elif go_to == "list":
        return httprespred(reverse("tracking:subscriptions"))
示例#3
0
def _add_new_reply(request, post_info, user, com_id):
    ''' check form data, create and save new reply '''
    error = None
    new_rep = {}
    for key, val in post_info.items():
        if not val:
            continue
        else:
            new_rep[key] = val

    if not new_rep:
        return None, 'Please fill all fields'

    resp = None
    comment = Comment.objects.get(pk=com_id)
    if not error:
        new_rep['number'] = comment.number_replies() + 1
        new_rep['comment'] = comment
        new_rep['mod_date'] = timezone.now()
        new_rep['mod_by'] = user
        new_rep['owner'] = user
        reply = Reply(**new_rep)
        reply.save()

        rev = comment.revision.first()
        _update_subscriptions(drawing=rev.drawing, mod_date=new_rep['mod_date'],
                              mod_by=new_rep['mod_by'],
                              mod_info='add reply({}) on {}'.format(reply.number,
                                                                    comment))

        resp = httprespred(reverse('tracking:reply_detail',
                                   args=[comment.id, new_rep['number']]))
    return resp, error
示例#4
0
文件: attachments.py 项目: jaemk/drc
def _remove_attch(request, item_type, item_id, info):
    ''' remove & delete specified uploaded attachments '''
    attch = {'drawing':DrawingAttachment, 'revision':RevisionAttachment,
             'comment':CommentAttachment, 'reply':ReplyAttachment}
    table = {'drawing':Drawing, 'revision':Revision,
             'comment':Comment, 'reply':Reply}
    detail = {'drawing':'tracking:drawing_detail', 'revision':'tracking:revision_detail',
             'comment':'tracking:comment_detail', 'reply':'tracking:reply_detail'}
    obj = table[item_type].objects.get(pk=item_id)
    
    for f in info['files']:
        filepath = f.upload.name
        f.delete()
        os.remove(os.path.join(settings.MEDIA_ROOT, filepath))
        base = os.path.dirname(os.path.join(settings.MEDIA_ROOT, filepath))
        if not os.listdir(base):
            os.rmdir(base)

    args = { 'drawing':[obj.name]        if item_type == 'drawing' else None, 
            'revision':[obj.drawing.name, 
                        obj.number]      if item_type == 'revision' else None,
             'comment':[obj.id]          if item_type == 'comment' else None, 
               'reply':[obj.comment.id,
                        obj.number]      if item_type == 'reply' else None}
    return httprespred(reverse(detail[item_type],
                           args=args[item_type]))
示例#5
0
文件: comments.py 项目: jaemk/drc
def _add_new_comment(request, post_info, user):
    ''' check form data create and save new comment '''
    error = None
    new_com = {}
    for key, val in post_info.items():
        if not val:
            continue
        if key == 'status':
            stat = {'open':True, 'closed':False, '':True}
            new_com['status'] = stat[val]
        elif key == 'desc':
            new_com[key] = val.lower()
        elif key == 'revision':
            revs = val
        else:
            new_com[key] = val

    resp = None
    if not error:
        new_com['mod_date'] = timezone.now()
        new_com['mod_by'] = user
        new_com['owner'] = user
        comment = Comment(**new_com)
        comment.save()
        for rev in revs:
            comment.revision.add(rev)
            comment.save()

        _update_subscriptions(drawing=revs[0].drawing, mod_date=new_com['mod_date'],
                              mod_by=new_com['mod_by'],
                              mod_info='new comment({}) on {}'.format(comment.id,
                                                                      revs[0]))
        resp = httprespred(reverse('tracking:comment_detail',
                                   args=[comment.id]))
    return resp, error
示例#6
0
文件: attachments.py 项目: jaemk/drc
def _store_attch(request, item_type, item_id, user):
    ''' store upload to correct table specified by item_type '''
    attch = {'drawing':DrawingAttachment, 'revision':RevisionAttachment,
             'comment':CommentAttachment, 'reply':ReplyAttachment}
    table = {'drawing':Drawing, 'revision':Revision,
             'comment':Comment, 'reply':Reply}
    detail = {'drawing':'tracking:drawing_detail', 'revision':'tracking:revision_detail',
             'comment':'tracking:comment_detail', 'reply':'tracking:reply_detail'}
    obj = table[item_type].objects.get(pk=item_id)
    newfile = attch[item_type](upload=request.FILES['newfile'],
                               link=obj,
                               mod_by=user)
    # print(newfile.upload.name)
    # print(newfile.filename())
    # print(newfile.link)
    # print(newfile.mod_by)
    newfile.save()
    args = { 'drawing':[obj.name]        if item_type == 'drawing' else None, 
            'revision':[obj.drawing.name, 
                        obj.number]      if item_type == 'revision' else None,
             'comment':[obj.id]          if item_type == 'comment' else None, 
               'reply':[obj.comment.id,
                        obj.number]      if item_type == 'reply' else None}
    return httprespred(reverse(detail[item_type],
                           args=args[item_type]))
示例#7
0
文件: general.py 项目: jaemk/drc
def toggle_comment(request, com_id):
    user = request.user
    comment = Comment.objects.get(pk=com_id)
    if comment.owner == user or comment.owner == None:
        comment.status = not comment.status
        comment.save()
        com_stat = 'open' if comment.status else 'closed'
        _update_subscriptions(drawing=comment.revision.first().drawing, mod_date=timezone.now(),
                              mod_by=user,
                              mod_info='changed comment({}) status to {}'.format(comment.id, com_stat))

    return httprespred(reverse('tracking:comment_detail', args=[com_id]))
示例#8
0
def toggle_comment(request, com_id):
    user = request.user
    comment = Comment.objects.get(pk=com_id)
    if comment.owner == user or comment.owner == None:
        comment.status = not comment.status
        comment.save()
        com_stat = 'open' if comment.status else 'closed'
        _update_subscriptions(
            drawing=comment.revision.first().drawing,
            mod_date=timezone.now(),
            mod_by=user,
            mod_info='changed comment({}) status to {}'.format(
                comment.id, com_stat))

    return httprespred(reverse('tracking:comment_detail', args=[com_id]))
示例#9
0
文件: backups.py 项目: pmzhou/drc
def dump_data(request, dump_type):
    ''' Dump database json to
        /backup/user/ or /backup/auto '''
    if not request.user.is_superuser:
        return httprespred(reverse('tracking:index'))

    if dump_type == 'json':
        zip_name = 'data_user_json_dump.zip'
        dump_name = 'data_user_dump.json'
        dump_names = [dump_name]
        dump_path = os.path.join(settings.BASE_DIR, 'backup', 'user',
                                 dump_name)
        zip_path = os.path.join(settings.BASE_DIR, 'backup', 'user', zip_name)

        subprocess.call([
            sys.executable, 'manage.py', 'dumpdata', '--indent', '2',
            '--verbosity', '0', '-o', dump_path
        ],
                        env=os.environ.copy())

    else:  #dump_type=='csv':
        zip_name = 'data_user_csv_dump.zip'
        zip_path = os.path.join(settings.BASE_DIR, 'backup', 'user', zip_name)
        dump_names = _extract_to_csv(zip_name, zip_path)

    os.chdir(os.path.dirname(zip_path))
    with ZipFile(zip_name, 'w') as zip_dump:
        for item in dump_names:
            zip_dump.write(item)
    os.chdir(settings.BASE_DIR)

    try:
        with open(zip_path, 'rb') as dump:
            response = httpresp(dump.read(),
                                content_type=mimetypes.guess_type(zip_path)[0])
            response['Content-Disposition'] = 'filename={}'.format(zip_name)
            response['Set-Cookie'] = 'fileDownload=true; path=/'
            return response
    except Exception as ex:
        return httpresp('''Error: {} <br/>
                        Unable to serve file: {}
                        </br>Please notify James Kominick
                        </br>Close this tab'''\
                        .format(ex, zip_name))
示例#10
0
文件: revisions.py 项目: jaemk/drc
def _add_new_revision(request, post_info, user):
    ''' check form data against name regex's 
        create and save new drawing '''
    error = None
    new_rev = {}
    for key, val in post_info.items():
        if not val:
            continue
        if key == 'number':
            new_rev[key] = val.strip().replace(' ','-').lower()
            if not REV_TEST.match(new_rev[key]):
                error = 'Invalid character(s). Please use alphanumeric and \'_ . -\''
                break
            if Revision.objects.filter(number=new_rev[key],
                                       drawing=post_info['drawing']).exists():
                error = 'Revision already exists...'
                break
        elif key == 'desc':
            new_rev[key] = val.lower()
        elif key == 'add_date':
            if not val:
                new_rev[key] = timezone.now()
            else:
                new_rev[key] = val
        else:
            new_rev[key] = val

    resp = None
    if not error:
        new_rev['mod_date'] = timezone.now()
        new_rev['mod_by'] = user
        revision = Revision(**new_rev)
        revision.save()
        _update_subscriptions(drawing=revision.drawing, mod_date=new_rev['mod_date'],
                              mod_by=new_rev['mod_by'],
                              mod_info='new rev {}-{}'.format(revision.drawing.name.upper(),
                                                              revision.number.upper()))
        resp = httprespred(reverse('tracking:revision_detail',
                                   args=[revision.drawing.name,
                                         revision.number]))
    return resp, error
示例#11
0
文件: attachments.py 项目: pmzhou/drc
def _remove_attch(request, item_type, item_id, info):
    ''' remove & delete specified uploaded attachments '''
    attch = {
        'drawing': DrawingAttachment,
        'revision': RevisionAttachment,
        'comment': CommentAttachment,
        'reply': ReplyAttachment
    }
    table = {
        'drawing': Drawing,
        'revision': Revision,
        'comment': Comment,
        'reply': Reply
    }
    detail = {
        'drawing': 'tracking:drawing_detail',
        'revision': 'tracking:revision_detail',
        'comment': 'tracking:comment_detail',
        'reply': 'tracking:reply_detail'
    }
    obj = table[item_type].objects.get(pk=item_id)

    for f in info['files']:
        filepath = f.upload.name
        f.delete()
        os.remove(os.path.join(settings.MEDIA_ROOT, filepath))
        base = os.path.dirname(os.path.join(settings.MEDIA_ROOT, filepath))
        if not os.listdir(base):
            os.rmdir(base)

    args = {
        'drawing': [obj.name] if item_type == 'drawing' else None,
        'revision':
        [obj.drawing.name, obj.number] if item_type == 'revision' else None,
        'comment': [obj.id] if item_type == 'comment' else None,
        'reply': [obj.comment.id, obj.number] if item_type == 'reply' else None
    }
    return httprespred(reverse(detail[item_type], args=args[item_type]))
示例#12
0
def _add_new_drawing(request, post_info, user):
    ''' check form data against name regex's 
        create and save new drawing '''
    error = None
    new_drawing = {}
    for key, val in post_info.items():
        if not val or key == 'block':
            continue
        if key == 'name':
            new_drawing[key] = val.strip().replace(' ', '-').lower()
            if not DWG_TEST.match(new_drawing[key]):
                error = 'Invalid character(s). Please use alphanumeric and \'_, -\''
                break
            if Drawing.objects.filter(name=new_drawing[key]).exists():
                error = 'Drawing already exists...'
                break
        elif key == 'desc':
            new_drawing[key] = val.lower()
        elif key == 'received':
            choice = {'yes': True, 'no': False}
            new_drawing[key] = choice[val]
        else:
            new_drawing[key] = val

    resp = None
    if not error:
        new_drawing['add_date'] = timezone.now()
        new_drawing['mod_date'] = timezone.now()
        new_drawing['mod_by'] = user
        drawing = Drawing(**new_drawing)
        drawing.save()
        if 'block' in post_info:
            for block in post_info['block']:
                drawing.block.add(block)
            drawing.save()
        resp = httprespred(
            reverse('tracking:drawing_detail', args=[drawing.name]))
    return resp, error
示例#13
0
文件: drawings.py 项目: jaemk/drc
def _add_new_drawing(request, post_info, user):
    """ check form data against name regex's 
        create and save new drawing """
    error = None
    new_drawing = {}
    for key, val in post_info.items():
        if not val or key == "block":
            continue
        if key == "name":
            new_drawing[key] = val.strip().replace(" ", "-").lower()
            if not DWG_TEST.match(new_drawing[key]):
                error = "Invalid character(s). Please use alphanumeric and '_, -'"
                break
            if Drawing.objects.filter(name=new_drawing[key]).exists():
                error = "Drawing already exists..."
                break
        elif key == "desc":
            new_drawing[key] = val.lower()
        elif key == "received":
            choice = {"yes": True, "no": False}
            new_drawing[key] = choice[val]
        else:
            new_drawing[key] = val

    resp = None
    if not error:
        new_drawing["add_date"] = timezone.now()
        new_drawing["mod_date"] = timezone.now()
        new_drawing["mod_by"] = user
        drawing = Drawing(**new_drawing)
        drawing.save()
        if "block" in post_info:
            for block in post_info["block"]:
                drawing.block.add(block)
            drawing.save()
        resp = httprespred(reverse("tracking:drawing_detail", args=[drawing.name]))
    return resp, error
示例#14
0
文件: attachments.py 项目: pmzhou/drc
def _store_attch(request, item_type, item_id, user):
    ''' store upload to correct table specified by item_type '''
    attch = {
        'drawing': DrawingAttachment,
        'revision': RevisionAttachment,
        'comment': CommentAttachment,
        'reply': ReplyAttachment
    }
    table = {
        'drawing': Drawing,
        'revision': Revision,
        'comment': Comment,
        'reply': Reply
    }
    detail = {
        'drawing': 'tracking:drawing_detail',
        'revision': 'tracking:revision_detail',
        'comment': 'tracking:comment_detail',
        'reply': 'tracking:reply_detail'
    }
    obj = table[item_type].objects.get(pk=item_id)
    newfile = attch[item_type](upload=request.FILES['newfile'],
                               link=obj,
                               mod_by=user)
    # print(newfile.upload.name)
    # print(newfile.filename())
    # print(newfile.link)
    # print(newfile.mod_by)
    newfile.save()
    args = {
        'drawing': [obj.name] if item_type == 'drawing' else None,
        'revision':
        [obj.drawing.name, obj.number] if item_type == 'revision' else None,
        'comment': [obj.id] if item_type == 'comment' else None,
        'reply': [obj.comment.id, obj.number] if item_type == 'reply' else None
    }
    return httprespred(reverse(detail[item_type], args=args[item_type]))
示例#15
0
def _add_new_comment(request, post_info, user):
    ''' check form data create and save new comment '''
    error = None
    new_com = {}
    for key, val in post_info.items():
        if not val:
            continue
        if key == 'status':
            stat = {'open': True, 'closed': False, '': True}
            new_com['status'] = stat[val]
        elif key == 'desc':
            new_com[key] = val.lower()
        elif key == 'revision':
            revs = val
        else:
            new_com[key] = val

    resp = None
    if not error:
        new_com['mod_date'] = timezone.now()
        new_com['mod_by'] = user
        new_com['owner'] = user
        comment = Comment(**new_com)
        comment.save()
        for rev in revs:
            comment.revision.add(rev)
            comment.save()

        _update_subscriptions(drawing=revs[0].drawing,
                              mod_date=new_com['mod_date'],
                              mod_by=new_com['mod_by'],
                              mod_info='new comment({}) on {}'.format(
                                  comment.id, revs[0]))
        resp = httprespred(
            reverse('tracking:comment_detail', args=[comment.id]))
    return resp, error
示例#16
0
    1. Add an import:  from blog import urls as blog_urls
    2. Import the include() function: from django.conf.urls import url, include
    3. Add a URL to urlpatterns:  url(r'^blog/', include(blog_urls))
"""
import os
from django.conf.urls import url
from django.conf.urls import patterns
from django.conf.urls import include
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static
from django.http import HttpResponseRedirect as httprespred

from tracking import urls as tracking_urls
from tracking import views as tracking_views

urlpatterns = [
    url(r'^drc/admin/', admin.site.urls, name='admin'),
    url(r'^drc/favicon\.ico$', lambda x: httprespred(os.path.join(settings.STATIC_URL, 
                                                              'images', 'favicon.ico'))),
    url(r'^drc/accounts/login',auth_views.login, {'template_name': 'tracking/login.html'}, name='login'),
    url(r'^drc/accounts/logout', tracking_views.logout_view, name='logout'),
    url(r'^drc/', include(tracking_urls)),
    url(r'^', include(tracking_urls)),
    url(r'^drc/tracking/', include(tracking_urls)),
    url(r'drc/session_security/', include('session_security.urls')),
    
] + (static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT))

示例#17
0
文件: backups.py 项目: pmzhou/drc
def backup(request):
    ''' backup menu '''
    if not request.user.is_superuser:
        return httprespred(reverse('tracking:index'))
    user = request.user
    return render(request, 'tracking/dump_menu.html', {'username': user})